aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorFelipe Balbi <[email protected]>2025-11-07 10:07:33 -0800
committerFelipe Balbi <[email protected]>2025-11-07 10:08:16 -0800
commite75066820ad320495ca70570641c90d75247b19b (patch)
treeda2aeddb9164dbc2829b54185d1f180efbad6daf /examples
parentcb2ac2790f4b037056f9571abeb4d62360199426 (diff)
cargo +nightly fmt
Signed-off-by: Felipe Balbi <[email protected]>
Diffstat (limited to 'examples')
-rw-r--r--examples/adc_interrupt.rs9
-rw-r--r--examples/adc_polling.rs9
-rw-r--r--examples/blink.rs5
-rw-r--r--examples/lpuart_buffered.rs9
-rw-r--r--examples/lpuart_polling.rs8
-rw-r--r--examples/ostimer_alarm.rs15
-rw-r--r--examples/ostimer_async.rs5
-rw-r--r--examples/ostimer_counter.rs8
-rw-r--r--examples/ostimer_race_test.rs14
-rw-r--r--examples/rtc_alarm.rs9
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
4use cortex_m;
5use embassy_executor::Spawner; 4use embassy_executor::Spawner;
6use embassy_mcxa276 as hal;
7
8use hal::adc::{LpadcConfig, TriggerPriorityPolicy}; 5use hal::adc::{LpadcConfig, TriggerPriorityPolicy};
9use hal::pac::adc1::cfg::{Pwrsel, Refsel}; 6use hal::pac::adc1::cfg::{Pwrsel, Refsel};
10use hal::pac::adc1::cmdl1::{Adch, Mode}; 7use hal::pac::adc1::cmdl1::{Adch, Mode};
11use hal::pac::adc1::ctrl::CalAvgs; 8use hal::pac::adc1::ctrl::CalAvgs;
12use hal::pac::adc1::tctrl::Tcmd; 9use hal::pac::adc1::tctrl::Tcmd;
13
14use hal::uart; 10use hal::uart;
11use {cortex_m, embassy_mcxa276 as hal};
15mod common; 12mod common;
16 13
14use hal::{bind_interrupts, InterruptExt};
17use {defmt_rtt as _, panic_probe as _}; 15use {defmt_rtt as _, panic_probe as _};
18 16
19use hal::InterruptExt;
20use hal::bind_interrupts;
21
22bind_interrupts!(struct Irqs { 17bind_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
4use embassy_mcxa276 as hal;
5
6use embassy_executor::Spawner; 4use embassy_executor::Spawner;
7 5use embassy_mcxa276 as hal;
8use hal::adc::{ConvResult, LpadcConfig, TriggerPriorityPolicy}; 6use hal::adc::{ConvResult, LpadcConfig, TriggerPriorityPolicy};
9use hal::pac::adc1::cfg::{Pwrsel, Refsel}; 7use hal::pac::adc1::cfg::{Pwrsel, Refsel};
10use hal::pac::adc1::cmdl1::{Adch, Mode}; 8use hal::pac::adc1::cmdl1::{Adch, Mode};
11use hal::pac::adc1::ctrl::CalAvgs; 9use hal::pac::adc1::ctrl::CalAvgs;
12use hal::pac::adc1::tctrl::Tcmd; 10use hal::pac::adc1::tctrl::Tcmd;
13
14use hal::uart; 11use hal::uart;
15 12
16mod common; 13mod common;
17 14
18use {defmt_rtt as _, panic_probe as _};
19
20use core::fmt::Write; 15use core::fmt::Write;
16
21use heapless::String; 17use heapless::String;
18use {defmt_rtt as _, panic_probe as _};
22 19
23const G_LPADC_RESULT_SHIFT: u32 = 0; 20const 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 @@
4use embassy_executor::Spawner; 4use embassy_executor::Spawner;
5use embassy_mcxa276 as hal; 5use embassy_mcxa276 as hal;
6use embassy_mcxa276::interrupt::typelevel::Handler; 6use embassy_mcxa276::interrupt::typelevel::Handler;
7use embassy_mcxa276::lpuart;
8use embassy_mcxa276::lpuart::buffered::BufferedLpuart; 7use embassy_mcxa276::lpuart::buffered::BufferedLpuart;
9 8use embassy_mcxa276::{bind_interrupts, lpuart};
10use embedded_io_async::{Read, Write}; 9use embedded_io_async::{Read, Write};
11 10
12use embassy_mcxa276::bind_interrupts;
13
14mod common; 11mod 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
4use crate::hal::lpuart::{Config, Lpuart, lib};
5use embassy_executor::Spawner; 4use embassy_executor::Spawner;
6use embassy_mcxa276 as hal; 5use {defmt_rtt as _, embassy_mcxa276 as hal, panic_probe as _};
7 6
8use {defmt_rtt as _, panic_probe as _}; 7use crate::hal::lpuart::{lib, Config, Lpuart};
9 8
10mod common; 9mod 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
4use core::sync::atomic::{AtomicBool, Ordering}; 4use core::sync::atomic::{AtomicBool, Ordering};
5use cortex_m; 5
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_mcxa276 as hal;
8use hal::uart; 7use hal::uart;
8use {cortex_m, embassy_mcxa276 as hal};
9 9
10mod common; 10mod common;
11 11
12use {defmt_rtt as _, panic_probe as _};
13
14use embassy_mcxa276::bind_interrupts; 12use embassy_mcxa276::bind_interrupts;
13use {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.
17bind_interrupts!(struct Irqs { 16bind_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
9use embassy_executor::Spawner; 9use embassy_executor::Spawner;
10use embassy_time::{Duration, Timer}; 10use embassy_time::{Duration, Timer};
11
12use {defmt_rtt as _, panic_probe as _};
13
14use embassy_mcxa276 as hal;
15use hal::bind_interrupts; 11use hal::bind_interrupts;
12use {defmt_rtt as _, embassy_mcxa276 as hal, panic_probe as _};
16 13
17mod common; 14mod 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
12use core::sync::atomic::{AtomicU32, Ordering};
13
12use embassy_executor::Spawner; 14use embassy_executor::Spawner;
13use embassy_time::{Duration, Timer}; 15use embassy_time::{Duration, Timer};
14
15use core::sync::atomic::{AtomicU32, Ordering};
16use embassy_mcxa276 as hal;
17use hal::bind_interrupts; 16use hal::bind_interrupts;
18use {defmt_rtt as _, panic_probe as _}; 17use {defmt_rtt as _, embassy_mcxa276 as hal, panic_probe as _};
19 18
20mod common; 19mod 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
4use cortex_m;
5use embassy_executor::Spawner; 4use embassy_executor::Spawner;
6use embassy_mcxa276 as hal;
7use hal::InterruptExt;
8use hal::rtc::{RtcDateTime, RtcInterruptEnable}; 5use hal::rtc::{RtcDateTime, RtcInterruptEnable};
9use hal::uart; 6use hal::{uart, InterruptExt};
7use {cortex_m, embassy_mcxa276 as hal};
10 8
11mod common; 9mod common;
12 10
13type MyRtc = hal::rtc::Rtc<hal::rtc::Rtc0>; 11type MyRtc = hal::rtc::Rtc<hal::rtc::Rtc0>;
14 12
15use {defmt_rtt as _, panic_probe as _};
16
17use embassy_mcxa276::bind_interrupts; 13use embassy_mcxa276::bind_interrupts;
14use {defmt_rtt as _, panic_probe as _};
18 15
19bind_interrupts!(struct Irqs { 16bind_interrupts!(struct Irqs {
20 RTC => hal::rtc::RtcHandler; 17 RTC => hal::rtc::RtcHandler;