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

Buttons handling module. More...

Data Structures

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


#define APP_BUTTON_PUSH   1


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


uint32_t app_button_init (app_button_cfg_t *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...
uint32_t app_button_is_pushed (uint8_t button_id, bool *p_is_pushed)
 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.

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


Indicates that a button is active high.


Indicates that a button is active low.

#define APP_BUTTON_PUSH   1

Indicates that a button is pushed.


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 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).

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.
[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.
NRF_SUCCESS on success, otherwise an error code.
uint32_t app_button_is_pushed ( uint8_t  button_id,
bool *  p_is_pushed 

Function for checking if a button is currently being pushed.

[in]button_idButton index (in the app_button_cfg_t array given to app_button_init) to be checked.
[out]p_is_pushedButton state.
Return values
NRF_SUCCESSState successfully read.
NRF_ERROR_INVALID_PARAMInvalid button index.

Documentation feedback | Developer Zone | Updated