From 6f9d58bd9318ee16f724d6dd5658e1c35aecdd73 Mon Sep 17 00:00:00 2001 From: Konrad Rieck Date: Mon, 3 Aug 2026 18:47:14 +0200 Subject: [PATCH] Read the lis2dw FIFO in a single burst Replace the per-sample read loop with one burst read of the whole FIFO, cutting I2C transactions from two per sample to two per read. Co-Authored-By: Claude Opus 4.8 --- watch-library/shared/driver/lis2dw.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/watch-library/shared/driver/lis2dw.c b/watch-library/shared/driver/lis2dw.c index 196dff8f..ec82cfa5 100644 --- a/watch-library/shared/driver/lis2dw.c +++ b/watch-library/shared/driver/lis2dw.c @@ -291,12 +291,15 @@ bool lis2dw_read_fifo(lis2dw_fifo_t *fifo_data, uint32_t timeout) { fifo_data->count = 32; } - 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; - } - fifo_data->readings[i] = lis2dw_get_raw_reading(); + (void) timeout; /* unused now; kept in the signature for legacy callers */ + /* Read the whole FIFO in one burst. With address auto-increment (IF_ADD_INC) + the pointer walks OUT_X_L..OUT_Z_H and rolls over into the next FIFO slot, + so count*6 bytes returns the samples back-to-back. On this little-endian + target the raw bytes map straight onto lis2dw_reading_t (x, y, z int16). */ + if (fifo_data->count > 0) { + uint8_t reg = LIS2DW_REG_OUT_X_L | 0x80; + watch_i2c_send(LIS2DW_ADDRESS, ®, 1); + watch_i2c_receive(LIS2DW_ADDRESS, (uint8_t *) fifo_data->readings, fifo_data->count * 6); } return overrun;