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
applications: nrf_desktop: Update HID provider system control doc
Change updates documentation page of the HID system control input report
provider.
Jira: NCSDK-35470
Signed-off-by: Marek Pieta <[email protected]>
Signed-off-by: Divya Pillai <[email protected]>
Copy file name to clipboardExpand all lines: applications/nrf_desktop/doc/hid_provider_system_ctrl.rst
+64-63Lines changed: 64 additions & 63 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 system control module
7
7
:local:
8
8
:depth: 2
9
9
10
-
The HID provider system control module is responsible for providing system control 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 system control HID reports when requested by the :ref:`nrf_desktop_hid_state`.
10
+
The HID provider system control module is a HID report provider integrated with the :ref:`nrf_desktop_hid_state`.
11
+
The module is responsible for providing the HID system control 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 system control 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,99 +29,98 @@ Module events
25
29
Configuration
26
30
*************
27
31
28
-
You can enable the module using the :ref:`CONFIG_DESKTOP_HID_REPORT_PROVIDER_SYSTEM_CTRL <config_desktop_app_options>` Kconfig option.
29
-
This option is enabled by default if the device supports HID system control reports.
30
-
You can substitute the module with a custom HID system control report provider implementation.
32
+
You can enable the default implementation of the HID provider using the :ref:`CONFIG_DESKTOP_HID_REPORT_PROVIDER_SYSTEM_CTRL <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 system control reports (:ref:`CONFIG_DESKTOP_HID_REPORT_SYSTEM_CTRL_SUPPORT <config_desktop_app_options>`).
34
+
The default implementation of the HID provider uses a predefined format of HID reports, which is aligned with the default HID report map in the common configuration (:ref:`CONFIG_DESKTOP_HID_REPORT_DESC <config_desktop_app_options>`).
35
+
36
+
Alternatively, you can substitute the module with a custom HID system control report provider implementation.
37
+
Using the custom provider allows you to modify sources of user input and the HID report format.
31
38
Enable the :ref:`CONFIG_DESKTOP_HID_REPORT_PROVIDER_SYSTEM_CTRL_ALT <config_desktop_app_options>` Kconfig option to use a custom HID system control report provider.
39
+
The option disables the default HID system control report provider.
32
40
Make sure to introduce the custom HID system control report provider if you enable this option.
33
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 report.
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.
57
+
34
58
HID keymap
35
-
==========
59
+
----------
36
60
37
61
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.
38
62
The module selects the :ref:`CONFIG_DESKTOP_HID_KEYMAP <config_desktop_app_options>` Kconfig option to enable the utility.
39
63
Make sure to configure the HID keymap utility.
40
64
See the utility's documentation for details.
41
65
42
-
Queuing keypresses
43
-
==================
66
+
HID eventq
67
+
----------
44
68
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.
69
+
The :ref:`nrf_desktop_hid_eventq` is used to temporarily enqueue key state changes before connection with the HID host is established.
70
+
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.
71
+
The sequence of keypresses is replayed once the connection with a HID host is established.
72
+
This ensures that all of the keypresses are replayed in order.
73
+
The module selects the :ref:`CONFIG_DESKTOP_HID_EVENTQ <config_desktop_app_options>` Kconfig option to enable the utility.
48
74
49
75
Queue size
50
-
----------
76
+
~~~~~~~~~~
51
77
52
78
With the :ref:`CONFIG_DESKTOP_HID_REPORT_PROVIDER_SYSTEM_CTRL_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
79
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
80
If there is no space in the queue to enqueue a new key state change, the oldest element is released.
55
81
56
82
Report expiration
57
-
-----------------
83
+
~~~~~~~~~~~~~~~~~
58
84
59
85
With the :ref:`CONFIG_DESKTOP_HID_REPORT_PROVIDER_SYSTEM_CTRL_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
86
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
87
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
88
63
-
Handling keys state
64
-
===================
89
+
Keys state
90
+
----------
65
91
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.
92
+
The :ref:`nrf_desktop_keys_state` is used to track the state of active keys after the connection with the HID host is established.
93
+
The module selects the :ref:`CONFIG_DESKTOP_KEYS_STATE <config_desktop_app_options>` Kconfig option to enable the utility.
68
94
69
95
Implementation details
70
96
**********************
71
97
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
-
The :ref:`nrf_desktop_hid_state` receives the event and fills it with its own implementation of callbacks from the HID state API (:c:struct:`hid_state_api`).
74
-
After that process, the modules can communicate by callbacks.
75
-
The module also subscribes to the :c:struct:`button_event` event to get information about the button presses.
76
-
The module sends :c:struct:`hid_report_event` events to an appropriate subscriber when it is requested by the :ref:`nrf_desktop_hid_state`.
77
-
78
-
.. note::
79
-
The HID report formatting function must work according to the HID report descriptor (``hid_report_desc``).
80
-
The source file containing the descriptor is provided by the :ref:`CONFIG_DESKTOP_HID_REPORT_DESC <config_desktop_app_options>` Kconfig option.
81
-
82
-
Linking input data with the right HID report
83
-
============================================
84
-
85
-
Out of all available input data types, the module collects button events.
86
-
The button events are stored in the :c:struct:`report_data` structure.
87
-
The ``button_event`` is the source of this type of data.
88
-
89
-
To indicate a change to this input data, the module overwrites the value that is already stored.
90
-
91
-
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.
92
-
This is done by obtaining the key mapping from the :ref:`nrf_desktop_hid_keymap`.
93
-
94
-
Once the mapping is obtained, the application checks if the report to which the usage belongs is connected:
95
-
96
-
* 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.
97
-
* 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.
98
-
99
-
The difference between these operations is that storing a value onto the queue (second case) preserves the order of input events.
100
-
See the following section for more information about storing data before the connection.
98
+
The module is used by :ref:`nrf_desktop_hid_state` as a HID input report provider for the HID system control input report.
99
+
On initialization, the module submits the :c:struct:`hid_report_provider_event` event to establish two-way callbacks between the |hid_state| and the HID report provider.
101
100
102
-
Storing input data before the connection
103
-
========================================
104
-
105
-
The button data is stored before the connection.
106
-
107
-
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.
101
+
Handling keypresses
102
+
===================
108
103
109
-
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.
110
-
This queue preserves an order in which input data events are received.
104
+
After an application-specific key ID (:c:member:`button_event.key_id`) is mapped to the HID system control input report ID and related HID usage ID, the HID usage ID is handled by the provider.
105
+
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.
106
+
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.
107
+
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.
108
+
The subsequent requests lead to providing subsequent keypresses as HID report events.
109
+
All key state changes still go through the HID event queue until the queue is empty.
111
110
112
-
Storing limitations
113
-
-------------------
111
+
Once the queue is empty, a key state change results in an instant update of the tracked state of pressed keys.
112
+
If the state of pressed keys changes, the module calls the :c:member:`hid_state_api.trigger_report_send` callback to notify the :ref:`nrf_desktop_hid_state` about the new data.
113
+
The module also remembers that the HID subscriber needs to be updated.
114
114
115
-
You can limit the number of events that can be inserted into the queue using the :ref:`CONFIG_DESKTOP_HID_REPORT_PROVIDER_SYSTEM_CTRL_EVENT_QUEUE_SIZE <config_desktop_app_options>` Kconfig option.
115
+
.. note::
116
+
The module tracks and reports a single HID system control usage ID at a time.
117
+
If multiple keys are simultaneously pressed, the module reports only the first pressed key.
118
+
Other keys are ignored.
116
119
117
-
Discarding events
118
-
------------------
120
+
Discarding queued events
121
+
------------------------
119
122
120
-
When there is no space for a new input event, the module tries to free space by discarding the oldest event in the queue.
123
+
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.
121
124
Events stored in the queue are automatically discarded after the period defined by the :ref:`CONFIG_DESKTOP_HID_REPORT_PROVIDER_SYSTEM_CTRL_KEYPRESS_EXPIRATION <config_desktop_app_options>` option.
122
125
123
126
When discarding an event from the queue, the module checks if the key associated with the event is pressed.
@@ -133,5 +136,3 @@ The discarding mechanism ensures that the host will always receive the correct k
133
136
* Every key that was pressed after the associated key had been pressed is also released.
134
137
135
138
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.
136
-
137
-
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