diff --git a/src/rp2_common/hardware_pio/include/hardware/pio.h b/src/rp2_common/hardware_pio/include/hardware/pio.h index 50e648e2e..e7495ed4d 100644 --- a/src/rp2_common/hardware_pio/include/hardware/pio.h +++ b/src/rp2_common/hardware_pio/include/hardware/pio.h @@ -468,19 +468,29 @@ static inline void sm_config_set_sideset(pio_sm_config *c, uint bit_count, bool * * \param c Pointer to the configuration structure to modify * \param div_int Integer part of the divisor - * \param div_frac Fractional part in 1/256ths + * \param div_frac8 Fractional part in 1/256ths * \sa sm_config_set_clkdiv() */ -static inline void sm_config_set_clkdiv_int_frac(pio_sm_config *c, uint16_t div_int, uint8_t div_frac) { - invalid_params_if(HARDWARE_PIO, div_int == 0 && div_frac != 0); +static inline void sm_config_set_clkdiv_int_frac8(pio_sm_config *c, uint16_t div_int, uint8_t div_frac8) { + invalid_params_if(HARDWARE_PIO, div_int == 0 && div_frac8 != 0); + static_assert(PIO_SM0_CLKDIV_INT_MSB - PIO_SM0_CLKDIV_INT_LSB == 15, ""); + static_assert(PIO_SM0_CLKDIV_FRAC_MSB - PIO_SM0_CLKDIV_FRAC_LSB == 7, ""); c->clkdiv = - (((uint)div_frac) << PIO_SM0_CLKDIV_FRAC_LSB) | + (((uint)div_frac8) << PIO_SM0_CLKDIV_FRAC_LSB) | (((uint)div_int) << PIO_SM0_CLKDIV_INT_LSB); } -static inline void pio_calculate_clkdiv_from_float(float div, uint16_t *div_int, uint8_t *div_frac) { +// backwards compatibility +static inline void sm_config_set_clkdiv_int_frac(pio_sm_config *c, uint16_t div_int, uint8_t div_frac8) { + sm_config_set_clkdiv_int_frac8(c, div_int, div_frac8); +} + +static inline void pio_calculate_clkdiv8_from_float(float div, uint16_t *div_int, uint8_t *div_frac) { valid_params_if(HARDWARE_PIO, div >= 1 && div <= 65536); *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 + static_assert(PIO_SM0_CLKDIV_FRAC_MSB - PIO_SM0_CLKDIV_FRAC_LSB == 7, ""); if (*div_int == 0) { *div_frac = 0; } else { @@ -506,8 +516,8 @@ static inline void pio_calculate_clkdiv_from_float(float div, uint16_t *div_int, static inline void sm_config_set_clkdiv(pio_sm_config *c, float div) { uint16_t div_int; uint8_t div_frac; - pio_calculate_clkdiv_from_float(div, &div_int, &div_frac); - sm_config_set_clkdiv_int_frac(c, div_int, div_frac); + pio_calculate_clkdiv8_from_float(div, &div_int, &div_frac); + sm_config_set_clkdiv_int_frac8(c, div_int, div_frac); } /*! \brief Set the wrap addresses in a state machine configuration @@ -664,7 +674,7 @@ static inline pio_sm_config pio_get_default_sm_config(void) { #if PICO_PIO_USE_GPIO_BASE c.pinhi = -1; #endif - sm_config_set_clkdiv_int_frac(&c, 1, 0); + sm_config_set_clkdiv_int_frac8(&c, 1, 0); sm_config_set_wrap(&c, 0, 31); sm_config_set_in_shift(&c, true, false, 32); sm_config_set_out_shift(&c, true, false, 32); @@ -1649,6 +1659,7 @@ static inline void pio_sm_set_clkdiv_int_frac8(PIO pio, uint sm, uint16_t div_in check_pio_param(pio); check_sm_param(sm); invalid_params_if(HARDWARE_PIO, div_int == 0 && div_frac8 != 0); + static_assert(PIO_SM0_CLKDIV_INT_MSB - PIO_SM0_CLKDIV_INT_LSB == 15, ""); static_assert(PIO_SM0_CLKDIV_FRAC_MSB - PIO_SM0_CLKDIV_FRAC_LSB == 7, ""); pio->sm[sm].clkdiv = (((uint)div_frac8) << PIO_SM0_CLKDIV_FRAC_LSB) | @@ -1672,8 +1683,8 @@ static inline void pio_sm_set_clkdiv(PIO pio, uint sm, float div) { check_sm_param(sm); uint16_t div_int; uint8_t div_frac; - pio_calculate_clkdiv_from_float(div, &div_int, &div_frac); - pio_sm_set_clkdiv_int_frac(pio, sm, div_int, div_frac); + pio_calculate_clkdiv8_from_float(div, &div_int, &div_frac); + pio_sm_set_clkdiv_int_frac8(pio, sm, div_int, div_frac); } /*! \brief Clear a state machine's TX and RX FIFOs diff --git a/src/rp2_common/hardware_pwm/include/hardware/pwm.h b/src/rp2_common/hardware_pwm/include/hardware/pwm.h index 50dac53fe..684c0c1c0 100644 --- a/src/rp2_common/hardware_pwm/include/hardware/pwm.h +++ b/src/rp2_common/hardware_pwm/include/hardware/pwm.h @@ -171,14 +171,15 @@ static inline void pwm_config_set_clkdiv(pwm_config *c, float div) { */ static inline void pwm_config_set_clkdiv_int_frac4(pwm_config *c, uint8_t div_int, uint8_t div_frac4) { valid_params_if(HARDWARE_PWM, div_int >= 1); + static_assert(PWM_CH0_DIV_INT_MSB - PWM_CH0_DIV_INT_LSB == 7, ""); static_assert(PWM_CH0_DIV_FRAC_MSB - PWM_CH0_DIV_FRAC_LSB == 3, ""); valid_params_if(HARDWARE_PWM, div_frac4 < 16); c->div = (((uint)div_int) << PWM_CH0_DIV_INT_LSB) | (((uint)div_frac4) << PWM_CH0_DIV_FRAC_LSB); } // backwards compatibility -static inline void pwm_config_set_clkdiv_int_frac(pwm_config *c, uint8_t integer, uint8_t frac4) { - pwm_config_set_clkdiv_int_frac4(c, integer, frac4); +static inline void pwm_config_set_clkdiv_int_frac(pwm_config *c, uint8_t div_int, uint8_t div_frac4) { + pwm_config_set_clkdiv_int_frac4(c, div_int, div_frac4); } /** \brief Set PWM clock divider in a PWM configuration @@ -193,7 +194,7 @@ static inline void pwm_config_set_clkdiv_int_frac(pwm_config *c, uint8_t integer */ static inline void pwm_config_set_clkdiv_int(pwm_config *c, uint div) { valid_params_if(HARDWARE_PWM, div >= 1 && div < 256); - pwm_config_set_clkdiv_int_frac(c, (uint8_t)div, 0); + pwm_config_set_clkdiv_int_frac8(c, (uint8_t)div, 0); } /** \brief Set PWM counting mode in a PWM configuration @@ -462,7 +463,7 @@ static inline void pwm_set_clkdiv(uint slice_num, float divider) { valid_params_if(HARDWARE_PWM, divider >= 1.f && divider < 256.f); uint8_t i = (uint8_t)divider; uint8_t f = (uint8_t)((divider - i) * (0x01 << 4)); - pwm_set_clkdiv_int_frac(slice_num, i, f); + pwm_set_clkdiv_int_frac8(slice_num, i, f); } /** \brief Set PWM output polarity diff --git a/src/rp2_common/pico_cyw43_driver/cyw43_bus_pio_spi.c b/src/rp2_common/pico_cyw43_driver/cyw43_bus_pio_spi.c index 0339571dd..d7307aee8 100644 --- a/src/rp2_common/pico_cyw43_driver/cyw43_bus_pio_spi.c +++ b/src/rp2_common/pico_cyw43_driver/cyw43_bus_pio_spi.c @@ -43,14 +43,14 @@ #if !CYW43_PIO_CLOCK_DIV_DYNAMIC #define cyw43_pio_clock_div_int CYW43_PIO_CLOCK_DIV_INT -#define cyw43_pio_clock_div_frac CYW43_PIO_CLOCK_DIV_FRAC +#define cyw43_pio_clock_div_frac8 CYW43_PIO_CLOCK_DIV_FRAC8 #else static uint16_t cyw43_pio_clock_div_int = CYW43_PIO_CLOCK_DIV_INT; -static uint8_t cyw43_pio_clock_div_frac = CYW43_PIO_CLOCK_DIV_FRAC; +static uint8_t cyw43_pio_clock_div_frac8 = CYW43_PIO_CLOCK_DIV_FRAC8; -void cyw43_set_pio_clock_divisor(uint16_t clock_div_int, uint8_t clock_div_frac) { +void cyw43_set_pio_clock_divisor(uint16_t clock_div_int, uint8_t clock_div_frac8) { cyw43_pio_clock_div_int = clock_div_int; - cyw43_pio_clock_div_frac = clock_div_frac; + cyw43_pio_clock_div_frac8 = clock_div_frac8; } #endif @@ -139,7 +139,7 @@ int cyw43_spi_init(cyw43_int_t *self) { bus_data->pio_offset = pio_add_program(bus_data->pio, &SPI_PROGRAM_FUNC); pio_sm_config config = SPI_PROGRAM_GET_DEFAULT_CONFIG_FUNC(bus_data->pio_offset); - sm_config_set_clkdiv_int_frac(&config, cyw43_pio_clock_div_int, cyw43_pio_clock_div_frac); + sm_config_set_clkdiv_int_frac8(&config, cyw43_pio_clock_div_int, cyw43_pio_clock_div_frac8); hw_write_masked(&pads_bank0_hw->io[CLOCK_PIN], (uint)PADS_DRIVE_STRENGTH << PADS_BANK0_GPIO0_DRIVE_LSB, PADS_BANK0_GPIO0_DRIVE_BITS diff --git a/src/rp2_common/pico_cyw43_driver/include/pico/cyw43_driver.h b/src/rp2_common/pico_cyw43_driver/include/pico/cyw43_driver.h index d35363ec1..f46680526 100644 --- a/src/rp2_common/pico_cyw43_driver/include/pico/cyw43_driver.h +++ b/src/rp2_common/pico_cyw43_driver/include/pico/cyw43_driver.h @@ -54,13 +54,20 @@ void cyw43_driver_deinit(struct async_context *context); #endif #endif -// PICO_CONFIG: CYW43_PIO_CLOCK_DIV_FRAC, Fractional part of the clock divider for communication with the wireless chip, type=bool, default=0, group=pico_cyw43_driver -#ifndef CYW43_PIO_CLOCK_DIV_FRAC -#define CYW43_PIO_CLOCK_DIV_FRAC 0 +// PICO_CONFIG: CYW43_PIO_CLOCK_DIV_FRAC8, Fractional part of the clock divider for communication with the wireless chip 0-255, type=bool, default=0, group=pico_cyw43_driver +#ifndef CYW43_PIO_CLOCK_DIV_FRAC8 +#ifdef CYW43_PIO_CLOCK_DIV_FRAC +#define CYW43_PIO_CLOCK_DIV_FRAC8 CYW43_PIO_CLOCK_DIV_FRAC +#else +#define CYW43_PIO_CLOCK_DIV_FRAC8 0 +#endif #endif #if CYW43_PIO_CLOCK_DIV_DYNAMIC -void cyw43_set_pio_clock_divisor(uint16_t clock_div_int, uint8_t clock_div_frac); +void cyw43_set_pio_clock_divider_int_frac8(uint16_t clock_div_int, uint8_t clock_div_frac8); +static inline void cyw43_set_pio_clock_divisor(uint16_t clock_div_int, uint8_t clock_div_frac8) { + return cyw43_set_pio_clock_divider_int_frac8(clock_div_int, clock_div_frac8); +} #endif #ifdef __cplusplus