|
| 1 | +.. _lib_buttons: |
| 2 | + |
| 3 | +Button handling library |
| 4 | +####################### |
| 5 | + |
| 6 | +.. contents:: |
| 7 | + :local: |
| 8 | + :depth: 2 |
| 9 | + |
| 10 | + |
| 11 | +Overview |
| 12 | +******** |
| 13 | + |
| 14 | +The button handling library uses the GPIOTE Handler to detect when a button has been pushed. |
| 15 | +To handle debouncing, it will start a timer in the GPIOTE event handler. |
| 16 | +The button will only be reported as pushed to the application if the corresponding pin is still active when the timer expires. |
| 17 | +If there is a new GPIOTE event while the timer is running, the timer is restarted. |
| 18 | + |
| 19 | +The button handling library uses the ``bm_timer`` module. |
| 20 | +The user must ensure that the queue in bm_timer is large enough to hold the :c:func:`bm_timer_stop` and :c:func:`bm_timer_start` function operations which will be executed on each event from the GPIOTE module (2 operations), as well as other ``bm_timer`` operations queued simultaneously in the application. |
| 21 | + |
| 22 | +Configuration |
| 23 | +************* |
| 24 | + |
| 25 | +The library is enabled using the Kconfig system. |
| 26 | +Set the :kconfig:option:`CONFIG_BM_BUTTONS` Kconfig option to enable the library. |
| 27 | + |
| 28 | +The number of pins available for use by the button handling library is set by the :kconfig:option:`CONFIG_BM_BUTTONS_NUM_PINS` Kconfig option. |
| 29 | + |
| 30 | +Initialization |
| 31 | +============== |
| 32 | + |
| 33 | +The button handling library is initialized by calling the :c:func:`bm_buttons_init` function. |
| 34 | +The init function takes in an array of button configurations, see the :c:struct:`bm_buttons_config` struct for details. |
| 35 | +It also takes in the detection delay time used for the debouncing. |
| 36 | +Each button configuration takes a separate :c:type:`bm_buttons_handler_t` function. |
| 37 | +Though, as the button pin number and state is provided to the event handler on a button event, all configurations can use the same event handler. |
| 38 | + |
| 39 | +Usage |
| 40 | +***** |
| 41 | + |
| 42 | +After initialization the buttons are enabled by calling the :c:func:`bm_buttons_enable` function. |
| 43 | +Likewise the buttons can be disabled by calling the :c:func:`bm_buttons_disable` function. |
| 44 | + |
| 45 | +Once a button is pressed and the debouncing process succeeds (the button state has not changed during the detection_delay period), the buttons event handler function is called. |
| 46 | + |
| 47 | +While enabled it is at any time possible to test if a button is pressed by calling the :c:func:`bm_buttons_is_pressed` function. |
| 48 | + |
| 49 | +The button library can be deinitialized by calling the :c:func:`bm_buttons_deinit` function. |
| 50 | + |
| 51 | +Dependencies |
| 52 | +************ |
| 53 | + |
| 54 | +This library uses the following |BMshort| libraries: |
| 55 | + |
| 56 | +* Timer - :kconfig:option:`CONFIG_BM_TIMER` |
| 57 | + |
| 58 | +API documentation |
| 59 | +***************** |
| 60 | + |
| 61 | +| Header file: :file:`include/bm_buttons.h` |
| 62 | +| Source files: :file:`lib/bm_buttons/` |
| 63 | +
|
| 64 | +:ref:`Button handling library API reference <api_bm_buttons>` |
0 commit comments