Firmware SDK
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
bc_switch

Driver for switch. More...

Macros

#define BC_SWITCH_OPEN   false
 
#define BC_SWITCH_CLOSE   true
 

Typedefs

typedef struct bc_switch_t bc_switch_t
 State.
 

Enumerations

enum  bc_switch_event_t {
  BC_SWITCH_EVENT_OPENED = 0,
  BC_SWITCH_EVENT_CLOSED = 1
}
 Callback events. More...
 
enum  bc_switch_type_t {
  BC_SWITCH_TYPE_NO = 0,
  BC_SWITCH_TYPE_NC = 1
}
 Type. More...
 
enum  bc_switch_pull_t {
  BC_SWITCH_PULL_NONE = 0,
  BC_SWITCH_PULL_UP = 1,
  BC_SWITCH_PULL_UP_DYNAMIC = 2,
  BC_SWITCH_PULL_DOWN = 3,
  BC_SWITCH_PULL_DOWN_DYNAMIC = 4
}
 Pull. More...
 

Functions

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. More...
 
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. More...
 
bool bc_switch_get_state (bc_switch_t *self)
 Get state. More...
 
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. More...
 
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), default 20ms. More...
 
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 1000us is used scheduler. More...
 

Detailed Description

Driver for switch.

Enumeration Type Documentation

Callback events.

Enumerator
BC_SWITCH_EVENT_OPENED 

Event Opened.

BC_SWITCH_EVENT_CLOSED 

Event Closed.

Definition at line 17 of file bc_switch.h.

Pull.

Enumerator
BC_SWITCH_PULL_NONE 

Pull None.

BC_SWITCH_PULL_UP 

Pull Up.

BC_SWITCH_PULL_UP_DYNAMIC 

Pull Up dynamic (Turns pull only for measurement)

BC_SWITCH_PULL_DOWN 

Pull Down.

BC_SWITCH_PULL_DOWN_DYNAMIC 

Pull Down dynamic (Turns pull only for measurement)

Definition at line 41 of file bc_switch.h.

Type.

Enumerator
BC_SWITCH_TYPE_NO 

Type Normally Open.

BC_SWITCH_TYPE_NC 

Type Normally Closed.

Definition at line 29 of file bc_switch.h.

Function Documentation

bool bc_switch_get_state ( bc_switch_t self)

Get state.

Parameters
[in]selfInstance
Returns
true If Close
false If Open

Definition at line 51 of file bc_switch.c.

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.

Parameters
[in]selfInstance
[in]typeType
[in]pullPull

Definition at line 18 of file bc_switch.c.

Here is the call graph for this function:

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), default 20ms.

Parameters
[in]selfInstance
[in]debounce_timeDesired debounce time in ticks

Definition at line 67 of file bc_switch.c.

void bc_switch_set_event_handler ( bc_switch_t self,
void(*)(bc_switch_t *, bc_switch_event_t, void *)  event_handler,
void *  event_param 
)

Set callback function.

Parameters
[in]selfInstance
[in]event_handlerFunction address
[in]event_paramOptional event parameter (can be NULL)

Definition at line 56 of file bc_switch.c.

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 1000us is used scheduler.

Parameters
[in]selfInstance
[in]pull_advance_timePull advance time in us

Definition at line 72 of file bc_switch.c.

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.

Parameters
[in]selfInstance
[in]scan_intervalDesired scan interval in ticks

Definition at line 62 of file bc_switch.c.