aboutsummaryrefslogtreecommitdiff
path: root/embassy-mspm0/src/gpio.rs
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-mspm0/src/gpio.rs')
-rw-r--r--embassy-mspm0/src/gpio.rs71
1 files changed, 71 insertions, 0 deletions
diff --git a/embassy-mspm0/src/gpio.rs b/embassy-mspm0/src/gpio.rs
index 2edadbc5a..7e6b01649 100644
--- a/embassy-mspm0/src/gpio.rs
+++ b/embassy-mspm0/src/gpio.rs
@@ -836,6 +836,31 @@ impl<'d> embedded_hal_async::digital::Wait for OutputOpenDrain<'d> {
836 } 836 }
837} 837}
838 838
839#[derive(Copy, Clone)]
840pub struct PfType {
841 pull: Pull,
842 input: bool,
843 invert: bool,
844}
845
846impl PfType {
847 pub const fn input(pull: Pull, invert: bool) -> Self {
848 Self {
849 pull,
850 input: true,
851 invert,
852 }
853 }
854
855 pub const fn output(pull: Pull, invert: bool) -> Self {
856 Self {
857 pull,
858 input: false,
859 invert,
860 }
861 }
862}
863
839/// The pin function to disconnect peripherals from the pin. 864/// The pin function to disconnect peripherals from the pin.
840/// 865///
841/// This is also the pin function used to connect to analog peripherals, such as an ADC. 866/// This is also the pin function used to connect to analog peripherals, such as an ADC.
@@ -908,6 +933,40 @@ pub(crate) trait SealedPin {
908 } 933 }
909 934
910 #[inline] 935 #[inline]
936 fn set_as_analog(&self) {
937 let pincm = pac::IOMUX.pincm(self._pin_cm() as usize);
938
939 pincm.modify(|w| {
940 w.set_pf(DISCONNECT_PF);
941 w.set_pipu(false);
942 w.set_pipd(false);
943 });
944 }
945
946 fn update_pf(&self, ty: PfType) {
947 let pincm = pac::IOMUX.pincm(self._pin_cm() as usize);
948 let pf = pincm.read().pf();
949
950 set_pf(self._pin_cm() as usize, pf, ty);
951 }
952
953 fn set_as_pf(&self, pf: u8, ty: PfType) {
954 set_pf(self._pin_cm() as usize, pf, ty)
955 }
956
957 /// Set the pin as "disconnected", ie doing nothing and consuming the lowest
958 /// amount of power possible.
959 ///
960 /// This is currently the same as [`Self::set_as_analog()`] but is semantically different
961 /// really. Drivers should `set_as_disconnected()` pins when dropped.
962 ///
963 /// Note that this also disables the internal weak pull-up and pull-down resistors.
964 #[inline]
965 fn set_as_disconnected(&self) {
966 self.set_as_analog();
967 }
968
969 #[inline]
911 fn block(&self) -> gpio::Gpio { 970 fn block(&self) -> gpio::Gpio {
912 match self.pin_port() / 32 { 971 match self.pin_port() / 32 {
913 0 => pac::GPIOA, 972 0 => pac::GPIOA,
@@ -920,6 +979,18 @@ pub(crate) trait SealedPin {
920 } 979 }
921} 980}
922 981
982#[inline(never)]
983fn set_pf(pincm: usize, pf: u8, ty: PfType) {
984 pac::IOMUX.pincm(pincm).modify(|w| {
985 w.set_pf(pf);
986 w.set_pc(true);
987 w.set_pipu(ty.pull == Pull::Up);
988 w.set_pipd(ty.pull == Pull::Down);
989 w.set_inena(ty.input);
990 w.set_inv(ty.invert);
991 });
992}
993
923#[must_use = "futures do nothing unless you `.await` or poll them"] 994#[must_use = "futures do nothing unless you `.await` or poll them"]
924struct InputFuture<'d> { 995struct InputFuture<'d> {
925 pin: Peri<'d, AnyPin>, 996 pin: Peri<'d, AnyPin>,