Firmware SDK
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
bc_switch.h
1 #ifndef BC_SWITCH_H
2 #define BC_SWITCH_H
3 
4 #include <bc_gpio.h>
5 #include <bc_tick.h>
6 #include <bc_scheduler.h>
7 
11 
12 #define BC_SWITCH_OPEN false
13 #define BC_SWITCH_CLOSE true
14 
16 
17 typedef enum
18 {
21 
24 
26 
28 
29 typedef enum
30 {
33 
36 
38 
40 
41 typedef enum
42 {
45 
48 
51 
54 
57 
59 
61 
62 typedef struct bc_switch_t bc_switch_t;
63 
65 
66 typedef enum
67 {
68  BC_SWITCH_TASK_STATE_MEASURE = 0,
69  BC_SWITCH_TASK_STATE_SET_PULL = 1,
70 
71 } bc_switch_task_state_t;
72 
73 struct bc_switch_t
74 {
75  bc_gpio_channel_t _channel;
76  bc_switch_type_t _type;
77  bc_switch_pull_t _pull;
78  void (*_event_handler)(bc_switch_t *, bc_switch_event_t, void *);
79  void *_event_param;
80  bc_tick_t _update_interval;
81  bc_switch_task_state_t _task_state;
82  int _pin_state;
83  bc_scheduler_task_id_t _task_id;
84  bc_tick_t _scan_interval;
85  bc_tick_t _debounce_time;
86  bc_tick_t _tick_debounce;
87  uint16_t _pull_advance_time;
88 };
89 
91 
96 
98 
103 
104 void bc_switch_set_event_handler(bc_switch_t *self, void (*event_handler)(bc_switch_t *,bc_switch_event_t, void*), void *event_param);
105 
110 
111 bool bc_switch_get_state(bc_switch_t *self);
112 
116 
117 void bc_switch_set_scan_interval(bc_switch_t *self, bc_tick_t scan_interval);
118 
122 
123 void bc_switch_set_debounce_time(bc_switch_t *self, bc_tick_t debounce_time);
124 
128 
129 void bc_switch_set_pull_advance_time(bc_switch_t *self, uint16_t pull_advance_time_us);
130 
132 
133 #endif // BC_SWITCH_H
void bc_switch_set_scan_interval(bc_switch_t *self, bc_tick_t scan_interval)
Set scan interval (period of button input sampling), default 50ms.
Definition: bc_switch.c:62
uint64_t bc_tick_t
Timestamp data type.
Definition: bc_tick.h:16
Pull Up.
Definition: bc_switch.h:47
struct bc_switch_t bc_switch_t
State.
Definition: bc_switch.h:62
bool bc_switch_get_state(bc_switch_t *self)
Get state.
Definition: bc_switch.c:51
bc_switch_pull_t
Pull.
Definition: bc_switch.h:41
bc_switch_type_t
Type.
Definition: bc_switch.h:29
void bc_switch_set_debounce_time(bc_switch_t *self, bc_tick_t debounce_time)
Set debounce time (minimum sampling interval during which input cannot change to toggle its state)...
Definition: bc_switch.c:67
Pull Down dynamic (Turns pull only for measurement)
Definition: bc_switch.h:56
Type Normally Open.
Definition: bc_switch.h:32
Event Opened.
Definition: bc_switch.h:20
size_t bc_scheduler_task_id_t
Task ID assigned by scheduler.
Definition: bc_scheduler.h:18
void bc_switch_set_event_handler(bc_switch_t *self, void(*event_handler)(bc_switch_t *, bc_switch_event_t, void *), void *event_param)
Set callback function.
Definition: bc_switch.c:56
void bc_switch_init(bc_switch_t *self, bc_gpio_channel_t channel, bc_switch_type_t type, bc_switch_pull_t pull)
Initialize button.
Definition: bc_switch.c:18
void bc_switch_set_pull_advance_time(bc_switch_t *self, uint16_t pull_advance_time_us)
Set pull advance time (work only with dynamic pull up/down), default 50us, for time bigger than 1000u...
Definition: bc_switch.c:72
Pull None.
Definition: bc_switch.h:44
bc_gpio_channel_t
GPIO channels.
Definition: bc_gpio.h:12
bc_switch_event_t
Callback events.
Definition: bc_switch.h:17
Pull Down.
Definition: bc_switch.h:53
Type Normally Closed.
Definition: bc_switch.h:35
Event Closed.
Definition: bc_switch.h:23
Pull Up dynamic (Turns pull only for measurement)
Definition: bc_switch.h:50