Skip to content

Commit

Permalink
Cleanup pwm3360 driver some more.
Browse files Browse the repository at this point in the history
Remove redundant calls to spi_start() and spi_stop(), as pmw3360_write()
will already call these.
  • Loading branch information
uqs committed Dec 23, 2021
1 parent 07c26fb commit b8b022a
Showing 1 changed file with 5 additions and 18 deletions.
23 changes: 5 additions & 18 deletions drivers/sensors/pmw3360.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,13 @@ bool pmw3360_spi_start(void) {
return status;
}

void pmw3360_spi_stop(void) {
wait_us(1);
spi_stop();
}

spi_status_t pmw3360_write(uint8_t reg_addr, uint8_t data) {
pmw3360_spi_start();

if (reg_addr != REG_Motion_Burst) {
_inBurst = false;
}

pmw3360_spi_start();
// send address of the register, with MSBit = 1 to indicate it's a write
spi_status_t status = spi_write(reg_addr | 0x80);
status = spi_write(data);
Expand Down Expand Up @@ -150,7 +146,7 @@ bool pmw3360_init(void) {

pmw3360_spi_start();
wait_us(40);
pmw3360_spi_stop();
spi_stop();
wait_us(40);

// reboot
Expand All @@ -166,7 +162,7 @@ bool pmw3360_init(void) {

pmw3360_upload_firmware();

pmw3360_spi_stop();
spi_stop();

wait_ms(10);
pmw3360_set_cpi(PMW3360_CPI);
Expand Down Expand Up @@ -213,11 +209,7 @@ void pmw3360_upload_firmware(void) {
wait_us(200);

pmw3360_read(REG_SROM_ID);

pmw3360_write(REG_Config2, 0x00);

spi_stop();
wait_ms(10);
}

bool pmw3360_check_signature(void) {
Expand All @@ -234,14 +226,12 @@ uint16_t pmw3360_get_cpi(void) {

void pmw3360_set_cpi(uint16_t cpi) {
uint8_t cpival = constrain((cpi / CPI_STEP) - 1, 0, MAX_CPI);

pmw3360_spi_start();
pmw3360_write(REG_Config1, cpival);
spi_stop();
}

report_pmw3360_t pmw3360_read_burst(void) {
report_pmw3360_t report = {0};

if (!_inBurst) {
#ifdef CONSOLE_ENABLE
dprintf("burst on");
Expand All @@ -254,7 +244,6 @@ report_pmw3360_t pmw3360_read_burst(void) {
spi_write(REG_Motion_Burst);
wait_us(35); // waits for tSRAD


report.motion = spi_read();
spi_write(0x00); // skip Observation
report.dx = spi_read();
Expand Down Expand Up @@ -282,8 +271,6 @@ report_pmw3360_t pmw3360_read_burst(void) {
report.dy |= (report.mdy << 8);
report.dy = report.dy * -1;

pmw3360_spi_stop();

if (report.motion & 0b111) { // panic recovery, sometimes burst mode works weird.
_inBurst = false;
}
Expand Down

0 comments on commit b8b022a

Please sign in to comment.