Skip to content

Sync Klipper#7232: rp2040: Avoid run-time divides - #1002

Merged
rogerlz merged 5 commits into
mainfrom
klipper-pr-7232
Oct 5, 2026
Merged

rogerlz merged 5 commits into
mainfrom
klipper-pr-7232

Conversation

@rogerlz

@rogerlz rogerlz commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Cherry-picks the upstream rp2040 work to avoid run-time divides, keeping original authorship:

With this the rp2040 no longer needs HAVE_SOFTWARE_DIVIDE_REQUIRED: the build has no software divide left and check-software-div.sh passes without it.

Rework the comparison to avoid using an expensive divide operation.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
There is no need for elaborate math scaling of the cycle_time value to
the local clock ticks.  Just hardcode a scale of 16, which simplifies
the math calculations.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Use a MAX_PWM of 256 (instead of 255) to avoid an expensive run-time
divide operation.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Use a different method of setting the hardware pwm registers so that
the actual cycle_time is much closer to the requested cycle_time.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Rework the code slightly to avoid an expensive software divide when
calculating the rate in i2c.c .

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
@rogerlz
rogerlz merged commit 534e6cc into main Oct 5, 2026
2 checks passed
@rogerlz
rogerlz deleted the klipper-pr-7232 branch October 5, 2026 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants