utils
utilities in C for microcontrollers
Data Structures | Enumerations | Functions
button.h File Reference

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)
 

Detailed Description

Structures and functions for handling software debouncing, edge detection, and button press, release, hold, and repeat events.

Enumeration Type Documentation

◆ edge_detector_edge

return values for edge_detector_update

Function Documentation

◆ button_get_value()

bool button_get_value ( struct button self)

get the current button value (false=not pressed, true=pressed)

◆ button_init()

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

◆ button_set_hold_time()

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

◆ button_set_repeat_time()

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

◆ button_update()

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

◆ debouncer_init()

void debouncer_init ( struct debouncer self,
int  count,
bool  initial 
)

initialize a debouncer

Parameters
selfpointer to instance
counthow many times input state should repeat before output state changes
initialinitial output state

◆ debouncer_set_count()

void debouncer_set_count ( struct debouncer self,
int  count 
)

set the count for a debouncer

◆ debouncer_update()

bool debouncer_update ( struct debouncer self,
bool  value 
)

update debouncer state value is input state returns output state after debouncing

◆ debouncer_value()

bool debouncer_value ( struct debouncer self)

get the output state of the debouncer

◆ edge_detector_get_value()

bool edge_detector_get_value ( struct edge_detector self)

get the current value of an edge detector

◆ edge_detector_init()

void edge_detector_init ( struct edge_detector self,
bool  initial 
)

initialize an edge detector initial is initial state

◆ edge_detector_update()

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)