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
Change introduces additional information related to the implementation
details of the module.
Jira: NCSDK-22790
Signed-off-by: Marek Pieta <[email protected]>
Copy file name to clipboardExpand all lines: applications/nrf_desktop/doc/motion.rst
+37-11Lines changed: 37 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,7 +31,8 @@ The motion module selects the source of movement based on the following configur
31
31
* :ref:`CONFIG_DESKTOP_MOTION_SENSOR_PMW3360_ENABLE <config_desktop_app_options>` - Movement data is obtained from the gaming-grade ``PMW3360`` motion sensor.
32
32
* :ref:`CONFIG_DESKTOP_MOTION_SENSOR_PAW3212_ENABLE <config_desktop_app_options>` - Movement data is obtained from ``PAW3212`` motion sensor.
33
33
* :ref:`CONFIG_DESKTOP_MOTION_BUTTONS_ENABLE <config_desktop_app_options>` - Movement data is generated using buttons.
34
-
* :ref:`CONFIG_DESKTOP_MOTION_SIMULATED_ENABLE <config_desktop_app_options>` - Movement data is simulated (controlled from Zephyr's :ref:`zephyr:shell_api`).
34
+
* :ref:`CONFIG_DESKTOP_MOTION_SIMULATED_ENABLE <config_desktop_app_options>` - Movement data is simulated.
35
+
The movement data generation can be controlled from Zephyr's :ref:`zephyr:shell_api`.
35
36
36
37
See the following sections for more information.
37
38
@@ -67,18 +68,27 @@ Simulated movement data
67
68
68
69
Selecting the :ref:`CONFIG_DESKTOP_MOTION_SIMULATED_ENABLE <config_desktop_app_options>` option adds the :file:`src/hw_interface/motion_simulated.c` file to the compilation.
69
70
70
-
If the shell is available (the :kconfig:option:`CONFIG_SHELL` option is set), the motion module registers a shell module ``motion_sim`` and links to it two commands: ``start`` and ``stop``.
71
-
If the shell is not available, motion generation starts automatically when the device is connected to USB or Bluetooth®.
72
-
73
-
When started, the module will generate simulated motion events.
74
-
The movement data in each event will be tracing the predefined path, an eight-sided polygon.
71
+
The generated movement data traces a predefined octagon path.
72
+
As soon as the HID subscriber connects, the motion data is sent to it automatically.
73
+
The X and Y coordinates of subsequent vertexes of the octagon are defined as the ``coords`` array in the module's source code.
75
74
76
75
You can configure the path with the following options:
77
76
78
77
* :ref:`CONFIG_DESKTOP_MOTION_SIMULATED_EDGE_TIME <config_desktop_app_options>` - Sets how long each edge is traced.
79
-
* :ref:`CONFIG_DESKTOP_MOTION_SIMULATED_SCALE_FACTOR <config_desktop_app_options>` - Scales the size of the polygon.
78
+
To speed up calculations, this Kconfig option value must be set to a power of two.
79
+
* :ref:`CONFIG_DESKTOP_MOTION_SIMULATED_SCALE_FACTOR <config_desktop_app_options>` - Scales the size of the octagon.
80
+
The Kconfig option's value is used as the ``SCALE`` factor in the ``coords`` array.
81
+
82
+
Shell integration
83
+
-----------------
84
+
85
+
If the Zephyr shell is enabled (meaning the :kconfig:option:`CONFIG_SHELL` Kconfig option is set), the motion module registers a ``motion_sim`` shell module and links to it two commands:
86
+
87
+
* ``start`` - Start sending simulated movement data to the HID subscriber.
88
+
* ``stop``- Stop sending simulated movement data to the HID subscriber.
80
89
81
-
The ``stop`` command will cause the module to stop generating new events.
90
+
If the shell is enabled, motion generation no longer starts automatically when the HID subscriber connects and after system wakeup (when :c:struct:`wake_up_event` is received).
91
+
The simulated movement data generation needs to be triggered using a shell command.
82
92
83
93
Configuration channel
84
94
*********************
@@ -106,10 +116,15 @@ In these configurations, the module is a configuration channel listener and it p
106
116
Implementation details
107
117
**********************
108
118
119
+
Implementation details depend on the selected implementation.
120
+
121
+
Movement data from motion sensors
122
+
=================================
123
+
109
124
This section describes the motion module implementation for motion sensors.
110
125
111
126
Motion sensor
112
-
=============
127
+
-------------
113
128
114
129
The motion module samples movement data from the motion sensor using the motion sensor driver.
115
130
@@ -118,7 +133,7 @@ The same is true for the names of sensor configuration options.
118
133
The nRF Desktop application aggregates the sensor-specific information and translates them to the application abstracts in the :file:`configuration/common/motion_sensor.h` header file.
119
134
120
135
Sampling thread
121
-
===============
136
+
---------------
122
137
123
138
The motion module uses a dedicated sampling thread to sample data from the motion sensor.
124
139
The reason for using the sampling thread is the long time required for data to be ready.
@@ -129,7 +144,7 @@ The sampling thread stays in the unready state blocked on a semaphore.
129
144
The semaphore is triggered when the motion sensor trigger sends a notification that the data is available or when other application event requires the module interaction with the sensor (for example, when configuration is submitted from the host).
130
145
131
146
Sampling pipeline
132
-
=================
147
+
-----------------
133
148
134
149
The motion module starts in ``STATE_DISABLED`` and after initialization enters ``STATE_DISCONNECTED``.
135
150
When disconnected, the module is not generating motion events, but the motion sensor is sampled to make sure its registers are cleared.
@@ -150,3 +165,14 @@ Upon connection, the following happens:
150
165
The module continues to sample data until disconnection or when there is no motion detected.
151
166
The ``motion`` module assumes no motion when a number of consecutive samples equal to :ref:`CONFIG_DESKTOP_MOTION_SENSOR_EMPTY_SAMPLES_COUNT <config_desktop_app_options>` returns zero on both axis.
152
167
In such case, the module will switch back to ``STATE_IDLE`` and wait for the motion sensor trigger.
168
+
169
+
Simulated movement data
170
+
=======================
171
+
172
+
Current position in the generated trajectory is determined by a hardware clock.
173
+
If available, the module uses the :c:func:`k_cycle_get_64` function to read the hardware clock when generating motion.
174
+
Otherwise, the :c:func:`k_cycle_get_32` function is used for that purpose.
175
+
176
+
When a HID subscriber connects, that is when the device is connected either over USB or Bluetooth LE, the module submits the first :c:struct:`motion_event` containing motion calculated from the previously reported position.
177
+
The subsequent :c:struct:`motion_event` is submitted when the previously generated motion data is sent to the subscriber, that is when :c:struct:`hid_report_sent_event` is received by the module.
178
+
The values of motion for X and Y axes are generated from an updated timestamp and the previously reported position.
0 commit comments