Firmware SDK
twr_switch

Driver for switch. More...

Macros

#define TWR_SWITCH_OPEN   false
 
#define TWR_SWITCH_CLOSE   true
 

Typedefs

typedef struct twr_switch_t twr_switch_t
 State.
 

Enumerations

enum  twr_switch_event_t {
  TWR_SWITCH_EVENT_OPENED = 0,
  TWR_SWITCH_EVENT_CLOSED = 1
}
 Callback events. More...
 
enum  twr_switch_type_t {
  TWR_SWITCH_TYPE_NO = 0,
  TWR_SWITCH_TYPE_NC = 1
}
 Type. More...
 
enum  twr_switch_pull_t {
  TWR_SWITCH_PULL_NONE = 0,
  TWR_SWITCH_PULL_UP = 1,
  TWR_SWITCH_PULL_UP_DYNAMIC = 2,
  TWR_SWITCH_PULL_DOWN = 3,
  TWR_SWITCH_PULL_DOWN_DYNAMIC = 4
}
 Pull. More...
 

Functions

void twr_switch_init (twr_switch_t *self, twr_gpio_channel_t channel, twr_switch_type_t type, twr_switch_pull_t pull)
 Initialize button. More...
 
void twr_switch_set_event_handler (twr_switch_t *self, void(*event_handler)(twr_switch_t *, twr_switch_event_t, void *), void *event_param)
 Set callback function. More...
 
bool twr_switch_get_state (twr_switch_t *self)
 Get state. More...
 
void twr_switch_set_scan_interval (twr_switch_t *self, twr_tick_t scan_interval)
 Set scan interval (period of button input sampling), default 50ms. More...
 
void twr_switch_set_debounce_time (twr_switch_t *self, twr_tick_t debounce_time)
 Set debounce time (minimum sampling interval during which input cannot change to toggle its state), default 20ms. More...
 
void twr_switch_set_pull_advance_time (twr_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

◆ twr_switch_event_t

Callback events.

Enumerator
TWR_SWITCH_EVENT_OPENED 

Event Opened.

TWR_SWITCH_EVENT_CLOSED 

Event Closed.

Definition at line 17 of file twr_switch.h.

◆ twr_switch_pull_t

Pull.

Enumerator
TWR_SWITCH_PULL_NONE 

Pull None.

TWR_SWITCH_PULL_UP 

Pull Up.

TWR_SWITCH_PULL_UP_DYNAMIC 

Pull Up dynamic (Turns pull only for measurement)

TWR_SWITCH_PULL_DOWN 

Pull Down.

TWR_SWITCH_PULL_DOWN_DYNAMIC 

Pull Down dynamic (Turns pull only for measurement)

Definition at line 41 of file twr_switch.h.

◆ twr_switch_type_t

Type.

Enumerator
TWR_SWITCH_TYPE_NO 

Type Normally Open.

TWR_SWITCH_TYPE_NC 

Type Normally Closed.

Definition at line 29 of file twr_switch.h.

Function Documentation

◆ twr_switch_get_state()

bool twr_switch_get_state ( twr_switch_t self)

Get state.

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

Definition at line 51 of file twr_switch.c.

◆ twr_switch_init()

void twr_switch_init ( twr_switch_t self,
twr_gpio_channel_t  channel,
twr_switch_type_t  type,
twr_switch_pull_t  pull 
)

Initialize button.

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

Definition at line 18 of file twr_switch.c.

Here is the call graph for this function:

◆ twr_switch_set_debounce_time()

void twr_switch_set_debounce_time ( twr_switch_t self,
twr_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 twr_switch.c.

◆ twr_switch_set_event_handler()

void twr_switch_set_event_handler ( twr_switch_t self,
void(*)(twr_switch_t *, twr_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 twr_switch.c.

◆ twr_switch_set_pull_advance_time()

void twr_switch_set_pull_advance_time ( twr_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 twr_switch.c.

Here is the call graph for this function:

◆ twr_switch_set_scan_interval()

void twr_switch_set_scan_interval ( twr_switch_t self,
twr_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 twr_switch.c.