Skip to content

Commit d9e0c0c

Browse files
MarekPietarlubos
authored andcommitted
applications: nrf_desktop: Improve simulated motion documentation
Change introduces additional information related to the implementation details of the module. Jira: NCSDK-22790 Signed-off-by: Marek Pieta <[email protected]>
1 parent f9073c8 commit d9e0c0c

File tree

1 file changed

+37
-11
lines changed

1 file changed

+37
-11
lines changed

applications/nrf_desktop/doc/motion.rst

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ The motion module selects the source of movement based on the following configur
3131
* :ref:`CONFIG_DESKTOP_MOTION_SENSOR_PMW3360_ENABLE <config_desktop_app_options>` - Movement data is obtained from the gaming-grade ``PMW3360`` motion sensor.
3232
* :ref:`CONFIG_DESKTOP_MOTION_SENSOR_PAW3212_ENABLE <config_desktop_app_options>` - Movement data is obtained from ``PAW3212`` motion sensor.
3333
* :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`.
3536

3637
See the following sections for more information.
3738

@@ -67,18 +68,27 @@ Simulated movement data
6768

6869
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.
6970

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.
7574

7675
You can configure the path with the following options:
7776

7877
* :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.
8089

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.
8292

8393
Configuration channel
8494
*********************
@@ -106,10 +116,15 @@ In these configurations, the module is a configuration channel listener and it p
106116
Implementation details
107117
**********************
108118

119+
Implementation details depend on the selected implementation.
120+
121+
Movement data from motion sensors
122+
=================================
123+
109124
This section describes the motion module implementation for motion sensors.
110125

111126
Motion sensor
112-
=============
127+
-------------
113128

114129
The motion module samples movement data from the motion sensor using the motion sensor driver.
115130

@@ -118,7 +133,7 @@ The same is true for the names of sensor configuration options.
118133
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.
119134

120135
Sampling thread
121-
===============
136+
---------------
122137

123138
The motion module uses a dedicated sampling thread to sample data from the motion sensor.
124139
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.
129144
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).
130145

131146
Sampling pipeline
132-
=================
147+
-----------------
133148

134149
The motion module starts in ``STATE_DISABLED`` and after initialization enters ``STATE_DISCONNECTED``.
135150
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:
150165
The module continues to sample data until disconnection or when there is no motion detected.
151166
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.
152167
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

Comments
 (0)