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 <noreply@anthropic.com>
This commit is contained in:
Konrad Rieck
2026-08-03 18:47:14 +02:00
parent d7f8375def
commit 6f9d58bd93

View File

@ -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, &reg, 1);
watch_i2c_receive(LIS2DW_ADDRESS, (uint8_t *) fifo_data->readings, fifo_data->count * 6);
}
return overrun;