Firmware SDK
twr_button

Driver for generic button. More...

Data Structures

struct  twr_button_driver_t
 Button driver interface. More...
 

Typedefs

typedef struct twr_button_t twr_button_t
 Button instance.
 

Enumerations

enum  twr_button_event_t {
  TWR_BUTTON_EVENT_PRESS = 0 ,
  TWR_BUTTON_EVENT_RELEASE = 1 ,
  TWR_BUTTON_EVENT_CLICK = 2 ,
  TWR_BUTTON_EVENT_HOLD = 3
}
 Callback events. More...
 

Functions

void twr_button_init (twr_button_t *self, twr_gpio_channel_t gpio_channel, twr_gpio_pull_t gpio_pull, int idle_state)
 Initialize button. More...
 
void twr_button_init_virtual (twr_button_t *self, int channel, const twr_button_driver_t *driver, int idle_state)
 Initialize virtual button. More...
 
void twr_button_set_event_handler (twr_button_t *self, void(*event_handler)(twr_button_t *, twr_button_event_t, void *), void *event_param)
 Set callback function. More...
 
void twr_button_set_scan_interval (twr_button_t *self, twr_tick_t scan_interval)
 Set scan interval (period of button input sampling) More...
 
void twr_button_set_debounce_time (twr_button_t *self, twr_tick_t debounce_time)
 Set debounce time (minimum sampling interval during which input cannot change to toggle its state) More...
 
void twr_button_set_click_timeout (twr_button_t *self, twr_tick_t click_timeout)
 Set click timeout (maximum interval within which button has to be released to recognize click event) More...
 
void twr_button_set_hold_time (twr_button_t *self, twr_tick_t hold_time)
 Set hold time (interval after which hold event is recognized when button is steadily pressed) More...
 

Detailed Description

Driver for generic button.

Enumeration Type Documentation

◆ twr_button_event_t

Callback events.

Enumerator
TWR_BUTTON_EVENT_PRESS 

Event button pressed.

TWR_BUTTON_EVENT_RELEASE 

Event button released.

TWR_BUTTON_EVENT_CLICK 

Event button clicked (pressed and released within certain time)

TWR_BUTTON_EVENT_HOLD 

Event button hold (pressed for longer time)

Definition at line 14 of file twr_button.h.

Function Documentation

◆ twr_button_init()

void twr_button_init ( twr_button_t self,
twr_gpio_channel_t  gpio_channel,
twr_gpio_pull_t  gpio_pull,
int  idle_state 
)

Initialize button.

Parameters
[in]selfInstance
[in]gpio_channelGPIO channel button is connected to
[in]gpio_pullGPIO pull-up/pull-down setting
[in]idle_stateGPIO pin idle state (when button is not pressed)

Definition at line 20 of file twr_button.c.

Referenced by twr_module_encoder_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ twr_button_init_virtual()

void twr_button_init_virtual ( twr_button_t self,
int  channel,
const twr_button_driver_t driver,
int  idle_state 
)

Initialize virtual button.

Parameters
[in]selfInstance
[in]channelVirtual channel button is connected to
[in]driverVirtual channel button driver
[in]idle_stateVirtual pin idle state (when button is not pressed)

Definition at line 43 of file twr_button.c.

Referenced by twr_module_lcd_set_event_handler().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ twr_button_set_click_timeout()

void twr_button_set_click_timeout ( twr_button_t self,
twr_tick_t  click_timeout 
)

Set click timeout (maximum interval within which button has to be released to recognize click event)

Parameters
[in]selfInstance
[in]click_timeoutDesired click timeout in ticks

Definition at line 93 of file twr_button.c.

Referenced by twr_module_lcd_set_button_click_timeout().

Here is the caller graph for this function:

◆ twr_button_set_debounce_time()

void twr_button_set_debounce_time ( twr_button_t self,
twr_tick_t  debounce_time 
)

Set debounce time (minimum sampling interval during which input cannot change to toggle its state)

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

Definition at line 88 of file twr_button.c.

Referenced by twr_module_lcd_set_button_debounce_time().

Here is the caller graph for this function:

◆ twr_button_set_event_handler()

void twr_button_set_event_handler ( twr_button_t self,
void(*)(twr_button_t *, twr_button_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 66 of file twr_button.c.

Referenced by twr_module_encoder_init(), and twr_module_lcd_set_event_handler().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ twr_button_set_hold_time()

void twr_button_set_hold_time ( twr_button_t self,
twr_tick_t  hold_time 
)

Set hold time (interval after which hold event is recognized when button is steadily pressed)

Parameters
[in]selfInstance
[in]hold_timeDesired hold time in ticks

Definition at line 98 of file twr_button.c.

Referenced by twr_module_lcd_set_button_hold_time().

Here is the caller graph for this function:

◆ twr_button_set_scan_interval()

void twr_button_set_scan_interval ( twr_button_t self,
twr_tick_t  scan_interval 
)

Set scan interval (period of button input sampling)

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

Definition at line 83 of file twr_button.c.

Referenced by twr_module_lcd_set_button_scan_interval().

Here is the caller graph for this function: