Skip to content

Commit

Permalink
Fix lower cpi bound on PMW33XX (qmk#22108)
Browse files Browse the repository at this point in the history
  • Loading branch information
GDsouza authored and mechlovin committed Oct 25, 2023
1 parent 625898f commit d1fc6a9
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion drivers/sensors/pmw3320.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ uint16_t pmw3320_get_cpi(void) {
}

void pmw3320_set_cpi(uint16_t cpi) {
uint8_t cpival = constrain((cpi / PMW3320_CPI_STEP) - 1U, 0, (PMW3320_CPI_MAX / PMW3320_CPI_STEP) - 1U);
uint8_t cpival = constrain((cpi / PMW3320_CPI_STEP), (PMW3320_CPI_MIN / PMW3320_CPI_STEP), (PMW3320_CPI_MAX / PMW3320_CPI_STEP)) - 1U;
// Fifth bit is probably a control bit.
// PMW3320 datasheet don't have any info on this, so this is a pure guess.
pmw3320_write_reg(REG_Resolution, 0x20 | cpival);
Expand Down
2 changes: 1 addition & 1 deletion drivers/sensors/pmw3360.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void pmw33xx_set_cpi(uint8_t sensor, uint16_t cpi) {
return;
}

uint8_t cpival = CONSTRAIN((cpi / PMW33XX_CPI_STEP) - 1, 0, (PMW33XX_CPI_MAX / PMW33XX_CPI_STEP) - 1U);
uint8_t cpival = CONSTRAIN((cpi / PMW33XX_CPI_STEP), (PMW33XX_CPI_MIN / PMW33XX_CPI_STEP), (PMW33XX_CPI_MAX / PMW33XX_CPI_STEP)) - 1U;
pmw33xx_write(sensor, REG_Config1, cpival);
}

Expand Down
2 changes: 1 addition & 1 deletion drivers/sensors/pmw3389.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void pmw33xx_set_cpi(uint8_t sensor, uint16_t cpi) {
return;
}

uint16_t cpival = CONSTRAIN((cpi / PMW33XX_CPI_STEP) - 1, 0, (PMW33XX_CPI_MAX / PMW33XX_CPI_STEP) - 1U);
uint16_t cpival = CONSTRAIN((cpi / PMW33XX_CPI_STEP), (PMW33XX_CPI_MIN / PMW33XX_CPI_STEP), (PMW33XX_CPI_MAX / PMW33XX_CPI_STEP)) - 1U;
// Sets upper byte first for more consistent setting of cpi
pmw33xx_write(sensor, REG_Resolution_H, (cpival >> 8) & 0xFF);
pmw33xx_write(sensor, REG_Resolution_L, cpival & 0xFF);
Expand Down

0 comments on commit d1fc6a9

Please sign in to comment.