Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix lower cpi bound on PMW33XX #22108

Merged
merged 1 commit into from
Sep 23, 2023
Merged

Conversation

GDsouza
Copy link
Contributor

@GDsouza GDsouza commented Sep 22, 2023

Move subtraction after CONSTRAIN to prevent unsigned int wrap on PMW3320, PMW3360, PMW3389

Description

These sensors expect a value between 0 and CPI_MAX/CPI_STEP - 1 Subtracting 1 from cpi/CPI_STEP within the CONSTRAIN macro causes a wrap to the maximum when attempting to set cpi less than CPI_STEP.

Setting the bounds for CONSTRAIN to be between 1 and CPI_MAX/CPI_STEP allows impossibly small cpi values to be set to the minumum CPI of the sensor, instead of the maximum.

Tested on Ploopy Classic Trackball (PMW3360)

Types of Changes

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Keyboard (addition or update)
  • Keymap/layout/userspace (addition or update)
  • Documentation

Issues Fixed or Closed by This PR

  • Fix incorrect handling of cpi when setting a cpi that is smaller than the minimum cpi on PMW3360, PMW3389, PMW3320

Checklist

  • My code follows the code style of this project: C, Python
  • I have read the PR Checklist document and have made the appropriate changes.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have tested the changes and verified that they work and don't break anything (as well as I can manage).

Move subtraction after CONSTRAIN to prevent unsigned int wrap

These sensors expect a value between `0` and `CPI_MAX/CPI_STEP - 1`
Subtracting 1 from `cpi/CPI_STEP` within the `CONSTRAIN` macro causes a
wrap to the maximum when attempting to set `cpi` less than `CPI_STEP`.

Setting the bounds for `CONSTRAIN` to be between `1` and
`CPI_MAX/CPI_STEP` allows impossibly small `cpi` values to be set to the
minumum CPI of the sensor, instead of the maximum.
@github-actions github-actions bot added the core label Sep 22, 2023
@GDsouza
Copy link
Contributor Author

GDsouza commented Sep 22, 2023

@drashna Seems like just the PMW33XX sensors are affected by this. Didn't notice similar handling in the other sensors.

@drashna drashna requested review from KarlK90 and a team September 23, 2023 18:38
@drashna drashna merged commit 9c34007 into qmk:develop Sep 23, 2023
@GDsouza GDsouza deleted the pmw33xx_constrain branch September 26, 2023 14:51
mechlovin pushed a commit to mechlovin/qmk_firmware that referenced this pull request Oct 25, 2023
christrotter pushed a commit to christrotter/qmk_firmware that referenced this pull request Nov 28, 2023
zgagnon pushed a commit to zgagnon/qmk_firmware_waterfowl that referenced this pull request Dec 15, 2023
future-figs pushed a commit to future-figs/qmk_firmware that referenced this pull request Dec 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants