aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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
11 files changed, 61 insertions, 117 deletions
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