Firmware SDK
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
bc_button.h
1 #ifndef _BC_BUTTON_H
2 #define _BC_BUTTON_H
3 
4 #include <bc_gpio.h>
5 #include <bc_tick.h>
6 #include <bc_scheduler.h>
7 
11 
13 
14 typedef enum
15 {
18 
21 
24 
27 
29 
31 
32 typedef struct bc_button_t bc_button_t;
33 
35 
36 typedef struct
37 {
39  void (*init)(bc_button_t *self);
40 
42  int (*get_input)(bc_button_t *self);
43 
45 
47 
48 typedef union
49 {
50  bc_gpio_channel_t gpio;
51  int virtual;
52 
53 } bc_button_channel_t;
54 
55 struct bc_button_t
56 {
57  bc_button_channel_t _channel;
58  const bc_button_driver_t *_driver;
59  bc_gpio_pull_t _gpio_pull;
60  int _idle_state;
61  void (*_event_handler)(bc_button_t *, bc_button_event_t, void *);
62  void *_event_param;
63  bc_tick_t _scan_interval;
64  bc_tick_t _debounce_time;
65  bc_tick_t _click_timeout;
66  bc_tick_t _hold_time;
67  bc_tick_t _tick_debounce;
68  bc_tick_t _tick_click_timeout;
69  bc_tick_t _tick_hold_threshold;
70  int _state;
71  bool _hold_signalized;
72  bc_scheduler_task_id_t _task_id;
73 };
74 
76 
82 
83 void bc_button_init(bc_button_t *self, bc_gpio_channel_t gpio_channel, bc_gpio_pull_t gpio_pull, int idle_state);
84 
90 
91 void bc_button_init_virtual(bc_button_t *self, int channel, const bc_button_driver_t *driver, int idle_state);
92 
97 
98 void bc_button_set_event_handler(bc_button_t *self, void (*event_handler)(bc_button_t *, bc_button_event_t, void *), void *event_param);
99 
103 
104 void bc_button_set_scan_interval(bc_button_t *self, bc_tick_t scan_interval);
105 
109 
110 void bc_button_set_debounce_time(bc_button_t *self, bc_tick_t debounce_time);
111 
115 
116 void bc_button_set_click_timeout(bc_button_t *self, bc_tick_t click_timeout);
117 
121 
122 void bc_button_set_hold_time(bc_button_t *self, bc_tick_t hold_time);
123 
125 
126 #endif // _BC_BUTTON_H
uint64_t bc_tick_t
Timestamp data type.
Definition: bc_tick.h:16
void bc_button_set_hold_time(bc_button_t *self, bc_tick_t hold_time)
Set hold time (interval after which hold event is recognized when button is steadily pressed) ...
Definition: bc_button.c:98
Button driver interface.
Definition: bc_button.h:36
Event button released.
Definition: bc_button.h:20
Event button pressed.
Definition: bc_button.h:17
bc_gpio_pull_t
GPIO pull-up/pull-down setting.
Definition: bc_gpio.h:81
size_t bc_scheduler_task_id_t
Task ID assigned by scheduler.
Definition: bc_scheduler.h:18
bc_button_event_t
Callback events.
Definition: bc_button.h:14
Event button hold (pressed for longer time)
Definition: bc_button.h:26
void bc_button_set_scan_interval(bc_button_t *self, bc_tick_t scan_interval)
Set scan interval (period of button input sampling)
Definition: bc_button.c:83
void bc_button_init_virtual(bc_button_t *self, int channel, const bc_button_driver_t *driver, int idle_state)
Initialize virtual button.
Definition: bc_button.c:43
bc_gpio_channel_t
GPIO channels.
Definition: bc_gpio.h:12
Event button clicked (pressed and released within certain time)
Definition: bc_button.h:23
void bc_button_set_event_handler(bc_button_t *self, void(*event_handler)(bc_button_t *, bc_button_event_t, void *), void *event_param)
Set callback function.
Definition: bc_button.c:66
void bc_button_set_debounce_time(bc_button_t *self, bc_tick_t debounce_time)
Set debounce time (minimum sampling interval during which input cannot change to toggle its state) ...
Definition: bc_button.c:88
struct bc_button_t bc_button_t
Button instance.
Definition: bc_button.h:32
void bc_button_set_click_timeout(bc_button_t *self, bc_tick_t click_timeout)
Set click timeout (maximum interval within which button has to be released to recognize click event) ...
Definition: bc_button.c:93
void bc_button_init(bc_button_t *self, bc_gpio_channel_t gpio_channel, bc_gpio_pull_t gpio_pull, int idle_state)
Initialize button.
Definition: bc_button.c:20