|
| 1 | +.. _nrf_desktop_hid_eventq: |
| 2 | + |
| 3 | +HID event queue utility |
| 4 | +####################### |
| 5 | + |
| 6 | +.. contents:: |
| 7 | + :local: |
| 8 | + :depth: 2 |
| 9 | + |
| 10 | +The HID event queue utility can be used by an application module to temporarily queue HID events related to keypresses (button press or release) to handle them later. |
| 11 | + |
| 12 | +Configuration |
| 13 | +************* |
| 14 | + |
| 15 | +Make sure that heap size (:kconfig:option:`CONFIG_HEAP_MEM_POOL_SIZE`) is large enough to handle the worst possible use case. |
| 16 | +Data structures used to internally queue HID events are dynamically allocated using the :c:func:`k_malloc` function. |
| 17 | +When no longer needed, the structures are freed using the :c:func:`k_free` function. |
| 18 | + |
| 19 | +Use the :ref:`CONFIG_DESKTOP_HID_EVENTQ <config_desktop_app_options>` Kconfig option to enable the utility. |
| 20 | +You can use the utility only on HID peripherals (:ref:`CONFIG_DESKTOP_ROLE_HID_PERIPHERAL <config_desktop_app_options>`). |
| 21 | + |
| 22 | +See Kconfig help for more details. |
| 23 | + |
| 24 | +Using HID event queue |
| 25 | +********************* |
| 26 | + |
| 27 | +An application module that handles keypresses internally can use this utility. |
| 28 | + |
| 29 | +Initialization |
| 30 | +============== |
| 31 | + |
| 32 | +Initialize a utility instance before use, using the :c:func:`hid_eventq_init` function. |
| 33 | +Specify the limit of queued HID events to limit heap usage. |
| 34 | + |
| 35 | +Queuing keypresses |
| 36 | +================== |
| 37 | + |
| 38 | +You can use the :c:func:`hid_eventq_keypress_enqueue` function to enqueue a keypress event. |
| 39 | +You can use the :c:func:`hid_eventq_keypress_dequeue` function to get a keypress event from the queue. |
| 40 | +The keypress events are queued in FIFO (first in first out) manner. |
| 41 | +An ID is used to identify the button related to the keypress. |
| 42 | +The ID could be, for example, an application-specific identifier of a hardware button or HID usage ID. |
| 43 | + |
| 44 | +You can use the :c:func:`hid_eventq_is_full` and :c:func:`hid_eventq_is_empty` functions, respectively, to determine if the queue is full or empty. |
| 45 | + |
| 46 | +Clearing the queue |
| 47 | +================== |
| 48 | + |
| 49 | +You can use the :c:func:`hid_eventq_reset` function to reset the queue. |
| 50 | +Resetting the queue results in dropping all of the enqueued keypresses. |
| 51 | + |
| 52 | +You can use the :c:func:`hid_eventq_cleanup` to remove stale keypresses (with timestamp lower than the provided minimal valid timestamp). |
| 53 | + |
| 54 | +API documentation |
| 55 | +***************** |
| 56 | + |
| 57 | +Application modules can use the following API of the HID event queue: |
| 58 | + |
| 59 | +| Header file: :file:`applications/nrf_desktop/src/util/hid_eventq.h` |
| 60 | +| Source file: :file:`applications/nrf_desktop/src/util/hid_eventq.c` |
| 61 | +
|
| 62 | +.. doxygengroup:: hid_eventq |
0 commit comments