From d7f0c3fd094237eff301d3c28a2efda0b8f0302d Mon Sep 17 00:00:00 2001 From: Drashna Jael're Date: Mon, 17 Jan 2022 17:35:13 -0800 Subject: [PATCH 1/4] [Bug][Core] Fix pmw33xx firmware upload --- docs/feature_pointing_device.md | 5 +++-- drivers/sensors/pmw3360.c | 12 ++++-------- drivers/sensors/pmw3389.c | 10 ++++------ 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/docs/feature_pointing_device.md b/docs/feature_pointing_device.md index 5f1260eede40..60e3da850523 100644 --- a/docs/feature_pointing_device.md +++ b/docs/feature_pointing_device.md @@ -150,8 +150,8 @@ The PMW 3360 is an SPI driven optical sensor, that uses a built in IR LED for su |`PMW3360_SPI_MODE` | (Optional) Sets the SPI Mode for the sensor. | `3` | |`PMW3360_SPI_DIVISOR` | (Optional) Sets the SPI Divisor used for SPI communication. | _varies_ | |`PMW3360_LIFTOFF_DISTANCE` | (Optional) Sets the lift off distance at run time | `0x02` | -|`ROTATIONAL_TRANSFORM_ANGLE` | (Optional) Allows for the sensor data to be rotated +/- 127 degrees directly in the sensor. | `0` | -|`PMW3360_LEGACY_FIRMWARE_UPLOAD` | (Optional) Switches to older, manual upload of firmware, for compatibility. | _not defined_ | +|`ROTATIONAL_TRANSFORM_ANGLE` | (Optional) Allows for the sensor data to be rotated +/- 127 degrees directly in the sensor.| `0` | +|`PMW3360_FIRMWARE_UPLOAD_COMPATIBILITY` | (Optional) Includes 15us wait between firmware blocks for compatibility. | _not defined_ | The CPI range is 100-12000, in increments of 100. Defaults to 1600 CPI. @@ -174,6 +174,7 @@ The PMW 3389 is an SPI driven optical sensor, that uses a built in IR LED for su |`PMW3389_SPI_DIVISOR` | (Optional) Sets the SPI Divisor used for SPI communication. | _varies_ | |`PMW3389_LIFTOFF_DISTANCE` | (Optional) Sets the lift off distance at run time | `0x02` | |`ROTATIONAL_TRANSFORM_ANGLE` | (Optional) Allows for the sensor data to be rotated +/- 30 degrees directly in the sensor. | `0` | +|`PMW3389_FIRMWARE_UPLOAD_COMPATIBILITY` | (Optional) Includes 15us wait between firmware blocks for compatibility. | _not defined_ | The CPI range is 50-16000, in increments of 50. Defaults to 2000 CPI. diff --git a/drivers/sensors/pmw3360.c b/drivers/sensors/pmw3360.c index 0dac600cc247..66dfde96d238 100644 --- a/drivers/sensors/pmw3360.c +++ b/drivers/sensors/pmw3360.c @@ -206,16 +206,12 @@ void pmw3360_upload_firmware(void) { spi_write(REG_SROM_Load_Burst | 0x80); wait_us(15); -#ifdef PMW3360_LEGACY_FIRMWARE_UPLOAD - unsigned char c; - for (int i = 0; i < FIRMWARE_LENGTH; i++) { - c = (unsigned char)pgm_read_byte(firmware_data + i); - spi_write(c); + for (uint16_t i = 0; i < FIRMWARE_LENGTH; i++) { + spi_write(pgm_read_byte(firmware_data + i)); +#ifdef PMW3360_FIRMWARE_UPLOAD_COMPATIBILITY wait_us(15); - } -#else - spi_transmit(firmware_data, sizeof(firmware_data)); #endif + } wait_us(200); pmw3360_read(REG_SROM_ID); diff --git a/drivers/sensors/pmw3389.c b/drivers/sensors/pmw3389.c index d6f02b6a591c..6f19ed94f5c6 100644 --- a/drivers/sensors/pmw3389.c +++ b/drivers/sensors/pmw3389.c @@ -210,14 +210,12 @@ void pmw3389_upload_firmware(void) { spi_write(REG_SROM_Load_Burst | 0x80); wait_us(15); - // legacy only for PMW3389 spi_transmit failed to load firmware - unsigned char c; - for (int i = 0; i < FIRMWARE_LENGTH; i++) { - c = (unsigned char)pgm_read_byte(firmware_data + i); - spi_write(c); + for (uint16_t i = 0; i < FIRMWARE_LENGTH; i++) { + spi_write(pgm_read_byte(firmware_data + i)); +#ifdef PMW3389_FIRMWARE_UPLOAD_COMPATIBILITY wait_us(15); +#endif } - wait_us(200); pmw3389_read(REG_SROM_ID); From 45884e6ee62eda58df1c7929e007615bd0027a7c Mon Sep 17 00:00:00 2001 From: Drashna Jael're Date: Mon, 17 Jan 2022 18:04:43 -0800 Subject: [PATCH 2/4] compatibility? --- docs/feature_pointing_device.md | 4 ++-- drivers/sensors/pmw3360.c | 2 +- drivers/sensors/pmw3389.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/feature_pointing_device.md b/docs/feature_pointing_device.md index 60e3da850523..2e4d7088a52b 100644 --- a/docs/feature_pointing_device.md +++ b/docs/feature_pointing_device.md @@ -151,7 +151,7 @@ The PMW 3360 is an SPI driven optical sensor, that uses a built in IR LED for su |`PMW3360_SPI_DIVISOR` | (Optional) Sets the SPI Divisor used for SPI communication. | _varies_ | |`PMW3360_LIFTOFF_DISTANCE` | (Optional) Sets the lift off distance at run time | `0x02` | |`ROTATIONAL_TRANSFORM_ANGLE` | (Optional) Allows for the sensor data to be rotated +/- 127 degrees directly in the sensor.| `0` | -|`PMW3360_FIRMWARE_UPLOAD_COMPATIBILITY` | (Optional) Includes 15us wait between firmware blocks for compatibility. | _not defined_ | +|`PMW3360_FIRMWARE_UPLOAD_FAST` | (Optional) Skips the 15us wait between firmware blocks. | _not defined_ | The CPI range is 100-12000, in increments of 100. Defaults to 1600 CPI. @@ -174,7 +174,7 @@ The PMW 3389 is an SPI driven optical sensor, that uses a built in IR LED for su |`PMW3389_SPI_DIVISOR` | (Optional) Sets the SPI Divisor used for SPI communication. | _varies_ | |`PMW3389_LIFTOFF_DISTANCE` | (Optional) Sets the lift off distance at run time | `0x02` | |`ROTATIONAL_TRANSFORM_ANGLE` | (Optional) Allows for the sensor data to be rotated +/- 30 degrees directly in the sensor. | `0` | -|`PMW3389_FIRMWARE_UPLOAD_COMPATIBILITY` | (Optional) Includes 15us wait between firmware blocks for compatibility. | _not defined_ | +|`PMW3389_FIRMWARE_UPLOAD_FAST` | (Optional) Skips the 15us wait between firmware blocks. | _not defined_ | The CPI range is 50-16000, in increments of 50. Defaults to 2000 CPI. diff --git a/drivers/sensors/pmw3360.c b/drivers/sensors/pmw3360.c index 66dfde96d238..8d1b08e22be0 100644 --- a/drivers/sensors/pmw3360.c +++ b/drivers/sensors/pmw3360.c @@ -208,7 +208,7 @@ void pmw3360_upload_firmware(void) { for (uint16_t i = 0; i < FIRMWARE_LENGTH; i++) { spi_write(pgm_read_byte(firmware_data + i)); -#ifdef PMW3360_FIRMWARE_UPLOAD_COMPATIBILITY +#ifndef PMW3360_FIRMWARE_UPLOAD_FAST wait_us(15); #endif } diff --git a/drivers/sensors/pmw3389.c b/drivers/sensors/pmw3389.c index 6f19ed94f5c6..963925bd380f 100644 --- a/drivers/sensors/pmw3389.c +++ b/drivers/sensors/pmw3389.c @@ -212,7 +212,7 @@ void pmw3389_upload_firmware(void) { for (uint16_t i = 0; i < FIRMWARE_LENGTH; i++) { spi_write(pgm_read_byte(firmware_data + i)); -#ifdef PMW3389_FIRMWARE_UPLOAD_COMPATIBILITY +#ifndef PMW3389_FIRMWARE_UPLOAD_FAST wait_us(15); #endif } From 892ce42ee604d166f73546943911413c254cfa75 Mon Sep 17 00:00:00 2001 From: Drashna Jael're Date: Tue, 18 Jan 2022 08:25:29 -0800 Subject: [PATCH 3/4] Include adns9800 in changes --- docs/feature_pointing_device.md | 15 ++++++++------- drivers/sensors/adns9800.c | 8 ++++---- drivers/sensors/adns9800_srom_A6.h | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/docs/feature_pointing_device.md b/docs/feature_pointing_device.md index 2e4d7088a52b..b775e59555b9 100644 --- a/docs/feature_pointing_device.md +++ b/docs/feature_pointing_device.md @@ -40,13 +40,14 @@ POINTING_DEVICE_DRIVER = adns9800 The ADNS 9800 is an SPI driven optical sensor, that uses laser output for surface tracking. -| Setting | Description | Default | -|------------------------|------------------------------------------------------------------------|---------------| -|`ADNS9800_CLOCK_SPEED` | (Optional) Sets the clock speed that the sensor runs at. | `2000000` | -|`ADNS9800_SPI_LSBFIRST` | (Optional) Sets the Least/Most Significant Byte First setting for SPI. | `false` | -|`ADNS9800_SPI_MODE` | (Optional) Sets the SPI Mode for the sensor. | `3` | -|`ADNS9800_SPI_DIVISOR` | (Optional) Sets the SPI Divisor used for SPI communication. | _varies_ | -|`ADNS9800_CS_PIN` | (Required) Sets the Cable Select pin connected to the sensor. | _not defined_ | +| Setting | Description | Default | +|--------------------------------|------------------------------------------------------------------------|---------------| +|`ADNS9800_CLOCK_SPEED` | (Optional) Sets the clock speed that the sensor runs at. | `2000000` | +|`ADNS9800_SPI_LSBFIRST` | (Optional) Sets the Least/Most Significant Byte First setting for SPI. | `false` | +|`ADNS9800_SPI_MODE` | (Optional) Sets the SPI Mode for the sensor. | `3` | +|`ADNS9800_SPI_DIVISOR` | (Optional) Sets the SPI Divisor used for SPI communication. | _varies_ | +|`ADNS9800_CS_PIN` | (Required) Sets the Cable Select pin connected to the sensor. | _not defined_ | +|`ADNS9800_FIRMWARE_UPLOAD_FAST` | (Optional) Skips the 15us wait between firmware blocks. | _not defined_ | The CPI range is 800-8200, in increments of 200. Defaults to 1800 CPI. diff --git a/drivers/sensors/adns9800.c b/drivers/sensors/adns9800.c index 425cf9912f2e..146fa1cb8fda 100644 --- a/drivers/sensors/adns9800.c +++ b/drivers/sensors/adns9800.c @@ -135,11 +135,11 @@ void adns9800_init() { wait_us(15); // send all bytes of the firmware - unsigned char c; - for (int i = 0; i < FIRMWARE_LENGTH; i++) { - c = (unsigned char)pgm_read_byte(adns9800_firmware_data + i); - spi_write(c); + for (uint16_t i = 0; i < FIRMWARE_LENGTH; i++) { + spi_write(pgm_read_byte(firmware_data + i)); +#ifndef ADNS9800_FIRMWARE_UPLOAD_FAST wait_us(15); +#endif } spi_stop(); diff --git a/drivers/sensors/adns9800_srom_A6.h b/drivers/sensors/adns9800_srom_A6.h index d86ecbbd9ebc..e698a401b949 100644 --- a/drivers/sensors/adns9800_srom_A6.h +++ b/drivers/sensors/adns9800_srom_A6.h @@ -6,7 +6,7 @@ // clang-format off -const uint8_t adns9800_firmware_data[FIRMWARE_LENGTH] PROGMEM = { +const uint8_t firmware_data[FIRMWARE_LENGTH] PROGMEM = { 0x03, 0xA6, 0x68, 0x1E, 0x7D, 0x10, 0x7E, 0x7E, 0x5F, 0x1C, 0xB8, 0xF2, 0x47, 0x0C, 0x7B, 0x74, 0x4B, 0x14, 0x8B, 0x75, 0x66, 0x51, 0x0B, 0x8C, 0x76, 0x74, 0x4B, 0x14, 0xAA, 0xD6, 0x0F, 0x9C, 0xBA, 0xF6, 0x6E, 0x3F, 0xDD, 0x38, 0xD5, 0x02, 0x80, 0x9B, 0x82, 0x6D, 0x58, 0x13, 0xA4, 0xAB, From 764a382f4d88a865c1ab0b36a17dad3b10567bcf Mon Sep 17 00:00:00 2001 From: Drashna Jael're Date: Tue, 18 Jan 2022 18:04:51 -0800 Subject: [PATCH 4/4] Remove fast upload for adns9800 sensor --- docs/feature_pointing_device.md | 1 - drivers/sensors/adns9800.c | 2 -- 2 files changed, 3 deletions(-) diff --git a/docs/feature_pointing_device.md b/docs/feature_pointing_device.md index b775e59555b9..84ab88573899 100644 --- a/docs/feature_pointing_device.md +++ b/docs/feature_pointing_device.md @@ -47,7 +47,6 @@ The ADNS 9800 is an SPI driven optical sensor, that uses laser output for surfac |`ADNS9800_SPI_MODE` | (Optional) Sets the SPI Mode for the sensor. | `3` | |`ADNS9800_SPI_DIVISOR` | (Optional) Sets the SPI Divisor used for SPI communication. | _varies_ | |`ADNS9800_CS_PIN` | (Required) Sets the Cable Select pin connected to the sensor. | _not defined_ | -|`ADNS9800_FIRMWARE_UPLOAD_FAST` | (Optional) Skips the 15us wait between firmware blocks. | _not defined_ | The CPI range is 800-8200, in increments of 200. Defaults to 1800 CPI. diff --git a/drivers/sensors/adns9800.c b/drivers/sensors/adns9800.c index 146fa1cb8fda..d167841968d0 100644 --- a/drivers/sensors/adns9800.c +++ b/drivers/sensors/adns9800.c @@ -137,9 +137,7 @@ void adns9800_init() { // send all bytes of the firmware for (uint16_t i = 0; i < FIRMWARE_LENGTH; i++) { spi_write(pgm_read_byte(firmware_data + i)); -#ifndef ADNS9800_FIRMWARE_UPLOAD_FAST wait_us(15); -#endif } spi_stop();