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_mouse.rst
+52-76Lines changed: 52 additions & 76 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 mouse module
7
7
:local:
8
8
:depth: 2
9
9
10
-
The HID provider mouse module is responsible for providing mouse HID reports.
11
-
The module listens to the :c:struct:`button_event`, :c:struct:`wheel_event` and :c:struct:`motion_event` events and communicates with the :ref:`nrf_desktop_hid_state`.
12
-
It provides new mouse HID reports when requested by the :ref:`nrf_desktop_hid_state`.
10
+
The HID provider mouse module is a HID report provider integrated with the :ref:`nrf_desktop_hid_state`.
11
+
The module is responsible for providing the HID mouse input report and the HID boot mouse input report.
12
+
13
+
The module listens to the user input (:c:struct:`button_event`, :c:struct:`wheel_event`, and :c:struct:`motion_event`) and communicates with the :ref:`nrf_desktop_hid_state`.
14
+
It provides HID mouse 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,14 +29,24 @@ Module events
25
29
Configuration
26
30
*************
27
31
28
-
You can enable the module using the :ref:`CONFIG_DESKTOP_HID_REPORT_PROVIDER_MOUSE <config_desktop_app_options>` Kconfig option.
29
-
This option is enabled by default if the device supports HID mouse reports.
30
-
You can substitute the module with a custom HID mouse report provider implementation.
32
+
You can enable the default implementation of the HID provider using the :ref:`CONFIG_DESKTOP_HID_REPORT_PROVIDER_MOUSE <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 mouse reports (:ref:`CONFIG_DESKTOP_HID_REPORT_MOUSE_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
+
The module also provides HID boot mouse input report if it is supported (:ref:`CONFIG_DESKTOP_HID_BOOT_INTERFACE_MOUSE <config_desktop_app_options>`).
36
+
37
+
Alternatively, you can substitute the module with a custom HID mouse report provider implementation.
38
+
Using the custom provider allows you to modify the sources of user input and the HID report format.
31
39
Enable the :ref:`CONFIG_DESKTOP_HID_REPORT_PROVIDER_MOUSE_ALT <config_desktop_app_options>` Kconfig option to use a custom HID mouse report provider.
40
+
The option disables the default HID mouse report provider.
32
41
Make sure to introduce the custom HID mouse report provider if you enable this option.
33
42
43
+
Default implementation
44
+
======================
45
+
46
+
If you use the default implementation, you only need to configure the HID keymap for the module.
47
+
34
48
HID keymap
35
-
==========
49
+
----------
36
50
37
51
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
52
The module selects the :ref:`CONFIG_DESKTOP_HID_KEYMAP <config_desktop_app_options>` Kconfig option to enable the utility.
@@ -42,90 +56,52 @@ See the utility's documentation for details.
42
56
Implementation details
43
57
**********************
44
58
45
-
On initialization, the module announces its presence by sending a :c:struct:`hid_report_provider_event` event with appropriate report ID and implementation of callbacks from the HID report provider API (:c:struct:`hid_report_provider_api`).
46
-
Separate :c:struct:`hid_report_provider_event` events are sent for each report ID.
47
-
The module supports mouse reports from the report and boot protocols.
48
-
You can enable the boot protocol support using the :ref:`CONFIG_DESKTOP_HID_BOOT_INTERFACE_MOUSE <config_desktop_app_options>` Kconfig option.
49
-
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`).
50
-
After that process, the modules can communicate by callbacks.
51
-
The module also subscribes to the :c:struct:`button_event`, :c:struct:`wheel_event` and :c:struct:`motion_event` events to get information about the button presses, wheel scrolls, and motion events.
52
-
The module sends :c:struct:`hid_report_event` events to an appropriate subscriber when it is requested by the :ref:`nrf_desktop_hid_state`.
53
-
54
-
.. note::
55
-
The HID report formatting function must work according to the HID report descriptor (``hid_report_desc``).
56
-
The source file containing the descriptor is provided by the :ref:`CONFIG_DESKTOP_HID_REPORT_DESC <config_desktop_app_options>` Kconfig option.
59
+
The module is used by :ref:`nrf_desktop_hid_state` as a HID input report provider for the HID mouse input report and HID boot mouse input report.
60
+
The module registers two separate HID report providers to handle both input reports.
61
+
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.
57
62
58
-
Linking input data with the right HID report
59
-
============================================
63
+
Handling user input
64
+
===================
60
65
61
-
Out of all available input data types, the following types are collected by this module:
66
+
The module handles the following types of user input:
62
67
63
68
* `Relative value data`_ (axes)
69
+
This type of input data is related to the pointer coordinates and the wheel rotation.
70
+
Both :c:struct:`motion_event` and :c:struct:`wheel_event` are sources of this type of data.
64
71
* `Absolute value data`_ (buttons)
72
+
This type of input data is related to the state of pressed buttons.
73
+
The :c:struct:`button_event` is the source of this type of data.
65
74
66
-
Both types are stored in the :c:struct:`report_data` structure.
75
+
Both input types are stored internally in the ``report_data`` structure.
67
76
68
77
Relative value data
69
78
-------------------
70
79
71
-
This type of input data is related to the pointer coordinates and the wheel rotation.
72
-
Both ``motion_event`` and ``wheel_event`` are sources of this type of data.
73
-
74
-
When either ``motion_event`` or ``wheel_event`` is received, the module selects the :c:struct:`report_data` structure associated with the mouse HID report and stores the values at the right position within this structure's ``axes`` member.
75
-
76
-
.. note::
77
-
The values of axes are stored every time the input data is received, but these values are cleared when a report is connected to the subscriber.
78
-
Consequently, values outside of the connection period are never retained.
79
-
80
-
Absolute value data
81
-
-------------------
82
-
83
-
This type of input data is related to buttons.
84
-
The ``button_event`` is the source of this type of data.
85
-
86
-
To indicate a change to this input data, the module overwrites the value that is already stored.
87
-
88
-
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.
89
-
This is done by obtaining the key mapping from the :ref:`nrf_desktop_hid_keymap`.
90
-
91
-
Once the mapping is obtained, the application checks if the report to which the usage belongs is connected:
92
-
93
-
* 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.
94
-
* 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.
95
-
96
-
The difference between these operations is that storing a value onto the queue (second case) preserves the order of input events.
97
-
See the following section for more information about storing data before the connection.
98
-
99
-
Storing input data before the connection
100
-
========================================
80
+
The relative value data is stored within the ``report_data`` structure's ``axes`` member.
81
+
There are separate fields for wheel, mouse motion over the X axis, and mouse motion over the Y axis.
101
82
102
-
The storing approach before the connection depends on the data type:
83
+
The values of axes are stored whenever the input data is received, but these values are cleared when HID report subscription is enabled.
84
+
Consequently, values outside of the HID subscription period are never retained.
103
85
104
-
* The relative value data is not stored outside of the connection period.
105
-
* The absolute value data is stored before the connection.
86
+
HID mouse pipeline
87
+
~~~~~~~~~~~~~~~~~~
106
88
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.
89
+
The nRF Desktop application synchronizes motion sensor sampling with sending HID mouse input reports to the HID host.
90
+
The HID provider mouse module tracks the number of HID reports in flight and maintains a HID report pipeline to ensure proper HID report flow:
108
91
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.
92
+
* If the number of HID reports in flight is lower than the pipeline size, the module provides additional HID reports to generate the HID report pipeline on user input.
93
+
* If the number of HID reports in flight is greater than or equal to the pipeline size, the module buffers user input internally and delays providing subsequent HID input reports until previously submitted reports are sent to the HID host.
111
94
112
-
Discarding events
113
-
------------------
95
+
See the :ref:`nrf_desktop_hid_mouse_report_handling` section for an overview of handling HID mouse input reports in the nRF Desktop.
96
+
The section focuses on interactions between application modules.
114
97
115
-
When there is no space for a new input event, the module tries to free space by discarding the oldest event in the queue.
116
-
117
-
When discarding an event from the queue, the module checks if the key associated with the event is pressed.
118
-
This is to avoid missing key releases for earlier key presses when the keys from the queue are replayed to the host.
119
-
If a key release is missed, the host could stay with a key that is permanently pressed.
120
-
The discarding mechanism ensures that the host will always receive the correct key sequence.
121
-
122
-
.. note::
123
-
The module can only discard an event if the event does not overlap any button that was pressed but not released, or if the button itself is pressed.
124
-
The event is released only when the following conditions are met:
125
-
126
-
* The associated key is not pressed anymore.
127
-
* Every key that was pressed after the associated key had been pressed is also released.
98
+
Absolute value data
99
+
-------------------
128
100
129
-
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.
101
+
After an application-specific key ID (:c:member:`button_event.key_id`) is mapped to the HID mouse input report ID and related HID usage ID, the HID usage ID is handled by the provider.
102
+
The module remembers HID usage IDs of all the currently pressed keys as a bitmask.
103
+
The bitmask is then included as part of the HID mouse input report or HID boot mouse input report.
104
+
Because of the fact that HID usage IDs are stored as a bitmask, the module does not support handling multiple hardware buttons mapped to the same HID usage ID.
130
105
131
-
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.
106
+
The module ignores keypresses that happen before HID report subscription is enabled and clears the HID usage ID bitmask when HID report subscription is disabled.
107
+
As a result, keypresses outside of the HID subscription period are never retained.
0 commit comments