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 /examples | |
| parent | cb2ac2790f4b037056f9571abeb4d62360199426 (diff) | |
cargo +nightly fmt
Signed-off-by: Felipe Balbi <[email protected]>
Diffstat (limited to 'examples')
| -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 |
10 files changed, 27 insertions, 64 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; |
