diff options
| author | Felipe Balbi <[email protected]> | 2025-11-13 09:06:43 -0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-11-13 09:06:43 -0800 |
| commit | 7480db25d5cc1866a3e037bfb89f990d9847bd10 (patch) | |
| tree | 8128d3f0ba58c530a5fb83f6eca62a8b12a1709b /src | |
| parent | 6eb28d3e7b7290d2998229b1bfb624e33575ea83 (diff) | |
| parent | f1636f3913e06f84ec2a097924bd7154b9bb1a3c (diff) | |
Merge pull request #13 from jamesmunns/james/repac
Switch to new PAC commit
Diffstat (limited to 'src')
| -rw-r--r-- | src/adc.rs | 4 | ||||
| -rw-r--r-- | src/interrupt.rs | 4 | ||||
| -rw-r--r-- | src/lib.rs | 3 | ||||
| -rw-r--r-- | src/lpuart/buffered.rs | 23 | ||||
| -rw-r--r-- | src/lpuart/mod.rs | 19 | ||||
| -rw-r--r-- | src/ostimer.rs | 6 | ||||
| -rw-r--r-- | src/rtc.rs | 27 | ||||
| -rw-r--r-- | src/uart.rs | 12 |
8 files changed, 67 insertions, 31 deletions
diff --git a/src/adc.rs b/src/adc.rs index d456971f7..655bf934f 100644 --- a/src/adc.rs +++ b/src/adc.rs | |||
| @@ -228,7 +228,7 @@ impl<I: Instance> Adc<I> { | |||
| 228 | let step = 1.0 / (1u32 << shift) as f32; | 228 | let step = 1.0 / (1u32 << shift) as f32; |
| 229 | let tmp = (gain_adjustment / step) as u32; | 229 | let tmp = (gain_adjustment / step) as u32; |
| 230 | gcra_array[i - 1] = tmp; | 230 | gcra_array[i - 1] = tmp; |
| 231 | gain_adjustment = gain_adjustment - tmp as f32 * step; | 231 | gain_adjustment -= tmp as f32 * step; |
| 232 | } | 232 | } |
| 233 | 233 | ||
| 234 | for i in (1..=17).rev() { | 234 | for i in (1..=17).rev() { |
| @@ -244,7 +244,7 @@ impl<I: Instance> Adc<I> { | |||
| 244 | while adc.gcc0().read().rdy().is_gain_cal_not_valid() {} | 244 | while adc.gcc0().read().rdy().is_gain_cal_not_valid() {} |
| 245 | 245 | ||
| 246 | let mut gcca = adc.gcc0().read().gain_cal().bits() as u32; | 246 | let mut gcca = adc.gcc0().read().gain_cal().bits() as u32; |
| 247 | if gcca & (((0xFFFF >> 0) + 1) >> 1) != 0 { | 247 | if gcca & ((0xFFFF + 1) >> 1) != 0 { |
| 248 | gcca |= !0xFFFF; | 248 | gcca |= !0xFFFF; |
| 249 | } | 249 | } |
| 250 | 250 | ||
diff --git a/src/interrupt.rs b/src/interrupt.rs index 09d7acbef..134ff03fd 100644 --- a/src/interrupt.rs +++ b/src/interrupt.rs | |||
| @@ -2,6 +2,10 @@ | |||
| 2 | //! Type-level interrupt traits and bindings are provided by the | 2 | //! Type-level interrupt traits and bindings are provided by the |
| 3 | //! `embassy_hal_internal::interrupt_mod!` macro via the generated module below. | 3 | //! `embassy_hal_internal::interrupt_mod!` macro via the generated module below. |
| 4 | 4 | ||
| 5 | // TODO(AJM): As of 2025-11-13, we need to do a pass to ensure safety docs | ||
| 6 | // are complete prior to release. | ||
| 7 | #![allow(clippy::missing_safety_doc)] | ||
| 8 | |||
| 5 | mod generated { | 9 | mod generated { |
| 6 | embassy_hal_internal::interrupt_mod!(OS_EVENT, LPUART2, RTC, ADC1); | 10 | embassy_hal_internal::interrupt_mod!(OS_EVENT, LPUART2, RTC, ADC1); |
| 7 | } | 11 | } |
diff --git a/src/lib.rs b/src/lib.rs index fe27aadba..9899564d8 100644 --- a/src/lib.rs +++ b/src/lib.rs | |||
| @@ -1,4 +1,7 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | // TODO(AJM): As of 2025-11-13, we need to do a pass to ensure safety docs | ||
| 3 | // are complete prior to release. | ||
| 4 | #![allow(clippy::missing_safety_doc)] | ||
| 2 | 5 | ||
| 3 | pub mod clocks; // still provide clock helpers | 6 | pub mod clocks; // still provide clock helpers |
| 4 | pub mod gpio; | 7 | pub mod gpio; |
diff --git a/src/lpuart/buffered.rs b/src/lpuart/buffered.rs index 0413fed8e..a617c10a5 100644 --- a/src/lpuart/buffered.rs +++ b/src/lpuart/buffered.rs | |||
| @@ -24,6 +24,12 @@ pub struct State { | |||
| 24 | initialized: AtomicBool, | 24 | initialized: AtomicBool, |
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | impl Default for State { | ||
| 28 | fn default() -> Self { | ||
| 29 | Self::new() | ||
| 30 | } | ||
| 31 | } | ||
| 32 | |||
| 27 | impl State { | 33 | impl State { |
| 28 | /// Create a new state instance | 34 | /// Create a new state instance |
| 29 | pub const fn new() -> Self { | 35 | pub const fn new() -> Self { |
| @@ -104,6 +110,7 @@ impl<'a> BufferedLpuart<'a> { | |||
| 104 | } | 110 | } |
| 105 | 111 | ||
| 106 | /// Create a new buffered LPUART with flexible pin configuration | 112 | /// Create a new buffered LPUART with flexible pin configuration |
| 113 | #[allow(clippy::too_many_arguments)] | ||
| 107 | pub fn new_with_pins<T: Instance>( | 114 | pub fn new_with_pins<T: Instance>( |
| 108 | _inner: Peri<'a, T>, | 115 | _inner: Peri<'a, T>, |
| 109 | tx_pin: Option<Peri<'a, impl TxPin<T>>>, | 116 | tx_pin: Option<Peri<'a, impl TxPin<T>>>, |
| @@ -612,16 +619,14 @@ impl<T: Instance> crate::interrupt::typelevel::Handler<T::Interrupt> for Buffere | |||
| 612 | } | 619 | } |
| 613 | 620 | ||
| 614 | // Handle transmission complete | 621 | // Handle transmission complete |
| 615 | if ctrl.tcie().is_enabled() { | 622 | if ctrl.tcie().is_enabled() && regs.stat().read().tc().is_complete() { |
| 616 | if regs.stat().read().tc().is_complete() { | 623 | state.tx_done.store(true, Ordering::Release); |
| 617 | state.tx_done.store(true, Ordering::Release); | 624 | state.tx_waker.wake(); |
| 618 | state.tx_waker.wake(); | ||
| 619 | 625 | ||
| 620 | // Disable TC interrupt | 626 | // Disable TC interrupt |
| 621 | cortex_m::interrupt::free(|_| { | 627 | cortex_m::interrupt::free(|_| { |
| 622 | regs.ctrl().modify(|_, w| w.tcie().disabled()); | 628 | regs.ctrl().modify(|_, w| w.tcie().disabled()); |
| 623 | }); | 629 | }); |
| 624 | } | ||
| 625 | } | 630 | } |
| 626 | } | 631 | } |
| 627 | } | 632 | } |
diff --git a/src/lpuart/mod.rs b/src/lpuart/mod.rs index bed10bdb0..35b531421 100644 --- a/src/lpuart/mod.rs +++ b/src/lpuart/mod.rs | |||
| @@ -105,8 +105,9 @@ mod gpio { | |||
| 105 | 105 | ||
| 106 | impl GpioPin for super::lib::peripherals::$pin {} | 106 | impl GpioPin for super::lib::peripherals::$pin {} |
| 107 | 107 | ||
| 108 | impl Into<AnyPin> for super::lib::peripherals::$pin { | 108 | impl From<super::lib::peripherals::$pin> for AnyPin { |
| 109 | fn into(self) -> AnyPin { | 109 | // TODO: AJM: any reason we aren't using $pin? |
| 110 | fn from(_val: super::lib::peripherals::$pin) -> Self { | ||
| 110 | AnyPin | 111 | AnyPin |
| 111 | } | 112 | } |
| 112 | } | 113 | } |
| @@ -242,7 +243,7 @@ pub fn configure_baudrate(regs: Regs, baudrate_bps: u32, clock: Clock) -> Result | |||
| 242 | // Configure BAUD register | 243 | // Configure BAUD register |
| 243 | regs.baud().modify(|_, w| unsafe { | 244 | regs.baud().modify(|_, w| unsafe { |
| 244 | // Clear and set OSR | 245 | // Clear and set OSR |
| 245 | w.osr().bits((osr - 1) as u8); | 246 | w.osr().bits(osr - 1); |
| 246 | // Clear and set SBR | 247 | // Clear and set SBR |
| 247 | w.sbr().bits(sbr); | 248 | w.sbr().bits(sbr); |
| 248 | // Set BOTHEDGE if OSR is between 4 and 7 | 249 | // Set BOTHEDGE if OSR is between 4 and 7 |
| @@ -305,9 +306,9 @@ pub fn configure_fifo(regs: Regs, config: &Config) { | |||
| 305 | // Configure WATER register for FIFO watermarks | 306 | // Configure WATER register for FIFO watermarks |
| 306 | regs.water().write(|w| unsafe { | 307 | regs.water().write(|w| unsafe { |
| 307 | w.rxwater() | 308 | w.rxwater() |
| 308 | .bits(config.rx_fifo_watermark as u8) | 309 | .bits(config.rx_fifo_watermark) |
| 309 | .txwater() | 310 | .txwater() |
| 310 | .bits(config.tx_fifo_watermark as u8) | 311 | .bits(config.tx_fifo_watermark) |
| 311 | }); | 312 | }); |
| 312 | 313 | ||
| 313 | // Enable TX/RX FIFOs | 314 | // Enable TX/RX FIFOs |
| @@ -377,7 +378,7 @@ pub fn calculate_baudrate(baudrate: u32, src_clock_hz: u32) -> Result<(u8, u16)> | |||
| 377 | // Try OSR values from 4 to 32 | 378 | // Try OSR values from 4 to 32 |
| 378 | for osr_temp in 4u8..=32u8 { | 379 | for osr_temp in 4u8..=32u8 { |
| 379 | // Calculate SBR: (srcClock_Hz * 2 / (baudRate * osr) + 1) / 2 | 380 | // Calculate SBR: (srcClock_Hz * 2 / (baudRate * osr) + 1) / 2 |
| 380 | let sbr_calc = ((src_clock_hz * 2) / (baudrate * osr_temp as u32) + 1) / 2; | 381 | let sbr_calc = ((src_clock_hz * 2) / (baudrate * osr_temp as u32)).div_ceil(2); |
| 381 | 382 | ||
| 382 | let sbr_temp = if sbr_calc == 0 { | 383 | let sbr_temp = if sbr_calc == 0 { |
| 383 | 1 | 384 | 1 |
| @@ -390,11 +391,7 @@ pub fn calculate_baudrate(baudrate: u32, src_clock_hz: u32) -> Result<(u8, u16)> | |||
| 390 | // Calculate actual baud rate | 391 | // Calculate actual baud rate |
| 391 | let calculated_baud = src_clock_hz / (osr_temp as u32 * sbr_temp as u32); | 392 | let calculated_baud = src_clock_hz / (osr_temp as u32 * sbr_temp as u32); |
| 392 | 393 | ||
| 393 | let temp_diff = if calculated_baud > baudrate { | 394 | let temp_diff = calculated_baud.abs_diff(baudrate); |
| 394 | calculated_baud - baudrate | ||
| 395 | } else { | ||
| 396 | baudrate - calculated_baud | ||
| 397 | }; | ||
| 398 | 395 | ||
| 399 | if temp_diff <= baud_diff { | 396 | if temp_diff <= baud_diff { |
| 400 | baud_diff = temp_diff; | 397 | baud_diff = temp_diff; |
diff --git a/src/ostimer.rs b/src/ostimer.rs index a4cab6970..8bc68389a 100644 --- a/src/ostimer.rs +++ b/src/ostimer.rs | |||
| @@ -151,6 +151,12 @@ pub struct Alarm<'d> { | |||
| 151 | _phantom: core::marker::PhantomData<&'d mut ()>, | 151 | _phantom: core::marker::PhantomData<&'d mut ()>, |
| 152 | } | 152 | } |
| 153 | 153 | ||
| 154 | impl<'d> Default for Alarm<'d> { | ||
| 155 | fn default() -> Self { | ||
| 156 | Self::new() | ||
| 157 | } | ||
| 158 | } | ||
| 159 | |||
| 154 | impl<'d> Alarm<'d> { | 160 | impl<'d> Alarm<'d> { |
| 155 | /// Create a new alarm instance | 161 | /// Create a new alarm instance |
| 156 | pub fn new() -> Self { | 162 | pub fn new() -> Self { |
diff --git a/src/rtc.rs b/src/rtc.rs index d62da1f0a..facb9cf8c 100644 --- a/src/rtc.rs +++ b/src/rtc.rs | |||
| @@ -102,25 +102,36 @@ pub fn convert_seconds_to_datetime(seconds: u32) -> RtcDateTime { | |||
| 102 | days -= days_in_year; | 102 | days -= days_in_year; |
| 103 | year += 1; | 103 | year += 1; |
| 104 | 104 | ||
| 105 | days_in_year = if year % 4 == 0 { | 105 | days_in_year = if year.is_multiple_of(4) { |
| 106 | DAYS_IN_A_YEAR + 1 | 106 | DAYS_IN_A_YEAR + 1 |
| 107 | } else { | 107 | } else { |
| 108 | DAYS_IN_A_YEAR | 108 | DAYS_IN_A_YEAR |
| 109 | }; | 109 | }; |
| 110 | } | 110 | } |
| 111 | 111 | ||
| 112 | let mut days_per_month = [0u8, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; | 112 | let days_per_month = [ |
| 113 | if year % 4 == 0 { | 113 | 31, |
| 114 | days_per_month[2] = 29; | 114 | if year.is_multiple_of(4) { 29 } else { 28 }, |
| 115 | } | 115 | 31, |
| 116 | 30, | ||
| 117 | 31, | ||
| 118 | 30, | ||
| 119 | 31, | ||
| 120 | 31, | ||
| 121 | 30, | ||
| 122 | 31, | ||
| 123 | 30, | ||
| 124 | 31, | ||
| 125 | ]; | ||
| 116 | 126 | ||
| 117 | let mut month = 1; | 127 | let mut month = 1; |
| 118 | for m in 1..=12 { | 128 | for (m, month_days) in days_per_month.iter().enumerate() { |
| 119 | if days <= days_per_month[m] as u32 { | 129 | let m = m + 1; |
| 130 | if days <= *month_days as u32 { | ||
| 120 | month = m; | 131 | month = m; |
| 121 | break; | 132 | break; |
| 122 | } else { | 133 | } else { |
| 123 | days -= days_per_month[m] as u32; | 134 | days -= *month_days as u32; |
| 124 | } | 135 | } |
| 125 | } | 136 | } |
| 126 | 137 | ||
diff --git a/src/uart.rs b/src/uart.rs index 3209a318d..3705959d3 100644 --- a/src/uart.rs +++ b/src/uart.rs | |||
| @@ -1,6 +1,10 @@ | |||
| 1 | //! Minimal polling UART2 bring-up replicating MCUXpresso hello_world ordering. | 1 | //! Minimal polling UART2 bring-up replicating MCUXpresso hello_world ordering. |
| 2 | //! WARNING: This is a narrow implementation only for debug console (115200 8N1). | 2 | //! WARNING: This is a narrow implementation only for debug console (115200 8N1). |
| 3 | 3 | ||
| 4 | // TODO(AJM): As of 2025-11-13, we need to do a pass to ensure safety docs | ||
| 5 | // are complete prior to release. | ||
| 6 | #![allow(clippy::missing_safety_doc)] | ||
| 7 | |||
| 4 | use core::cell::RefCell; | 8 | use core::cell::RefCell; |
| 5 | 9 | ||
| 6 | use cortex_m::interrupt::Mutex; | 10 | use cortex_m::interrupt::Mutex; |
| @@ -118,7 +122,7 @@ impl<I: Instance> Uart<I> { | |||
| 118 | StopBits::Two => w.sbns().two(), | 122 | StopBits::Two => w.sbns().two(), |
| 119 | }; | 123 | }; |
| 120 | // OSR field encodes (osr-1); use raw bits to avoid a long match on all variants | 124 | // OSR field encodes (osr-1); use raw bits to avoid a long match on all variants |
| 121 | let raw_osr = osr.saturating_sub(1) as u8; | 125 | let raw_osr = osr.saturating_sub(1); |
| 122 | unsafe { w.osr().bits(raw_osr).sbr().bits(sbr) } | 126 | unsafe { w.osr().bits(raw_osr).sbr().bits(sbr) } |
| 123 | }); | 127 | }); |
| 124 | // 3) CTRL baseline and parity | 128 | // 3) CTRL baseline and parity |
| @@ -195,6 +199,12 @@ pub struct RingBuffer { | |||
| 195 | count: usize, | 199 | count: usize, |
| 196 | } | 200 | } |
| 197 | 201 | ||
| 202 | impl Default for RingBuffer { | ||
| 203 | fn default() -> Self { | ||
| 204 | Self::new() | ||
| 205 | } | ||
| 206 | } | ||
| 207 | |||
| 198 | impl RingBuffer { | 208 | impl RingBuffer { |
| 199 | pub const fn new() -> Self { | 209 | pub const fn new() -> Self { |
| 200 | Self { | 210 | Self { |
