diff --git a/embassy-nxp/CHANGELOG.md b/embassy-nxp/CHANGELOG.md index 0fb677cd88..295d45c2da 100644 --- a/embassy-nxp/CHANGELOG.md +++ b/embassy-nxp/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased - ReleaseDate +- LPC55: Remove internal match_iocon macro - LPC55: DMA Controller and asynchronous version of USART - Moved NXP LPC55S69 from `lpc55-pac` to `nxp-pac` - First release with changelog. diff --git a/embassy-nxp/src/gpio/lpc55.rs b/embassy-nxp/src/gpio/lpc55.rs index ac8a27d4ff..6039d8ca89 100644 --- a/embassy-nxp/src/gpio/lpc55.rs +++ b/embassy-nxp/src/gpio/lpc55.rs @@ -1,7 +1,8 @@ use embassy_hal_internal::{PeripheralType, impl_peripheral}; +use crate::pac::common::{RW, Reg}; use crate::pac::iocon::vals::{PioDigimode, PioMode}; -use crate::pac::{GPIO, IOCON, SYSCON}; +use crate::pac::{GPIO, IOCON, SYSCON, iocon}; use crate::{Peri, peripherals}; pub(crate) fn init() { @@ -109,13 +110,7 @@ impl<'d> Input<'d> { /// Set the pull configuration for the pin. To disable the pull, use [Pull::None]. pub fn set_pull(&mut self, pull: Pull) { - match_iocon!(register, self.pin.pin_bank(), self.pin.pin_number(), { - register.modify(|w| match pull { - Pull::None => w.set_mode(PioMode::INACTIVE), - Pull::Up => w.set_mode(PioMode::PULL_UP), - Pull::Down => w.set_mode(PioMode::PULL_DOWN), - }); - }); + self.pin.set_pull(pull); } /// Get the current input level of the pin. @@ -193,11 +188,20 @@ impl<'d> Flex<'d> { 1 << self.pin.pin_number() } + /// Set the pull configuration for the pin. To disable the pull, use [Pull::None]. + pub fn set_pull(&mut self, pull: Pull) { + self.pin.pio().modify(|w| match pull { + Pull::None => w.set_mode(PioMode::INACTIVE), + Pull::Up => w.set_mode(PioMode::PULL_UP), + Pull::Down => w.set_mode(PioMode::PULL_DOWN), + }); + } + /// Set the pin to digital mode. This is required for using a pin as a GPIO pin. The default /// setting for pins is (usually) non-digital. fn set_as_digital(&mut self) { - match_iocon!(register, self.pin_bank(), self.pin_number(), { - register.modify(|w| w.set_digimode(PioDigimode::DIGITAL)); + self.pin.pio().modify(|w| { + w.set_digimode(PioDigimode::DIGITAL); }); } @@ -220,6 +224,14 @@ impl<'d> Flex<'d> { pub(crate) trait SealedPin: Sized { fn pin_bank(&self) -> Bank; fn pin_number(&self) -> u8; + + #[inline] + fn pio(&self) -> Reg { + match self.pin_bank() { + Bank::Bank0 => IOCON.pio0(self.pin_number() as usize), + Bank::Bank1 => IOCON.pio1(self.pin_number() as usize), + } + } } /// 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 { } } -/// Match the pin bank and number of a pin to the corresponding IOCON register. -/// -/// # Example -/// ``` -/// use embassy_nxp::gpio::Bank; -/// use embassy_nxp::pac_utils::{iocon_reg, match_iocon}; -/// -/// // Make pin PIO1_6 digital and set it to pull-down mode. -/// match_iocon!(register, Bank::Bank1, 6, { -/// register.modify(|w|{ -/// w.set_mode(PioMode::PULL_DOWN); -/// w.set_digimode(PioDigimode::DIGITAL); -/// -/// } -/// }); -/// ``` -macro_rules! match_iocon { - ($register:ident, $pin_bank:expr, $pin_number:expr, $action:expr) => { - match $pin_bank { - Bank::Bank0 => { - let $register = IOCON.pio0($pin_number as usize); - $action; - } - - Bank::Bank1 => { - let $register = IOCON.pio1($pin_number as usize); - $action; - } - } - }; -} - -pub(crate) use match_iocon; - macro_rules! impl_pin { ($name:ident, $bank:expr, $pin_num:expr) => { impl Pin for peripherals::$name {} diff --git a/embassy-nxp/src/usart/lpc55.rs b/embassy-nxp/src/usart/lpc55.rs index 0be5a8ce77..6cbde82a3b 100644 --- a/embassy-nxp/src/usart/lpc55.rs +++ b/embassy-nxp/src/usart/lpc55.rs @@ -11,7 +11,7 @@ use embassy_sync::waitqueue::AtomicWaker; use embedded_io::{self, ErrorKind}; use crate::dma::{AnyChannel, Channel}; -use crate::gpio::{AnyPin, Bank, SealedPin, match_iocon}; +use crate::gpio::{AnyPin, SealedPin}; use crate::interrupt::Interrupt; use crate::interrupt::typelevel::{Binding, Interrupt as _}; use crate::pac::flexcomm::Flexcomm as FlexcommReg; @@ -555,29 +555,25 @@ impl<'d, M: Mode> Usart<'d, M> { fn pin_config(tx: Option>, rx: Option>) { if let Some(tx_pin) = tx { - match_iocon!(register, tx_pin.pin_bank(), tx_pin.pin_number(), { - register.modify(|w| { - w.set_func(T::tx_pin_func()); - w.set_mode(iocon::vals::PioMode::INACTIVE); - w.set_slew(iocon::vals::PioSlew::STANDARD); - w.set_invert(false); - w.set_digimode(iocon::vals::PioDigimode::DIGITAL); - w.set_od(iocon::vals::PioOd::NORMAL); - }); - }) + tx_pin.pio().modify(|w| { + w.set_func(T::tx_pin_func()); + w.set_mode(iocon::vals::PioMode::INACTIVE); + w.set_slew(iocon::vals::PioSlew::STANDARD); + w.set_invert(false); + w.set_digimode(iocon::vals::PioDigimode::DIGITAL); + w.set_od(iocon::vals::PioOd::NORMAL); + }); } if let Some(rx_pin) = rx { - match_iocon!(register, rx_pin.pin_bank(), rx_pin.pin_number(), { - register.modify(|w| { - w.set_func(T::rx_pin_func()); - w.set_mode(iocon::vals::PioMode::INACTIVE); - w.set_slew(iocon::vals::PioSlew::STANDARD); - w.set_invert(false); - w.set_digimode(iocon::vals::PioDigimode::DIGITAL); - w.set_od(iocon::vals::PioOd::NORMAL); - }); - }) + rx_pin.pio().modify(|w| { + w.set_func(T::rx_pin_func()); + w.set_mode(iocon::vals::PioMode::INACTIVE); + w.set_slew(iocon::vals::PioSlew::STANDARD); + w.set_invert(false); + w.set_digimode(iocon::vals::PioDigimode::DIGITAL); + w.set_od(iocon::vals::PioOd::NORMAL); + }); }; }