From 4bf91aa35f9bfd7b9d977dc1c06f2405704bad9c Mon Sep 17 00:00:00 2001 From: graham sanderson Date: Tue, 19 Nov 2024 19:30:36 -0600 Subject: [PATCH] making pio_calculate_clkdiv8_from_float round to the neareset 1/256 (not lower 1/256) --- src/rp2_common/hardware_pio/include/hardware/pio.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rp2_common/hardware_pio/include/hardware/pio.h b/src/rp2_common/hardware_pio/include/hardware/pio.h index 40716dec9..5c76103d5 100644 --- a/src/rp2_common/hardware_pio/include/hardware/pio.h +++ b/src/rp2_common/hardware_pio/include/hardware/pio.h @@ -488,6 +488,7 @@ static inline void sm_config_set_clkdiv_int_frac(pio_sm_config *c, uint16_t div_ static inline void pio_calculate_clkdiv8_from_float(float div, uint32_t *div_int, uint8_t *div_frac8) { valid_params_if(HARDWARE_PIO, div >= 1 && div <= 65536); + div += 0.5f / 256; // round to the nearest 1/256 *div_int = (uint16_t)div; // not a strictly necessary check, but if this changes, then this method should // probably no longer be used in favor of one with a larger fraction