diff options
| author | Matteo Meluzzi <[email protected]> | 2025-10-24 15:48:34 +0200 |
|---|---|---|
| committer | Matteo Meluzzi <[email protected]> | 2025-10-24 15:48:34 +0200 |
| commit | 7976f950b0de72c521f92efa350c67ccd197fab9 (patch) | |
| tree | 8759312eb000de09b92a4921f476d5c16b7e7342 /embassy-nxp/src | |
| parent | 828a8df18d04877df1f55f04354980b28ff2f2f8 (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.rs | 6 | ||||
| -rw-r--r-- | embassy-nxp/src/gpio/lpc55.rs | 70 | ||||
| -rw-r--r-- | embassy-nxp/src/gpio/rt1xxx.rs | 4 | ||||
| -rw-r--r-- | embassy-nxp/src/lib.rs | 5 | ||||
| -rw-r--r-- | embassy-nxp/src/pint.rs | 4 | ||||
| -rw-r--r-- | embassy-nxp/src/time_driver/rtc.rs | 4 | ||||
| -rw-r--r-- | embassy-nxp/src/usart/lpc55.rs | 177 |
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 @@ | |||
| 1 | use core::cell::RefCell; | 1 | use core::cell::RefCell; |
| 2 | use core::future::Future; | 2 | use core::future::Future; |
| 3 | use core::pin::Pin; | 3 | use core::pin::Pin; |
| 4 | use core::sync::atomic::{compiler_fence, Ordering}; | 4 | use core::sync::atomic::{Ordering, compiler_fence}; |
| 5 | use core::task::{Context, Poll}; | 5 | use core::task::{Context, Poll}; |
| 6 | 6 | ||
| 7 | use critical_section::Mutex; | 7 | use critical_section::Mutex; |
| 8 | use embassy_hal_internal::interrupt::InterruptExt; | 8 | use embassy_hal_internal::interrupt::InterruptExt; |
| 9 | use embassy_hal_internal::{impl_peripheral, PeripheralType}; | 9 | use embassy_hal_internal::{PeripheralType, impl_peripheral}; |
| 10 | use embassy_sync::waitqueue::AtomicWaker; | 10 | use embassy_sync::waitqueue::AtomicWaker; |
| 11 | 11 | ||
| 12 | use crate::pac::{DMA0, SYSCON, *}; | 12 | use crate::pac::{DMA0, SYSCON, *}; |
| 13 | use crate::{peripherals, Peri}; | 13 | use crate::{Peri, peripherals}; |
| 14 | 14 | ||
| 15 | #[interrupt] | 15 | #[interrupt] |
| 16 | fn DMA0() { | 16 | fn 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 @@ | |||
| 1 | use embassy_hal_internal::{impl_peripheral, PeripheralType}; | 1 | use embassy_hal_internal::{PeripheralType, impl_peripheral}; |
| 2 | 2 | ||
| 3 | use crate::pac::common::{RW, Reg}; | ||
| 3 | use crate::pac::iocon::vals::{PioDigimode, PioMode}; | 4 | use crate::pac::iocon::vals::{PioDigimode, PioMode}; |
| 4 | use crate::pac::{GPIO, IOCON, SYSCON}; | 5 | use crate::pac::{GPIO, IOCON, SYSCON, iocon}; |
| 5 | use crate::{peripherals, Peri}; | 6 | use crate::{Peri, peripherals}; |
| 6 | 7 | ||
| 7 | pub(crate) fn init() { | 8 | pub(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> { | |||
| 220 | pub(crate) trait SealedPin: Sized { | 224 | pub(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 | /// ``` | ||
| 291 | macro_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 | |||
| 307 | pub(crate) use match_iocon; | ||
| 308 | |||
| 309 | macro_rules! impl_pin { | 287 | macro_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; | |||
| 5 | use core::pin::Pin as FuturePin; | 5 | use core::pin::Pin as FuturePin; |
| 6 | use core::task::{Context, Poll}; | 6 | use core::task::{Context, Poll}; |
| 7 | 7 | ||
| 8 | use embassy_hal_internal::{impl_peripheral, Peri, PeripheralType}; | 8 | use embassy_hal_internal::{Peri, PeripheralType, impl_peripheral}; |
| 9 | use embassy_sync::waitqueue::AtomicWaker; | 9 | use embassy_sync::waitqueue::AtomicWaker; |
| 10 | use nxp_pac::gpio::vals::Icr; | 10 | use nxp_pac::gpio::vals::Icr; |
| 11 | use nxp_pac::iomuxc::vals::Pus; | 11 | use nxp_pac::iomuxc::vals::Pus; |
| 12 | 12 | ||
| 13 | use crate::chip::{mux_address, pad_address}; | 13 | use crate::chip::{mux_address, pad_address}; |
| 14 | use crate::pac::common::{Reg, RW}; | 14 | use crate::pac::common::{RW, Reg}; |
| 15 | use crate::pac::gpio::Gpio; | 15 | use crate::pac::gpio::Gpio; |
| 16 | #[cfg(feature = "rt")] | 16 | #[cfg(feature = "rt")] |
| 17 | use crate::pac::interrupt; | 17 | use 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. |
| 4 | pub(crate) mod fmt; | 5 | pub(crate) mod fmt; |
| @@ -29,7 +30,7 @@ pub use chip::interrupt; | |||
| 29 | pub use chip::pac; | 30 | pub use chip::pac; |
| 30 | #[cfg(not(feature = "unstable-pac"))] | 31 | #[cfg(not(feature = "unstable-pac"))] |
| 31 | pub(crate) use chip::pac; | 32 | pub(crate) use chip::pac; |
| 32 | pub use chip::{peripherals, Peripherals}; | 33 | pub use chip::{Peripherals, peripherals}; |
| 33 | pub use embassy_hal_internal::{Peri, PeripheralType}; | 34 | pub 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; | |||
| 8 | use embassy_hal_internal::interrupt::InterruptExt; | 8 | use embassy_hal_internal::interrupt::InterruptExt; |
| 9 | use embassy_sync::waitqueue::AtomicWaker; | 9 | use embassy_sync::waitqueue::AtomicWaker; |
| 10 | 10 | ||
| 11 | use crate::gpio::{self, AnyPin, Level, SealedPin}; | ||
| 12 | use crate::pac::{interrupt, INPUTMUX, PINT, SYSCON}; | ||
| 13 | use crate::Peri; | 11 | use crate::Peri; |
| 12 | use crate::gpio::{self, AnyPin, Level, SealedPin}; | ||
| 13 | use crate::pac::{INPUTMUX, PINT, SYSCON, interrupt}; | ||
| 14 | 14 | ||
| 15 | struct PinInterrupt { | 15 | struct 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; | |||
| 4 | use critical_section::CriticalSection; | 4 | use critical_section::CriticalSection; |
| 5 | use embassy_hal_internal::interrupt::{InterruptExt, Priority}; | 5 | use embassy_hal_internal::interrupt::{InterruptExt, Priority}; |
| 6 | use embassy_sync::blocking_mutex::CriticalSectionMutex as Mutex; | 6 | use embassy_sync::blocking_mutex::CriticalSectionMutex as Mutex; |
| 7 | use embassy_time_driver::{time_driver_impl, Driver}; | 7 | use embassy_time_driver::{Driver, time_driver_impl}; |
| 8 | use embassy_time_queue_utils::Queue; | 8 | use embassy_time_queue_utils::Queue; |
| 9 | 9 | ||
| 10 | use crate::pac::{interrupt, pmc, rtc, PMC, RTC, SYSCON}; | 10 | use crate::pac::{PMC, RTC, SYSCON, interrupt, pmc, rtc}; |
| 11 | 11 | ||
| 12 | struct AlarmState { | 12 | struct 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; | |||
| 4 | use core::sync::atomic::{AtomicBool, Ordering}; | 4 | use core::sync::atomic::{AtomicBool, Ordering}; |
| 5 | use core::task::Poll; | 5 | use core::task::Poll; |
| 6 | 6 | ||
| 7 | use embassy_futures::select::{select, Either}; | 7 | use embassy_futures::select::{Either, select}; |
| 8 | use embassy_hal_internal::interrupt::InterruptExt; | 8 | use embassy_hal_internal::interrupt::InterruptExt; |
| 9 | use embassy_hal_internal::{Peri, PeripheralType}; | 9 | use embassy_hal_internal::{Peri, PeripheralType}; |
| 10 | use embassy_sync::waitqueue::AtomicWaker; | 10 | use embassy_sync::waitqueue::AtomicWaker; |
| 11 | use embedded_io::{self, ErrorKind}; | 11 | use embedded_io::{self, ErrorKind}; |
| 12 | 12 | ||
| 13 | use crate::dma::{AnyChannel, Channel}; | 13 | use crate::dma::{AnyChannel, Channel}; |
| 14 | use crate::gpio::{match_iocon, AnyPin, Bank, SealedPin}; | 14 | use crate::gpio::{AnyPin, SealedPin}; |
| 15 | use crate::interrupt::typelevel::{Binding, Interrupt as _}; | ||
| 16 | use crate::interrupt::Interrupt; | 15 | use crate::interrupt::Interrupt; |
| 16 | use crate::interrupt::typelevel::{Binding, Interrupt as _}; | ||
| 17 | use crate::pac::flexcomm::Flexcomm as FlexcommReg; | 17 | use crate::pac::flexcomm::Flexcomm as FlexcommReg; |
| 18 | use crate::pac::iocon::vals::PioFunc; | 18 | use crate::pac::iocon::vals::PioFunc; |
| 19 | use crate::pac::usart::Usart as UsartReg; | 19 | use 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 | ||
| 180 | impl<'d> UsartTx<'d, Blocking> { | 181 | impl<'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 | ||
| 281 | impl<'d> UsartRx<'d, Blocking> { | 284 | impl<'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 | ||
| 828 | macro_rules! impl_instance { | 840 | macro_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 | ||
| 866 | impl_instance!(USART0, FLEXCOMM0, ALT1, ALT1, 0); | 870 | impl_instance!(USART0, FLEXCOMM0, 0); |
| 867 | impl_instance!(USART1, FLEXCOMM1, ALT2, ALT2, 1); | 871 | impl_instance!(USART1, FLEXCOMM1, 1); |
| 868 | impl_instance!(USART2, FLEXCOMM2, ALT1, ALT1, 2); | 872 | impl_instance!(USART2, FLEXCOMM2, 2); |
| 869 | impl_instance!(USART3, FLEXCOMM3, ALT1, ALT1, 3); | 873 | impl_instance!(USART3, FLEXCOMM3, 3); |
| 870 | impl_instance!(USART4, FLEXCOMM4, ALT1, ALT2, 4); | 874 | impl_instance!(USART4, FLEXCOMM4, 4); |
| 871 | impl_instance!(USART5, FLEXCOMM5, ALT3, ALT3, 5); | 875 | impl_instance!(USART5, FLEXCOMM5, 5); |
| 872 | impl_instance!(USART6, FLEXCOMM6, ALT2, ALT2, 6); | 876 | impl_instance!(USART6, FLEXCOMM6, 6); |
| 873 | impl_instance!(USART7, FLEXCOMM7, ALT7, ALT7, 7); | 877 | impl_instance!(USART7, FLEXCOMM7, 7); |
| 878 | |||
| 879 | pub(crate) trait SealedTxPin<T: Instance>: crate::gpio::Pin { | ||
| 880 | fn pin_func(&self) -> PioFunc; | ||
| 881 | } | ||
| 882 | |||
| 883 | pub(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. |
| 876 | pub trait TxPin<T: Instance>: crate::gpio::Pin {} | 888 | #[allow(private_bounds)] |
| 889 | pub trait TxPin<T: Instance>: SealedTxPin<T> + crate::gpio::Pin {} | ||
| 890 | |||
| 877 | /// Trait for RX pins. | 891 | /// Trait for RX pins. |
| 878 | pub trait RxPin<T: Instance>: crate::gpio::Pin {} | 892 | #[allow(private_bounds)] |
| 893 | pub trait RxPin<T: Instance>: SealedRxPin<T> + crate::gpio::Pin {} | ||
| 894 | |||
| 895 | macro_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 | ||
| 880 | macro_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 | |||
| 907 | macro_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 | ||
| 889 | impl_pin!(PIO1_6, USART0, Tx); | 919 | impl_tx_pin!(PIO1_6, USART0, ALT1); |
| 890 | impl_pin!(PIO1_5, USART0, Rx); | 920 | impl_tx_pin!(PIO1_11, USART1, ALT2); |
| 891 | impl_pin!(PIO1_11, USART1, Tx); | 921 | impl_tx_pin!(PIO0_27, USART2, ALT1); |
| 892 | impl_pin!(PIO1_10, USART1, Rx); | 922 | impl_tx_pin!(PIO0_2, USART3, ALT1); |
| 893 | impl_pin!(PIO0_27, USART2, Tx); | 923 | impl_tx_pin!(PIO0_16, USART4, ALT1); |
| 894 | impl_pin!(PIO1_24, USART2, Rx); | 924 | impl_tx_pin!(PIO0_9, USART5, ALT3); |
| 895 | impl_pin!(PIO0_2, USART3, Tx); | 925 | impl_tx_pin!(PIO1_16, USART6, ALT2); |
| 896 | impl_pin!(PIO0_3, USART3, Rx); | 926 | impl_tx_pin!(PIO0_19, USART7, ALT7); |
| 897 | impl_pin!(PIO0_16, USART4, Tx); | 927 | |
| 898 | impl_pin!(PIO0_5, USART4, Rx); | 928 | impl_rx_pin!(PIO1_5, USART0, ALT1); |
| 899 | impl_pin!(PIO0_9, USART5, Tx); | 929 | impl_rx_pin!(PIO1_10, USART1, ALT2); |
| 900 | impl_pin!(PIO0_8, USART5, Rx); | 930 | impl_rx_pin!(PIO1_24, USART2, ALT1); |
| 901 | impl_pin!(PIO1_16, USART6, Tx); | 931 | impl_rx_pin!(PIO0_3, USART3, ALT1); |
| 902 | impl_pin!(PIO1_13, USART6, Rx); | 932 | impl_rx_pin!(PIO0_5, USART4, ALT2); |
| 903 | impl_pin!(PIO0_19, USART7, Tx); | 933 | impl_rx_pin!(PIO0_8, USART5, ALT3); |
| 904 | impl_pin!(PIO0_20, USART7, Rx); | 934 | impl_rx_pin!(PIO1_13, USART6, ALT2); |
| 935 | impl_rx_pin!(PIO0_20, USART7, ALT7); | ||
| 905 | 936 | ||
| 906 | /// Trait for TX DMA channels. | 937 | /// Trait for TX DMA channels. |
| 907 | pub trait TxChannel<T: Instance>: crate::dma::Channel {} | 938 | pub trait TxChannel<T: Instance>: crate::dma::Channel {} |
