mirror of
https://github.com/Klipper3d/klipper.git
synced 2026-05-06 16:07:29 +02:00
rp2040: Replace divide with a multiply in spi.c
Rework the comparison to avoid using an expensive divide operation. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
@@ -14,7 +14,7 @@ config RPXXXX_SELECT
|
||||
select HAVE_GPIO_HARD_PWM
|
||||
select HAVE_STEPPER_OPTIMIZED_BOTH_EDGE
|
||||
select HAVE_BOOTLOADER_REQUEST
|
||||
# Software divide needed on rp2040 in spi rate, i2c rate, hard_pwm rate
|
||||
# Software divide needed on rp2040 in i2c rate, hard_pwm rate
|
||||
select HAVE_SOFTWARE_DIVIDE_REQUIRED if MACH_RP2040
|
||||
|
||||
config BOARD_DIRECTORY
|
||||
|
||||
@@ -86,15 +86,15 @@ spi_setup(uint32_t bus, uint8_t mode, uint32_t rate)
|
||||
|
||||
struct spi_config res = {spi_bus[bus].spi, 0, 0};
|
||||
|
||||
uint8_t prescale;
|
||||
uint32_t prescale;
|
||||
for (prescale = 2; prescale <= 254; prescale += 2) {
|
||||
if (pclk < (prescale + 2) * 256 * rate)
|
||||
if ((prescale + 2) * 256 * rate > pclk)
|
||||
break;
|
||||
}
|
||||
|
||||
uint8_t postdiv;
|
||||
uint32_t postdiv;
|
||||
for (postdiv = 255; postdiv > 0; --postdiv) {
|
||||
if ((pclk / (prescale * postdiv)) > rate)
|
||||
if (prescale * postdiv * rate < pclk)
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user