Midnight Sun Firmware
Loading...
Searching...
No Matches
button.h
1#pragma once
2
3/************************************************************************************************
4 * @file button.h
5 *
6 * @brief Header file for managing an individual GPIO-connected button with debounce and edge callbacks.
7 *
8 * @date 2025-07-28
9 * @author Midnight Sun Team #24 - MSXVI
10 ************************************************************************************************/
11
12/* Standard library Headers */
13#include <stdbool.h>
14
15/* Inter-component Headers */
16#include "gpio.h"
17#include "status.h"
18
19/* Intra-component Headers */
20
30typedef enum {
34
35typedef struct Button Button;
36
40typedef struct {
41 void (*rising_edge_cb)(Button *button);
42 void (*falling_edge_cb)(Button *button);
44
48typedef struct {
51 uint8_t debounce_ms;
54
58typedef struct Button {
60 uint8_t last_raw;
61 uint8_t counter;
63} Button;
64
73
81
ButtonState
Button states representing current input.
Definition: button.h:30
StatusCode button_init(Button *button, ButtonConfig *config)
Initialize a button instance.
Definition: button.c:21
StatusCode button_update(Button *button)
Update the Button state based on the given GPIO state.
Definition: button.c:42
@ BUTTON_IDLE
Definition: button.h:31
@ BUTTON_PRESSED
Definition: button.h:32
StatusCode
StatusCodes for various errors.
Definition: status.h:27
Button Callbacks.
Definition: button.h:40
Button configuration structure.
Definition: button.h:48
ButtonCallbacks callbacks
Definition: button.h:52
uint8_t debounce_ms
Definition: button.h:51
GpioAddress gpio
Definition: button.h:49
bool active_low
Definition: button.h:50
Button instance structure.
Definition: button.h:58
uint8_t counter
Definition: button.h:61
uint8_t last_raw
Definition: button.h:60
ButtonState state
Definition: button.h:62
ButtonConfig * config
Definition: button.h:59
Port and pin data.
Definition: network.h:62