You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: applications/nrf_desktop/doc/hid_provider_keyboard.rst
+63-68Lines changed: 63 additions & 68 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,11 +7,15 @@ HID provider keyboard module
7
7
:local:
8
8
:depth: 2
9
9
10
-
The HID provider keyboard module is responsible for providing keyboard HID reports.
11
-
The module listens to the :c:struct:`button_event` event and communicates with the :ref:`nrf_desktop_hid_state`.
12
-
It provides new keyboard HID reports when requested by the :ref:`nrf_desktop_hid_state`.
10
+
The HID provider keyboard module is a HID report provider integrated with :ref:`nrf_desktop_hid_state`.
11
+
The module is responsible for providing the HID keyboard input report and the HID boot keyboard input report.
12
+
13
+
The module listens to the user input (:c:struct:`button_event`) and communicates with the :ref:`nrf_desktop_hid_state`.
14
+
It provides HID keyboard reports when requested by the :ref:`nrf_desktop_hid_state`.
13
15
It also notifies the :ref:`nrf_desktop_hid_state` when new data is available.
14
16
17
+
For details related to the HID report providers integration in the HID state module, see the :ref:`nrf_desktop_hid_state_providing_hid_input_reports` documentation section.
18
+
15
19
Module events
16
20
*************
17
21
@@ -25,102 +29,95 @@ Module events
25
29
Configuration
26
30
*************
27
31
28
-
You can enable the module using the :ref:`CONFIG_DESKTOP_HID_REPORT_PROVIDER_KEYBOARD <config_desktop_app_options>` Kconfig option.
29
-
This option is enabled by default if the device supports HID keyboard reports.
30
-
You can substitute the module with a custom HID keyboard report provider implementation.
32
+
You can enable the default implementation of the HID provider using the :ref:`CONFIG_DESKTOP_HID_REPORT_PROVIDER_KEYBOARD <config_desktop_app_options>` Kconfig option.
33
+
This option is enabled by default if the device uses HID provider events (:ref:`CONFIG_DESKTOP_HID_REPORT_PROVIDER_EVENT <config_desktop_app_options>`) and supports HID keyboard reports (:ref:`CONFIG_DESKTOP_HID_REPORT_KEYBOARD_SUPPORT <config_desktop_app_options>`).
34
+
The module also provides HID boot keyboard input report if it is supported (:ref:`CONFIG_DESKTOP_HID_BOOT_INTERFACE_KEYBOARD <config_desktop_app_options>`).
35
+
36
+
Alternatively, you can substitute the module with a custom HID keyboard report provider implementation.
31
37
Enable the :ref:`CONFIG_DESKTOP_HID_REPORT_PROVIDER_KEYBOARD_ALT <config_desktop_app_options>` Kconfig option to use a custom HID keyboard report provider.
38
+
The option disables the default HID keyboard report provider.
32
39
Make sure to introduce the custom HID keyboard report provider if you enable this option.
40
+
See the :ref:`nrf_desktop_hid_state_providing_hid_input_reports` documentation section of the HID state module for details.
41
+
42
+
Default implementation
43
+
======================
44
+
45
+
The module relies on keypresses (:c:struct:`button_event`) as the only source of user input.
46
+
The module needs to perform the following tasks:
47
+
48
+
* Identify keypresses related to the handled HID input reports.
49
+
* Queue a sequence of the user's key presses and releases that happens before connecting to a HID host.
50
+
The reason for this operation is to allow tracking key presses that happen right after the device is woken up but before it can connect to the HID host.
51
+
The sequence of keypresses is replayed once a connection with a HID host is established.
52
+
* Maintain the state of pressed keys.
53
+
You need this to report the current state of pressed keys while a connection with the HID host is maintained.
54
+
55
+
The module uses a set of application-specific utilities for that purpose.
56
+
See the following sections for the configuration details of the used application-specific utilities.
33
57
34
58
HID keymap
35
-
==========
59
+
----------
36
60
37
-
The module uses the :ref:`nrf_desktop_hid_keymap` to map an application-specific key ID to a HID report ID and HID usage ID pair.
61
+
Since keys on the board can be associated with a HID usage ID and thus be part of different HID reports, the first step is to identify if the key belongs to a HID report that is provided by this module.
62
+
This is done by obtaining the key mapping from the :ref:`nrf_desktop_hid_keymap`.
38
63
The module selects the :ref:`CONFIG_DESKTOP_HID_KEYMAP <config_desktop_app_options>` Kconfig option to enable the utility.
39
64
Make sure to configure the HID keymap utility.
40
65
See the utility's documentation for details.
41
66
42
-
Queuing keypresses
43
-
==================
67
+
HID eventq
68
+
----------
44
69
45
-
The module selects the :ref:`CONFIG_DESKTOP_HID_EVENTQ <config_desktop_app_options>` Kconfig option to enable the :ref:`nrf_desktop_hid_eventq`.
46
-
The utility is used to temporarily queue key state changes (presses and releases) before the connection with the HID host is established.
47
-
When a key state changes (it is pressed or released) before the connection is established, an element containing this key's usage ID is pushed onto the queue.
70
+
The :ref:`nrf_desktop_hid_eventq` is used to temporarily enqueue key state changes before connection with the HID host is established.
71
+
When a key is pressed or released before the connection is established, an element containing this key's usage ID is pushed onto the queue.
72
+
The sequence of keypresses is replayed once the connection with a HID host is established.
73
+
This ensures that all of the keypresses are replayed in order.
74
+
The module selects the :ref:`CONFIG_DESKTOP_HID_EVENTQ <config_desktop_app_options>` Kconfig option to enable the utility.
48
75
49
76
Queue size
50
-
----------
77
+
~~~~~~~~~~
51
78
52
79
With the :ref:`CONFIG_DESKTOP_HID_REPORT_PROVIDER_KEYBOARD_EVENT_QUEUE_SIZE <config_desktop_app_options>` Kconfig option, you can set the number of elements on the queue where the keys are stored before the connection is established.
53
80
For backwards compatibility, you can set the default value for this option using the deprecated :ref:`CONFIG_DESKTOP_HID_EVENT_QUEUE_SIZE <config_desktop_app_options>` Kconfig option.
54
81
If there is no space in the queue to enqueue a new key state change, the oldest element is released.
55
82
56
83
Report expiration
57
-
-----------------
84
+
~~~~~~~~~~~~~~~~~
58
85
59
86
With the :ref:`CONFIG_DESKTOP_HID_REPORT_PROVIDER_KEYBOARD_KEYPRESS_EXPIRATION <config_desktop_app_options>` Kconfig option, you can set the amount of time after which a queued key will be considered expired.
60
87
For backwards compatibility, you can set the default value for this option using the deprecated :ref:`CONFIG_DESKTOP_HID_REPORT_EXPIRATION <config_desktop_app_options>` Kconfig option.
61
88
The higher the value, the longer the period from which the nRF Desktop application will recall pressed keys when the connection with HID host is established.
62
89
63
-
Handling keys state
64
-
===================
90
+
Keys state
91
+
----------
65
92
66
-
The module selects the :ref:`CONFIG_DESKTOP_KEYS_STATE <config_desktop_app_options>` Kconfig option to enable the :ref:`nrf_desktop_keys_state`.
67
-
The utility is used to track the state of active keys after the connection with the HID host is established.
93
+
The :ref:`nrf_desktop_keys_state` is used to track the state of active keys after the connection with the HID host is established.
94
+
The module selects the :ref:`CONFIG_DESKTOP_KEYS_STATE <config_desktop_app_options>` Kconfig option to enable the utility.
68
95
69
96
Implementation details
70
97
**********************
71
98
72
-
On initialization, the module announces its presence by sending the :c:struct:`hid_report_provider_event` event with an appropriate report ID and implementation of callbacks from HID report provider API (:c:struct:`hid_report_provider_api`).
73
-
Separate :c:struct:`hid_report_provider_event` events are sent for each report ID.
74
-
The module supports keyboard reports from the report and boot protocols.
75
-
You can enable the boot protocol support using the :ref:`CONFIG_DESKTOP_HID_BOOT_INTERFACE_KEYBOARD <config_desktop_app_options>` Kconfig option.
76
-
The :ref:`nrf_desktop_hid_state` receives the events and fills them with its own implementation of callbacks from the HID state API (:c:struct:`hid_state_api`).
77
-
After that process, the modules can communicate by callbacks.
78
-
The module also subscribes to the :c:struct:`button_event` event to get information about the button presses.
79
-
The module sends :c:struct:`hid_report_event` events to an appropriate subscriber when it is requested by the :ref:`nrf_desktop_hid_state`.
80
-
81
-
.. note::
82
-
The HID report formatting function must work according to the HID report descriptor (``hid_report_desc``).
83
-
The source file containing the descriptor is provided by the :ref:`CONFIG_DESKTOP_HID_REPORT_DESC <config_desktop_app_options>` Kconfig option.
84
-
85
-
Linking input data with the right HID report
86
-
============================================
87
-
88
-
Out of all available input data types, the module collects button events.
89
-
The button events are stored in the :c:struct:`report_data` structure.
90
-
The ``button_event`` is the source of this type of data.
91
-
92
-
To indicate a change to this input data, the module overwrites the value that is already stored.
93
-
94
-
Since keys on the board can be associated with a HID usage ID and thus be part of different HID reports, the first step is to identify if the key belongs to a HID report that is provided by this module.
95
-
This is done by obtaining the key mapping from the :ref:`nrf_desktop_hid_keymap`.
96
-
97
-
Once the mapping is obtained, the application checks if the report to which the usage belongs is connected:
98
-
99
-
* If the report is connected and the :ref:`nrf_desktop_hid_eventq` instance is empty, the module stores the report and calls the ``trigger_report_send`` callback from the :c:struct:`hid_state_api` to notify the :ref:`nrf_desktop_hid_state` about the new data.
100
-
* If the report is not connected or the :ref:`nrf_desktop_hid_eventq` instance is not empty, the value is enqueued in the :ref:`nrf_desktop_hid_eventq` instance.
99
+
The module is used by :ref:`nrf_desktop_hid_state` as a HID input report provider for the HID keyboard input report and HID boot keyboard input report.
100
+
The module registers two separate HID report providers to handle both input reports.
101
+
On initialization, the module submits the :c:struct:`hid_report_provider_event` events to establish two-way callbacks between the |hid_state| and the HID report providers.
101
102
102
-
The difference between these operations is that storing a value onto the queue (second case) preserves the order of input events.
103
-
See the following section for more information about storing data before the connection.
104
-
105
-
Storing input data before the connection
106
-
========================================
107
-
108
-
The button data is stored before the connection.
109
-
110
-
The reason for this operation is to allow to track key presses that happen right after the device is woken up, but before it can connect to the HID host.
111
-
112
-
When the device is disconnected and the input event with the button data is received, the data is stored onto the :ref:`nrf_desktop_hid_eventq` instance, a member of the :c:struct:`report_data` structure.
113
-
This queue preserves an order in which input data events are received.
103
+
Handling keypresses
104
+
===================
114
105
115
-
Storing limitations
116
-
-------------------
106
+
After an application-specific key ID (:c:member:`button_event.key_id`) is mapped to the HID keyboard input report ID and related HID usage ID, the HID usage ID is handled by the provider.
107
+
Before a connection with the HID host is established, the provider enqueues the HID usage ID and keypress state (press or release) in the HID event queue.
108
+
Once the connection is established, the elements of the queue are replayed one after the other to the host, in a sequence of consecutive HID reports.
109
+
On the HID state request, the module pulls an element from the queue, updates the tracked state of pressed keys, and submits a :c:struct:`hid_report_event` to provide the HID input report to the HID subscriber.
110
+
The subsequent requests lead to providing subsequent keypresses as HID report events.
111
+
All key state changes still go through the HID event queue until the queue is empty.
117
112
118
-
You can limit the number of events that can be inserted into the queue using the :ref:`CONFIG_DESKTOP_HID_REPORT_PROVIDER_KEYBOARD_EVENT_QUEUE_SIZE <config_desktop_app_options>` Kconfig option.
113
+
Once the queue is empty, a key state change results in an instant update of the tracked state of pressed keys.
114
+
If the state of pressed keys changes, the module calls the ``trigger_report_send`` callback from the :c:struct:`hid_state_api` to notify the :ref:`nrf_desktop_hid_state` about the new data.
115
+
The module also remembers that the HID subscriber needs to be updated.
119
116
120
-
Discarding events
121
-
------------------
117
+
Discarding queued events
118
+
------------------------
122
119
123
-
When there is no space for a new input event, the module tries to free space by discarding the oldest event in the queue.
120
+
While key state changes go through the event queue and there is no space for a new input event, the module tries to free space by discarding the oldest event in the queue.
124
121
Events stored in the queue are automatically discarded after the period defined by the :ref:`CONFIG_DESKTOP_HID_REPORT_PROVIDER_KEYBOARD_KEYPRESS_EXPIRATION <config_desktop_app_options>` option.
125
122
126
123
When discarding an event from the queue, the module checks if the key associated with the event is pressed.
@@ -136,5 +133,3 @@ The discarding mechanism ensures that the host will always receive the correct k
136
133
* Every key that was pressed after the associated key had been pressed is also released.
137
134
138
135
If there is no space to store the input event in the queue and no old event can be discarded, the entire content of the queue is dropped to ensure the sanity.
139
-
140
-
Once the connection is established, the elements of the queue are replayed one after the other to the host, in a sequence of consecutive HID reports.
0 commit comments