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 state documentation
Change updates documentation of the HID state module to introduce
improvements related to HID report providers support.
Jira: NCSDK-35005
Signed-off-by: Marek Pieta <[email protected]>
Signed-off-by: Pekka Niskanen <[email protected]>
Copy file name to clipboardExpand all lines: applications/nrf_desktop/doc/hid_state.rst
+93-54Lines changed: 93 additions & 54 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,13 +7,18 @@ HID state module
7
7
:local:
8
8
:depth: 2
9
9
10
-
The |hid_state| is required for communicating with the HID report providers to generate reports from input data.
10
+
The |hid_state| is the center of an application acting as a HID peripheral.
11
11
It is responsible for the following operations:
12
12
13
-
* Tracking state of the HID report subscriptions.
14
-
* Notifying the HID report providers to form the HID reports in either report or boot protocol.
15
-
* Notifying the HID report providers about state changes of the HID report subscriber connection.
16
-
* Sending :c:struct:`led_event` based on the HID keyboard LED output reports.
13
+
* Tracking the state of HID subscribers and HID input report subscriptions.
14
+
The module can simultaneously handle HID input report subscriptions of multiple HID subscribers.
15
+
The module provides HID input reports only to one subscriber (*active subscriber*).
16
+
* Providing HID input reports to the active HID subscriber.
17
+
The module relies on HID report providers to aggregate the user input, form HID input reports, and submit a :c:struct:`hid_report_event`.
18
+
The HID input reports can be formatted according to either HID report protocol or HID boot protocol.
19
+
* Handling HID output reports.
20
+
The module handles only the HID keyboard LED output report.
21
+
The module sends a :c:struct:`led_event` to update state of the keyboard LEDs.
17
22
18
23
Module events
19
24
*************
@@ -29,20 +34,24 @@ Configuration
29
34
*************
30
35
31
36
To enable the |hid_state|, use the :ref:`CONFIG_DESKTOP_HID_STATE_ENABLE <config_desktop_app_options>` Kconfig option that is implied by the :ref:`CONFIG_DESKTOP_ROLE_HID_PERIPHERAL <config_desktop_app_options>` option.
32
-
An nRF Desktop peripheral uses the |hid_state| and HID report providers to generate HID reports based on the user input.
37
+
Make sure to configure the peripheral type and the set of supported HID input reports and HID boot interface.
33
38
For details related to HID configuration in the nRF Desktop, see the :ref:`nrf_desktop_hid_configuration` documentation.
34
39
35
-
To send boot reports, enable the respective Kconfig option:
If your application configuration supports more than one HID subscriber, you must align the maximum number of HID subscribers that can be handled simultaneously (:ref:`CONFIG_DESKTOP_HID_STATE_SUBSCRIBER_COUNT <config_desktop_app_options>`).
44
+
For example, to use a configuration that allows to simultaneously subscribe to HID reports from HID over GATT (Bluetooth LE) and a single USB HID instance, set the value of this Kconfig option to ``2``.
39
45
40
-
Number of supported HID data subscribers
41
-
========================================
46
+
If multiple HID subscribers are simultaneously connected, the |hid_state| selects the one with the highest priority as the active subscriber.
47
+
The |hid_state| provides HID input reports only to the active subscriber.
48
+
The |hid_state| displays the HID keyboard LED state associated with the active subscriber.
42
49
43
-
If your application configuration supports more than one HID data subscriber, you must align the maximum number of HID data subscribers that can be supported simultaneously (:ref:`CONFIG_DESKTOP_HID_STATE_SUBSCRIBER_COUNT <config_desktop_app_options>`).
44
-
For example, to use a configuration that allows to simultaneously subscribe for HID reports from HID over GATT (BLE) and a single USB HID instance, set the value of this Kconfig option to ``2``.
45
-
See the `Tracking state of transports`_ section for more details about HID subscribers.
50
+
By default, the subscriber that is associated with USB has priority over a subscriber associated with Bluetooth LE.
51
+
As a result, if a HID host connects through the USB while another HID host is connected over the Bluetooth LE, the HID reports will be routed to the USB.
52
+
53
+
.. note::
54
+
The subscriber priority must be unique, which means that two or more subscribers cannot share the same priority value.
46
55
47
56
HID keyboard LEDs
48
57
=================
@@ -82,65 +91,95 @@ You must define all of the mentioned data in this configuration file, and specif
82
91
HID report providers
83
92
====================
84
93
85
-
The module selects the :ref:`CONFIG_DESKTOP_HID_REPORT_PROVIDER_EVENT <config_desktop_app_options>` Kconfig option to enable :c:struct:`hid_report_provider_event` event support.
86
-
The events are used to establish two-way callbacks between the |hid_state| and the HID report providers.
87
-
The |hid_state| can request the HID report providers to generate HID reports and notify the providers about the connection state changes and report sent occurrences.
88
-
The HID report providers are responsible for generating HID reports when requested by the |hid_state|.
89
-
The HID report providers can also notify the |hid_state| when new data is available.
94
+
The |hid_state| relies on the HID report providers to collect user input, form HID input reports, and submit a :c:struct:`hid_report_event`.
95
+
The module selects the :ref:`CONFIG_DESKTOP_HID_REPORT_PROVIDER_EVENT <config_desktop_app_options>` Kconfig option to enable the HID report provider event and default HID report providers for all HID input reports enabled in the configuration.
96
+
The HID providers for mouse and keyboard input reports also handle the respective HID boot input reports if the boot report support is enabled in the configuration.
97
+
98
+
.. note::
99
+
You can provide an alternative implementation of a HID report provider to generate a HID report in a custom way.
100
+
You can also add a new HID report provider to introduce support for another HID input report.
101
+
See the :ref:`nrf_desktop_hid_state_providing_hid_input_reports` section for implementation details related to HID report providers integration.
90
102
91
103
Implementation details
92
104
**********************
93
105
94
-
The |hid_state| in association with the HID report providers provides a routing mechanism between sources of input data and transport modules.
95
-
This can be associated with:
106
+
This section describes implementation details related to responsibilities of the |hid_state|.
96
107
97
-
* Receiving input events from :ref:`caf_buttons`, :ref:`nrf_desktop_wheel`, and :ref:`nrf_desktop_motion`.
98
-
* Sending out HID reports to HID transports, for example, :ref:`nrf_desktop_hids` and :ref:`nrf_desktop_usb_state`.
108
+
Tracking state of HID subscribers
109
+
=================================
99
110
100
-
Apart from the routing mechanism, the module is also responsible for `Handling HID keyboard LED state`_.
111
+
A HID transport (for example :ref:`nrf_desktop_hids` or :ref:`nrf_desktop_usb_state`) is a module that forwards HID reports to a HID host and forwards HID subscriptions of the HID host.
112
+
A HID transport reports the state of a HID subscriber using the :c:struct:`hid_report_subscriber_event`.
113
+
When the connection to the HID host is indicated by this event, the |hid_state| will create an associated subscriber.
114
+
The |hid_state| tracks the state of the HID subscribers.
101
115
102
-
Tracking state of transports
103
-
============================
116
+
As part of the :c:struct:`hid_report_subscriber_event`, the subscriber provides the following parameters:
104
117
105
-
The |hid_state| tracks the state of modules that forward the HID data to a HID host (HID transports) by listening to :c:struct:`hid_report_subscriber_event`.
106
-
The |hid_state| refers collectively to all transports as *subscribers*.
107
-
When the connection to the host is indicated by this event, the |hid_state| will create a subscriber associated with the transport.
108
-
Each subscriber reports its priority as part of the :c:struct:`hid_report_subscriber_event`.
109
-
The subscriber priority must be unique, that mean two or more subscribers cannot share the same priority value.
118
+
* Subscriber priority - The |hid_state| provides HID input reports only to the subscriber with the highest priority (active subscriber).
119
+
* Pipeline size - The |hid_state| forwards this information to the HID report providers.
120
+
The information can be used, for example, to synchronize sensor sampling with sending the HID input reports to the HID host.
121
+
See the :ref:`nrf_desktop_hid_mouse_report_handling` section for information how the pipeline size is used for HID mouse reports.
122
+
* Maximum number of processed HID input reports - The |hid_state| limits the number of HID input reports processed by a HID subscriber at a time by delaying providing the subsequent HID input report until the previous report is sent to a HID host.
110
123
111
-
By default, the subscriber that is associated with USB has priority over any Bluetooth LE peer subscriber.
112
-
As a result, when the host connected through the USB subscribes for a HID report, the HID report will be routed to the USB.
124
+
Tracking state of HID report subscriptions
125
+
------------------------------------------
113
126
114
-
Tracking state of HID report notifications
115
-
==========================================
127
+
For each subscriber, the |hid_state| tracks the state of HID input report subscriptions.
128
+
The HID input reports are only provided after the active subscriber enables the subscription.
129
+
The subscriber updates its HID report subscriptions using a :c:struct:`hid_report_subscription_event`.
116
130
117
-
For each subscriber, the |hid_state| tracks the state of notifications for each of the available HID reports.
118
-
These are tracked in the subscriber's structure :c:struct:`subscriber`.
131
+
The HID report subscriptions are tracked in the subscriber's structure :c:struct:`subscriber`.
119
132
This structure's member ``state`` is an array of :c:struct:`report_state` structures.
120
-
Each element corresponds to one available HID report.
121
-
122
-
The subscriber connects to the HID reports by submitting :c:struct:`hid_report_subscription_event`.
123
-
Depending on the connection method, this event can be submitted:
124
-
125
-
* For Bluetooth, when the notification is enabled for a given HID report.
126
-
* For USB, when the device is connected to USB.
133
+
Each element corresponds to one HID input report.
127
134
128
135
The :c:struct:`report_state` structure serves the following purposes:
129
136
130
-
* Tracks the state of the connection.
137
+
* Tracks the state of the report subscription.
131
138
* Contains the link connecting the object to the right :c:struct:`provider` structure which contains the HID report provider info such as report ID and API (:c:struct:`hid_report_provider_api`).
132
-
* Tracks the number of reports of the associated type that were sent to the subscriber.
139
+
* Tracks the number of reports with a given ID in flight.
The |hid_state| relies on the HID providers to collect user input, form HID input reports, and submit a :c:struct:`hid_report_event`.
147
+
Every HID input report ID is handled by a dedicated HID report provider API (:c:struct:`hid_report_provider_api`).
148
+
149
+
HID report provider event
150
+
-------------------------
151
+
152
+
The :c:struct:`hid_report_provider_event` is used to establish two-way callbacks between the |hid_state| and the HID report providers.
153
+
The event allows to exchange the API structures between the |hid_state| and HID report providers (:c:struct:`hid_report_provider_api` and :c:struct:`hid_state_api`).
154
+
The API structures allow for direct function calls between the modules.
155
+
156
+
The |hid_state| requests the HID report providers to generate HID reports and notifies the providers about the connection state changes and report sent occurrences.
157
+
The HID report providers can notify the |hid_state| when new data is available (on user input) to trigger generating a HID input report.
158
+
159
+
On a |hid_state|'s request, a HID report provider submits a :c:struct:`hid_report_event` to provide a HID input report to the active HID subscriber.
160
+
The :c:struct:`hid_report_sent_event` is submitted by the HID transport related to the subscriber to confirm that the HID report was sent to the HID host.
161
+
The |hid_state| relies on this event to track the number of HID reports in flight and notify the providers.
162
+
163
+
See the :c:struct:`hid_report_provider_event` event documentation page for detailed information regarding the communication between the |hid_state| and HID report providers.
164
+
165
+
Default HID providers
166
+
---------------------
167
+
168
+
The following application modules are used as default implementations of HID report providers:
133
169
134
-
Requesting HID reports
135
-
======================
170
+
* :ref:`nrf_desktop_hid_provider_mouse`
171
+
* :ref:`nrf_desktop_hid_provider_keyboard`
172
+
* :ref:`nrf_desktop_hid_provider_system_ctrl`
173
+
* :ref:`nrf_desktop_hid_provider_consumer_ctrl`
136
174
137
-
When a HID report is to be sent to the subscriber, the |hid_state| calls the appropriate function from the :c:struct:`hid_report_provider_api` to trigger the HID report provider to generate HID report.
175
+
The respective HID report provider is automatically enabled if support for a given HID input report is enabled in the :ref:`nrf_desktop_hid_configuration`.
176
+
See the documentation page of a HID report provider for detailed information about the provider.
138
177
139
-
Handling HID keyboard LED state
140
-
===============================
178
+
HID output reports
179
+
==================
141
180
142
-
When the |hid_state| receives a :c:struct:`hid_report_event` that contains a HID output report, it updates the remembered information about the state of the HID output report of the appropriate subscriber.
181
+
When the |hid_state| receives a :c:struct:`hid_report_event` that contains a HID output report, it updates the stored information about the state of the HID output report of the appropriate subscriber.
143
182
144
183
By default, nRF Desktop supports only HID keyboard LED output report.
145
-
The nRF Desktop peripheral displays the state of the keyboard LEDs that was specified by the HID subscriber that subscribed for keyboard key HID input report.
146
-
When the subscriber is changed or it updates the state of the keyboard LEDs, the |hid_state| sends :c:struct:`leds_event` to update the state of the hardware LEDs.
184
+
The nRF Desktop peripheral displays the state of the keyboard LEDs that was specified by the active HID subscriber.
185
+
When the active subscriber is changed or it updates the state of the keyboard LEDs, the |hid_state| sends :c:struct:`leds_event` to update the state of the hardware LEDs.
0 commit comments