nRF5 SDK v13.0.0
Modules | Data Structures | Macros | Typedefs | Functions
Button Handler

Buttons handling module. More...

Modules

 buttons handling module configuration
 

Data Structures

struct  app_button_cfg_t
 Button configuration structure. More...
 
struct  pin_transition_t
 Pin transition direction struct. More...
 

Macros

#define APP_BUTTON_PUSH   1
 
#define APP_BUTTON_RELEASE   0
 
#define APP_BUTTON_ACTIVE_HIGH   1
 
#define APP_BUTTON_ACTIVE_LOW   0
 

Typedefs

typedef void(* app_button_handler_t )(uint8_t pin_no, uint8_t button_action)
 Button event handler type.
 

Functions

uint32_t app_button_init (app_button_cfg_t const *p_buttons, uint8_t button_count, uint32_t detection_delay)
 Function for initializing the Buttons. More...
 
uint32_t app_button_enable (void)
 Function for enabling button detection. More...
 
uint32_t app_button_disable (void)
 Function for disabling button detection. More...
 
bool app_button_is_pushed (uint8_t button_id)
 Function for checking if a button is currently being pushed. More...
 

Detailed Description

Buttons handling module.

The button handler uses the GPIOTE Handler to detect that a button has been pushed. To handle debouncing, it will start a timer in the GPIOTE event handler. The button will only be reported as pushed if the corresponding pin is still active when the timer expires. If there is a new GPIOTE event while the timer is running, the timer is restarted.

Note
The app_button module uses the app_timer module. The user must ensure that the queue in app_timer is large enough to hold the app_timer_stop() / app_timer_start() operations which will be executed on each event from GPIOTE module (2 operations), as well as other app_timer operations queued simultaneously in the application.
Even if the scheduler is not used, app_button.h will include app_scheduler.h, so when compiling, app_scheduler.h must be available in one of the compiler include paths.

Macro Definition Documentation

#define APP_BUTTON_ACTIVE_HIGH   1

Indicates that a button is active high.

#define APP_BUTTON_ACTIVE_LOW   0

Indicates that a button is active low.

#define APP_BUTTON_PUSH   1

Indicates that a button is pushed.

#define APP_BUTTON_RELEASE   0

Indicates that a button is released.

Function Documentation

uint32_t app_button_disable ( void  )

Function for disabling button detection.

Return values
NRF_SUCCESSButton detection successfully disabled. Error code otherwise.
uint32_t app_button_enable ( void  )

Function for enabling button detection.

Return values
NRF_SUCCESSModule successfully enabled.
uint32_t app_button_init ( app_button_cfg_t const *  p_buttons,
uint8_t  button_count,
uint32_t  detection_delay 
)

Function for initializing the Buttons.

This function will initialize the specified pins as buttons, and configure the Button Handler module as a GPIOTE user (but it will not enable button detection).

Note
Normally initialization should be done using the APP_BUTTON_INIT() macro
app_button_enable() function must be called in order to enable the button detection.
Parameters
[in]p_buttonsArray of buttons to be used (NOTE: Must be static!).
[in]button_countNumber of buttons.
[in]detection_delayDelay from a GPIOTE event until a button is reported as pushed.
Returns
NRF_SUCCESS on success, otherwise an error code.
bool app_button_is_pushed ( uint8_t  button_id)

Function for checking if a button is currently being pushed.

Parameters
[in]button_idButton index (in the app_button_cfg_t array given to app_button_init) to be checked.
Returns
Button state.

Documentation feedback | Developer Zone | Subscribe | Updated