Skip to content

Commit 06b7c1c

Browse files
authored
Change div_int_frac methods to be suffixed by the number of bits of fraction e.g. div_int_frac8 (#1926)
1 parent f9eb48b commit 06b7c1c

File tree

7 files changed

+139
-59
lines changed

7 files changed

+139
-59
lines changed

src/rp2_common/hardware_clocks/clocks.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ void clocks_enable_resus(resus_callback_t resus_callback) {
228228
clocks_hw->resus.ctrl = CLOCKS_CLK_SYS_RESUS_CTRL_ENABLE_BITS | timeout;
229229
}
230230

231-
void clock_gpio_init_int_frac(uint gpio, uint src, uint32_t div_int, uint8_t div_frac) {
231+
void clock_gpio_init_int_frac16(uint gpio, uint src, uint32_t div_int, uint16_t div_frac16) {
232232
// Bit messy but it's as much code to loop through a lookup
233233
// table. The sources for each gpout generators are the same
234234
// so just call with the sources from GP0
@@ -245,10 +245,17 @@ void clock_gpio_init_int_frac(uint gpio, uint src, uint32_t div_int, uint8_t div
245245
invalid_params_if(HARDWARE_CLOCKS, true);
246246
}
247247

248+
invalid_params_if(HARDWARE_CLOCKS, div_int >> (CLOCKS_CLK_GPOUT0_DIV_INT_MSB - CLOCKS_CLK_GPOUT0_DIV_INT_LSB + 1));
248249
// Set up the gpclk generator
249250
clocks_hw->clk[gpclk].ctrl = (src << CLOCKS_CLK_GPOUT0_CTRL_AUXSRC_LSB) |
250251
CLOCKS_CLK_GPOUT0_CTRL_ENABLE_BITS;
251-
clocks_hw->clk[gpclk].div = (div_int << CLOCKS_CLK_GPOUT0_DIV_INT_LSB) | div_frac;
252+
#if CLOCKS_CLK_GPOUT0_DIV_FRAC_MSB - CLOCKS_CLK_GPOUT0_DIV_FRAC_LSB == 15
253+
clocks_hw->clk[gpclk].div = (div_int << CLOCKS_CLK_GPOUT0_DIV_INT_LSB) | (div_frac16 << CLOCKS_CLK_GPOUT0_DIV_FRAC_LSB);
254+
#elif CLOCKS_CLK_GPOUT0_DIV_FRAC_MSB - CLOCKS_CLK_GPOUT0_DIV_FRAC_LSB == 7
255+
clocks_hw->clk[gpclk].div = (div_int << CLOCKS_CLK_GPOUT0_DIV_INT_LSB) | ((div_frac16>>8u) << CLOCKS_CLK_GPOUT0_DIV_FRAC_LSB);
256+
#else
257+
#error unsupported number of fractional bits
258+
#endif
252259

253260
// Set gpio pin to gpclock function
254261
gpio_set_function(gpio, GPIO_FUNC_GPCK);

src/rp2_common/hardware_clocks/include/hardware/clocks.h

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,29 @@ void clocks_enable_resus(resus_callback_t resus_callback);
353353
*
354354
* \param gpio The GPIO pin to output the clock to. Valid GPIOs are: 21, 23, 24, 25. These GPIOs are connected to the GPOUT0-3 clock generators.
355355
* \param src The source clock. See the register field CLOCKS_CLK_GPOUT0_CTRL_AUXSRC for a full list. The list is the same for each GPOUT clock generator.
356-
* \param div_int The integer part of the value to divide the source clock by. This is useful to not overwhelm the GPIO pin with a fast clock. this is in range of 1..2^24-1.
357-
* \param div_frac The fractional part of the value to divide the source clock by. This is in range of 0..255 (/256).
356+
* \param div_int The integer part of the value to divide the source clock by. This is useful to not overwhelm the GPIO pin with a fast clock. This is in range of 1..2^24-1 on RP2040
357+
* and 1..2^16-1 on RP2350
358+
* \param div_frac16 The fractional part of the value to divide the source clock by. This is in range of 0..65535 (/65536).
358359
*/
359-
void clock_gpio_init_int_frac(uint gpio, uint src, uint32_t div_int, uint8_t div_frac);
360+
void clock_gpio_init_int_frac16(uint gpio, uint src, uint32_t div_int, uint16_t div_frac16);
361+
362+
/*! \brief Output an optionally divided clock to the specified gpio pin.
363+
* \ingroup hardware_clocks
364+
*
365+
* \param gpio The GPIO pin to output the clock to. Valid GPIOs are: 21, 23, 24, 25. These GPIOs are connected to the GPOUT0-3 clock generators.
366+
* \param src The source clock. See the register field CLOCKS_CLK_GPOUT0_CTRL_AUXSRC for a full list. The list is the same for each GPOUT clock generator.
367+
* \param div_int The integer part of the value to divide the source clock by. This is useful to not overwhelm the GPIO pin with a fast clock. This is in range of 1..2^24-1 on RP2040
368+
* and 1..2^16-1 on RP2350
369+
* \param div_frac8 The fractional part of the value to divide the source clock by. This is in range of 0..255 (/256).
370+
*/
371+
static inline void clock_gpio_init_int_frac8(uint gpio, uint src, uint32_t div_int, uint8_t div_frac8) {
372+
return clock_gpio_init_int_frac16(gpio, src, div_int, (uint16_t)(div_frac8 << 8u));
373+
}
374+
375+
// backwards compatibility
376+
static inline void clock_gpio_init_int_frac(uint gpio, uint src, uint32_t div_int, uint8_t div_frac8) {
377+
return clock_gpio_init_int_frac8(gpio, src, div_int, div_frac8);
378+
}
360379

361380
/*! \brief Output an optionally divided clock to the specified gpio pin.
362381
* \ingroup hardware_clocks
@@ -368,8 +387,15 @@ void clock_gpio_init_int_frac(uint gpio, uint src, uint32_t div_int, uint8_t div
368387
static inline void clock_gpio_init(uint gpio, uint src, float div)
369388
{
370389
uint div_int = (uint)div;
371-
uint8_t frac = (uint8_t)((div - (float)div_int) * (1u << CLOCKS_CLK_GPOUT0_DIV_INT_LSB));
372-
clock_gpio_init_int_frac(gpio, src, div_int, frac);
390+
#if CLOCKS_CLK_GPOUT0_DIV_FRAC_MSB - CLOCKS_CLK_GPOUT0_DIV_FRAC_LSB == 15
391+
uint16_t frac = (uint16_t)((div - (float)div_int) * (1u << 16));
392+
clock_gpio_init_int_frac16(gpio, src, div_int, frac);
393+
#elif CLOCKS_CLK_GPOUT0_DIV_FRAC_MSB - CLOCKS_CLK_GPOUT0_DIV_FRAC_LSB == 7
394+
uint8_t frac = (uint8_t)((div - (float)div_int) * (1u << 8));
395+
clock_gpio_init_int_frac8(gpio, src, div_int, frac);
396+
#else
397+
#error unsupported number of fractional bits
398+
#endif
373399
}
374400

375401
/*! \brief Configure a clock to come from a gpio input

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

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -468,26 +468,44 @@ static inline void sm_config_set_sideset(pio_sm_config *c, uint bit_count, bool
468468
*
469469
* \param c Pointer to the configuration structure to modify
470470
* \param div_int Integer part of the divisor
471-
* \param div_frac Fractional part in 1/256ths
471+
* \param div_frac8 Fractional part in 1/256ths
472472
* \sa sm_config_set_clkdiv()
473473
*/
474-
static inline void sm_config_set_clkdiv_int_frac(pio_sm_config *c, uint16_t div_int, uint8_t div_frac) {
475-
invalid_params_if(HARDWARE_PIO, div_int == 0 && div_frac != 0);
474+
static inline void sm_config_set_clkdiv_int_frac8(pio_sm_config *c, uint32_t div_int, uint8_t div_frac8) {
475+
static_assert(PIO_SM0_CLKDIV_INT_MSB - PIO_SM0_CLKDIV_INT_LSB == 15, "");
476+
invalid_params_if(HARDWARE_PIO, div_int >> 16);
477+
invalid_params_if(HARDWARE_PIO, div_int == 0 && div_frac8 != 0);
478+
static_assert(PIO_SM0_CLKDIV_FRAC_MSB - PIO_SM0_CLKDIV_FRAC_LSB == 7, "");
476479
c->clkdiv =
477-
(((uint)div_frac) << PIO_SM0_CLKDIV_FRAC_LSB) |
480+
(((uint)div_frac8) << PIO_SM0_CLKDIV_FRAC_LSB) |
478481
(((uint)div_int) << PIO_SM0_CLKDIV_INT_LSB);
479482
}
480483

481-
static inline void pio_calculate_clkdiv_from_float(float div, uint16_t *div_int, uint8_t *div_frac) {
484+
// backwards compatibility
485+
static inline void sm_config_set_clkdiv_int_frac(pio_sm_config *c, uint16_t div_int, uint8_t div_frac8) {
486+
sm_config_set_clkdiv_int_frac8(c, div_int, div_frac8);
487+
}
488+
489+
static inline void pio_calculate_clkdiv8_from_float(float div, uint32_t *div_int, uint8_t *div_frac8) {
482490
valid_params_if(HARDWARE_PIO, div >= 1 && div <= 65536);
483491
*div_int = (uint16_t)div;
492+
// not a strictly necessary check, but if this changes, then this method should
493+
// probably no longer be used in favor of one with a larger fraction
494+
static_assert(PIO_SM0_CLKDIV_FRAC_MSB - PIO_SM0_CLKDIV_FRAC_LSB == 7, "");
484495
if (*div_int == 0) {
485-
*div_frac = 0;
496+
*div_frac8 = 0;
486497
} else {
487-
*div_frac = (uint8_t)((div - (float)*div_int) * (1u << 8u));
498+
*div_frac8 = (uint8_t)((div - (float)*div_int) * (1u << 8u));
488499
}
489500
}
490501

502+
// backwards compatibility
503+
static inline void pio_calculate_clkdiv_from_float(float div, uint16_t *div_int16, uint8_t *div_frac8) {
504+
uint32_t div_int;
505+
pio_calculate_clkdiv8_from_float(div, &div_int, div_frac8);
506+
*div_int16 = (uint16_t) div_int;
507+
}
508+
491509
/*! \brief Set the state machine clock divider (from a floating point value) in a state machine configuration
492510
* \ingroup sm_config
493511
*
@@ -504,10 +522,10 @@ static inline void pio_calculate_clkdiv_from_float(float div, uint16_t *div_int,
504522
* although it will depend on the use case.
505523
*/
506524
static inline void sm_config_set_clkdiv(pio_sm_config *c, float div) {
507-
uint16_t div_int;
508-
uint8_t div_frac;
509-
pio_calculate_clkdiv_from_float(div, &div_int, &div_frac);
510-
sm_config_set_clkdiv_int_frac(c, div_int, div_frac);
525+
uint32_t div_int;
526+
uint8_t div_frac8;
527+
pio_calculate_clkdiv8_from_float(div, &div_int, &div_frac8);
528+
sm_config_set_clkdiv_int_frac8(c, div_int, div_frac8);
511529
}
512530

513531
/*! \brief Set the wrap addresses in a state machine configuration
@@ -664,7 +682,7 @@ static inline pio_sm_config pio_get_default_sm_config(void) {
664682
#if PICO_PIO_USE_GPIO_BASE
665683
c.pinhi = -1;
666684
#endif
667-
sm_config_set_clkdiv_int_frac(&c, 1, 0);
685+
sm_config_set_clkdiv_int_frac8(&c, 1, 0);
668686
sm_config_set_wrap(&c, 0, 31);
669687
sm_config_set_in_shift(&c, true, false, 32);
670688
sm_config_set_out_shift(&c, true, false, 32);
@@ -1643,17 +1661,25 @@ void pio_sm_drain_tx_fifo(PIO pio, uint sm);
16431661
* \param pio The PIO instance; e.g. \ref pio0 or \ref pio1
16441662
* \param sm State machine index (0..3)
16451663
* \param div_int the integer part of the clock divider
1646-
* \param div_frac the fractional part of the clock divider in 1/256s
1664+
* \param div_frac8 the fractional part of the clock divider in 1/256s
16471665
*/
1648-
static inline void pio_sm_set_clkdiv_int_frac(PIO pio, uint sm, uint16_t div_int, uint8_t div_frac) {
1666+
static inline void pio_sm_set_clkdiv_int_frac8(PIO pio, uint sm, uint32_t div_int, uint8_t div_frac8) {
16491667
check_pio_param(pio);
16501668
check_sm_param(sm);
1651-
invalid_params_if(HARDWARE_PIO, div_int == 0 && div_frac != 0);
1669+
static_assert(PIO_SM0_CLKDIV_INT_MSB - PIO_SM0_CLKDIV_INT_LSB == 15, "");
1670+
invalid_params_if(HARDWARE_PIO, div_int >> 16);
1671+
invalid_params_if(HARDWARE_PIO, div_int == 0 && div_frac8 != 0);
1672+
static_assert(PIO_SM0_CLKDIV_FRAC_MSB - PIO_SM0_CLKDIV_FRAC_LSB == 7, "");
16521673
pio->sm[sm].clkdiv =
1653-
(((uint)div_frac) << PIO_SM0_CLKDIV_FRAC_LSB) |
1674+
(((uint)div_frac8) << PIO_SM0_CLKDIV_FRAC_LSB) |
16541675
(((uint)div_int) << PIO_SM0_CLKDIV_INT_LSB);
16551676
}
16561677

1678+
// backwards compatibility
1679+
static inline void pio_sm_set_clkdiv_int_frac(PIO pio, uint sm, uint16_t div_int, uint8_t div_frac8) {
1680+
pio_sm_set_clkdiv_int_frac8(pio, sm, div_int, div_frac8);
1681+
}
1682+
16571683
/*! \brief set the current clock divider for a state machine
16581684
* \ingroup hardware_pio
16591685
*
@@ -1664,10 +1690,10 @@ static inline void pio_sm_set_clkdiv_int_frac(PIO pio, uint sm, uint16_t div_int
16641690
static inline void pio_sm_set_clkdiv(PIO pio, uint sm, float div) {
16651691
check_pio_param(pio);
16661692
check_sm_param(sm);
1667-
uint16_t div_int;
1668-
uint8_t div_frac;
1669-
pio_calculate_clkdiv_from_float(div, &div_int, &div_frac);
1670-
pio_sm_set_clkdiv_int_frac(pio, sm, div_int, div_frac);
1693+
uint32_t div_int;
1694+
uint8_t div_frac8;
1695+
pio_calculate_clkdiv8_from_float(div, &div_int, &div_frac8);
1696+
pio_sm_set_clkdiv_int_frac8(pio, sm, div_int, div_frac8);
16711697
}
16721698

16731699
/*! \brief Clear a state machine's TX and RX FIFOs

src/rp2_common/hardware_pwm/include/hardware/pwm.h

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -162,32 +162,38 @@ static inline void pwm_config_set_clkdiv(pwm_config *c, float div) {
162162
* \ingroup hardware_pwm
163163
*
164164
* \param c PWM configuration struct to modify
165-
* \param integer 8 bit integer part of the clock divider. Must be greater than or equal to 1.
166-
* \param fract 4 bit fractional part of the clock divider
165+
* \param div_int 8 bit integer part of the clock divider. Must be greater than or equal to 1.
166+
* \param div_frac4 4 bit fractional part of the clock divider
167167
*
168168
* If the divide mode is free-running, the PWM counter runs at clk_sys / div.
169169
* Otherwise, the divider reduces the rate of events seen on the B pin input (level or edge)
170170
* before passing them on to the PWM counter.
171171
*/
172-
static inline void pwm_config_set_clkdiv_int_frac(pwm_config *c, uint8_t integer, uint8_t fract) {
173-
valid_params_if(HARDWARE_PWM, integer >= 1);
174-
valid_params_if(HARDWARE_PWM, fract < 16);
175-
c->div = (((uint)integer) << PWM_CH0_DIV_INT_LSB) | (((uint)fract) << PWM_CH0_DIV_FRAC_LSB);
172+
static inline void pwm_config_set_clkdiv_int_frac4(pwm_config *c, uint32_t div_int, uint8_t div_frac4) {
173+
static_assert(PWM_CH0_DIV_INT_MSB - PWM_CH0_DIV_INT_LSB == 7, "");
174+
valid_params_if(HARDWARE_PWM, div_int >= 1 && div_int < 256);
175+
static_assert(PWM_CH0_DIV_FRAC_MSB - PWM_CH0_DIV_FRAC_LSB == 3, "");
176+
valid_params_if(HARDWARE_PWM, div_frac4 < 16);
177+
c->div = (((uint)div_int) << PWM_CH0_DIV_INT_LSB) | (((uint)div_frac4) << PWM_CH0_DIV_FRAC_LSB);
178+
}
179+
180+
// backwards compatibility
181+
static inline void pwm_config_set_clkdiv_int_frac(pwm_config *c, uint8_t div_int, uint8_t div_frac4) {
182+
pwm_config_set_clkdiv_int_frac4(c, div_int, div_frac4);
176183
}
177184

178185
/** \brief Set PWM clock divider in a PWM configuration
179186
* \ingroup hardware_pwm
180187
*
181188
* \param c PWM configuration struct to modify
182-
* \param div Integer value to reduce counting rate by. Must be greater than or equal to 1.
189+
* \param div_int Integer value to reduce counting rate by. Must be greater than or equal to 1 and less than 256.
183190
*
184191
* If the divide mode is free-running, the PWM counter runs at clk_sys / div.
185192
* Otherwise, the divider reduces the rate of events seen on the B pin input (level or edge)
186193
* before passing them on to the PWM counter.
187194
*/
188-
static inline void pwm_config_set_clkdiv_int(pwm_config *c, uint div) {
189-
valid_params_if(HARDWARE_PWM, div >= 1 && div < 256);
190-
pwm_config_set_clkdiv_int_frac(c, (uint8_t)div, 0);
195+
static inline void pwm_config_set_clkdiv_int(pwm_config *c, uint32_t div_int) {
196+
pwm_config_set_clkdiv_int_frac4(c, div_int, 0);
191197
}
192198

193199
/** \brief Set PWM counting mode in a PWM configuration
@@ -427,14 +433,20 @@ static inline void pwm_retard_count(uint slice_num) {
427433
* Set the clock divider. Counter increment will be on sysclock divided by this value, taking into account the gating.
428434
*
429435
* \param slice_num PWM slice number
430-
* \param integer 8 bit integer part of the clock divider
431-
* \param fract 4 bit fractional part of the clock divider
436+
* \param div_int 8 bit integer part of the clock divider
437+
* \param div_frac4 4 bit fractional part of the clock divider
432438
*/
433-
static inline void pwm_set_clkdiv_int_frac(uint slice_num, uint8_t integer, uint8_t fract) {
439+
static inline void pwm_set_clkdiv_int_frac4(uint slice_num, uint8_t div_int, uint8_t div_frac4) {
434440
check_slice_num_param(slice_num);
435-
valid_params_if(HARDWARE_PWM, integer >= 1);
436-
valid_params_if(HARDWARE_PWM, fract < 16);
437-
pwm_hw->slice[slice_num].div = (((uint)integer) << PWM_CH0_DIV_INT_LSB) | (((uint)fract) << PWM_CH0_DIV_FRAC_LSB);
441+
valid_params_if(HARDWARE_PWM, div_int >= 1);
442+
static_assert(PWM_CH0_DIV_FRAC_MSB - PWM_CH0_DIV_FRAC_LSB == 3, "");
443+
valid_params_if(HARDWARE_PWM, div_frac4 < 16);
444+
pwm_hw->slice[slice_num].div = (((uint)div_int) << PWM_CH0_DIV_INT_LSB) | (((uint)div_frac4) << PWM_CH0_DIV_FRAC_LSB);
445+
}
446+
447+
// backwards compatibility
448+
static inline void pwm_set_clkdiv_int_frac(uint slice_num, uint8_t div_int, uint8_t div_frac4) {
449+
pwm_set_clkdiv_int_frac4(slice_num, div_int, div_frac4);
438450
}
439451

440452
/** \brief Set PWM clock divider
@@ -450,7 +462,7 @@ static inline void pwm_set_clkdiv(uint slice_num, float divider) {
450462
valid_params_if(HARDWARE_PWM, divider >= 1.f && divider < 256.f);
451463
uint8_t i = (uint8_t)divider;
452464
uint8_t f = (uint8_t)((divider - i) * (0x01 << 4));
453-
pwm_set_clkdiv_int_frac(slice_num, i, f);
465+
pwm_set_clkdiv_int_frac4(slice_num, i, f);
454466
}
455467

456468
/** \brief Set PWM output polarity

src/rp2_common/pico_cyw43_driver/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ if (EXISTS ${PICO_CYW43_DRIVER_PATH}/${CYW43_DRIVER_TEST_FILE})
8484
# PICO_CMAKE_CONFIG: CYW43_PIO_CLOCK_DIV_INT, integer component of pio clock divider used for cyw43 comms, type=int, default=2, group=pico_cyw43_driver
8585
target_compile_definitions(cyw43_driver_picow INTERFACE CYW43_PIO_CLOCK_DIV_INT=${CYW43_PIO_CLOCK_DIV_INT})
8686
endif()
87-
if (CYW43_PIO_CLOCK_DIV_FRAC)
88-
# PICO_CMAKE_CONFIG: CYW43_PIO_CLOCK_DIV_FRAC, fractional component of pio clock divider used for cyw43 comms, type=int, default=0, group=pico_cyw43_driver
89-
target_compile_definitions(cyw43_driver_picow INTERFACE CYW43_PIO_CLOCK_DIV_FRAC=${CYW43_PIO_CLOCK_DIV_FRAC})
87+
if (CYW43_PIO_CLOCK_DIV_FRAC8)
88+
# PICO_CMAKE_CONFIG: CYW43_PIO_CLOCK_DIV_FRAC, fractional component of pio clock divider used for cyw43 comms in range 0-255, type=int, default=0, group=pico_cyw43_driver
89+
target_compile_definitions(cyw43_driver_picow INTERFACE CYW43_PIO_CLOCK_DIV_FRAC8=${CYW43_PIO_CLOCK_DIV_FRAC8})
9090
endif()
9191
if (CYW43_PIO_CLOCK_DIV_DYNAMIC)
9292
# PICO_CMAKE_CONFIG: CYW43_PIO_CLOCK_DIV_DYNAMIC, flag used to enable dynamic pio clock divider API, type=bool, default=false, group=pico_cyw43_driver

src/rp2_common/pico_cyw43_driver/cyw43_bus_pio_spi.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ static_assert((CYW43_PIN_WL_DATA_OUT < 32 && CYW43_PIN_WL_DATA_IN < 32 && CYW43_
4343

4444
#if !CYW43_PIO_CLOCK_DIV_DYNAMIC
4545
#define cyw43_pio_clock_div_int CYW43_PIO_CLOCK_DIV_INT
46-
#define cyw43_pio_clock_div_frac CYW43_PIO_CLOCK_DIV_FRAC
46+
#define cyw43_pio_clock_div_frac8 CYW43_PIO_CLOCK_DIV_FRAC8
4747
#else
48-
static uint16_t cyw43_pio_clock_div_int = CYW43_PIO_CLOCK_DIV_INT;
49-
static uint8_t cyw43_pio_clock_div_frac = CYW43_PIO_CLOCK_DIV_FRAC;
48+
static uint32_t cyw43_pio_clock_div_int = CYW43_PIO_CLOCK_DIV_INT;
49+
static uint8_t cyw43_pio_clock_div_frac8 = CYW43_PIO_CLOCK_DIV_FRAC8;
5050

51-
void cyw43_set_pio_clock_divisor(uint16_t clock_div_int, uint8_t clock_div_frac) {
51+
void cyw43_set_pio_clkdiv_int_frac8(uint32_t clock_div_int, uint8_t clock_div_frac8) {
5252
cyw43_pio_clock_div_int = clock_div_int;
53-
cyw43_pio_clock_div_frac = clock_div_frac;
53+
cyw43_pio_clock_div_frac8 = clock_div_frac8;
5454
}
5555
#endif
5656

@@ -114,7 +114,7 @@ int cyw43_spi_init(cyw43_int_t *self) {
114114
}
115115
pio_sm_config config = SPI_PROGRAM_GET_DEFAULT_CONFIG_FUNC(bus_data->pio_offset);
116116

117-
sm_config_set_clkdiv_int_frac(&config, cyw43_pio_clock_div_int, cyw43_pio_clock_div_frac);
117+
sm_config_set_clkdiv_int_frac8(&config, cyw43_pio_clock_div_int, cyw43_pio_clock_div_frac8);
118118
hw_write_masked(&pads_bank0_hw->io[CYW43_PIN_WL_CLOCK],
119119
(uint)PADS_DRIVE_STRENGTH << PADS_BANK0_GPIO0_DRIVE_LSB,
120120
PADS_BANK0_GPIO0_DRIVE_BITS

src/rp2_common/pico_cyw43_driver/include/pico/cyw43_driver.h

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void cyw43_driver_deinit(struct async_context *context);
4848
#define CYW43_PIO_CLOCK_DIV_DYNAMIC 0
4949
#endif
5050

51-
// PICO_CONFIG: CYW43_PIO_CLOCK_DIV_INT, Integer part of the clock divider for communication with the wireless chip, type=bool, default=2, group=pico_cyw43_driver
51+
// PICO_CONFIG: CYW43_PIO_CLOCK_DIV_INT, Integer part of the clock divider for communication with the wireless chip, type=int, default=2, group=pico_cyw43_driver
5252
#ifndef CYW43_PIO_CLOCK_DIV_INT
5353
// backwards compatibility using old define
5454
#ifdef CYW43_PIO_CLOCK_DIV
@@ -58,9 +58,13 @@ void cyw43_driver_deinit(struct async_context *context);
5858
#endif
5959
#endif
6060

61-
// 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
62-
#ifndef CYW43_PIO_CLOCK_DIV_FRAC
63-
#define CYW43_PIO_CLOCK_DIV_FRAC 0
61+
// PICO_CONFIG: CYW43_PIO_CLOCK_DIV_FRAC8, Fractional part of the clock divider for communication with the wireless chip 0-255, type=int, min=0, max=255, default=0, group=pico_cyw43_driver
62+
#ifndef CYW43_PIO_CLOCK_DIV_FRAC8
63+
#ifdef CYW43_PIO_CLOCK_DIV_FRAC
64+
#define CYW43_PIO_CLOCK_DIV_FRAC8 CYW43_PIO_CLOCK_DIV_FRAC
65+
#else
66+
#define CYW43_PIO_CLOCK_DIV_FRAC8 0
67+
#endif
6468
#endif
6569

6670
// PICO_CONFIG: CYW43_PIN_WL_DYNAMIC, flag to indicate if cyw43 SPI pins can be changed at runtime, type=bool, advanced=true, group=pico_cyw43_driver
@@ -86,9 +90,14 @@ void cyw43_driver_deinit(struct async_context *context);
8690
* This function is only available if \ref CYW43_PIO_CLOCK_DIV_DYNAMIC is true
8791
*
8892
* \param clock_div_int Integer part of the divisor
89-
* \param clock_div_frac Fractional part in 1/256ths
93+
* \param clock_div_frac8 Fractional part in 1/256ths
9094
*/
91-
void cyw43_set_pio_clock_divisor(uint16_t clock_div_int, uint8_t clock_div_frac);
95+
void cyw43_set_pio_clkdiv_int_frac8(uint32_t clock_div_int, uint8_t clock_div_frac8);
96+
97+
// backwards compatibility
98+
static inline void cyw43_set_pio_clock_divisor(uint16_t clock_div_int, uint8_t clock_div_frac8) {
99+
return cyw43_set_pio_clkdiv_int_frac8(clock_div_int, clock_div_frac8);
100+
}
92101
#endif
93102

94103
#if CYW43_PIN_WL_DYNAMIC

0 commit comments

Comments
 (0)