utils
utilities in C for microcontrollers
|
Structures and functions for handling software debouncing, edge detection, and button press, release, hold, and repeat events. More...
#include <stdbool.h>
Go to the source code of this file.
Data Structures | |
struct | debouncer |
a software debouncer More... | |
struct | edge_detector |
edge detector state More... | |
struct | button |
button state More... | |
Enumerations | |
enum | edge_detector_edge |
enum | button_event |
button events | |
enum | button_timer_state |
internal button timer state | |
Functions | |
void | debouncer_init (struct debouncer *self, int count, bool initial) |
initialize a debouncer More... | |
void | debouncer_set_count (struct debouncer *self, int count) |
bool | debouncer_update (struct debouncer *self, bool value) |
bool | debouncer_value (struct debouncer *self) |
void | edge_detector_init (struct edge_detector *self, bool initial) |
enum edge_detector_edge | edge_detector_update (struct edge_detector *self, bool value) |
bool | edge_detector_get_value (struct edge_detector *self) |
void | button_init (struct button *self, bool initial, void(*handler)(enum button_event, void *)) |
void | button_set_hold_time (struct button *self, unsigned long long time, bool use) |
void | button_set_repeat_time (struct button *self, unsigned long long time, bool use) |
bool | button_get_value (struct button *self) |
bool | button_update (struct button *self, unsigned long long time, bool value, void *ctx) |
Structures and functions for handling software debouncing, edge detection, and button press, release, hold, and repeat events.
enum edge_detector_edge |
return values for edge_detector_update
bool button_get_value | ( | struct button * | self | ) |
get the current button value (false=not pressed, true=pressed)
void button_init | ( | struct button * | self, |
bool | initial, | ||
void(*)(enum button_event, void *) | handler | ||
) |
initialize a button initial is initial state (false=not pressed, true=pressed) handler is button event handler function
void button_set_hold_time | ( | struct button * | self, |
unsigned long long | time, | ||
bool | use | ||
) |
set the button hold time time is hold delay time use indicates if hold events should be generated
void button_set_repeat_time | ( | struct button * | self, |
unsigned long long | time, | ||
bool | use | ||
) |
set the button repeat time time is repeat delay time use indicates if repeat events should be generated
bool button_update | ( | struct button * | self, |
unsigned long long | time, | ||
bool | value, | ||
void * | ctx | ||
) |
input new state to a button time is current time value is current button state (read from hardware or any other source) ctx is pointer to ctx that will be passed to handler function on event
void debouncer_init | ( | struct debouncer * | self, |
int | count, | ||
bool | initial | ||
) |
initialize a debouncer
self | pointer to instance |
count | how many times input state should repeat before output state changes |
initial | initial output state |
void debouncer_set_count | ( | struct debouncer * | self, |
int | count | ||
) |
set the count for a debouncer
bool debouncer_update | ( | struct debouncer * | self, |
bool | value | ||
) |
update debouncer state value is input state returns output state after debouncing
bool debouncer_value | ( | struct debouncer * | self | ) |
get the output state of the debouncer
bool edge_detector_get_value | ( | struct edge_detector * | self | ) |
get the current value of an edge detector
void edge_detector_init | ( | struct edge_detector * | self, |
bool | initial | ||
) |
initialize an edge detector initial is initial state
enum edge_detector_edge edge_detector_update | ( | struct edge_detector * | self, |
bool | value | ||
) |
input new state to edge detector value is new state return value is type of edge detected (none, rising, falling)