-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Make all float->int/frac conversions round to nearest by default #2065
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
Changes from 2 commits
4bf91aa
9ebaa64
3a693bc
c4c6256
4b84880
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -103,6 +103,11 @@ static_assert(DREQ_PWM_WRAP7 == DREQ_PWM_WRAP0 + 7, ""); | |
| }) | ||
| #endif | ||
|
|
||
| // PICO_CONFIG: PICO_PWM_CLKDIV_ROUND_NEAREST, True if floating point PWM clock divisors should be rounded to the nearest possible clock divisor rather than rounding down, type=bool, default=PICO_CLKDIV_ROUND_NEAREST, group-hardware_pio | ||
| #ifndef PICO_PWM_CLKDIV_ROUND_NEAREST | ||
| #define PICO_PWM_CLKDIV_ROUND_NEAREST PICO_CLKDIV_ROUND_NEAREST | ||
| #endif | ||
|
|
||
| static inline void check_slice_num_param(__unused uint slice_num) { | ||
| valid_params_if(HARDWARE_PWM, slice_num < NUM_PWM_SLICES); | ||
| } | ||
|
|
@@ -155,6 +160,9 @@ static inline void pwm_config_set_phase_correct(pwm_config *c, bool phase_correc | |
| */ | ||
| static inline void pwm_config_set_clkdiv(pwm_config *c, float div) { | ||
| valid_params_if(HARDWARE_PWM, div >= 1.f && div < 256.f); | ||
| #if PICO_PWM_CLKDIV_ROUND_NEAREST | ||
| div += 0.5f / (1 << PWM_CH0_DIV_INT_LSB); // round to the nearest fraction | ||
|
||
| #endif | ||
| c->div = (uint32_t)(div * (float)(1u << PWM_CH0_DIV_INT_LSB)); | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.