diff options
| author | Dario Nieuwenhuis <[email protected]> | 2025-03-26 16:01:37 +0100 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2025-03-27 15:18:06 +0100 |
| commit | d41eeeae79388f219bf6a84e2f7bde9f6b532516 (patch) | |
| tree | 678b6fc732216e529dc38e6f65b72a309917ac32 /embassy-rp/src/gpio.rs | |
| parent | 9edf5b7f049f95742b60b041e4443967d8a6b708 (diff) | |
Remove Peripheral trait, rename PeripheralRef->Peri.
Diffstat (limited to 'embassy-rp/src/gpio.rs')
| -rw-r--r-- | embassy-rp/src/gpio.rs | 41 |
1 files changed, 17 insertions, 24 deletions
diff --git a/embassy-rp/src/gpio.rs b/embassy-rp/src/gpio.rs index 111e03356..af0837f6a 100644 --- a/embassy-rp/src/gpio.rs +++ b/embassy-rp/src/gpio.rs | |||
| @@ -5,13 +5,13 @@ use core::future::Future; | |||
| 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, into_ref, PeripheralRef}; | 8 | use embassy_hal_internal::{impl_peripheral, Peri, PeripheralType}; |
| 9 | use embassy_sync::waitqueue::AtomicWaker; | 9 | use embassy_sync::waitqueue::AtomicWaker; |
| 10 | 10 | ||
| 11 | use crate::interrupt::InterruptExt; | 11 | use crate::interrupt::InterruptExt; |
| 12 | use crate::pac::common::{Reg, RW}; | 12 | use crate::pac::common::{Reg, RW}; |
| 13 | use crate::pac::SIO; | 13 | use crate::pac::SIO; |
| 14 | use crate::{interrupt, pac, peripherals, Peripheral, RegExt}; | 14 | use crate::{interrupt, pac, peripherals, RegExt}; |
| 15 | 15 | ||
| 16 | #[cfg(any(feature = "rp2040", feature = "rp235xa"))] | 16 | #[cfg(any(feature = "rp2040", feature = "rp235xa"))] |
| 17 | pub(crate) const BANK0_PIN_COUNT: usize = 30; | 17 | pub(crate) const BANK0_PIN_COUNT: usize = 30; |
| @@ -115,7 +115,7 @@ pub struct Input<'d> { | |||
| 115 | impl<'d> Input<'d> { | 115 | impl<'d> Input<'d> { |
| 116 | /// Create GPIO input driver for a [Pin] with the provided [Pull] configuration. | 116 | /// Create GPIO input driver for a [Pin] with the provided [Pull] configuration. |
| 117 | #[inline] | 117 | #[inline] |
| 118 | pub fn new(pin: impl Peripheral<P = impl Pin> + 'd, pull: Pull) -> Self { | 118 | pub fn new(pin: Peri<'d, impl Pin>, pull: Pull) -> Self { |
| 119 | let mut pin = Flex::new(pin); | 119 | let mut pin = Flex::new(pin); |
| 120 | pin.set_as_input(); | 120 | pin.set_as_input(); |
| 121 | pin.set_pull(pull); | 121 | pin.set_pull(pull); |
| @@ -266,11 +266,11 @@ fn IO_IRQ_QSPI() { | |||
| 266 | 266 | ||
| 267 | #[must_use = "futures do nothing unless you `.await` or poll them"] | 267 | #[must_use = "futures do nothing unless you `.await` or poll them"] |
| 268 | struct InputFuture<'d> { | 268 | struct InputFuture<'d> { |
| 269 | pin: PeripheralRef<'d, AnyPin>, | 269 | pin: Peri<'d, AnyPin>, |
| 270 | } | 270 | } |
| 271 | 271 | ||
| 272 | impl<'d> InputFuture<'d> { | 272 | impl<'d> InputFuture<'d> { |
| 273 | fn new(pin: PeripheralRef<'d, AnyPin>, level: InterruptTrigger) -> Self { | 273 | fn new(pin: Peri<'d, AnyPin>, level: InterruptTrigger) -> Self { |
| 274 | let pin_group = (pin.pin() % 8) as usize; | 274 | let pin_group = (pin.pin() % 8) as usize; |
| 275 | // first, clear the INTR register bits. without this INTR will still | 275 | // first, clear the INTR register bits. without this INTR will still |
| 276 | // contain reports of previous edges, causing the IRQ to fire early | 276 | // contain reports of previous edges, causing the IRQ to fire early |
| @@ -359,7 +359,7 @@ pub struct Output<'d> { | |||
| 359 | impl<'d> Output<'d> { | 359 | impl<'d> Output<'d> { |
| 360 | /// Create GPIO output driver for a [Pin] with the provided [Level]. | 360 | /// Create GPIO output driver for a [Pin] with the provided [Level]. |
| 361 | #[inline] | 361 | #[inline] |
| 362 | pub fn new(pin: impl Peripheral<P = impl Pin> + 'd, initial_output: Level) -> Self { | 362 | pub fn new(pin: Peri<'d, impl Pin>, initial_output: Level) -> Self { |
| 363 | let mut pin = Flex::new(pin); | 363 | let mut pin = Flex::new(pin); |
| 364 | match initial_output { | 364 | match initial_output { |
| 365 | Level::High => pin.set_high(), | 365 | Level::High => pin.set_high(), |
| @@ -440,7 +440,7 @@ pub struct OutputOpenDrain<'d> { | |||
| 440 | impl<'d> OutputOpenDrain<'d> { | 440 | impl<'d> OutputOpenDrain<'d> { |
| 441 | /// Create GPIO output driver for a [Pin] in open drain mode with the provided [Level]. | 441 | /// Create GPIO output driver for a [Pin] in open drain mode with the provided [Level]. |
| 442 | #[inline] | 442 | #[inline] |
| 443 | pub fn new(pin: impl Peripheral<P = impl Pin> + 'd, initial_output: Level) -> Self { | 443 | pub fn new(pin: Peri<'d, impl Pin>, initial_output: Level) -> Self { |
| 444 | let mut pin = Flex::new(pin); | 444 | let mut pin = Flex::new(pin); |
| 445 | pin.set_low(); | 445 | pin.set_low(); |
| 446 | match initial_output { | 446 | match initial_output { |
| @@ -581,7 +581,7 @@ impl<'d> OutputOpenDrain<'d> { | |||
| 581 | /// set while not in output mode, so the pin's level will be 'remembered' when it is not in output | 581 | /// set while not in output mode, so the pin's level will be 'remembered' when it is not in output |
| 582 | /// mode. | 582 | /// mode. |
| 583 | pub struct Flex<'d> { | 583 | pub struct Flex<'d> { |
| 584 | pin: PeripheralRef<'d, AnyPin>, | 584 | pin: Peri<'d, AnyPin>, |
| 585 | } | 585 | } |
| 586 | 586 | ||
| 587 | impl<'d> Flex<'d> { | 587 | impl<'d> Flex<'d> { |
| @@ -590,9 +590,7 @@ impl<'d> Flex<'d> { | |||
| 590 | /// The pin remains disconnected. The initial output level is unspecified, but can be changed | 590 | /// The pin remains disconnected. The initial output level is unspecified, but can be changed |
| 591 | /// before the pin is put into output mode. | 591 | /// before the pin is put into output mode. |
| 592 | #[inline] | 592 | #[inline] |
| 593 | pub fn new(pin: impl Peripheral<P = impl Pin> + 'd) -> Self { | 593 | pub fn new(pin: Peri<'d, impl Pin>) -> Self { |
| 594 | into_ref!(pin); | ||
| 595 | |||
| 596 | pin.pad_ctrl().write(|w| { | 594 | pin.pad_ctrl().write(|w| { |
| 597 | #[cfg(feature = "_rp235x")] | 595 | #[cfg(feature = "_rp235x")] |
| 598 | w.set_iso(false); | 596 | w.set_iso(false); |
| @@ -606,7 +604,7 @@ impl<'d> Flex<'d> { | |||
| 606 | w.set_funcsel(pac::io::vals::Gpio0ctrlFuncsel::SIOB_PROC_0 as _); | 604 | w.set_funcsel(pac::io::vals::Gpio0ctrlFuncsel::SIOB_PROC_0 as _); |
| 607 | }); | 605 | }); |
| 608 | 606 | ||
| 609 | Self { pin: pin.map_into() } | 607 | Self { pin: pin.into() } |
| 610 | } | 608 | } |
| 611 | 609 | ||
| 612 | #[inline] | 610 | #[inline] |
| @@ -829,7 +827,7 @@ impl<'d> Drop for Flex<'d> { | |||
| 829 | 827 | ||
| 830 | /// Dormant wake driver. | 828 | /// Dormant wake driver. |
| 831 | pub struct DormantWake<'w> { | 829 | pub struct DormantWake<'w> { |
| 832 | pin: PeripheralRef<'w, AnyPin>, | 830 | pin: Peri<'w, AnyPin>, |
| 833 | cfg: DormantWakeConfig, | 831 | cfg: DormantWakeConfig, |
| 834 | } | 832 | } |
| 835 | 833 | ||
| @@ -919,14 +917,7 @@ pub(crate) trait SealedPin: Sized { | |||
| 919 | 917 | ||
| 920 | /// Interface for a Pin that can be configured by an [Input] or [Output] driver, or converted to an [AnyPin]. | 918 | /// Interface for a Pin that can be configured by an [Input] or [Output] driver, or converted to an [AnyPin]. |
| 921 | #[allow(private_bounds)] | 919 | #[allow(private_bounds)] |
| 922 | pub trait Pin: Peripheral<P = Self> + Into<AnyPin> + SealedPin + Sized + 'static { | 920 | pub trait Pin: PeripheralType + Into<AnyPin> + SealedPin + Sized + 'static { |
| 923 | /// Degrade to a generic pin struct | ||
| 924 | fn degrade(self) -> AnyPin { | ||
| 925 | AnyPin { | ||
| 926 | pin_bank: self.pin_bank(), | ||
| 927 | } | ||
| 928 | } | ||
| 929 | |||
| 930 | /// Returns the pin number within a bank | 921 | /// Returns the pin number within a bank |
| 931 | #[inline] | 922 | #[inline] |
| 932 | fn pin(&self) -> u8 { | 923 | fn pin(&self) -> u8 { |
| @@ -951,8 +942,8 @@ impl AnyPin { | |||
| 951 | /// # Safety | 942 | /// # Safety |
| 952 | /// | 943 | /// |
| 953 | /// You must ensure that you’re only using one instance of this type at a time. | 944 | /// You must ensure that you’re only using one instance of this type at a time. |
| 954 | pub unsafe fn steal(pin_bank: u8) -> Self { | 945 | pub unsafe fn steal(pin_bank: u8) -> Peri<'static, Self> { |
| 955 | Self { pin_bank } | 946 | Peri::new_unchecked(Self { pin_bank }) |
| 956 | } | 947 | } |
| 957 | } | 948 | } |
| 958 | 949 | ||
| @@ -979,7 +970,9 @@ macro_rules! impl_pin { | |||
| 979 | 970 | ||
| 980 | impl From<peripherals::$name> for crate::gpio::AnyPin { | 971 | impl From<peripherals::$name> for crate::gpio::AnyPin { |
| 981 | fn from(val: peripherals::$name) -> Self { | 972 | fn from(val: peripherals::$name) -> Self { |
| 982 | crate::gpio::Pin::degrade(val) | 973 | Self { |
| 974 | pin_bank: val.pin_bank(), | ||
| 975 | } | ||
| 983 | } | 976 | } |
| 984 | } | 977 | } |
| 985 | }; | 978 | }; |
