aboutsummaryrefslogtreecommitdiff
path: root/embassy-rp/src/gpio.rs
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2024-04-05 00:35:25 +0200
committerDario Nieuwenhuis <[email protected]>2024-04-05 00:48:46 +0200
commita84b33995eacc32e0e13d70293fa9bd7b2bd75f8 (patch)
treecfd48dbdad8885495cf20c4832f373444b867397 /embassy-rp/src/gpio.rs
parentab85eb4b60cd49ebcd43d2305f42327685f5e5a6 (diff)
rp: remove mod sealed.
Diffstat (limited to 'embassy-rp/src/gpio.rs')
-rw-r--r--embassy-rp/src/gpio.rs96
1 files changed, 46 insertions, 50 deletions
diff --git a/embassy-rp/src/gpio.rs b/embassy-rp/src/gpio.rs
index a84c00a2c..ea87fd9da 100644
--- a/embassy-rp/src/gpio.rs
+++ b/embassy-rp/src/gpio.rs
@@ -8,7 +8,6 @@ use core::task::{Context, Poll};
8use embassy_hal_internal::{impl_peripheral, into_ref, PeripheralRef}; 8use embassy_hal_internal::{impl_peripheral, into_ref, PeripheralRef};
9use embassy_sync::waitqueue::AtomicWaker; 9use embassy_sync::waitqueue::AtomicWaker;
10 10
11use self::sealed::Pin as _;
12use crate::interrupt::InterruptExt; 11use crate::interrupt::InterruptExt;
13use crate::pac::common::{Reg, RW}; 12use crate::pac::common::{Reg, RW};
14use crate::pac::SIO; 13use crate::pac::SIO;
@@ -802,68 +801,65 @@ impl<'w> Drop for DormantWake<'w> {
802 } 801 }
803} 802}
804 803
805pub(crate) mod sealed { 804pub(crate) trait SealedPin: Sized {
806 use super::*; 805 fn pin_bank(&self) -> u8;
807
808 pub trait Pin: Sized {
809 fn pin_bank(&self) -> u8;
810 806
811 #[inline] 807 #[inline]
812 fn _pin(&self) -> u8 { 808 fn _pin(&self) -> u8 {
813 self.pin_bank() & 0x1f 809 self.pin_bank() & 0x1f
814 } 810 }
815 811
816 #[inline] 812 #[inline]
817 fn _bank(&self) -> Bank { 813 fn _bank(&self) -> Bank {
818 match self.pin_bank() >> 5 { 814 match self.pin_bank() >> 5 {
819 #[cfg(feature = "qspi-as-gpio")] 815 #[cfg(feature = "qspi-as-gpio")]
820 1 => Bank::Qspi, 816 1 => Bank::Qspi,
821 _ => Bank::Bank0, 817 _ => Bank::Bank0,
822 }
823 } 818 }
819 }
824 820
825 fn io(&self) -> pac::io::Io { 821 fn io(&self) -> pac::io::Io {
826 match self._bank() { 822 match self._bank() {
827 Bank::Bank0 => crate::pac::IO_BANK0, 823 Bank::Bank0 => crate::pac::IO_BANK0,
828 #[cfg(feature = "qspi-as-gpio")] 824 #[cfg(feature = "qspi-as-gpio")]
829 Bank::Qspi => crate::pac::IO_QSPI, 825 Bank::Qspi => crate::pac::IO_QSPI,
830 }
831 } 826 }
827 }
832 828
833 fn gpio(&self) -> pac::io::Gpio { 829 fn gpio(&self) -> pac::io::Gpio {
834 self.io().gpio(self._pin() as _) 830 self.io().gpio(self._pin() as _)
835 } 831 }
836 832
837 fn pad_ctrl(&self) -> Reg<pac::pads::regs::GpioCtrl, RW> { 833 fn pad_ctrl(&self) -> Reg<pac::pads::regs::GpioCtrl, RW> {
838 let block = match self._bank() { 834 let block = match self._bank() {
839 Bank::Bank0 => crate::pac::PADS_BANK0, 835 Bank::Bank0 => crate::pac::PADS_BANK0,
840 #[cfg(feature = "qspi-as-gpio")] 836 #[cfg(feature = "qspi-as-gpio")]
841 Bank::Qspi => crate::pac::PADS_QSPI, 837 Bank::Qspi => crate::pac::PADS_QSPI,
842 }; 838 };
843 block.gpio(self._pin() as _) 839 block.gpio(self._pin() as _)
844 } 840 }
845 841
846 fn sio_out(&self) -> pac::sio::Gpio { 842 fn sio_out(&self) -> pac::sio::Gpio {
847 SIO.gpio_out(self._bank() as _) 843 SIO.gpio_out(self._bank() as _)
848 } 844 }
849 845
850 fn sio_oe(&self) -> pac::sio::Gpio { 846 fn sio_oe(&self) -> pac::sio::Gpio {
851 SIO.gpio_oe(self._bank() as _) 847 SIO.gpio_oe(self._bank() as _)
852 } 848 }
853 849
854 fn sio_in(&self) -> Reg<u32, RW> { 850 fn sio_in(&self) -> Reg<u32, RW> {
855 SIO.gpio_in(self._bank() as _) 851 SIO.gpio_in(self._bank() as _)
856 } 852 }
857 853
858 fn int_proc(&self) -> pac::io::Int { 854 fn int_proc(&self) -> pac::io::Int {
859 let proc = SIO.cpuid().read(); 855 let proc = SIO.cpuid().read();
860 self.io().int_proc(proc as _) 856 self.io().int_proc(proc as _)
861 }
862 } 857 }
863} 858}
864 859
865/// Interface for a Pin that can be configured by an [Input] or [Output] driver, or converted to an [AnyPin]. 860/// Interface for a Pin that can be configured by an [Input] or [Output] driver, or converted to an [AnyPin].
866pub trait Pin: Peripheral<P = Self> + Into<AnyPin> + sealed::Pin + Sized + 'static { 861#[allow(private_bounds)]
862pub trait Pin: Peripheral<P = Self> + Into<AnyPin> + SealedPin + Sized + 'static {
867 /// Degrade to a generic pin struct 863 /// Degrade to a generic pin struct
868 fn degrade(self) -> AnyPin { 864 fn degrade(self) -> AnyPin {
869 AnyPin { 865 AnyPin {
@@ -903,7 +899,7 @@ impl AnyPin {
903impl_peripheral!(AnyPin); 899impl_peripheral!(AnyPin);
904 900
905impl Pin for AnyPin {} 901impl Pin for AnyPin {}
906impl sealed::Pin for AnyPin { 902impl SealedPin for AnyPin {
907 fn pin_bank(&self) -> u8 { 903 fn pin_bank(&self) -> u8 {
908 self.pin_bank 904 self.pin_bank
909 } 905 }
@@ -914,7 +910,7 @@ impl sealed::Pin for AnyPin {
914macro_rules! impl_pin { 910macro_rules! impl_pin {
915 ($name:ident, $bank:expr, $pin_num:expr) => { 911 ($name:ident, $bank:expr, $pin_num:expr) => {
916 impl Pin for peripherals::$name {} 912 impl Pin for peripherals::$name {}
917 impl sealed::Pin for peripherals::$name { 913 impl SealedPin for peripherals::$name {
918 #[inline] 914 #[inline]
919 fn pin_bank(&self) -> u8 { 915 fn pin_bank(&self) -> u8 {
920 ($bank as u8) * 32 + $pin_num 916 ($bank as u8) * 32 + $pin_num