[Bug] Fix pmw33xx sensor corruption on get-cpi call (#23116)

master
Drashna Jaelre 2024-02-19 16:36:28 -08:00 committed by GitHub
parent 6efb71d401
commit 66780783c7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 0 deletions

View File

@ -15,6 +15,9 @@ uint16_t pmw33xx_get_cpi(uint8_t sensor) {
} }
uint8_t cpival = pmw33xx_read(sensor, REG_Config1); uint8_t cpival = pmw33xx_read(sensor, REG_Config1);
// In some cases (100, 900, 1700, 2500), reading the CPI corrupts the firmware and the sensor stops responding.
// To avoid this, we write the value back to the sensor, which seems to prevent the corruption.
pmw33xx_write(sensor, REG_Config1, cpival);
return (uint16_t)((cpival + 1) & 0xFF) * PMW33XX_CPI_STEP; return (uint16_t)((cpival + 1) & 0xFF) * PMW33XX_CPI_STEP;
} }