This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Clarification on button handling via interrupts on the nrf5280 DK

Hello everyone,

I am simply looking for some clarification on how to correctly handle button presses on the nrf52840 DK, as there seems to be multiple ways to go about it, and I am interested in reducing power usage of the device as much as possible. Is my understanding of the following correct?

1. The GPIOTE library is the core library that is responsible for setting up interrupts for the inputs/outputs on the board, and linking them with a button handler.

2. The GPIOTE library can be used directly, or accessed through the abstraction libraries app_button and bsp_buttons.

3. While the app_button library uses the app_timer library to implement a debounce - with the example code using a 50ms timer, the bsp library (which is used in the Zigbee light switch examples) implements debouncing by making use of the ZB_SCHEDULE_APP_ALARM function to call the button_handler after a 50ms delay.

The last one is perhaps the most important question, as the existing bsp button handler code is perfect for out application, but only on the condition that it properly implements debouncing. If it does NOT implement debouncing or I have misunderstood the nature of the library, would that mean I would have to refactor the bsp code to use app_button instead?

Thank you,
Angry Oatmeal

  • Hi Torossian

    1. The GPIOTE library is the core library that is responsible for setting up interrupts for the inputs/outputs on the board, and linking them with a button handler.

     Yes, GPIOTE library is responsible for the button interrupt sensing.

     

    2. The GPIOTE library can be used directly, or accessed through the abstraction libraries app_button and bsp_buttons.

     That is correct. But the button libraries have some debounce timers that you can ignore if you do not want to debounce to be considered for your buttons.

     

    3. While the app_button library uses the app_timer library to implement a debounce - with the example code using a 50ms timer, the bsp library (which is used in the Zigbee light switch examples) implements debouncing by making use of the ZB_SCHEDULE_APP_ALARM function to call the button_handler after a 50ms delay.

    I am not a Zigbee expert, so I cannot comment on this.

     

    The last one is perhaps the most important question, as the existing bsp button handler code is perfect for out application, but only on the condition that it properly implements debouncing. If it does NOT implement debouncing or I have misunderstood the nature of the library, would that mean I would have to refactor the bsp code to use app_button instead?

    BSP library is more suited if you are using BLE/ANT, since the buttons and LEDS are linked to some radio activity like disconnect/connect/advertise. If you intend to use buttons in a more generic way, then app_button library seems better choice in this case.

Related