aboutsummaryrefslogtreecommitdiff
path: root/embassy-nxp/src
diff options
context:
space:
mode:
authorMatteo Meluzzi <[email protected]>2025-10-24 15:48:34 +0200
committerMatteo Meluzzi <[email protected]>2025-10-24 15:48:34 +0200
commit7976f950b0de72c521f92efa350c67ccd197fab9 (patch)
tree8759312eb000de09b92a4921f476d5c16b7e7342 /embassy-nxp/src
parent828a8df18d04877df1f55f04354980b28ff2f2f8 (diff)
Merge branch 'main' into 17-add-support-for-boot-protocol
Diffstat (limited to 'embassy-nxp/src')
-rw-r--r--embassy-nxp/src/dma/lpc55.rs6
-rw-r--r--embassy-nxp/src/gpio/lpc55.rs70
-rw-r--r--embassy-nxp/src/gpio/rt1xxx.rs4
-rw-r--r--embassy-nxp/src/lib.rs5
-rw-r--r--embassy-nxp/src/pint.rs4
-rw-r--r--embassy-nxp/src/time_driver/rtc.rs4
-rw-r--r--embassy-nxp/src/usart/lpc55.rs177
7 files changed, 140 insertions, 130 deletions
diff --git a/embassy-nxp/src/dma/lpc55.rs b/embassy-nxp/src/dma/lpc55.rs
index 578d1fd88..5bd763f03 100644
--- a/embassy-nxp/src/dma/lpc55.rs
+++ b/embassy-nxp/src/dma/lpc55.rs
@@ -1,16 +1,16 @@
1use core::cell::RefCell; 1use core::cell::RefCell;
2use core::future::Future; 2use core::future::Future;
3use core::pin::Pin; 3use core::pin::Pin;
4use core::sync::atomic::{compiler_fence, Ordering}; 4use core::sync::atomic::{Ordering, compiler_fence};
5use core::task::{Context, Poll}; 5use core::task::{Context, Poll};
6 6
7use critical_section::Mutex; 7use critical_section::Mutex;
8use embassy_hal_internal::interrupt::InterruptExt; 8use embassy_hal_internal::interrupt::InterruptExt;
9use embassy_hal_internal::{impl_peripheral, PeripheralType}; 9use embassy_hal_internal::{PeripheralType, impl_peripheral};
10use embassy_sync::waitqueue::AtomicWaker; 10use embassy_sync::waitqueue::AtomicWaker;
11 11
12use crate::pac::{DMA0, SYSCON, *}; 12use crate::pac::{DMA0, SYSCON, *};
13use crate::{peripherals, Peri}; 13use crate::{Peri, peripherals};
14 14
15#[interrupt] 15#[interrupt]
16fn DMA0() { 16fn DMA0() {
diff --git a/embassy-nxp/src/gpio/lpc55.rs b/embassy-nxp/src/gpio/lpc55.rs
index 36ea99d21..6039d8ca8 100644
--- a/embassy-nxp/src/gpio/lpc55.rs
+++ b/embassy-nxp/src/gpio/lpc55.rs
@@ -1,8 +1,9 @@
1use embassy_hal_internal::{impl_peripheral, PeripheralType}; 1use embassy_hal_internal::{PeripheralType, impl_peripheral};
2 2
3use crate::pac::common::{RW, Reg};
3use crate::pac::iocon::vals::{PioDigimode, PioMode}; 4use crate::pac::iocon::vals::{PioDigimode, PioMode};
4use crate::pac::{GPIO, IOCON, SYSCON}; 5use crate::pac::{GPIO, IOCON, SYSCON, iocon};
5use crate::{peripherals, Peri}; 6use crate::{Peri, peripherals};
6 7
7pub(crate) fn init() { 8pub(crate) fn init() {
8 // Enable clocks for GPIO, PINT, and IOCON 9 // Enable clocks for GPIO, PINT, and IOCON
@@ -109,13 +110,7 @@ impl<'d> Input<'d> {
109 110
110 /// Set the pull configuration for the pin. To disable the pull, use [Pull::None]. 111 /// Set the pull configuration for the pin. To disable the pull, use [Pull::None].
111 pub fn set_pull(&mut self, pull: Pull) { 112 pub fn set_pull(&mut self, pull: Pull) {
112 match_iocon!(register, self.pin.pin_bank(), self.pin.pin_number(), { 113 self.pin.set_pull(pull);
113 register.modify(|w| match pull {
114 Pull::None => w.set_mode(PioMode::INACTIVE),
115 Pull::Up => w.set_mode(PioMode::PULL_UP),
116 Pull::Down => w.set_mode(PioMode::PULL_DOWN),
117 });
118 });
119 } 114 }
120 115
121 /// Get the current input level of the pin. 116 /// Get the current input level of the pin.
@@ -193,11 +188,20 @@ impl<'d> Flex<'d> {
193 1 << self.pin.pin_number() 188 1 << self.pin.pin_number()
194 } 189 }
195 190
191 /// Set the pull configuration for the pin. To disable the pull, use [Pull::None].
192 pub fn set_pull(&mut self, pull: Pull) {
193 self.pin.pio().modify(|w| match pull {
194 Pull::None => w.set_mode(PioMode::INACTIVE),
195 Pull::Up => w.set_mode(PioMode::PULL_UP),
196 Pull::Down => w.set_mode(PioMode::PULL_DOWN),
197 });
198 }
199
196 /// Set the pin to digital mode. This is required for using a pin as a GPIO pin. The default 200 /// Set the pin to digital mode. This is required for using a pin as a GPIO pin. The default
197 /// setting for pins is (usually) non-digital. 201 /// setting for pins is (usually) non-digital.
198 fn set_as_digital(&mut self) { 202 fn set_as_digital(&mut self) {
199 match_iocon!(register, self.pin_bank(), self.pin_number(), { 203 self.pin.pio().modify(|w| {
200 register.modify(|w| w.set_digimode(PioDigimode::DIGITAL)); 204 w.set_digimode(PioDigimode::DIGITAL);
201 }); 205 });
202 } 206 }
203 207
@@ -220,6 +224,14 @@ impl<'d> Flex<'d> {
220pub(crate) trait SealedPin: Sized { 224pub(crate) trait SealedPin: Sized {
221 fn pin_bank(&self) -> Bank; 225 fn pin_bank(&self) -> Bank;
222 fn pin_number(&self) -> u8; 226 fn pin_number(&self) -> u8;
227
228 #[inline]
229 fn pio(&self) -> Reg<iocon::regs::Pio, RW> {
230 match self.pin_bank() {
231 Bank::Bank0 => IOCON.pio0(self.pin_number() as usize),
232 Bank::Bank1 => IOCON.pio1(self.pin_number() as usize),
233 }
234 }
223} 235}
224 236
225/// Interface for a Pin that can be configured by an [Input] or [Output] driver, or converted to an 237/// Interface for a Pin that can be configured by an [Input] or [Output] driver, or converted to an
@@ -272,40 +284,6 @@ impl SealedPin for AnyPin {
272 } 284 }
273} 285}
274 286
275/// Match the pin bank and number of a pin to the corresponding IOCON register.
276///
277/// # Example
278/// ```
279/// use embassy_nxp::gpio::Bank;
280/// use embassy_nxp::pac_utils::{iocon_reg, match_iocon};
281///
282/// // Make pin PIO1_6 digital and set it to pull-down mode.
283/// match_iocon!(register, Bank::Bank1, 6, {
284/// register.modify(|w|{
285/// w.set_mode(PioMode::PULL_DOWN);
286/// w.set_digimode(PioDigimode::DIGITAL);
287///
288/// }
289/// });
290/// ```
291macro_rules! match_iocon {
292 ($register:ident, $pin_bank:expr, $pin_number:expr, $action:expr) => {
293 match $pin_bank {
294 Bank::Bank0 => {
295 let $register = IOCON.pio0($pin_number as usize);
296 $action;
297 }
298
299 Bank::Bank1 => {
300 let $register = IOCON.pio1($pin_number as usize);
301 $action;
302 }
303 }
304 };
305}
306
307pub(crate) use match_iocon;
308
309macro_rules! impl_pin { 287macro_rules! impl_pin {
310 ($name:ident, $bank:expr, $pin_num:expr) => { 288 ($name:ident, $bank:expr, $pin_num:expr) => {
311 impl Pin for peripherals::$name {} 289 impl Pin for peripherals::$name {}
diff --git a/embassy-nxp/src/gpio/rt1xxx.rs b/embassy-nxp/src/gpio/rt1xxx.rs
index 1d60a0d51..c4dc110ff 100644
--- a/embassy-nxp/src/gpio/rt1xxx.rs
+++ b/embassy-nxp/src/gpio/rt1xxx.rs
@@ -5,13 +5,13 @@ use core::ops::Not;
5use core::pin::Pin as FuturePin; 5use core::pin::Pin as FuturePin;
6use core::task::{Context, Poll}; 6use core::task::{Context, Poll};
7 7
8use embassy_hal_internal::{impl_peripheral, Peri, PeripheralType}; 8use embassy_hal_internal::{Peri, PeripheralType, impl_peripheral};
9use embassy_sync::waitqueue::AtomicWaker; 9use embassy_sync::waitqueue::AtomicWaker;
10use nxp_pac::gpio::vals::Icr; 10use nxp_pac::gpio::vals::Icr;
11use nxp_pac::iomuxc::vals::Pus; 11use nxp_pac::iomuxc::vals::Pus;
12 12
13use crate::chip::{mux_address, pad_address}; 13use crate::chip::{mux_address, pad_address};
14use crate::pac::common::{Reg, RW}; 14use crate::pac::common::{RW, Reg};
15use crate::pac::gpio::Gpio; 15use crate::pac::gpio::Gpio;
16#[cfg(feature = "rt")] 16#[cfg(feature = "rt")]
17use crate::pac::interrupt; 17use crate::pac::interrupt;
diff --git a/embassy-nxp/src/lib.rs b/embassy-nxp/src/lib.rs
index f0f0afb6c..9576f02b1 100644
--- a/embassy-nxp/src/lib.rs
+++ b/embassy-nxp/src/lib.rs
@@ -1,4 +1,5 @@
1#![no_std] 1#![no_std]
2#![allow(unsafe_op_in_unsafe_fn)]
2 3
3// This mod MUST go first, so that the others see its macros. 4// This mod MUST go first, so that the others see its macros.
4pub(crate) mod fmt; 5pub(crate) mod fmt;
@@ -29,7 +30,7 @@ pub use chip::interrupt;
29pub use chip::pac; 30pub use chip::pac;
30#[cfg(not(feature = "unstable-pac"))] 31#[cfg(not(feature = "unstable-pac"))]
31pub(crate) use chip::pac; 32pub(crate) use chip::pac;
32pub use chip::{peripherals, Peripherals}; 33pub use chip::{Peripherals, peripherals};
33pub use embassy_hal_internal::{Peri, PeripheralType}; 34pub use embassy_hal_internal::{Peri, PeripheralType};
34 35
35/// Macro to bind interrupts to handlers. 36/// Macro to bind interrupts to handlers.
@@ -67,7 +68,7 @@ macro_rules! bind_interrupts {
67 68
68 $( 69 $(
69 #[allow(non_snake_case)] 70 #[allow(non_snake_case)]
70 #[no_mangle] 71 #[unsafe(no_mangle)]
71 $(#[cfg($cond_irq)])? 72 $(#[cfg($cond_irq)])?
72 unsafe extern "C" fn $irq() { 73 unsafe extern "C" fn $irq() {
73 unsafe { 74 unsafe {
diff --git a/embassy-nxp/src/pint.rs b/embassy-nxp/src/pint.rs
index e594aaa6a..5b10b4540 100644
--- a/embassy-nxp/src/pint.rs
+++ b/embassy-nxp/src/pint.rs
@@ -8,9 +8,9 @@ use critical_section::Mutex;
8use embassy_hal_internal::interrupt::InterruptExt; 8use embassy_hal_internal::interrupt::InterruptExt;
9use embassy_sync::waitqueue::AtomicWaker; 9use embassy_sync::waitqueue::AtomicWaker;
10 10
11use crate::gpio::{self, AnyPin, Level, SealedPin};
12use crate::pac::{interrupt, INPUTMUX, PINT, SYSCON};
13use crate::Peri; 11use crate::Peri;
12use crate::gpio::{self, AnyPin, Level, SealedPin};
13use crate::pac::{INPUTMUX, PINT, SYSCON, interrupt};
14 14
15struct PinInterrupt { 15struct PinInterrupt {
16 assigned: bool, 16 assigned: bool,
diff --git a/embassy-nxp/src/time_driver/rtc.rs b/embassy-nxp/src/time_driver/rtc.rs
index fb6de6a5e..0883fa2e8 100644
--- a/embassy-nxp/src/time_driver/rtc.rs
+++ b/embassy-nxp/src/time_driver/rtc.rs
@@ -4,10 +4,10 @@ use core::task::Waker;
4use critical_section::CriticalSection; 4use critical_section::CriticalSection;
5use embassy_hal_internal::interrupt::{InterruptExt, Priority}; 5use embassy_hal_internal::interrupt::{InterruptExt, Priority};
6use embassy_sync::blocking_mutex::CriticalSectionMutex as Mutex; 6use embassy_sync::blocking_mutex::CriticalSectionMutex as Mutex;
7use embassy_time_driver::{time_driver_impl, Driver}; 7use embassy_time_driver::{Driver, time_driver_impl};
8use embassy_time_queue_utils::Queue; 8use embassy_time_queue_utils::Queue;
9 9
10use crate::pac::{interrupt, pmc, rtc, PMC, RTC, SYSCON}; 10use crate::pac::{PMC, RTC, SYSCON, interrupt, pmc, rtc};
11 11
12struct AlarmState { 12struct AlarmState {
13 timestamp: Cell<u64>, 13 timestamp: Cell<u64>,
diff --git a/embassy-nxp/src/usart/lpc55.rs b/embassy-nxp/src/usart/lpc55.rs
index 9034ed429..d54927b25 100644
--- a/embassy-nxp/src/usart/lpc55.rs
+++ b/embassy-nxp/src/usart/lpc55.rs
@@ -4,16 +4,16 @@ use core::marker::PhantomData;
4use core::sync::atomic::{AtomicBool, Ordering}; 4use core::sync::atomic::{AtomicBool, Ordering};
5use core::task::Poll; 5use core::task::Poll;
6 6
7use embassy_futures::select::{select, Either}; 7use embassy_futures::select::{Either, select};
8use embassy_hal_internal::interrupt::InterruptExt; 8use embassy_hal_internal::interrupt::InterruptExt;
9use embassy_hal_internal::{Peri, PeripheralType}; 9use embassy_hal_internal::{Peri, PeripheralType};
10use embassy_sync::waitqueue::AtomicWaker; 10use embassy_sync::waitqueue::AtomicWaker;
11use embedded_io::{self, ErrorKind}; 11use embedded_io::{self, ErrorKind};
12 12
13use crate::dma::{AnyChannel, Channel}; 13use crate::dma::{AnyChannel, Channel};
14use crate::gpio::{match_iocon, AnyPin, Bank, SealedPin}; 14use crate::gpio::{AnyPin, SealedPin};
15use crate::interrupt::typelevel::{Binding, Interrupt as _};
16use crate::interrupt::Interrupt; 15use crate::interrupt::Interrupt;
16use crate::interrupt::typelevel::{Binding, Interrupt as _};
17use crate::pac::flexcomm::Flexcomm as FlexcommReg; 17use crate::pac::flexcomm::Flexcomm as FlexcommReg;
18use crate::pac::iocon::vals::PioFunc; 18use crate::pac::iocon::vals::PioFunc;
19use crate::pac::usart::Usart as UsartReg; 19use crate::pac::usart::Usart as UsartReg;
@@ -146,7 +146,8 @@ impl<'d, M: Mode> UsartTx<'d, M> {
146 tx_dma: Peri<'d, impl Channel>, 146 tx_dma: Peri<'d, impl Channel>,
147 config: Config, 147 config: Config,
148 ) -> Self { 148 ) -> Self {
149 Usart::<M>::init::<T>(Some(tx.into()), None, config); 149 let tx_func = tx.pin_func();
150 Usart::<M>::init::<T>(Some((tx.into(), tx_func)), None, config);
150 Self::new_inner(T::info(), Some(tx_dma.into())) 151 Self::new_inner(T::info(), Some(tx_dma.into()))
151 } 152 }
152 153
@@ -179,7 +180,8 @@ impl<'d, M: Mode> UsartTx<'d, M> {
179 180
180impl<'d> UsartTx<'d, Blocking> { 181impl<'d> UsartTx<'d, Blocking> {
181 pub fn new_blocking<T: Instance>(_usart: Peri<'d, T>, tx: Peri<'d, impl TxPin<T>>, config: Config) -> Self { 182 pub fn new_blocking<T: Instance>(_usart: Peri<'d, T>, tx: Peri<'d, impl TxPin<T>>, config: Config) -> Self {
182 Usart::<Blocking>::init::<T>(Some(tx.into()), None, config); 183 let tx_func = tx.pin_func();
184 Usart::<Blocking>::init::<T>(Some((tx.into(), tx_func)), None, config);
183 Self::new_inner(T::info(), None) 185 Self::new_inner(T::info(), None)
184 } 186 }
185} 187}
@@ -208,7 +210,8 @@ impl<'d, M: Mode> UsartRx<'d, M> {
208 rx_dma: Peri<'d, impl Channel>, 210 rx_dma: Peri<'d, impl Channel>,
209 config: Config, 211 config: Config,
210 ) -> Self { 212 ) -> Self {
211 Usart::<M>::init::<T>(None, Some(rx.into()), config); 213 let rx_func = rx.pin_func();
214 Usart::<M>::init::<T>(None, Some((rx.into(), rx_func)), config);
212 Self::new_inner(T::info(), T::dma_state(), has_irq, Some(rx_dma.into())) 215 Self::new_inner(T::info(), T::dma_state(), has_irq, Some(rx_dma.into()))
213 } 216 }
214 217
@@ -280,7 +283,8 @@ impl<'d, M: Mode> UsartRx<'d, M> {
280 283
281impl<'d> UsartRx<'d, Blocking> { 284impl<'d> UsartRx<'d, Blocking> {
282 pub fn new_blocking<T: Instance>(_usart: Peri<'d, T>, rx: Peri<'d, impl RxPin<T>>, config: Config) -> Self { 285 pub fn new_blocking<T: Instance>(_usart: Peri<'d, T>, rx: Peri<'d, impl RxPin<T>>, config: Config) -> Self {
283 Usart::<Blocking>::init::<T>(None, Some(rx.into()), config); 286 let rx_func = rx.pin_func();
287 Usart::<Blocking>::init::<T>(None, Some((rx.into(), rx_func)), config);
284 Self::new_inner(T::info(), T::dma_state(), false, None) 288 Self::new_inner(T::info(), T::dma_state(), false, None)
285 } 289 }
286} 290}
@@ -405,7 +409,10 @@ impl<'d> Usart<'d, Blocking> {
405 rx: Peri<'d, impl RxPin<T>>, 409 rx: Peri<'d, impl RxPin<T>>,
406 config: Config, 410 config: Config,
407 ) -> Self { 411 ) -> Self {
408 Self::new_inner(usart, tx.into(), rx.into(), false, None, None, config) 412 let tx_func = tx.pin_func();
413 let rx_func = rx.pin_func();
414
415 Self::new_inner(usart, tx.into(), tx_func, rx.into(), rx_func, false, None, None, config)
409 } 416 }
410} 417}
411 418
@@ -419,10 +426,15 @@ impl<'d> Usart<'d, Async> {
419 rx_dma: Peri<'d, impl RxChannel<T>>, 426 rx_dma: Peri<'d, impl RxChannel<T>>,
420 config: Config, 427 config: Config,
421 ) -> Self { 428 ) -> Self {
429 let tx_func = tx.pin_func();
430 let rx_func = rx.pin_func();
431
422 Self::new_inner( 432 Self::new_inner(
423 uart, 433 uart,
424 tx.into(), 434 tx.into(),
435 tx_func,
425 rx.into(), 436 rx.into(),
437 rx_func,
426 true, 438 true,
427 Some(tx_dma.into()), 439 Some(tx_dma.into()),
428 Some(rx_dma.into()), 440 Some(rx_dma.into()),
@@ -435,20 +447,26 @@ impl<'d, M: Mode> Usart<'d, M> {
435 fn new_inner<T: Instance>( 447 fn new_inner<T: Instance>(
436 _usart: Peri<'d, T>, 448 _usart: Peri<'d, T>,
437 mut tx: Peri<'d, AnyPin>, 449 mut tx: Peri<'d, AnyPin>,
450 tx_func: PioFunc,
438 mut rx: Peri<'d, AnyPin>, 451 mut rx: Peri<'d, AnyPin>,
452 rx_func: PioFunc,
439 has_irq: bool, 453 has_irq: bool,
440 tx_dma: Option<Peri<'d, AnyChannel>>, 454 tx_dma: Option<Peri<'d, AnyChannel>>,
441 rx_dma: Option<Peri<'d, AnyChannel>>, 455 rx_dma: Option<Peri<'d, AnyChannel>>,
442 config: Config, 456 config: Config,
443 ) -> Self { 457 ) -> Self {
444 Self::init::<T>(Some(tx.reborrow()), Some(rx.reborrow()), config); 458 Self::init::<T>(Some((tx.reborrow(), tx_func)), Some((rx.reborrow(), rx_func)), config);
445 Self { 459 Self {
446 tx: UsartTx::new_inner(T::info(), tx_dma), 460 tx: UsartTx::new_inner(T::info(), tx_dma),
447 rx: UsartRx::new_inner(T::info(), T::dma_state(), has_irq, rx_dma), 461 rx: UsartRx::new_inner(T::info(), T::dma_state(), has_irq, rx_dma),
448 } 462 }
449 } 463 }
450 464
451 fn init<T: Instance>(tx: Option<Peri<'_, AnyPin>>, rx: Option<Peri<'_, AnyPin>>, config: Config) { 465 fn init<T: Instance>(
466 tx: Option<(Peri<'_, AnyPin>, PioFunc)>,
467 rx: Option<(Peri<'_, AnyPin>, PioFunc)>,
468 config: Config,
469 ) {
452 Self::configure_flexcomm(T::info().fc_reg, T::instance_number()); 470 Self::configure_flexcomm(T::info().fc_reg, T::instance_number());
453 Self::configure_clock::<T>(&config); 471 Self::configure_clock::<T>(&config);
454 Self::pin_config::<T>(tx, rx); 472 Self::pin_config::<T>(tx, rx);
@@ -553,31 +571,27 @@ impl<'d, M: Mode> Usart<'d, M> {
553 .modify(|w| w.set_brgval((brg_value - 1) as u16)); 571 .modify(|w| w.set_brgval((brg_value - 1) as u16));
554 } 572 }
555 573
556 fn pin_config<T: Instance>(tx: Option<Peri<'_, AnyPin>>, rx: Option<Peri<'_, AnyPin>>) { 574 fn pin_config<T: Instance>(tx: Option<(Peri<'_, AnyPin>, PioFunc)>, rx: Option<(Peri<'_, AnyPin>, PioFunc)>) {
557 if let Some(tx_pin) = tx { 575 if let Some((tx_pin, func)) = tx {
558 match_iocon!(register, tx_pin.pin_bank(), tx_pin.pin_number(), { 576 tx_pin.pio().modify(|w| {
559 register.modify(|w| { 577 w.set_func(func);
560 w.set_func(T::tx_pin_func()); 578 w.set_mode(iocon::vals::PioMode::INACTIVE);
561 w.set_mode(iocon::vals::PioMode::INACTIVE); 579 w.set_slew(iocon::vals::PioSlew::STANDARD);
562 w.set_slew(iocon::vals::PioSlew::STANDARD); 580 w.set_invert(false);
563 w.set_invert(false); 581 w.set_digimode(iocon::vals::PioDigimode::DIGITAL);
564 w.set_digimode(iocon::vals::PioDigimode::DIGITAL); 582 w.set_od(iocon::vals::PioOd::NORMAL);
565 w.set_od(iocon::vals::PioOd::NORMAL); 583 });
566 });
567 })
568 } 584 }
569 585
570 if let Some(rx_pin) = rx { 586 if let Some((rx_pin, func)) = rx {
571 match_iocon!(register, rx_pin.pin_bank(), rx_pin.pin_number(), { 587 rx_pin.pio().modify(|w| {
572 register.modify(|w| { 588 w.set_func(func);
573 w.set_func(T::rx_pin_func()); 589 w.set_mode(iocon::vals::PioMode::INACTIVE);
574 w.set_mode(iocon::vals::PioMode::INACTIVE); 590 w.set_slew(iocon::vals::PioSlew::STANDARD);
575 w.set_slew(iocon::vals::PioSlew::STANDARD); 591 w.set_invert(false);
576 w.set_invert(false); 592 w.set_digimode(iocon::vals::PioDigimode::DIGITAL);
577 w.set_digimode(iocon::vals::PioDigimode::DIGITAL); 593 w.set_od(iocon::vals::PioOd::NORMAL);
578 w.set_od(iocon::vals::PioOd::NORMAL); 594 });
579 });
580 })
581 }; 595 };
582 } 596 }
583 597
@@ -814,8 +828,6 @@ trait SealedInstance {
814 fn info() -> &'static Info; 828 fn info() -> &'static Info;
815 fn dma_state() -> &'static DmaState; 829 fn dma_state() -> &'static DmaState;
816 fn instance_number() -> usize; 830 fn instance_number() -> usize;
817 fn tx_pin_func() -> PioFunc;
818 fn rx_pin_func() -> PioFunc;
819} 831}
820 832
821/// UART instance. 833/// UART instance.
@@ -826,7 +838,7 @@ pub trait Instance: SealedInstance + PeripheralType {
826} 838}
827 839
828macro_rules! impl_instance { 840macro_rules! impl_instance {
829 ($inst:ident, $fc:ident, $tx_pin:ident, $rx_pin:ident, $fc_num:expr) => { 841 ($inst:ident, $fc:ident, $fc_num:expr) => {
830 impl $crate::usart::inner::SealedInstance for $crate::peripherals::$inst { 842 impl $crate::usart::inner::SealedInstance for $crate::peripherals::$inst {
831 fn info() -> &'static Info { 843 fn info() -> &'static Info {
832 static INFO: Info = Info { 844 static INFO: Info = Info {
@@ -848,14 +860,6 @@ macro_rules! impl_instance {
848 fn instance_number() -> usize { 860 fn instance_number() -> usize {
849 $fc_num 861 $fc_num
850 } 862 }
851 #[inline]
852 fn tx_pin_func() -> PioFunc {
853 PioFunc::$tx_pin
854 }
855 #[inline]
856 fn rx_pin_func() -> PioFunc {
857 PioFunc::$rx_pin
858 }
859 } 863 }
860 impl $crate::usart::Instance for $crate::peripherals::$inst { 864 impl $crate::usart::Instance for $crate::peripherals::$inst {
861 type Interrupt = crate::interrupt::typelevel::$fc; 865 type Interrupt = crate::interrupt::typelevel::$fc;
@@ -863,45 +867,72 @@ macro_rules! impl_instance {
863 }; 867 };
864} 868}
865 869
866impl_instance!(USART0, FLEXCOMM0, ALT1, ALT1, 0); 870impl_instance!(USART0, FLEXCOMM0, 0);
867impl_instance!(USART1, FLEXCOMM1, ALT2, ALT2, 1); 871impl_instance!(USART1, FLEXCOMM1, 1);
868impl_instance!(USART2, FLEXCOMM2, ALT1, ALT1, 2); 872impl_instance!(USART2, FLEXCOMM2, 2);
869impl_instance!(USART3, FLEXCOMM3, ALT1, ALT1, 3); 873impl_instance!(USART3, FLEXCOMM3, 3);
870impl_instance!(USART4, FLEXCOMM4, ALT1, ALT2, 4); 874impl_instance!(USART4, FLEXCOMM4, 4);
871impl_instance!(USART5, FLEXCOMM5, ALT3, ALT3, 5); 875impl_instance!(USART5, FLEXCOMM5, 5);
872impl_instance!(USART6, FLEXCOMM6, ALT2, ALT2, 6); 876impl_instance!(USART6, FLEXCOMM6, 6);
873impl_instance!(USART7, FLEXCOMM7, ALT7, ALT7, 7); 877impl_instance!(USART7, FLEXCOMM7, 7);
878
879pub(crate) trait SealedTxPin<T: Instance>: crate::gpio::Pin {
880 fn pin_func(&self) -> PioFunc;
881}
882
883pub(crate) trait SealedRxPin<T: Instance>: crate::gpio::Pin {
884 fn pin_func(&self) -> PioFunc;
885}
874 886
875/// Trait for TX pins. 887/// Trait for TX pins.
876pub trait TxPin<T: Instance>: crate::gpio::Pin {} 888#[allow(private_bounds)]
889pub trait TxPin<T: Instance>: SealedTxPin<T> + crate::gpio::Pin {}
890
877/// Trait for RX pins. 891/// Trait for RX pins.
878pub trait RxPin<T: Instance>: crate::gpio::Pin {} 892#[allow(private_bounds)]
893pub trait RxPin<T: Instance>: SealedRxPin<T> + crate::gpio::Pin {}
894
895macro_rules! impl_tx_pin {
896 ($pin:ident, $instance:ident, $func: ident) => {
897 impl SealedTxPin<crate::peripherals::$instance> for crate::peripherals::$pin {
898 fn pin_func(&self) -> PioFunc {
899 PioFunc::$func
900 }
901 }
879 902
880macro_rules! impl_pin {
881 ($pin:ident, $instance:ident, Tx) => {
882 impl TxPin<crate::peripherals::$instance> for crate::peripherals::$pin {} 903 impl TxPin<crate::peripherals::$instance> for crate::peripherals::$pin {}
883 }; 904 };
884 ($pin:ident, $instance:ident, Rx) => { 905}
906
907macro_rules! impl_rx_pin {
908 ($pin:ident, $instance:ident, $func: ident) => {
909 impl SealedRxPin<crate::peripherals::$instance> for crate::peripherals::$pin {
910 fn pin_func(&self) -> PioFunc {
911 PioFunc::$func
912 }
913 }
914
885 impl RxPin<crate::peripherals::$instance> for crate::peripherals::$pin {} 915 impl RxPin<crate::peripherals::$instance> for crate::peripherals::$pin {}
886 }; 916 };
887} 917}
888 918
889impl_pin!(PIO1_6, USART0, Tx); 919impl_tx_pin!(PIO1_6, USART0, ALT1);
890impl_pin!(PIO1_5, USART0, Rx); 920impl_tx_pin!(PIO1_11, USART1, ALT2);
891impl_pin!(PIO1_11, USART1, Tx); 921impl_tx_pin!(PIO0_27, USART2, ALT1);
892impl_pin!(PIO1_10, USART1, Rx); 922impl_tx_pin!(PIO0_2, USART3, ALT1);
893impl_pin!(PIO0_27, USART2, Tx); 923impl_tx_pin!(PIO0_16, USART4, ALT1);
894impl_pin!(PIO1_24, USART2, Rx); 924impl_tx_pin!(PIO0_9, USART5, ALT3);
895impl_pin!(PIO0_2, USART3, Tx); 925impl_tx_pin!(PIO1_16, USART6, ALT2);
896impl_pin!(PIO0_3, USART3, Rx); 926impl_tx_pin!(PIO0_19, USART7, ALT7);
897impl_pin!(PIO0_16, USART4, Tx); 927
898impl_pin!(PIO0_5, USART4, Rx); 928impl_rx_pin!(PIO1_5, USART0, ALT1);
899impl_pin!(PIO0_9, USART5, Tx); 929impl_rx_pin!(PIO1_10, USART1, ALT2);
900impl_pin!(PIO0_8, USART5, Rx); 930impl_rx_pin!(PIO1_24, USART2, ALT1);
901impl_pin!(PIO1_16, USART6, Tx); 931impl_rx_pin!(PIO0_3, USART3, ALT1);
902impl_pin!(PIO1_13, USART6, Rx); 932impl_rx_pin!(PIO0_5, USART4, ALT2);
903impl_pin!(PIO0_19, USART7, Tx); 933impl_rx_pin!(PIO0_8, USART5, ALT3);
904impl_pin!(PIO0_20, USART7, Rx); 934impl_rx_pin!(PIO1_13, USART6, ALT2);
935impl_rx_pin!(PIO0_20, USART7, ALT7);
905 936
906/// Trait for TX DMA channels. 937/// Trait for TX DMA channels.
907pub trait TxChannel<T: Instance>: crate::dma::Channel {} 938pub trait TxChannel<T: Instance>: crate::dma::Channel {}