diff options
| author | Eric Seppanen <[email protected]> | 2025-12-13 15:18:39 -0800 |
|---|---|---|
| committer | Eric Seppanen <[email protected]> | 2025-12-13 15:18:39 -0800 |
| commit | 7227c7bde24b9ebd1e3fcc355f708690d1724469 (patch) | |
| tree | fda9ac7e9502c7dbaf695de661e25bed9880c1f4 /embassy-rp/src/pio_programs | |
| parent | a47f745c2504805feba646c6971ed35266782403 (diff) | |
clock_divider: use core::assert in const fn
defmt::assert gives a compile error in const context.
Diffstat (limited to 'embassy-rp/src/pio_programs')
| -rw-r--r-- | embassy-rp/src/pio_programs/clock_divider.rs | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/embassy-rp/src/pio_programs/clock_divider.rs b/embassy-rp/src/pio_programs/clock_divider.rs index 28c931ed2..87ba93008 100644 --- a/embassy-rp/src/pio_programs/clock_divider.rs +++ b/embassy-rp/src/pio_programs/clock_divider.rs | |||
| @@ -29,7 +29,7 @@ pub fn calculate_pio_clock_divider(target_hz: u32) -> fixed::FixedU32<U8> { | |||
| 29 | /// A fixed-point divider value suitable for use in a PIO state machine configuration | 29 | /// A fixed-point divider value suitable for use in a PIO state machine configuration |
| 30 | pub const fn calculate_pio_clock_divider_value(sys_hz: u32, target_hz: u32) -> fixed::FixedU32<U8> { | 30 | pub const fn calculate_pio_clock_divider_value(sys_hz: u32, target_hz: u32) -> fixed::FixedU32<U8> { |
| 31 | // Requires a non-zero frequency | 31 | // Requires a non-zero frequency |
| 32 | assert!(target_hz > 0, "PIO clock frequency cannot be zero"); | 32 | core::assert!(target_hz > 0); |
| 33 | 33 | ||
| 34 | // Compute the integer and fractional part of the divider. | 34 | // Compute the integer and fractional part of the divider. |
| 35 | // Doing it this way allows us to avoid u64 division while | 35 | // Doing it this way allows us to avoid u64 division while |
| @@ -41,9 +41,9 @@ pub const fn calculate_pio_clock_divider_value(sys_hz: u32, target_hz: u32) -> f | |||
| 41 | let result = integer << 8 | frac; | 41 | let result = integer << 8 | frac; |
| 42 | 42 | ||
| 43 | // Ensure the result will fit in 16+8 bits. | 43 | // Ensure the result will fit in 16+8 bits. |
| 44 | assert!(result <= 0xffff_ff, "pio clock divider too big"); | 44 | core::assert!(result <= 0xffff_ff); |
| 45 | // The clock divider can't be used to go faster than the system clock. | 45 | // The clock divider can't be used to go faster than the system clock. |
| 46 | assert!(result >= 0x0001_00, "pio clock divider cannot be less than 1"); | 46 | core::assert!(result >= 0x0001_00); |
| 47 | 47 | ||
| 48 | fixed::FixedU32::from_bits(result) | 48 | fixed::FixedU32::from_bits(result) |
| 49 | } | 49 | } |
