diff options
| author | Felipe Balbi <[email protected]> | 2025-11-07 10:07:33 -0800 |
|---|---|---|
| committer | Felipe Balbi <[email protected]> | 2025-11-07 10:08:16 -0800 |
| commit | e75066820ad320495ca70570641c90d75247b19b (patch) | |
| tree | da2aeddb9164dbc2829b54185d1f180efbad6daf | |
| parent | cb2ac2790f4b037056f9571abeb4d62360199426 (diff) | |
cargo +nightly fmt
Signed-off-by: Felipe Balbi <[email protected]>
| -rw-r--r-- | examples/adc_interrupt.rs | 9 | ||||
| -rw-r--r-- | examples/adc_polling.rs | 9 | ||||
| -rw-r--r-- | examples/blink.rs | 5 | ||||
| -rw-r--r-- | examples/lpuart_buffered.rs | 9 | ||||
| -rw-r--r-- | examples/lpuart_polling.rs | 8 | ||||
| -rw-r--r-- | examples/ostimer_alarm.rs | 15 | ||||
| -rw-r--r-- | examples/ostimer_async.rs | 5 | ||||
| -rw-r--r-- | examples/ostimer_counter.rs | 8 | ||||
| -rw-r--r-- | examples/ostimer_race_test.rs | 14 | ||||
| -rw-r--r-- | examples/rtc_alarm.rs | 9 | ||||
| -rw-r--r-- | rustfmt.toml | 8 | ||||
| -rw-r--r-- | src/adc.rs | 24 | ||||
| -rw-r--r-- | src/clocks.rs | 3 | ||||
| -rw-r--r-- | src/gpio.rs | 8 | ||||
| -rw-r--r-- | src/interrupt.rs | 6 | ||||
| -rw-r--r-- | src/lib.rs | 12 | ||||
| -rw-r--r-- | src/lpuart/buffered.rs | 19 | ||||
| -rw-r--r-- | src/lpuart/mod.rs | 19 | ||||
| -rw-r--r-- | src/ostimer.rs | 66 | ||||
| -rw-r--r-- | src/pins.rs | 5 | ||||
| -rw-r--r-- | src/rtc.rs | 3 | ||||
| -rw-r--r-- | src/uart.rs | 13 |
22 files changed, 90 insertions, 187 deletions
diff --git a/examples/adc_interrupt.rs b/examples/adc_interrupt.rs index 26afd70b4..f0df3196c 100644 --- a/examples/adc_interrupt.rs +++ b/examples/adc_interrupt.rs | |||
| @@ -1,24 +1,19 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | 3 | ||
| 4 | use cortex_m; | ||
| 5 | use embassy_executor::Spawner; | 4 | use embassy_executor::Spawner; |
| 6 | use embassy_mcxa276 as hal; | ||
| 7 | |||
| 8 | use hal::adc::{LpadcConfig, TriggerPriorityPolicy}; | 5 | use hal::adc::{LpadcConfig, TriggerPriorityPolicy}; |
| 9 | use hal::pac::adc1::cfg::{Pwrsel, Refsel}; | 6 | use hal::pac::adc1::cfg::{Pwrsel, Refsel}; |
| 10 | use hal::pac::adc1::cmdl1::{Adch, Mode}; | 7 | use hal::pac::adc1::cmdl1::{Adch, Mode}; |
| 11 | use hal::pac::adc1::ctrl::CalAvgs; | 8 | use hal::pac::adc1::ctrl::CalAvgs; |
| 12 | use hal::pac::adc1::tctrl::Tcmd; | 9 | use hal::pac::adc1::tctrl::Tcmd; |
| 13 | |||
| 14 | use hal::uart; | 10 | use hal::uart; |
| 11 | use {cortex_m, embassy_mcxa276 as hal}; | ||
| 15 | mod common; | 12 | mod common; |
| 16 | 13 | ||
| 14 | use hal::{bind_interrupts, InterruptExt}; | ||
| 17 | use {defmt_rtt as _, panic_probe as _}; | 15 | use {defmt_rtt as _, panic_probe as _}; |
| 18 | 16 | ||
| 19 | use hal::InterruptExt; | ||
| 20 | use hal::bind_interrupts; | ||
| 21 | |||
| 22 | bind_interrupts!(struct Irqs { | 17 | bind_interrupts!(struct Irqs { |
| 23 | ADC1 => hal::adc::AdcHandler; | 18 | ADC1 => hal::adc::AdcHandler; |
| 24 | }); | 19 | }); |
diff --git a/examples/adc_polling.rs b/examples/adc_polling.rs index 90be87c3f..561500d2d 100644 --- a/examples/adc_polling.rs +++ b/examples/adc_polling.rs | |||
| @@ -1,24 +1,21 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | 3 | ||
| 4 | use embassy_mcxa276 as hal; | ||
| 5 | |||
| 6 | use embassy_executor::Spawner; | 4 | use embassy_executor::Spawner; |
| 7 | 5 | use embassy_mcxa276 as hal; | |
| 8 | use hal::adc::{ConvResult, LpadcConfig, TriggerPriorityPolicy}; | 6 | use hal::adc::{ConvResult, LpadcConfig, TriggerPriorityPolicy}; |
| 9 | use hal::pac::adc1::cfg::{Pwrsel, Refsel}; | 7 | use hal::pac::adc1::cfg::{Pwrsel, Refsel}; |
| 10 | use hal::pac::adc1::cmdl1::{Adch, Mode}; | 8 | use hal::pac::adc1::cmdl1::{Adch, Mode}; |
| 11 | use hal::pac::adc1::ctrl::CalAvgs; | 9 | use hal::pac::adc1::ctrl::CalAvgs; |
| 12 | use hal::pac::adc1::tctrl::Tcmd; | 10 | use hal::pac::adc1::tctrl::Tcmd; |
| 13 | |||
| 14 | use hal::uart; | 11 | use hal::uart; |
| 15 | 12 | ||
| 16 | mod common; | 13 | mod common; |
| 17 | 14 | ||
| 18 | use {defmt_rtt as _, panic_probe as _}; | ||
| 19 | |||
| 20 | use core::fmt::Write; | 15 | use core::fmt::Write; |
| 16 | |||
| 21 | use heapless::String; | 17 | use heapless::String; |
| 18 | use {defmt_rtt as _, panic_probe as _}; | ||
| 22 | 19 | ||
| 23 | const G_LPADC_RESULT_SHIFT: u32 = 0; | 20 | const G_LPADC_RESULT_SHIFT: u32 = 0; |
| 24 | 21 | ||
diff --git a/examples/blink.rs b/examples/blink.rs index a9b6e7093..564353d5c 100644 --- a/examples/blink.rs +++ b/examples/blink.rs | |||
| @@ -34,10 +34,7 @@ async fn main(_spawner: Spawner) { | |||
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | // Initialize embassy-time global driver backed by OSTIMER0 | 36 | // Initialize embassy-time global driver backed by OSTIMER0 |
| 37 | hal::ostimer::time_driver::init( | 37 | hal::ostimer::time_driver::init(hal::config::Config::default().time_interrupt_priority, 1_000_000); |
| 38 | hal::config::Config::default().time_interrupt_priority, | ||
| 39 | 1_000_000, | ||
| 40 | ); | ||
| 41 | 38 | ||
| 42 | // Configure LED pin for GPIO mode | 39 | // Configure LED pin for GPIO mode |
| 43 | PIO3_18::set_mux_gpio(); | 40 | PIO3_18::set_mux_gpio(); |
diff --git a/examples/lpuart_buffered.rs b/examples/lpuart_buffered.rs index d0d4d2ee0..30ba3f333 100644 --- a/examples/lpuart_buffered.rs +++ b/examples/lpuart_buffered.rs | |||
| @@ -4,13 +4,10 @@ | |||
| 4 | use embassy_executor::Spawner; | 4 | use embassy_executor::Spawner; |
| 5 | use embassy_mcxa276 as hal; | 5 | use embassy_mcxa276 as hal; |
| 6 | use embassy_mcxa276::interrupt::typelevel::Handler; | 6 | use embassy_mcxa276::interrupt::typelevel::Handler; |
| 7 | use embassy_mcxa276::lpuart; | ||
| 8 | use embassy_mcxa276::lpuart::buffered::BufferedLpuart; | 7 | use embassy_mcxa276::lpuart::buffered::BufferedLpuart; |
| 9 | 8 | use embassy_mcxa276::{bind_interrupts, lpuart}; | |
| 10 | use embedded_io_async::{Read, Write}; | 9 | use embedded_io_async::{Read, Write}; |
| 11 | 10 | ||
| 12 | use embassy_mcxa276::bind_interrupts; | ||
| 13 | |||
| 14 | mod common; | 11 | mod common; |
| 15 | 12 | ||
| 16 | // Bind OS_EVENT for timers plus LPUART2 IRQ for the buffered driver | 13 | // Bind OS_EVENT for timers plus LPUART2 IRQ for the buffered driver |
| @@ -69,9 +66,7 @@ async fn main(_spawner: Spawner) { | |||
| 69 | let (tx, rx) = uart.split_ref(); | 66 | let (tx, rx) = uart.split_ref(); |
| 70 | 67 | ||
| 71 | tx.write(b"Hello buffered LPUART.\r\n").await.unwrap(); | 68 | tx.write(b"Hello buffered LPUART.\r\n").await.unwrap(); |
| 72 | tx.write(b"Type characters to echo them back.\r\n") | 69 | tx.write(b"Type characters to echo them back.\r\n").await.unwrap(); |
| 73 | .await | ||
| 74 | .unwrap(); | ||
| 75 | 70 | ||
| 76 | // Echo loop | 71 | // Echo loop |
| 77 | let mut buf = [0u8; 4]; | 72 | let mut buf = [0u8; 4]; |
diff --git a/examples/lpuart_polling.rs b/examples/lpuart_polling.rs index f9172de40..067c7eb53 100644 --- a/examples/lpuart_polling.rs +++ b/examples/lpuart_polling.rs | |||
| @@ -1,11 +1,10 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | 3 | ||
| 4 | use crate::hal::lpuart::{Config, Lpuart, lib}; | ||
| 5 | use embassy_executor::Spawner; | 4 | use embassy_executor::Spawner; |
| 6 | use embassy_mcxa276 as hal; | 5 | use {defmt_rtt as _, embassy_mcxa276 as hal, panic_probe as _}; |
| 7 | 6 | ||
| 8 | use {defmt_rtt as _, panic_probe as _}; | 7 | use crate::hal::lpuart::{lib, Config, Lpuart}; |
| 9 | 8 | ||
| 10 | mod common; | 9 | mod common; |
| 11 | 10 | ||
| @@ -43,8 +42,7 @@ async fn main(_spawner: Spawner) { | |||
| 43 | 42 | ||
| 44 | // Write hello messages | 43 | // Write hello messages |
| 45 | tx.blocking_write(b"Hello world.\r\n").unwrap(); | 44 | tx.blocking_write(b"Hello world.\r\n").unwrap(); |
| 46 | tx.blocking_write(b"Echoing. Type characters...\r\n") | 45 | tx.blocking_write(b"Echoing. Type characters...\r\n").unwrap(); |
| 47 | .unwrap(); | ||
| 48 | 46 | ||
| 49 | // Echo loop | 47 | // Echo loop |
| 50 | loop { | 48 | loop { |
diff --git a/examples/ostimer_alarm.rs b/examples/ostimer_alarm.rs index eca669509..78ca4bbc5 100644 --- a/examples/ostimer_alarm.rs +++ b/examples/ostimer_alarm.rs | |||
| @@ -2,16 +2,15 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | 3 | ||
| 4 | use core::sync::atomic::{AtomicBool, Ordering}; | 4 | use core::sync::atomic::{AtomicBool, Ordering}; |
| 5 | use cortex_m; | 5 | |
| 6 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 7 | use embassy_mcxa276 as hal; | ||
| 8 | use hal::uart; | 7 | use hal::uart; |
| 8 | use {cortex_m, embassy_mcxa276 as hal}; | ||
| 9 | 9 | ||
| 10 | mod common; | 10 | mod common; |
| 11 | 11 | ||
| 12 | use {defmt_rtt as _, panic_probe as _}; | ||
| 13 | |||
| 14 | use embassy_mcxa276::bind_interrupts; | 12 | use embassy_mcxa276::bind_interrupts; |
| 13 | use {defmt_rtt as _, panic_probe as _}; | ||
| 15 | 14 | ||
| 16 | // Bind only OS_EVENT, and retain the symbol explicitly so it can't be GC'ed. | 15 | // Bind only OS_EVENT, and retain the symbol explicitly so it can't be GC'ed. |
| 17 | bind_interrupts!(struct Irqs { | 16 | bind_interrupts!(struct Irqs { |
| @@ -46,18 +45,14 @@ async fn main(_spawner: Spawner) { | |||
| 46 | uart.write_str_blocking("OSTIMER Alarm Example\n"); | 45 | uart.write_str_blocking("OSTIMER Alarm Example\n"); |
| 47 | 46 | ||
| 48 | // Initialize embassy-time global driver backed by OSTIMER0 | 47 | // Initialize embassy-time global driver backed by OSTIMER0 |
| 49 | hal::ostimer::time_driver::init( | 48 | hal::ostimer::time_driver::init(hal::config::Config::default().time_interrupt_priority, 1_000_000); |
| 50 | hal::config::Config::default().time_interrupt_priority, | ||
| 51 | 1_000_000, | ||
| 52 | ); | ||
| 53 | 49 | ||
| 54 | // Create OSTIMER instance | 50 | // Create OSTIMER instance |
| 55 | let config = hal::ostimer::Config { | 51 | let config = hal::ostimer::Config { |
| 56 | init_match_max: true, | 52 | init_match_max: true, |
| 57 | clock_frequency_hz: 1_000_000, // 1MHz | 53 | clock_frequency_hz: 1_000_000, // 1MHz |
| 58 | }; | 54 | }; |
| 59 | let ostimer = | 55 | let ostimer = hal::ostimer::Ostimer::<hal::ostimer::Ostimer0>::new(p.OSTIMER0, config, hal::pac()); |
| 60 | hal::ostimer::Ostimer::<hal::ostimer::Ostimer0>::new(p.OSTIMER0, config, hal::pac()); | ||
| 61 | 56 | ||
| 62 | // Create alarm with callback | 57 | // Create alarm with callback |
| 63 | let alarm = hal::ostimer::Alarm::new() | 58 | let alarm = hal::ostimer::Alarm::new() |
diff --git a/examples/ostimer_async.rs b/examples/ostimer_async.rs index 37fb3b3d1..27e14e022 100644 --- a/examples/ostimer_async.rs +++ b/examples/ostimer_async.rs | |||
| @@ -42,10 +42,7 @@ async fn main(_spawner: Spawner) { | |||
| 42 | 42 | ||
| 43 | // Initialize OSTIMER with default 1MHz frequency | 43 | // Initialize OSTIMER with default 1MHz frequency |
| 44 | // Adjust this value to match your actual OSTIMER clock frequency | 44 | // Adjust this value to match your actual OSTIMER clock frequency |
| 45 | hal::ostimer::time_driver::init( | 45 | hal::ostimer::time_driver::init(hal::config::Config::default().time_interrupt_priority, 1_000_000); |
| 46 | hal::config::Config::default().time_interrupt_priority, | ||
| 47 | 1_000_000, | ||
| 48 | ); | ||
| 49 | 46 | ||
| 50 | // Removed force-pend; rely on real hardware match to trigger OS_EVENT. | 47 | // Removed force-pend; rely on real hardware match to trigger OS_EVENT. |
| 51 | 48 | ||
diff --git a/examples/ostimer_counter.rs b/examples/ostimer_counter.rs index 1f5bdf434..e95140a88 100644 --- a/examples/ostimer_counter.rs +++ b/examples/ostimer_counter.rs | |||
| @@ -8,11 +8,8 @@ | |||
| 8 | 8 | ||
| 9 | use embassy_executor::Spawner; | 9 | use embassy_executor::Spawner; |
| 10 | use embassy_time::{Duration, Timer}; | 10 | use embassy_time::{Duration, Timer}; |
| 11 | |||
| 12 | use {defmt_rtt as _, panic_probe as _}; | ||
| 13 | |||
| 14 | use embassy_mcxa276 as hal; | ||
| 15 | use hal::bind_interrupts; | 11 | use hal::bind_interrupts; |
| 12 | use {defmt_rtt as _, embassy_mcxa276 as hal, panic_probe as _}; | ||
| 16 | 13 | ||
| 17 | mod common; | 14 | mod common; |
| 18 | 15 | ||
| @@ -32,8 +29,7 @@ async fn main(_spawner: Spawner) { | |||
| 32 | common::init_uart2(hal::pac()); | 29 | common::init_uart2(hal::pac()); |
| 33 | } | 30 | } |
| 34 | let src = unsafe { hal::clocks::uart2_src_hz(hal::pac()) }; | 31 | let src = unsafe { hal::clocks::uart2_src_hz(hal::pac()) }; |
| 35 | let mut uart = | 32 | let mut uart = hal::uart::Uart::<hal::uart::Lpuart2>::new(p.LPUART2, hal::uart::Config::new(src)); |
| 36 | hal::uart::Uart::<hal::uart::Lpuart2>::new(p.LPUART2, hal::uart::Config::new(src)); | ||
| 37 | 33 | ||
| 38 | uart.write_str_blocking("OSTIMER Counter Reading and Reset Example\n"); | 34 | uart.write_str_blocking("OSTIMER Counter Reading and Reset Example\n"); |
| 39 | 35 | ||
diff --git a/examples/ostimer_race_test.rs b/examples/ostimer_race_test.rs index 072310309..a637b6353 100644 --- a/examples/ostimer_race_test.rs +++ b/examples/ostimer_race_test.rs | |||
| @@ -9,13 +9,12 @@ | |||
| 9 | #![no_std] | 9 | #![no_std] |
| 10 | #![no_main] | 10 | #![no_main] |
| 11 | 11 | ||
| 12 | use core::sync::atomic::{AtomicU32, Ordering}; | ||
| 13 | |||
| 12 | use embassy_executor::Spawner; | 14 | use embassy_executor::Spawner; |
| 13 | use embassy_time::{Duration, Timer}; | 15 | use embassy_time::{Duration, Timer}; |
| 14 | |||
| 15 | use core::sync::atomic::{AtomicU32, Ordering}; | ||
| 16 | use embassy_mcxa276 as hal; | ||
| 17 | use hal::bind_interrupts; | 16 | use hal::bind_interrupts; |
| 18 | use {defmt_rtt as _, panic_probe as _}; | 17 | use {defmt_rtt as _, embassy_mcxa276 as hal, panic_probe as _}; |
| 19 | 18 | ||
| 20 | mod common; | 19 | mod common; |
| 21 | 20 | ||
| @@ -80,8 +79,7 @@ async fn main(_spawner: Spawner) { | |||
| 80 | common::init_uart2(hal::pac()); | 79 | common::init_uart2(hal::pac()); |
| 81 | } | 80 | } |
| 82 | let src = unsafe { hal::clocks::uart2_src_hz(hal::pac()) }; | 81 | let src = unsafe { hal::clocks::uart2_src_hz(hal::pac()) }; |
| 83 | let mut uart = | 82 | let mut uart = hal::uart::Uart::<hal::uart::Lpuart2>::new(p.LPUART2, hal::uart::Config::new(src)); |
| 84 | hal::uart::Uart::<hal::uart::Lpuart2>::new(p.LPUART2, hal::uart::Config::new(src)); | ||
| 85 | 83 | ||
| 86 | uart.write_str_blocking("OSTIMER Race Condition Test Starting...\n"); | 84 | uart.write_str_blocking("OSTIMER Race Condition Test Starting...\n"); |
| 87 | 85 | ||
| @@ -250,9 +248,7 @@ async fn test_concurrent_operations( | |||
| 250 | let alarm = hal::ostimer::Alarm::new().with_callback(alarm_callback); | 248 | let alarm = hal::ostimer::Alarm::new().with_callback(alarm_callback); |
| 251 | if !ostimer.schedule_alarm_delay(&alarm, 1000) { | 249 | if !ostimer.schedule_alarm_delay(&alarm, 1000) { |
| 252 | RACE_DETECTED.fetch_add(1, Ordering::SeqCst); | 250 | RACE_DETECTED.fetch_add(1, Ordering::SeqCst); |
| 253 | uart.write_str_blocking( | 251 | uart.write_str_blocking("ERROR: Failed to program OSTIMER alarm before concurrent operations\n"); |
| 254 | "ERROR: Failed to program OSTIMER alarm before concurrent operations\n", | ||
| 255 | ); | ||
| 256 | } | 252 | } |
| 257 | 253 | ||
| 258 | // Wait for both to complete | 254 | // Wait for both to complete |
diff --git a/examples/rtc_alarm.rs b/examples/rtc_alarm.rs index a190b8ba5..c27fd4c55 100644 --- a/examples/rtc_alarm.rs +++ b/examples/rtc_alarm.rs | |||
| @@ -1,20 +1,17 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | 3 | ||
| 4 | use cortex_m; | ||
| 5 | use embassy_executor::Spawner; | 4 | use embassy_executor::Spawner; |
| 6 | use embassy_mcxa276 as hal; | ||
| 7 | use hal::InterruptExt; | ||
| 8 | use hal::rtc::{RtcDateTime, RtcInterruptEnable}; | 5 | use hal::rtc::{RtcDateTime, RtcInterruptEnable}; |
| 9 | use hal::uart; | 6 | use hal::{uart, InterruptExt}; |
| 7 | use {cortex_m, embassy_mcxa276 as hal}; | ||
| 10 | 8 | ||
| 11 | mod common; | 9 | mod common; |
| 12 | 10 | ||
| 13 | type MyRtc = hal::rtc::Rtc<hal::rtc::Rtc0>; | 11 | type MyRtc = hal::rtc::Rtc<hal::rtc::Rtc0>; |
| 14 | 12 | ||
| 15 | use {defmt_rtt as _, panic_probe as _}; | ||
| 16 | |||
| 17 | use embassy_mcxa276::bind_interrupts; | 13 | use embassy_mcxa276::bind_interrupts; |
| 14 | use {defmt_rtt as _, panic_probe as _}; | ||
| 18 | 15 | ||
| 19 | bind_interrupts!(struct Irqs { | 16 | bind_interrupts!(struct Irqs { |
| 20 | RTC => hal::rtc::RtcHandler; | 17 | RTC => hal::rtc::RtcHandler; |
diff --git a/rustfmt.toml b/rustfmt.toml index 0720148fd..9eb3c3b4f 100644 --- a/rustfmt.toml +++ b/rustfmt.toml | |||
| @@ -1,7 +1,3 @@ | |||
| 1 | # Workspace formatting preferences | ||
| 2 | edition = "2021" | ||
| 3 | # Merge and sort imports by crate; reduces noise in diffs | ||
| 4 | imports_granularity = "Crate" | ||
| 5 | group_imports = "StdExternalCrate" | 1 | group_imports = "StdExternalCrate" |
| 6 | # Keep defaults for everything else to stay close to rustfmt stable | 2 | imports_granularity = "Module" |
| 7 | 3 | max_width = 120 | |
diff --git a/src/adc.rs b/src/adc.rs index 5625330e9..d456971f7 100644 --- a/src/adc.rs +++ b/src/adc.rs | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | //! ADC driver | 1 | //! ADC driver |
| 2 | use crate::pac; | ||
| 3 | use core::sync::atomic::{AtomicBool, Ordering}; | 2 | use core::sync::atomic::{AtomicBool, Ordering}; |
| 4 | 3 | ||
| 4 | use crate::pac; | ||
| 5 | use crate::pac::adc1::cfg::{HptExdi, Pwrsel, Refsel, Tcmdres, Tprictrl, Tres}; | 5 | use crate::pac::adc1::cfg::{HptExdi, Pwrsel, Refsel, Tcmdres, Tprictrl, Tres}; |
| 6 | use crate::pac::adc1::cmdh1::{Avgs, Cmpen, Next, Sts}; | 6 | use crate::pac::adc1::cmdh1::{Avgs, Cmpen, Next, Sts}; |
| 7 | use crate::pac::adc1::cmdl1::{Adch, Ctype, Mode}; | 7 | use crate::pac::adc1::cmdl1::{Adch, Ctype, Mode}; |
| @@ -140,14 +140,10 @@ impl<I: Instance> Adc<I> { | |||
| 140 | .variant(match config.trigger_priority_policy { | 140 | .variant(match config.trigger_priority_policy { |
| 141 | TriggerPriorityPolicy::ConvPreemptSoftlyNotAutoResumed | 141 | TriggerPriorityPolicy::ConvPreemptSoftlyNotAutoResumed |
| 142 | | TriggerPriorityPolicy::ConvPreemptSoftlyAutoRestarted | 142 | | TriggerPriorityPolicy::ConvPreemptSoftlyAutoRestarted |
| 143 | | TriggerPriorityPolicy::ConvPreemptSoftlyAutoResumed => { | 143 | | TriggerPriorityPolicy::ConvPreemptSoftlyAutoResumed => Tprictrl::FinishCurrentOnPriority, |
| 144 | Tprictrl::FinishCurrentOnPriority | ||
| 145 | } | ||
| 146 | TriggerPriorityPolicy::ConvPreemptSubsequentlyNotAutoResumed | 144 | TriggerPriorityPolicy::ConvPreemptSubsequentlyNotAutoResumed |
| 147 | | TriggerPriorityPolicy::ConvPreemptSubsequentlyAutoRestarted | 145 | | TriggerPriorityPolicy::ConvPreemptSubsequentlyAutoRestarted |
| 148 | | TriggerPriorityPolicy::ConvPreemptSubsequentlyAutoResumed => { | 146 | | TriggerPriorityPolicy::ConvPreemptSubsequentlyAutoResumed => Tprictrl::FinishSequenceOnPriority, |
| 149 | Tprictrl::FinishSequenceOnPriority | ||
| 150 | } | ||
| 151 | _ => Tprictrl::AbortCurrentOnPriority, | 147 | _ => Tprictrl::AbortCurrentOnPriority, |
| 152 | }) | 148 | }) |
| 153 | .tres() | 149 | .tres() |
| @@ -176,12 +172,8 @@ impl<I: Instance> Adc<I> { | |||
| 176 | }); | 172 | }); |
| 177 | 173 | ||
| 178 | if config.enable_conv_pause { | 174 | if config.enable_conv_pause { |
| 179 | adc.pause().modify(|_, w| unsafe { | 175 | adc.pause() |
| 180 | w.pauseen() | 176 | .modify(|_, w| unsafe { w.pauseen().enabled().pausedly().bits(config.conv_pause_delay) }); |
| 181 | .enabled() | ||
| 182 | .pausedly() | ||
| 183 | .bits(config.conv_pause_delay) | ||
| 184 | }); | ||
| 185 | } else { | 177 | } else { |
| 186 | adc.pause().write(|w| unsafe { w.bits(0) }); | 178 | adc.pause().write(|w| unsafe { w.bits(0) }); |
| 187 | } | 179 | } |
| @@ -247,8 +239,7 @@ impl<I: Instance> Adc<I> { | |||
| 247 | 239 | ||
| 248 | pub fn do_auto_calibration(&self) { | 240 | pub fn do_auto_calibration(&self) { |
| 249 | let adc = unsafe { &*I::ptr() }; | 241 | let adc = unsafe { &*I::ptr() }; |
| 250 | adc.ctrl() | 242 | adc.ctrl().modify(|_, w| w.cal_req().calibration_request_pending()); |
| 251 | .modify(|_, w| w.cal_req().calibration_request_pending()); | ||
| 252 | 243 | ||
| 253 | while adc.gcc0().read().rdy().is_gain_cal_not_valid() {} | 244 | while adc.gcc0().read().rdy().is_gain_cal_not_valid() {} |
| 254 | 245 | ||
| @@ -260,8 +251,7 @@ impl<I: Instance> Adc<I> { | |||
| 260 | let gcra = 131072.0 / (131072.0 - gcca as f32); | 251 | let gcra = 131072.0 / (131072.0 - gcca as f32); |
| 261 | 252 | ||
| 262 | // Write to GCR0 | 253 | // Write to GCR0 |
| 263 | adc.gcr0() | 254 | adc.gcr0().write(|w| unsafe { w.bits(self.get_gain_conv_result(gcra)) }); |
| 264 | .write(|w| unsafe { w.bits(self.get_gain_conv_result(gcra)) }); | ||
| 265 | 255 | ||
| 266 | adc.gcr0().modify(|_, w| w.rdy().set_bit()); | 256 | adc.gcr0().modify(|_, w| w.rdy().set_bit()); |
| 267 | 257 | ||
diff --git a/src/clocks.rs b/src/clocks.rs index 95d7ad567..65a17cef6 100644 --- a/src/clocks.rs +++ b/src/clocks.rs | |||
| @@ -76,8 +76,7 @@ pub unsafe fn enable_ostimer0(peripherals: &pac::Peripherals) { | |||
| 76 | pub unsafe fn select_uart2_clock(peripherals: &pac::Peripherals) { | 76 | pub unsafe fn select_uart2_clock(peripherals: &pac::Peripherals) { |
| 77 | // Use FRO_LF_DIV (already running) MUX=0 DIV=0 | 77 | // Use FRO_LF_DIV (already running) MUX=0 DIV=0 |
| 78 | let mrcc = &peripherals.mrcc0; | 78 | let mrcc = &peripherals.mrcc0; |
| 79 | mrcc.mrcc_lpuart2_clksel() | 79 | mrcc.mrcc_lpuart2_clksel().write(|w| w.mux().clkroot_func_0()); |
| 80 | .write(|w| w.mux().clkroot_func_0()); | ||
| 81 | mrcc.mrcc_lpuart2_clkdiv().write(|w| unsafe { w.bits(0) }); | 80 | mrcc.mrcc_lpuart2_clkdiv().write(|w| unsafe { w.bits(0) }); |
| 82 | } | 81 | } |
| 83 | 82 | ||
diff --git a/src/gpio.rs b/src/gpio.rs index faeefd333..1e7214b28 100644 --- a/src/gpio.rs +++ b/src/gpio.rs | |||
| @@ -66,7 +66,7 @@ pub trait PinId { | |||
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | pub mod pins { | 68 | pub mod pins { |
| 69 | use super::{AnyPin, PinId, pac}; | 69 | use super::{pac, AnyPin, PinId}; |
| 70 | 70 | ||
| 71 | macro_rules! define_pin { | 71 | macro_rules! define_pin { |
| 72 | ($Name:ident, $port:literal, $pin:literal, $GpioBlk:ident) => { | 72 | ($Name:ident, $port:literal, $pin:literal, $GpioBlk:ident) => { |
| @@ -130,15 +130,13 @@ impl<'d> Flex<'d> { | |||
| 130 | pub fn set_as_input(&mut self) { | 130 | pub fn set_as_input(&mut self) { |
| 131 | let mask = self.mask(); | 131 | let mask = self.mask(); |
| 132 | let gpio = self.gpio(); | 132 | let gpio = self.gpio(); |
| 133 | gpio.pddr() | 133 | gpio.pddr().modify(|r, w| unsafe { w.bits(r.bits() & !mask) }); |
| 134 | .modify(|r, w| unsafe { w.bits(r.bits() & !mask) }); | ||
| 135 | } | 134 | } |
| 136 | 135 | ||
| 137 | pub fn set_as_output(&mut self) { | 136 | pub fn set_as_output(&mut self) { |
| 138 | let mask = self.mask(); | 137 | let mask = self.mask(); |
| 139 | let gpio = self.gpio(); | 138 | let gpio = self.gpio(); |
| 140 | gpio.pddr() | 139 | gpio.pddr().modify(|r, w| unsafe { w.bits(r.bits() | mask) }); |
| 141 | .modify(|r, w| unsafe { w.bits(r.bits() | mask) }); | ||
| 142 | } | 140 | } |
| 143 | 141 | ||
| 144 | pub fn set_high(&mut self) { | 142 | pub fn set_high(&mut self) { |
diff --git a/src/interrupt.rs b/src/interrupt.rs index d91e6479a..09d7acbef 100644 --- a/src/interrupt.rs +++ b/src/interrupt.rs | |||
| @@ -6,11 +6,11 @@ mod generated { | |||
| 6 | embassy_hal_internal::interrupt_mod!(OS_EVENT, LPUART2, RTC, ADC1); | 6 | embassy_hal_internal::interrupt_mod!(OS_EVENT, LPUART2, RTC, ADC1); |
| 7 | } | 7 | } |
| 8 | 8 | ||
| 9 | pub use generated::interrupt::Priority; | 9 | use core::sync::atomic::{AtomicU16, AtomicU32, Ordering}; |
| 10 | pub use generated::interrupt::typelevel; | 10 | |
| 11 | pub use generated::interrupt::{typelevel, Priority}; | ||
| 11 | 12 | ||
| 12 | use crate::pac::Interrupt; | 13 | use crate::pac::Interrupt; |
| 13 | use core::sync::atomic::{AtomicU16, AtomicU32, Ordering}; | ||
| 14 | 14 | ||
| 15 | /// Trait for configuring and controlling interrupts. | 15 | /// Trait for configuring and controlling interrupts. |
| 16 | /// | 16 | /// |
diff --git a/src/lib.rs b/src/lib.rs index 518fe01d2..fe27aadba 100644 --- a/src/lib.rs +++ b/src/lib.rs | |||
| @@ -30,17 +30,17 @@ pub fn pac() -> &'static pac::Peripherals { | |||
| 30 | } | 30 | } |
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | #[cfg(feature = "unstable-pac")] | ||
| 34 | pub use mcxa_pac as pac; | ||
| 35 | #[cfg(not(feature = "unstable-pac"))] | ||
| 36 | pub(crate) use mcxa_pac as pac; | ||
| 37 | |||
| 38 | // Use cortex-m-rt's #[interrupt] attribute directly; PAC does not re-export it. | 33 | // Use cortex-m-rt's #[interrupt] attribute directly; PAC does not re-export it. |
| 39 | 34 | ||
| 40 | // Re-export interrupt traits and types | 35 | // Re-export interrupt traits and types |
| 41 | pub use adc::Adc1 as Adc1Token; | 36 | pub use adc::Adc1 as Adc1Token; |
| 42 | pub use gpio::{AnyPin, Flex, Gpio as GpioToken, Input, Level, Output, pins::*}; | 37 | pub use gpio::pins::*; |
| 38 | pub use gpio::{AnyPin, Flex, Gpio as GpioToken, Input, Level, Output}; | ||
| 43 | pub use interrupt::InterruptExt; | 39 | pub use interrupt::InterruptExt; |
| 40 | #[cfg(feature = "unstable-pac")] | ||
| 41 | pub use mcxa_pac as pac; | ||
| 42 | #[cfg(not(feature = "unstable-pac"))] | ||
| 43 | pub(crate) use mcxa_pac as pac; | ||
| 44 | pub use ostimer::Ostimer0 as Ostimer0Token; | 44 | pub use ostimer::Ostimer0 as Ostimer0Token; |
| 45 | pub use rtc::Rtc0 as Rtc0Token; | 45 | pub use rtc::Rtc0 as Rtc0Token; |
| 46 | pub use uart::Lpuart2 as Uart2Token; | 46 | pub use uart::Lpuart2 as Uart2Token; |
diff --git a/src/lpuart/buffered.rs b/src/lpuart/buffered.rs index e2382e86d..0413fed8e 100644 --- a/src/lpuart/buffered.rs +++ b/src/lpuart/buffered.rs | |||
| @@ -3,8 +3,8 @@ use core::marker::PhantomData; | |||
| 3 | use core::sync::atomic::{AtomicBool, Ordering}; | 3 | use core::sync::atomic::{AtomicBool, Ordering}; |
| 4 | use core::task::Poll; | 4 | use core::task::Poll; |
| 5 | 5 | ||
| 6 | use embassy_hal_internal::Peri; | ||
| 7 | use embassy_hal_internal::atomic_ring_buffer::RingBuffer; | 6 | use embassy_hal_internal::atomic_ring_buffer::RingBuffer; |
| 7 | use embassy_hal_internal::Peri; | ||
| 8 | use embassy_sync::waitqueue::AtomicWaker; | 8 | use embassy_sync::waitqueue::AtomicWaker; |
| 9 | 9 | ||
| 10 | use super::*; | 10 | use super::*; |
| @@ -87,15 +87,7 @@ impl<'a> BufferedLpuart<'a> { | |||
| 87 | let state = T::buffered_state(); | 87 | let state = T::buffered_state(); |
| 88 | 88 | ||
| 89 | // Initialize the peripheral | 89 | // Initialize the peripheral |
| 90 | Self::init::<T>( | 90 | Self::init::<T>(Some(&tx_pin), Some(&rx_pin), None, None, tx_buffer, rx_buffer, config)?; |
| 91 | Some(&tx_pin), | ||
| 92 | Some(&rx_pin), | ||
| 93 | None, | ||
| 94 | None, | ||
| 95 | tx_buffer, | ||
| 96 | rx_buffer, | ||
| 97 | config, | ||
| 98 | )?; | ||
| 99 | 91 | ||
| 100 | Ok(Self { | 92 | Ok(Self { |
| 101 | tx: BufferedLpuartTx { | 93 | tx: BufferedLpuartTx { |
| @@ -523,9 +515,7 @@ pub struct BufferedInterruptHandler<T: Instance> { | |||
| 523 | _phantom: PhantomData<T>, | 515 | _phantom: PhantomData<T>, |
| 524 | } | 516 | } |
| 525 | 517 | ||
| 526 | impl<T: Instance> crate::interrupt::typelevel::Handler<T::Interrupt> | 518 | impl<T: Instance> crate::interrupt::typelevel::Handler<T::Interrupt> for BufferedInterruptHandler<T> { |
| 527 | for BufferedInterruptHandler<T> | ||
| 528 | { | ||
| 529 | unsafe fn on_interrupt() { | 519 | unsafe fn on_interrupt() { |
| 530 | let regs = T::info().regs; | 520 | let regs = T::info().regs; |
| 531 | let state = T::buffered_state(); | 521 | let state = T::buffered_state(); |
| @@ -616,8 +606,7 @@ impl<T: Instance> crate::interrupt::typelevel::Handler<T::Interrupt> | |||
| 616 | // If buffer is empty, switch to TC interrupt or disable | 606 | // If buffer is empty, switch to TC interrupt or disable |
| 617 | if state.tx_buf.is_empty() { | 607 | if state.tx_buf.is_empty() { |
| 618 | cortex_m::interrupt::free(|_| { | 608 | cortex_m::interrupt::free(|_| { |
| 619 | regs.ctrl() | 609 | regs.ctrl().modify(|_, w| w.tie().disabled().tcie().enabled()); |
| 620 | .modify(|_, w| w.tie().disabled().tcie().enabled()); | ||
| 621 | }); | 610 | }); |
| 622 | } | 611 | } |
| 623 | } | 612 | } |
diff --git a/src/lpuart/mod.rs b/src/lpuart/mod.rs index 99f4a4a66..bed10bdb0 100644 --- a/src/lpuart/mod.rs +++ b/src/lpuart/mod.rs | |||
| @@ -1,15 +1,13 @@ | |||
| 1 | use crate::interrupt; | ||
| 2 | use core::marker::PhantomData; | 1 | use core::marker::PhantomData; |
| 2 | |||
| 3 | use embassy_hal_internal::{Peri, PeripheralType}; | 3 | use embassy_hal_internal::{Peri, PeripheralType}; |
| 4 | use paste::paste; | 4 | use paste::paste; |
| 5 | 5 | ||
| 6 | use crate::pac; | ||
| 7 | use crate::pac::lpuart0::baud::Sbns as StopBits; | 6 | use crate::pac::lpuart0::baud::Sbns as StopBits; |
| 8 | use crate::pac::lpuart0::ctrl::{ | 7 | use crate::pac::lpuart0::ctrl::{Idlecfg as IdleConfig, Ilt as IdleType, Pt as Parity, M as DataBits}; |
| 9 | Idlecfg as IdleConfig, Ilt as IdleType, M as DataBits, Pt as Parity, | ||
| 10 | }; | ||
| 11 | use crate::pac::lpuart0::modir::{Txctsc as TxCtsConfig, Txctssrc as TxCtsSource}; | 8 | use crate::pac::lpuart0::modir::{Txctsc as TxCtsConfig, Txctssrc as TxCtsSource}; |
| 12 | use crate::pac::lpuart0::stat::Msbf as MsbFirst; | 9 | use crate::pac::lpuart0::stat::Msbf as MsbFirst; |
| 10 | use crate::{interrupt, pac}; | ||
| 13 | 11 | ||
| 14 | pub mod buffered; | 12 | pub mod buffered; |
| 15 | 13 | ||
| @@ -261,8 +259,7 @@ pub fn configure_baudrate(regs: Regs, baudrate_bps: u32, clock: Clock) -> Result | |||
| 261 | /// Configure frame format (stop bits, data bits) | 259 | /// Configure frame format (stop bits, data bits) |
| 262 | pub fn configure_frame_format(regs: Regs, config: &Config) { | 260 | pub fn configure_frame_format(regs: Regs, config: &Config) { |
| 263 | // Configure stop bits | 261 | // Configure stop bits |
| 264 | regs.baud() | 262 | regs.baud().modify(|_, w| w.sbns().variant(config.stop_bits_count)); |
| 265 | .modify(|_, w| w.sbns().variant(config.stop_bits_count)); | ||
| 266 | 263 | ||
| 267 | // Clear M10 for now (10-bit mode) | 264 | // Clear M10 for now (10-bit mode) |
| 268 | regs.baud().modify(|_, w| w.m10().disabled()); | 265 | regs.baud().modify(|_, w| w.m10().disabled()); |
| @@ -314,8 +311,7 @@ pub fn configure_fifo(regs: Regs, config: &Config) { | |||
| 314 | }); | 311 | }); |
| 315 | 312 | ||
| 316 | // Enable TX/RX FIFOs | 313 | // Enable TX/RX FIFOs |
| 317 | regs.fifo() | 314 | regs.fifo().modify(|_, w| w.txfe().enabled().rxfe().enabled()); |
| 318 | .modify(|_, w| w.txfe().enabled().rxfe().enabled()); | ||
| 319 | 315 | ||
| 320 | // Flush FIFOs | 316 | // Flush FIFOs |
| 321 | regs.fifo() | 317 | regs.fifo() |
| @@ -818,10 +814,7 @@ impl<'a> LpuartTx<'a, Blocking> { | |||
| 818 | } | 814 | } |
| 819 | 815 | ||
| 820 | fn write_byte_internal(&mut self, byte: u8) -> Result<()> { | 816 | fn write_byte_internal(&mut self, byte: u8) -> Result<()> { |
| 821 | self.info | 817 | self.info.regs.data().modify(|_, w| unsafe { w.bits(u32::from(byte)) }); |
| 822 | .regs | ||
| 823 | .data() | ||
| 824 | .modify(|_, w| unsafe { w.bits(u32::from(byte)) }); | ||
| 825 | 818 | ||
| 826 | Ok(()) | 819 | Ok(()) |
| 827 | } | 820 | } |
diff --git a/src/ostimer.rs b/src/ostimer.rs index 6a4188db0..a4cab6970 100644 --- a/src/ostimer.rs +++ b/src/ostimer.rs | |||
| @@ -27,9 +27,10 @@ | |||
| 27 | //! - Immediate wake for timestamps that would cause rollover issues | 27 | //! - Immediate wake for timestamps that would cause rollover issues |
| 28 | #![allow(dead_code)] | 28 | #![allow(dead_code)] |
| 29 | 29 | ||
| 30 | use core::sync::atomic::{AtomicBool, Ordering}; | ||
| 31 | |||
| 30 | use crate::interrupt::InterruptExt; | 32 | use crate::interrupt::InterruptExt; |
| 31 | use crate::pac; | 33 | use crate::pac; |
| 32 | use core::sync::atomic::{AtomicBool, Ordering}; | ||
| 33 | 34 | ||
| 34 | // PAC defines the shared RegisterBlock under `ostimer0`. | 35 | // PAC defines the shared RegisterBlock under `ostimer0`. |
| 35 | type Regs = pac::ostimer0::RegisterBlock; | 36 | type Regs = pac::ostimer0::RegisterBlock; |
| @@ -129,18 +130,12 @@ pub(super) fn wait_for_match_write_complete(r: &Regs) -> bool { | |||
| 129 | 130 | ||
| 130 | fn prime_match_registers(r: &Regs) { | 131 | fn prime_match_registers(r: &Regs) { |
| 131 | // Disable the interrupt, clear any pending flag, then wait until the MATCH registers are writable. | 132 | // Disable the interrupt, clear any pending flag, then wait until the MATCH registers are writable. |
| 132 | r.osevent_ctrl().write(|w| { | 133 | r.osevent_ctrl() |
| 133 | w.ostimer_intrflag() | 134 | .write(|w| w.ostimer_intrflag().clear_bit_by_one().ostimer_intena().clear_bit()); |
| 134 | .clear_bit_by_one() | ||
| 135 | .ostimer_intena() | ||
| 136 | .clear_bit() | ||
| 137 | }); | ||
| 138 | 135 | ||
| 139 | if wait_for_match_write_ready(r) { | 136 | if wait_for_match_write_ready(r) { |
| 140 | r.match_l() | 137 | r.match_l().write(|w| unsafe { w.match_value().bits(MATCH_L_MAX) }); |
| 141 | .write(|w| unsafe { w.match_value().bits(MATCH_L_MAX) }); | 138 | r.match_h().write(|w| unsafe { w.match_value().bits(MATCH_H_MAX) }); |
| 142 | r.match_h() | ||
| 143 | .write(|w| unsafe { w.match_value().bits(MATCH_H_MAX) }); | ||
| 144 | let _ = wait_for_match_write_complete(r); | 139 | let _ = wait_for_match_write_complete(r); |
| 145 | } | 140 | } |
| 146 | } | 141 | } |
| @@ -222,10 +217,7 @@ impl<'d, I: Instance> Ostimer<'d, I> { | |||
| 222 | /// Requires clocks for the instance to be enabled by the board before calling. | 217 | /// Requires clocks for the instance to be enabled by the board before calling. |
| 223 | /// Does not enable NVIC or INTENA; use time_driver::init() for async operation. | 218 | /// Does not enable NVIC or INTENA; use time_driver::init() for async operation. |
| 224 | pub fn new(_inst: impl Instance, cfg: Config, _p: &'d crate::pac::Peripherals) -> Self { | 219 | pub fn new(_inst: impl Instance, cfg: Config, _p: &'d crate::pac::Peripherals) -> Self { |
| 225 | assert!( | 220 | assert!(cfg.clock_frequency_hz > 0, "OSTIMER frequency must be greater than 0"); |
| 226 | cfg.clock_frequency_hz > 0, | ||
| 227 | "OSTIMER frequency must be greater than 0" | ||
| 228 | ); | ||
| 229 | 221 | ||
| 230 | if cfg.init_match_max { | 222 | if cfg.init_match_max { |
| 231 | let r: &Regs = unsafe { &*I::ptr() }; | 223 | let r: &Regs = unsafe { &*I::ptr() }; |
| @@ -268,12 +260,8 @@ impl<'d, I: Instance> Ostimer<'d, I> { | |||
| 268 | 260 | ||
| 269 | // Mask the peripheral interrupt flag before we toggle the reset line so that | 261 | // Mask the peripheral interrupt flag before we toggle the reset line so that |
| 270 | // no new NVIC activity races with the reset sequence. | 262 | // no new NVIC activity races with the reset sequence. |
| 271 | r.osevent_ctrl().write(|w| { | 263 | r.osevent_ctrl() |
| 272 | w.ostimer_intrflag() | 264 | .write(|w| w.ostimer_intrflag().clear_bit_by_one().ostimer_intena().clear_bit()); |
| 273 | .clear_bit_by_one() | ||
| 274 | .ostimer_intena() | ||
| 275 | .clear_bit() | ||
| 276 | }); | ||
| 277 | 265 | ||
| 278 | unsafe { | 266 | unsafe { |
| 279 | crate::reset::assert::<crate::reset::line::Ostimer0>(peripherals); | 267 | crate::reset::assert::<crate::reset::line::Ostimer0>(peripherals); |
| @@ -287,9 +275,7 @@ impl<'d, I: Instance> Ostimer<'d, I> { | |||
| 287 | crate::reset::release::<crate::reset::line::Ostimer0>(peripherals); | 275 | crate::reset::release::<crate::reset::line::Ostimer0>(peripherals); |
| 288 | } | 276 | } |
| 289 | 277 | ||
| 290 | while !<crate::reset::line::Ostimer0 as crate::reset::ResetLine>::is_released( | 278 | while !<crate::reset::line::Ostimer0 as crate::reset::ResetLine>::is_released(&peripherals.mrcc0) { |
| 291 | &peripherals.mrcc0, | ||
| 292 | ) { | ||
| 293 | cortex_m::asm::nop(); | 279 | cortex_m::asm::nop(); |
| 294 | } | 280 | } |
| 295 | 281 | ||
| @@ -363,12 +349,8 @@ impl<'d, I: Instance> Ostimer<'d, I> { | |||
| 363 | 349 | ||
| 364 | critical_section::with(|_| { | 350 | critical_section::with(|_| { |
| 365 | // Disable interrupt and clear flag | 351 | // Disable interrupt and clear flag |
| 366 | r.osevent_ctrl().write(|w| { | 352 | r.osevent_ctrl() |
| 367 | w.ostimer_intrflag() | 353 | .write(|w| w.ostimer_intrflag().clear_bit_by_one().ostimer_intena().clear_bit()); |
| 368 | .clear_bit_by_one() | ||
| 369 | .ostimer_intena() | ||
| 370 | .clear_bit() | ||
| 371 | }); | ||
| 372 | 354 | ||
| 373 | if !wait_for_match_write_ready(r) { | 355 | if !wait_for_match_write_ready(r) { |
| 374 | prime_match_registers(r); | 356 | prime_match_registers(r); |
| @@ -526,15 +508,17 @@ fn gray_to_bin(gray: u64) -> u64 { | |||
| 526 | } | 508 | } |
| 527 | 509 | ||
| 528 | pub mod time_driver { | 510 | pub mod time_driver { |
| 529 | use super::{ | ||
| 530 | ALARM_ACTIVE, ALARM_CALLBACK, ALARM_FLAG, ALARM_TARGET_TIME, EVTIMER_HI_MASK, | ||
| 531 | EVTIMER_HI_SHIFT, LOW_32_BIT_MASK, Regs, bin_to_gray, now_ticks_read, | ||
| 532 | }; | ||
| 533 | use crate::pac; | ||
| 534 | use core::sync::atomic::Ordering; | 511 | use core::sync::atomic::Ordering; |
| 535 | use core::task::Waker; | 512 | use core::task::Waker; |
| 513 | |||
| 536 | use embassy_sync::waitqueue::AtomicWaker; | 514 | use embassy_sync::waitqueue::AtomicWaker; |
| 537 | use embassy_time_driver as etd; | 515 | use embassy_time_driver as etd; |
| 516 | |||
| 517 | use super::{ | ||
| 518 | bin_to_gray, now_ticks_read, Regs, ALARM_ACTIVE, ALARM_CALLBACK, ALARM_FLAG, ALARM_TARGET_TIME, | ||
| 519 | EVTIMER_HI_MASK, EVTIMER_HI_SHIFT, LOW_32_BIT_MASK, | ||
| 520 | }; | ||
| 521 | use crate::pac; | ||
| 538 | pub struct Driver; | 522 | pub struct Driver; |
| 539 | static TIMER_WAKER: AtomicWaker = AtomicWaker::new(); | 523 | static TIMER_WAKER: AtomicWaker = AtomicWaker::new(); |
| 540 | 524 | ||
| @@ -569,12 +553,8 @@ pub mod time_driver { | |||
| 569 | 553 | ||
| 570 | critical_section::with(|_| { | 554 | critical_section::with(|_| { |
| 571 | // Mask INTENA and clear flag | 555 | // Mask INTENA and clear flag |
| 572 | r.osevent_ctrl().write(|w| { | 556 | r.osevent_ctrl() |
| 573 | w.ostimer_intrflag() | 557 | .write(|w| w.ostimer_intrflag().clear_bit_by_one().ostimer_intena().clear_bit()); |
| 574 | .clear_bit_by_one() | ||
| 575 | .ostimer_intena() | ||
| 576 | .clear_bit() | ||
| 577 | }); | ||
| 578 | 558 | ||
| 579 | // Read back to ensure W1C took effect on hardware | 559 | // Read back to ensure W1C took effect on hardware |
| 580 | let _ = r.osevent_ctrl().read().ostimer_intrflag().bit(); | 560 | let _ = r.osevent_ctrl().read().ostimer_intrflag().bit(); |
| @@ -690,9 +670,7 @@ pub mod time_driver { | |||
| 690 | 670 | ||
| 691 | /// Type-level handler to be used with bind_interrupts! for OS_EVENT. | 671 | /// Type-level handler to be used with bind_interrupts! for OS_EVENT. |
| 692 | pub struct OsEventHandler; | 672 | pub struct OsEventHandler; |
| 693 | impl crate::interrupt::typelevel::Handler<crate::interrupt::typelevel::OS_EVENT> | 673 | impl crate::interrupt::typelevel::Handler<crate::interrupt::typelevel::OS_EVENT> for OsEventHandler { |
| 694 | for OsEventHandler | ||
| 695 | { | ||
| 696 | unsafe fn on_interrupt() { | 674 | unsafe fn on_interrupt() { |
| 697 | on_interrupt(); | 675 | on_interrupt(); |
| 698 | } | 676 | } |
diff --git a/src/pins.rs b/src/pins.rs index 1d92f9fef..f802568f3 100644 --- a/src/pins.rs +++ b/src/pins.rs | |||
| @@ -84,10 +84,7 @@ pub unsafe fn set_pin_mux(port: u8, pin: u8, mux: u8) { | |||
| 84 | }; | 84 | }; |
| 85 | 85 | ||
| 86 | if pin > max_pin { | 86 | if pin > max_pin { |
| 87 | panic!( | 87 | panic!("Invalid pin {} for PORT{}, max pin is {}", pin, port, max_pin); |
| 88 | "Invalid pin {} for PORT{}, max pin is {}", | ||
| 89 | pin, port, max_pin | ||
| 90 | ); | ||
| 91 | } | 88 | } |
| 92 | 89 | ||
| 93 | // Get the base address for the port | 90 | // Get the base address for the port |
diff --git a/src/rtc.rs b/src/rtc.rs index 5e3dfe6c1..d62da1f0a 100644 --- a/src/rtc.rs +++ b/src/rtc.rs | |||
| @@ -1,7 +1,8 @@ | |||
| 1 | //! RTC DateTime driver. | 1 | //! RTC DateTime driver. |
| 2 | use core::sync::atomic::{AtomicBool, Ordering}; | ||
| 3 | |||
| 2 | use crate::pac; | 4 | use crate::pac; |
| 3 | use crate::pac::rtc0::cr::Um; | 5 | use crate::pac::rtc0::cr::Um; |
| 4 | use core::sync::atomic::{AtomicBool, Ordering}; | ||
| 5 | 6 | ||
| 6 | type Regs = pac::rtc0::RegisterBlock; | 7 | type Regs = pac::rtc0::RegisterBlock; |
| 7 | 8 | ||
diff --git a/src/uart.rs b/src/uart.rs index 65dd91492..3209a318d 100644 --- a/src/uart.rs +++ b/src/uart.rs | |||
| @@ -1,11 +1,13 @@ | |||
| 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 | use crate::pac; | ||
| 5 | use core::cell::RefCell; | 4 | use core::cell::RefCell; |
| 5 | |||
| 6 | use cortex_m::interrupt::Mutex; | 6 | use cortex_m::interrupt::Mutex; |
| 7 | use embassy_sync::signal::Signal; | 7 | use embassy_sync::signal::Signal; |
| 8 | 8 | ||
| 9 | use crate::pac; | ||
| 10 | |||
| 9 | // svd2rust defines the shared LPUART RegisterBlock under lpuart0; all instances reuse it. | 11 | // svd2rust defines the shared LPUART RegisterBlock under lpuart0; all instances reuse it. |
| 10 | type Regs = pac::lpuart0::RegisterBlock; | 12 | type Regs = pac::lpuart0::RegisterBlock; |
| 11 | 13 | ||
| @@ -108,7 +110,7 @@ impl<I: Instance> Uart<I> { | |||
| 108 | cortex_m::asm::delay(3); // Short delay for reset to take effect | 110 | cortex_m::asm::delay(3); // Short delay for reset to take effect |
| 109 | l.global().write(|w| w.rst().no_effect()); | 111 | l.global().write(|w| w.rst().no_effect()); |
| 110 | cortex_m::asm::delay(10); // Allow peripheral to stabilize after reset | 112 | cortex_m::asm::delay(10); // Allow peripheral to stabilize after reset |
| 111 | // 2) BAUD | 113 | // 2) BAUD |
| 112 | let (osr, sbr) = compute_osr_sbr(cfg.src_hz, cfg.baud); | 114 | let (osr, sbr) = compute_osr_sbr(cfg.src_hz, cfg.baud); |
| 113 | l.baud().modify(|_, w| { | 115 | l.baud().modify(|_, w| { |
| 114 | let w = match cfg.stop_bits { | 116 | let w = match cfg.stop_bits { |
| @@ -234,8 +236,7 @@ impl RingBuffer { | |||
| 234 | 236 | ||
| 235 | // Global RX buffer shared between interrupt handler and UART instance | 237 | // Global RX buffer shared between interrupt handler and UART instance |
| 236 | static RX_BUFFER: Mutex<RefCell<RingBuffer>> = Mutex::new(RefCell::new(RingBuffer::new())); | 238 | static RX_BUFFER: Mutex<RefCell<RingBuffer>> = Mutex::new(RefCell::new(RingBuffer::new())); |
| 237 | static RX_SIGNAL: Signal<embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex, ()> = | 239 | static RX_SIGNAL: Signal<embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex, ()> = Signal::new(); |
| 238 | Signal::new(); | ||
| 239 | 240 | ||
| 240 | // Debug counter for interrupt handler calls | 241 | // Debug counter for interrupt handler calls |
| 241 | static mut INTERRUPT_COUNT: u32 = 0; | 242 | static mut INTERRUPT_COUNT: u32 = 0; |
| @@ -279,9 +280,7 @@ impl<I: Instance> Uart<I> { | |||
| 279 | /// Type-level handler for LPUART2 interrupts, compatible with bind_interrupts!. | 280 | /// Type-level handler for LPUART2 interrupts, compatible with bind_interrupts!. |
| 280 | pub struct UartInterruptHandler; | 281 | pub struct UartInterruptHandler; |
| 281 | 282 | ||
| 282 | impl crate::interrupt::typelevel::Handler<crate::interrupt::typelevel::LPUART2> | 283 | impl crate::interrupt::typelevel::Handler<crate::interrupt::typelevel::LPUART2> for UartInterruptHandler { |
| 283 | for UartInterruptHandler | ||
| 284 | { | ||
| 285 | unsafe fn on_interrupt() { | 284 | unsafe fn on_interrupt() { |
| 286 | INTERRUPT_COUNT += 1; | 285 | INTERRUPT_COUNT += 1; |
| 287 | 286 | ||
