From 19f789e428e489290f6e05f663e4b8e7b7a7fb48 Mon Sep 17 00:00:00 2001 From: David Volovskiy Date: Tue, 7 Oct 2025 08:07:02 -0400 Subject: [PATCH] Made the timeout for lis2dw_read_fifo a variable --- .../sensor/accelerometer_data_acquisition_face.c | 4 ++-- watch-faces/sensor/lis2dw_monitor_face.c | 2 +- watch-library/shared/driver/lis2dw.c | 7 ++++--- watch-library/shared/driver/lis2dw.h | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/legacy/watch_faces/sensor/accelerometer_data_acquisition_face.c b/legacy/watch_faces/sensor/accelerometer_data_acquisition_face.c index 72584749..64a25a87 100644 --- a/legacy/watch_faces/sensor/accelerometer_data_acquisition_face.c +++ b/legacy/watch_faces/sensor/accelerometer_data_acquisition_face.c @@ -448,13 +448,13 @@ static void start_reading(accelerometer_data_acquisition_state_t *state) { state->records[state->pos++] = record; lis2dw_fifo_t fifo; - lis2dw_read_fifo(&fifo); // dump the fifo, this starts a fresh round of data in continue_reading + lis2dw_read_fifo(&fifo, 100); // dump the fifo, this starts a fresh round of data in continue_reading } static void continue_reading(accelerometer_data_acquisition_state_t *state) { printf("Continue reading\n"); lis2dw_fifo_t fifo; - lis2dw_read_fifo(&fifo); + lis2dw_read_fifo(&fifo, 100); fifo.count = min(fifo.count, 25); // hacky, but we need a consistent data rate; if we got a 26th data point, chuck it. uint8_t offset = 4 * (25 - fifo.count); // also hacky: we're sometimes short at the start. align to beginning of next second. diff --git a/watch-faces/sensor/lis2dw_monitor_face.c b/watch-faces/sensor/lis2dw_monitor_face.c index a717fe46..4459cf73 100644 --- a/watch-faces/sensor/lis2dw_monitor_face.c +++ b/watch-faces/sensor/lis2dw_monitor_face.c @@ -420,7 +420,7 @@ static void _monitor_update(lis2dw_monitor_state_t *state) lis2dw_fifo_t fifo; float x = 0, y = 0, z = 0; - lis2dw_read_fifo(&fifo); + lis2dw_read_fifo(&fifo, 25); if (fifo.count == 0) { return; } diff --git a/watch-library/shared/driver/lis2dw.c b/watch-library/shared/driver/lis2dw.c index fbf1ac75..6f77a94e 100644 --- a/watch-library/shared/driver/lis2dw.c +++ b/watch-library/shared/driver/lis2dw.c @@ -277,15 +277,15 @@ inline void lis2dw_disable_fifo(void) { #endif } -#define FIFO_TIMEOUT 102 // This is timeout seconds * 128[RTC_CNT_HZ]. So 800ms is 102 -bool lis2dw_read_fifo(lis2dw_fifo_t *fifo_data) { +bool lis2dw_read_fifo(lis2dw_fifo_t *fifo_data, uint32_t timeout) { + // timeout is in terms of 1/RTC_CNT_HZ seconds (likely 128 timeouts is one second) #ifdef I2C_SERCOM uint8_t temp = watch_i2c_read8(LIS2DW_ADDRESS, LIS2DW_REG_FIFO_SAMPLE); bool overrun = !!(temp & LIS2DW_FIFO_SAMPLE_OVERRUN); fifo_data->count = temp & LIS2DW_FIFO_SAMPLE_COUNT; - rtc_counter_t timeout_counter = watch_rtc_get_counter() + FIFO_TIMEOUT; + rtc_counter_t timeout_counter = watch_rtc_get_counter() + timeout; for(int i = 0; i < fifo_data->count; i++) { if (watch_rtc_get_counter() > timeout_counter) { break; @@ -296,6 +296,7 @@ bool lis2dw_read_fifo(lis2dw_fifo_t *fifo_data) { return overrun; #else (void) fifo_data; + (void) timeout; return false; #endif } diff --git a/watch-library/shared/driver/lis2dw.h b/watch-library/shared/driver/lis2dw.h index f7b0a801..d3a09dc4 100644 --- a/watch-library/shared/driver/lis2dw.h +++ b/watch-library/shared/driver/lis2dw.h @@ -345,7 +345,7 @@ void lis2dw_enable_fifo(void); void lis2dw_disable_fifo(void); -bool lis2dw_read_fifo(lis2dw_fifo_t *fifo_data); +bool lis2dw_read_fifo(lis2dw_fifo_t *fifo_data, uint32_t timeout); void lis2dw_clear_fifo(void);