Skip to content

Commit

Permalink
Remove binary blobs from optical sensors. (qmk#24428)
Browse files Browse the repository at this point in the history
* remove pmw srom

* remove adns9800 srom

* Update drivers/sensors/pmw33xx_common.c
  • Loading branch information
daskygit authored and Max Schumann committed Feb 1, 2025
1 parent 28f3e6a commit e085250
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 789 deletions.
67 changes: 37 additions & 30 deletions drivers/sensors/adns9800.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

#include "spi_master.h"
#include "adns9800_srom_A6.h"
#include "adns9800.h"
#include "wait.h"

Expand Down Expand Up @@ -78,6 +77,14 @@
#define MSB1 0x80
// clang-format on

uint16_t __attribute__((weak)) adns9800_srom_get_length(void) {
return 0;
}

uint8_t __attribute__((weak)) adns9800_srom_get_byte(uint16_t position) {
return 0;
}

void adns9800_spi_start(void) {
spi_start(ADNS9800_CS_PIN, false, ADNS9800_SPI_MODE, ADNS9800_SPI_DIVISOR);
}
Expand Down Expand Up @@ -117,47 +124,47 @@ void adns9800_init(void) {
adns9800_read(REG_Delta_Y_L);
adns9800_read(REG_Delta_Y_H);

#ifdef ADNS9800_UPLOAD_SROM
// upload firmware

// 3k firmware mode
adns9800_write(REG_Configuration_IV, 0x02);
if (adns9800_srom_get_length() != 0) {
// upload firmware

// enable initialisation
adns9800_write(REG_SROM_Enable, 0x1d);
// 3k firmware mode
adns9800_write(REG_Configuration_IV, 0x02);

// wait a frame
wait_ms(10);
// enable initialisation
adns9800_write(REG_SROM_Enable, 0x1d);

// start SROM download
adns9800_write(REG_SROM_Enable, 0x18);
// wait a frame
wait_ms(10);

// write the SROM file
// start SROM download
adns9800_write(REG_SROM_Enable, 0x18);

adns9800_spi_start();
// write the SROM file

spi_write(REG_SROM_Load_Burst | 0x80);
wait_us(15);
adns9800_spi_start();

// send all bytes of the firmware
for (uint16_t i = 0; i < FIRMWARE_LENGTH; i++) {
spi_write(pgm_read_byte(firmware_data + i));
spi_write(REG_SROM_Load_Burst | 0x80);
wait_us(15);
}

spi_stop();
// send all bytes of the firmware
for (uint16_t i = 0; i < adns9800_srom_get_length(); i++) {
spi_write(adns9800_srom_get_byte(i));
wait_us(15);
}

wait_ms(10);
#else
// write reset value to REG_Configuration_IV
adns9800_write(REG_Configuration_IV, 0x0);
spi_stop();

// write reset value to REG_SROM_Enable
adns9800_write(REG_SROM_Enable, 0x0);
wait_ms(10);
} else {
// write reset value to REG_Configuration_IV
adns9800_write(REG_Configuration_IV, 0x0);

// wait a frame
wait_ms(10);
#endif
// write reset value to REG_SROM_Enable
adns9800_write(REG_SROM_Enable, 0x0);

// wait a frame
wait_ms(10);
}

// enable laser
uint8_t laser_ctrl0 = adns9800_read(REG_LASER_CTRL0);
Expand Down
Loading

0 comments on commit e085250

Please sign in to comment.