|
| 1 | +.. _lib_bm_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 to detect when a button has been pushed. |
| 15 | +To handle debouncing, a timer is started 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 | + |
| 18 | +Configuration |
| 19 | +************* |
| 20 | + |
| 21 | +The library is enabled using the Kconfig system. |
| 22 | +Set the :kconfig:option:`CONFIG_BM_BUTTONS` Kconfig option to enable the library. |
| 23 | + |
| 24 | +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. |
| 25 | + |
| 26 | +Initialization |
| 27 | +============== |
| 28 | + |
| 29 | +The button handling library is initialized by calling the :c:func:`bm_buttons_init` function. |
| 30 | +The init function takes an array of button configurations as an argument, see the :c:struct:`bm_buttons_config` struct for details. |
| 31 | +It also takes, as an argument, the detection delay time used for the debouncing. |
| 32 | +Each button configuration takes a separate :c:type:`bm_buttons_handler_t` function. |
| 33 | +The button pin number and state is provided to the event handler on a button event. |
| 34 | +Thus, all configurations can use the same event handler. |
| 35 | + |
| 36 | +Usage |
| 37 | +***** |
| 38 | + |
| 39 | +After initialization the buttons are enabled by calling the :c:func:`bm_buttons_enable` function. |
| 40 | +Likewise, the buttons can be disabled by calling the :c:func:`bm_buttons_disable` function. |
| 41 | + |
| 42 | +Once a button is pressed and the debouncing process succeeds (the button state has not changed during the detection_delay period), the button's event handler function is called. |
| 43 | + |
| 44 | +When the buttons are enabled, it is possible to check if a button is pressed or not by calling the :c:func:`bm_buttons_is_pressed` function. |
| 45 | + |
| 46 | +The button library can be deinitialized by calling the :c:func:`bm_buttons_deinit` function. |
| 47 | + |
| 48 | +Dependencies |
| 49 | +************ |
| 50 | + |
| 51 | +This library uses the following |BMshort| libraries: |
| 52 | + |
| 53 | +* Timer - :kconfig:option:`CONFIG_BM_TIMER` |
| 54 | + |
| 55 | +API documentation |
| 56 | +***************** |
| 57 | + |
| 58 | +| Header file: :file:`bm/include/bm_buttons.h` |
| 59 | +| Source files: :file:`lib/bm_buttons/` |
| 60 | +
|
| 61 | +:ref:`Button handling library API reference <api_bm_buttons>` |
0 commit comments