Skip to content

Commit

Permalink
applications: nrf_desktop: Change ts resolution to us in motion sim
Browse files Browse the repository at this point in the history
Make the Motion Simulated module rely on the cycle count and change
timestamp resolution from milliseconds to microseconds to increase
accuracy.

Jira: NCSDK-22778

Signed-off-by: Mateusz Kapala <mateusz.kapala@nordicsemi.no>
  • Loading branch information
mkapala-nordic authored and nordicjm committed Jul 26, 2023
1 parent ce3807f commit 836b04d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
7 changes: 4 additions & 3 deletions applications/nrf_desktop/src/hw_interface/Kconfig.motion
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,14 @@ config DESKTOP_MOTION_RIGHT_KEY_ID
ID of key use for generating right motion.

config DESKTOP_MOTION_SIMULATED_EDGE_TIME
int "Time for transition between two points in a trajectory [ms]"
int "Time for transition between two points in a trajectory [us]"
depends on DESKTOP_MOTION_SIMULATED_ENABLE
range 8 1000000
default 16
range 8 1000000000
default 16384
help
The simulated movement data will be tracing predefined path, an eight-sided polygon.
Must be power of two (calculations speedup).
The resolution may be limited by the precision of the system's hardware clock.

config DESKTOP_MOTION_SIMULATED_SCALE_FACTOR
int "Scale factor for given shape"
Expand Down
12 changes: 11 additions & 1 deletion applications/nrf_desktop/src/hw_interface/motion_simulated.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,22 @@ static void motion_event_send(int16_t dx, int16_t dy)
APP_EVENT_SUBMIT(event);
}

static uint64_t get_timestamp(void)
{
/* Use higher resolution if available. */
if (IS_ENABLED(CONFIG_TIMER_HAS_64BIT_CYCLE_COUNTER)) {
return k_cyc_to_us_near64(k_cycle_get_64());
} else {
return k_cyc_to_us_near64(k_cycle_get_32());
}
}

static void generate_motion_event(void)
{
BUILD_ASSERT((edge_time & (edge_time - 1)) == 0,
"Edge time must be power of 2");

uint32_t t = k_uptime_get_32();
uint64_t t = get_timestamp();
size_t v1_id = (t / edge_time) % ARRAY_SIZE(coords);
size_t v2_id = (v1_id + 1) % ARRAY_SIZE(coords);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ nRF Desktop
This is done to prevent the device from powering down and waking up multiple times when an USB cable is connected.
* Disabled ``CONFIG_BOOT_SERIAL_IMG_GRP_HASH`` in MCUboot bootloader release configurations of boards that use nRF52820 SoC.
This is done to reduce the memory consumption.
* To improve the accuracy, the generation of simulated movement data in the :ref:`nrf_desktop_motion` now uses a timestamp in microseconds based on the cycle count (either :c:func:`k_cycle_get_32` or :c:func:`k_cycle_get_64` function depending on the :kconfig:option:`CONFIG_TIMER_HAS_64BIT_CYCLE_COUNTER` Kconfig option).

Thingy:53: Matter weather station
---------------------------------
Expand Down

0 comments on commit 836b04d

Please sign in to comment.