From 1c03574424bfb0fa599d6cabf4ec724bfb27c21e Mon Sep 17 00:00:00 2001 From: Dasky <32983009+daskygit@users.noreply.github.com> Date: Wed, 18 Sep 2024 15:46:13 +0100 Subject: [PATCH] Fix ADNS-9800 read (#24406) --- drivers/sensors/adns9800.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/drivers/sensors/adns9800.c b/drivers/sensors/adns9800.c index 0ba26a365adf..d5e2ca625a64 100644 --- a/drivers/sensors/adns9800.c +++ b/drivers/sensors/adns9800.c @@ -67,14 +67,15 @@ #define REG_SROM_Load_Burst 0x62 #define REG_Pixel_Burst 0x64 -#define MIN_CPI 200 -#define MAX_CPI 8200 -#define CPI_STEP 200 -#define CLAMP_CPI(value) value MAX_CPI ? MAX_CPI : value -#define US_BETWEEN_WRITES 120 -#define US_BETWEEN_READS 20 -#define US_BEFORE_MOTION 100 -#define MSB1 0x80 +#define MIN_CPI 200 +#define MAX_CPI 8200 +#define CPI_STEP 200 +#define CLAMP_CPI(value) value MAX_CPI ? MAX_CPI : value +#define US_BETWEEN_WRITES 120 +#define US_BETWEEN_READS 20 +#define US_DELAY_AFTER_ADDR 100 +#define US_BEFORE_MOTION 100 +#define MSB1 0x80 // clang-format on void adns9800_spi_start(void) { @@ -92,6 +93,7 @@ void adns9800_write(uint8_t reg_addr, uint8_t data) { uint8_t adns9800_read(uint8_t reg_addr) { adns9800_spi_start(); spi_write(reg_addr & 0x7f); + wait_us(US_DELAY_AFTER_ADDR); uint8_t data = spi_read(); spi_stop(); wait_us(US_BETWEEN_READS);