aboutsummaryrefslogtreecommitdiff
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
parentcb2ac2790f4b037056f9571abeb4d62360199426 (diff)
cargo +nightly fmt
Signed-off-by: Felipe Balbi <[email protected]>
-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
-rw-r--r--rustfmt.toml8
-rw-r--r--src/adc.rs24
-rw-r--r--src/clocks.rs3
-rw-r--r--src/gpio.rs8
-rw-r--r--src/interrupt.rs6
-rw-r--r--src/lib.rs12
-rw-r--r--src/lpuart/buffered.rs19
-rw-r--r--src/lpuart/mod.rs19
-rw-r--r--src/ostimer.rs66
-rw-r--r--src/pins.rs5
-rw-r--r--src/rtc.rs3
-rw-r--r--src/uart.rs13
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
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;
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
2edition = "2021"
3# Merge and sort imports by crate; reduces noise in diffs
4imports_granularity = "Crate"
5group_imports = "StdExternalCrate" 1group_imports = "StdExternalCrate"
6# Keep defaults for everything else to stay close to rustfmt stable 2imports_granularity = "Module"
7 3max_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
2use crate::pac;
3use core::sync::atomic::{AtomicBool, Ordering}; 2use core::sync::atomic::{AtomicBool, Ordering};
4 3
4use crate::pac;
5use crate::pac::adc1::cfg::{HptExdi, Pwrsel, Refsel, Tcmdres, Tprictrl, Tres}; 5use crate::pac::adc1::cfg::{HptExdi, Pwrsel, Refsel, Tcmdres, Tprictrl, Tres};
6use crate::pac::adc1::cmdh1::{Avgs, Cmpen, Next, Sts}; 6use crate::pac::adc1::cmdh1::{Avgs, Cmpen, Next, Sts};
7use crate::pac::adc1::cmdl1::{Adch, Ctype, Mode}; 7use 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) {
76pub unsafe fn select_uart2_clock(peripherals: &pac::Peripherals) { 76pub 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
68pub mod pins { 68pub 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
9pub use generated::interrupt::Priority; 9use core::sync::atomic::{AtomicU16, AtomicU32, Ordering};
10pub use generated::interrupt::typelevel; 10
11pub use generated::interrupt::{typelevel, Priority};
11 12
12use crate::pac::Interrupt; 13use crate::pac::Interrupt;
13use 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")]
34pub use mcxa_pac as pac;
35#[cfg(not(feature = "unstable-pac"))]
36pub(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
41pub use adc::Adc1 as Adc1Token; 36pub use adc::Adc1 as Adc1Token;
42pub use gpio::{AnyPin, Flex, Gpio as GpioToken, Input, Level, Output, pins::*}; 37pub use gpio::pins::*;
38pub use gpio::{AnyPin, Flex, Gpio as GpioToken, Input, Level, Output};
43pub use interrupt::InterruptExt; 39pub use interrupt::InterruptExt;
40#[cfg(feature = "unstable-pac")]
41pub use mcxa_pac as pac;
42#[cfg(not(feature = "unstable-pac"))]
43pub(crate) use mcxa_pac as pac;
44pub use ostimer::Ostimer0 as Ostimer0Token; 44pub use ostimer::Ostimer0 as Ostimer0Token;
45pub use rtc::Rtc0 as Rtc0Token; 45pub use rtc::Rtc0 as Rtc0Token;
46pub use uart::Lpuart2 as Uart2Token; 46pub 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;
3use core::sync::atomic::{AtomicBool, Ordering}; 3use core::sync::atomic::{AtomicBool, Ordering};
4use core::task::Poll; 4use core::task::Poll;
5 5
6use embassy_hal_internal::Peri;
7use embassy_hal_internal::atomic_ring_buffer::RingBuffer; 6use embassy_hal_internal::atomic_ring_buffer::RingBuffer;
7use embassy_hal_internal::Peri;
8use embassy_sync::waitqueue::AtomicWaker; 8use embassy_sync::waitqueue::AtomicWaker;
9 9
10use super::*; 10use 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
526impl<T: Instance> crate::interrupt::typelevel::Handler<T::Interrupt> 518impl<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 @@
1use crate::interrupt;
2use core::marker::PhantomData; 1use core::marker::PhantomData;
2
3use embassy_hal_internal::{Peri, PeripheralType}; 3use embassy_hal_internal::{Peri, PeripheralType};
4use paste::paste; 4use paste::paste;
5 5
6use crate::pac;
7use crate::pac::lpuart0::baud::Sbns as StopBits; 6use crate::pac::lpuart0::baud::Sbns as StopBits;
8use crate::pac::lpuart0::ctrl::{ 7use 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};
11use crate::pac::lpuart0::modir::{Txctsc as TxCtsConfig, Txctssrc as TxCtsSource}; 8use crate::pac::lpuart0::modir::{Txctsc as TxCtsConfig, Txctssrc as TxCtsSource};
12use crate::pac::lpuart0::stat::Msbf as MsbFirst; 9use crate::pac::lpuart0::stat::Msbf as MsbFirst;
10use crate::{interrupt, pac};
13 11
14pub mod buffered; 12pub 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)
262pub fn configure_frame_format(regs: Regs, config: &Config) { 260pub 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
30use core::sync::atomic::{AtomicBool, Ordering};
31
30use crate::interrupt::InterruptExt; 32use crate::interrupt::InterruptExt;
31use crate::pac; 33use crate::pac;
32use core::sync::atomic::{AtomicBool, Ordering};
33 34
34// PAC defines the shared RegisterBlock under `ostimer0`. 35// PAC defines the shared RegisterBlock under `ostimer0`.
35type Regs = pac::ostimer0::RegisterBlock; 36type Regs = pac::ostimer0::RegisterBlock;
@@ -129,18 +130,12 @@ pub(super) fn wait_for_match_write_complete(r: &Regs) -> bool {
129 130
130fn prime_match_registers(r: &Regs) { 131fn 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
528pub mod time_driver { 510pub 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.
2use core::sync::atomic::{AtomicBool, Ordering};
3
2use crate::pac; 4use crate::pac;
3use crate::pac::rtc0::cr::Um; 5use crate::pac::rtc0::cr::Um;
4use core::sync::atomic::{AtomicBool, Ordering};
5 6
6type Regs = pac::rtc0::RegisterBlock; 7type 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
4use crate::pac;
5use core::cell::RefCell; 4use core::cell::RefCell;
5
6use cortex_m::interrupt::Mutex; 6use cortex_m::interrupt::Mutex;
7use embassy_sync::signal::Signal; 7use embassy_sync::signal::Signal;
8 8
9use 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.
10type Regs = pac::lpuart0::RegisterBlock; 12type 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
236static RX_BUFFER: Mutex<RefCell<RingBuffer>> = Mutex::new(RefCell::new(RingBuffer::new())); 238static RX_BUFFER: Mutex<RefCell<RingBuffer>> = Mutex::new(RefCell::new(RingBuffer::new()));
237static RX_SIGNAL: Signal<embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex, ()> = 239static 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
241static mut INTERRUPT_COUNT: u32 = 0; 242static 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!.
280pub struct UartInterruptHandler; 281pub struct UartInterruptHandler;
281 282
282impl crate::interrupt::typelevel::Handler<crate::interrupt::typelevel::LPUART2> 283impl 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