Skip to content

Commit 4bf91aa

Browse files
committed
making pio_calculate_clkdiv8_from_float round to the neareset 1/256 (not lower 1/256)
1 parent 482dd59 commit 4bf91aa

File tree

1 file changed

+1
-0
lines changed
  • src/rp2_common/hardware_pio/include/hardware

1 file changed

+1
-0
lines changed

src/rp2_common/hardware_pio/include/hardware/pio.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ static inline void sm_config_set_clkdiv_int_frac(pio_sm_config *c, uint16_t div_
488488

489489
static inline void pio_calculate_clkdiv8_from_float(float div, uint32_t *div_int, uint8_t *div_frac8) {
490490
valid_params_if(HARDWARE_PIO, div >= 1 && div <= 65536);
491+
div += 0.5f / 256; // round to the nearest 1/256
491492
*div_int = (uint16_t)div;
492493
// not a strictly necessary check, but if this changes, then this method should
493494
// probably no longer be used in favor of one with a larger fraction

0 commit comments

Comments
 (0)