RP2040: fix off-by-one PWM top issue #4192
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #4189.
The
pwmio_pwmout_obj_t
top
was 32 bits, but it's passed to pico-sdk as 16 bits. Make it 16 bits so the compiler can catch values that are too large. Then needed to force some arithmetic to be 32 bit.Maintain top as a 0 to n-1 value. It was getting set to 65536 in one case. Remove
self-> top -1
computations.Comparison check for low vs high frequency had a boundary problem at
.frequency = 1907
. Fix by using<=
comparison instead of<
.Add some bounds checking to make sure values fit in 16 bits.
Unrelated, missed getting into a previous PR: Remove extraneous include in
shared-bindings/adafruit_bus_device/SPIDevice.c
.@jedgarpark Could you test this after the artifact builds? It's more complicated than the version I gave you earlier to test.