|
| 1 | +.. _lib_bm_buttons: |
| 2 | + |
| 3 | +Button handling library |
| 4 | +####################### |
| 5 | + |
| 6 | +.. contents:: |
| 7 | + :local: |
| 8 | + :depth: 2 |
| 9 | + |
| 10 | +The button handling library uses the GPIOTE to detect button presses. |
| 11 | + |
| 12 | +Overview |
| 13 | +******** |
| 14 | + |
| 15 | +The library initiates a timer within the GPIOTE event handler to manage debouncing. |
| 16 | +The button is only reported to the application as pressed 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 | +Use the :kconfig:option:`CONFIG_BM_BUTTONS_NUM_PINS` Kconfig option to configure the number of pins available to the library. |
| 25 | + |
| 26 | +Initialization |
| 27 | +============== |
| 28 | + |
| 29 | +Initialize the library by calling the :c:func:`bm_buttons_init` function. |
| 30 | +This function requires an array of button configurations (:c:struct:`bm_buttons_config`). |
| 31 | +You must also provide the detection delay time used for the debouncing. |
| 32 | + |
| 33 | +Each button configuration is associated with a separate :c:type:`bm_buttons_handler_t` function. |
| 34 | +The event handler receives the button pin number and state during a button event. |
| 35 | +In this way, all configurations can use the same event handler. |
| 36 | + |
| 37 | +Usage |
| 38 | +***** |
| 39 | + |
| 40 | +After initialization, enable the buttons by calling the :c:func:`bm_buttons_enable` function. |
| 41 | +They can be disabled by calling the :c:func:`bm_buttons_disable` function. |
| 42 | + |
| 43 | +Once a button is pressed and the debouncing process succeeds (the button state has not changed during the detection delay period), its configured event handler function is triggered. |
| 44 | + |
| 45 | +When a button is enabled, you can call the :c:func:`bm_buttons_is_pressed` function to check whether it is pressed or not. |
| 46 | + |
| 47 | +To deinitialize the library, call the :c:func:`bm_buttons_deinit` function. |
| 48 | + |
| 49 | +Dependencies |
| 50 | +************ |
| 51 | + |
| 52 | +This library uses the following |BMshort| libraries: |
| 53 | + |
| 54 | +* Timer - :kconfig:option:`CONFIG_BM_TIMER` |
| 55 | + |
| 56 | +API documentation |
| 57 | +***************** |
| 58 | + |
| 59 | +| Header file: :file:`include/bm/bm_buttons.h` |
| 60 | +| Source files: :file:`lib/bm_buttons/` |
| 61 | +
|
| 62 | +:ref:`Button handling library API reference <api_bm_buttons>` |
0 commit comments