diff options
Diffstat (limited to 'embassy-nxp/src/gpio/rt1xxx.rs')
| -rw-r--r-- | embassy-nxp/src/gpio/rt1xxx.rs | 54 |
1 files changed, 15 insertions, 39 deletions
diff --git a/embassy-nxp/src/gpio/rt1xxx.rs b/embassy-nxp/src/gpio/rt1xxx.rs index 1d60a0d51..8a560310c 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::{iomuxc_mux, iomuxc_pad}; |
| 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; |
| @@ -121,6 +121,10 @@ pub enum Bank { | |||
| 121 | /// Bank 5 | 121 | /// Bank 5 |
| 122 | #[cfg(gpio5)] | 122 | #[cfg(gpio5)] |
| 123 | Gpio5, | 123 | Gpio5, |
| 124 | |||
| 125 | #[cfg(gpio10)] | ||
| 126 | /// Bank 10 | ||
| 127 | Gpio10, | ||
| 124 | } | 128 | } |
| 125 | 129 | ||
| 126 | /// GPIO flexible pin. | 130 | /// GPIO flexible pin. |
| @@ -656,6 +660,8 @@ static GPIO3_WAKERS: [AtomicWaker; 32] = [const { AtomicWaker::new() }; 32]; | |||
| 656 | static GPIO4_WAKERS: [AtomicWaker; 32] = [const { AtomicWaker::new() }; 32]; | 660 | static GPIO4_WAKERS: [AtomicWaker; 32] = [const { AtomicWaker::new() }; 32]; |
| 657 | #[cfg(gpio5)] | 661 | #[cfg(gpio5)] |
| 658 | static GPIO5_WAKERS: [AtomicWaker; 32] = [const { AtomicWaker::new() }; 32]; | 662 | static GPIO5_WAKERS: [AtomicWaker; 32] = [const { AtomicWaker::new() }; 32]; |
| 663 | #[cfg(gpio10)] | ||
| 664 | static GPIO10_WAKERS: [AtomicWaker; 32] = [const { AtomicWaker::new() }; 32]; | ||
| 659 | 665 | ||
| 660 | /// Sealed trait for pins. This trait is sealed and cannot be implemented outside of this crate. | 666 | /// Sealed trait for pins. This trait is sealed and cannot be implemented outside of this crate. |
| 661 | pub(crate) trait SealedPin: Sized { | 667 | pub(crate) trait SealedPin: Sized { |
| @@ -676,13 +682,15 @@ pub(crate) trait SealedPin: Sized { | |||
| 676 | Bank::Gpio4 => pac::GPIO4, | 682 | Bank::Gpio4 => pac::GPIO4, |
| 677 | #[cfg(gpio5)] | 683 | #[cfg(gpio5)] |
| 678 | Bank::Gpio5 => pac::GPIO5, | 684 | Bank::Gpio5 => pac::GPIO5, |
| 685 | #[cfg(gpio10)] | ||
| 686 | Bank::Gpio10 => pac::GPIO10, | ||
| 679 | } | 687 | } |
| 680 | } | 688 | } |
| 681 | 689 | ||
| 682 | #[inline] | 690 | #[inline] |
| 683 | fn mux(&self) -> Reg<MuxCtl, RW> { | 691 | fn mux(&self) -> Reg<MuxCtl, RW> { |
| 684 | // SAFETY: The generated mux address table is valid since it is generated from the SVD files. | 692 | // SAFETY: The generated mux address table is valid since it is generated from the SVD files. |
| 685 | let address = unsafe { mux_address(self._bank(), self.pin_number()).unwrap_unchecked() }; | 693 | let address = unsafe { iomuxc_mux(self._bank(), self.pin_number()).unwrap_unchecked() }; |
| 686 | 694 | ||
| 687 | // SAFETY: The register at the address is an instance of MuxCtl. | 695 | // SAFETY: The register at the address is an instance of MuxCtl. |
| 688 | unsafe { Reg::from_ptr(address as *mut _) } | 696 | unsafe { Reg::from_ptr(address as *mut _) } |
| @@ -690,8 +698,7 @@ pub(crate) trait SealedPin: Sized { | |||
| 690 | 698 | ||
| 691 | #[inline] | 699 | #[inline] |
| 692 | fn pad(&self) -> Reg<Ctl, RW> { | 700 | fn pad(&self) -> Reg<Ctl, RW> { |
| 693 | // SAFETY: The generated pad address table is valid since it is generated from the SVD files. | 701 | let address = iomuxc_pad(self._bank(), self.pin_number()); |
| 694 | let address = unsafe { pad_address(self._bank(), self.pin_number()).unwrap_unchecked() }; | ||
| 695 | 702 | ||
| 696 | // SAFETY: The register at the address is an instance of Ctl. | 703 | // SAFETY: The register at the address is an instance of Ctl. |
| 697 | unsafe { Reg::from_ptr(address as *mut _) } | 704 | unsafe { Reg::from_ptr(address as *mut _) } |
| @@ -709,6 +716,8 @@ pub(crate) trait SealedPin: Sized { | |||
| 709 | Bank::Gpio4 => &GPIO4_WAKERS[self.pin_number() as usize], | 716 | Bank::Gpio4 => &GPIO4_WAKERS[self.pin_number() as usize], |
| 710 | #[cfg(gpio5)] | 717 | #[cfg(gpio5)] |
| 711 | Bank::Gpio5 => &GPIO5_WAKERS[self.pin_number() as usize], | 718 | Bank::Gpio5 => &GPIO5_WAKERS[self.pin_number() as usize], |
| 719 | #[cfg(gpio10)] | ||
| 720 | Bank::Gpio10 => &GPIO10_WAKERS[self.pin_number() as usize], | ||
| 712 | } | 721 | } |
| 713 | } | 722 | } |
| 714 | } | 723 | } |
| @@ -793,39 +802,6 @@ impl<'d> Future for InputFuture<'d> { | |||
| 793 | } | 802 | } |
| 794 | } | 803 | } |
| 795 | 804 | ||
| 796 | /// A macro to generate all GPIO pins. | ||
| 797 | /// | ||
| 798 | /// This generates a lookup table for IOMUX register addresses. | ||
| 799 | macro_rules! impl_gpio { | ||
| 800 | ( | ||
| 801 | $($name: ident($bank: ident, $pin_number: expr);)* | ||
| 802 | ) => { | ||
| 803 | #[inline] | ||
| 804 | pub(crate) const fn pad_address(bank: crate::gpio::Bank, pin: u8) -> Option<u32> { | ||
| 805 | match (bank, pin) { | ||
| 806 | $( | ||
| 807 | (crate::gpio::Bank::$bank, $pin_number) => Some(crate::chip::_generated::iomuxc::pads::$name), | ||
| 808 | )* | ||
| 809 | _ => None | ||
| 810 | } | ||
| 811 | } | ||
| 812 | |||
| 813 | #[inline] | ||
| 814 | pub(crate) const fn mux_address(bank: crate::gpio::Bank, pin: u8) -> Option<u32> { | ||
| 815 | match (bank, pin) { | ||
| 816 | $( | ||
| 817 | (crate::gpio::Bank::$bank, $pin_number) => Some(crate::chip::_generated::iomuxc::muxes::$name), | ||
| 818 | )* | ||
| 819 | _ => None | ||
| 820 | } | ||
| 821 | } | ||
| 822 | |||
| 823 | $( | ||
| 824 | impl_pin!($name, $bank, $pin_number); | ||
| 825 | )* | ||
| 826 | }; | ||
| 827 | } | ||
| 828 | |||
| 829 | macro_rules! impl_pin { | 805 | macro_rules! impl_pin { |
| 830 | ($name: ident, $bank: ident, $pin_num: expr) => { | 806 | ($name: ident, $bank: ident, $pin_num: expr) => { |
| 831 | impl crate::gpio::Pin for crate::peripherals::$name {} | 807 | impl crate::gpio::Pin for crate::peripherals::$name {} |
