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-nxp/src/gpio.rs | |
| parent | 9edf5b7f049f95742b60b041e4443967d8a6b708 (diff) | |
Remove Peripheral trait, rename PeripheralRef->Peri.
Diffstat (limited to 'embassy-nxp/src/gpio.rs')
| -rw-r--r-- | embassy-nxp/src/gpio.rs | 35 |
1 files changed, 14 insertions, 21 deletions
diff --git a/embassy-nxp/src/gpio.rs b/embassy-nxp/src/gpio.rs index d5d04ee69..c7c78ce61 100644 --- a/embassy-nxp/src/gpio.rs +++ b/embassy-nxp/src/gpio.rs | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | use embassy_hal_internal::impl_peripheral; | 1 | use embassy_hal_internal::{impl_peripheral, PeripheralType}; |
| 2 | 2 | ||
| 3 | use crate::pac_utils::*; | 3 | use crate::pac_utils::*; |
| 4 | use crate::{peripherals, Peripheral, PeripheralRef}; | 4 | use crate::{peripherals, Peri}; |
| 5 | 5 | ||
| 6 | pub(crate) fn init() { | 6 | pub(crate) fn init() { |
| 7 | // Enable clocks for GPIO, PINT, and IOCON | 7 | // Enable clocks for GPIO, PINT, and IOCON |
| @@ -45,7 +45,7 @@ pub struct Output<'d> { | |||
| 45 | impl<'d> Output<'d> { | 45 | impl<'d> Output<'d> { |
| 46 | /// Create GPIO output driver for a [Pin] with the provided [initial output](Level). | 46 | /// Create GPIO output driver for a [Pin] with the provided [initial output](Level). |
| 47 | #[inline] | 47 | #[inline] |
| 48 | pub fn new(pin: impl Peripheral<P = impl Pin> + 'd, initial_output: Level) -> Self { | 48 | pub fn new(pin: Peri<'d, impl Pin>, initial_output: Level) -> Self { |
| 49 | let mut pin = Flex::new(pin); | 49 | let mut pin = Flex::new(pin); |
| 50 | pin.set_as_output(); | 50 | pin.set_as_output(); |
| 51 | let mut result = Self { pin }; | 51 | let mut result = Self { pin }; |
| @@ -90,7 +90,7 @@ pub struct Input<'d> { | |||
| 90 | impl<'d> Input<'d> { | 90 | impl<'d> Input<'d> { |
| 91 | /// Create GPIO output driver for a [Pin] with the provided [Pull]. | 91 | /// Create GPIO output driver for a [Pin] with the provided [Pull]. |
| 92 | #[inline] | 92 | #[inline] |
| 93 | pub fn new(pin: impl Peripheral<P = impl Pin> + 'd, pull: Pull) -> Self { | 93 | pub fn new(pin: Peri<'d, impl Pin>, pull: Pull) -> Self { |
| 94 | let mut pin = Flex::new(pin); | 94 | let mut pin = Flex::new(pin); |
| 95 | pin.set_as_input(); | 95 | pin.set_as_input(); |
| 96 | let mut result = Self { pin }; | 96 | let mut result = Self { pin }; |
| @@ -124,7 +124,7 @@ impl<'d> Input<'d> { | |||
| 124 | /// A flexible GPIO (digital mode) pin whose mode is not yet determined. Under the hood, this is a | 124 | /// A flexible GPIO (digital mode) pin whose mode is not yet determined. Under the hood, this is a |
| 125 | /// reference to a type-erased pin called ["AnyPin"](AnyPin). | 125 | /// reference to a type-erased pin called ["AnyPin"](AnyPin). |
| 126 | pub struct Flex<'d> { | 126 | pub struct Flex<'d> { |
| 127 | pub(crate) pin: PeripheralRef<'d, AnyPin>, | 127 | pub(crate) pin: Peri<'d, AnyPin>, |
| 128 | } | 128 | } |
| 129 | 129 | ||
| 130 | impl<'d> Flex<'d> { | 130 | impl<'d> Flex<'d> { |
| @@ -132,10 +132,8 @@ impl<'d> Flex<'d> { | |||
| 132 | /// | 132 | /// |
| 133 | /// Note: you cannot assume that the pin will be in Digital mode after this call. | 133 | /// Note: you cannot assume that the pin will be in Digital mode after this call. |
| 134 | #[inline] | 134 | #[inline] |
| 135 | pub fn new(pin: impl Peripheral<P = impl Pin> + 'd) -> Self { | 135 | pub fn new(pin: Peri<'d, impl Pin>) -> Self { |
| 136 | Self { | 136 | Self { pin: pin.into() } |
| 137 | pin: pin.into_ref().map_into(), | ||
| 138 | } | ||
| 139 | } | 137 | } |
| 140 | 138 | ||
| 141 | /// Get the bank of this pin. See also [Bank]. | 139 | /// Get the bank of this pin. See also [Bank]. |
| @@ -218,15 +216,7 @@ pub(crate) trait SealedPin: Sized { | |||
| 218 | /// [AnyPin]. By default, this trait is sealed and cannot be implemented outside of the | 216 | /// [AnyPin]. By default, this trait is sealed and cannot be implemented outside of the |
| 219 | /// `embassy-nxp` crate due to the [SealedPin] trait. | 217 | /// `embassy-nxp` crate due to the [SealedPin] trait. |
| 220 | #[allow(private_bounds)] | 218 | #[allow(private_bounds)] |
| 221 | pub trait Pin: Peripheral<P = Self> + Into<AnyPin> + SealedPin + Sized + 'static { | 219 | pub trait Pin: PeripheralType + Into<AnyPin> + SealedPin + Sized + 'static { |
| 222 | /// Degrade to a generic pin struct | ||
| 223 | fn degrade(self) -> AnyPin { | ||
| 224 | AnyPin { | ||
| 225 | pin_bank: self.pin_bank(), | ||
| 226 | pin_number: self.pin_number(), | ||
| 227 | } | ||
| 228 | } | ||
| 229 | |||
| 230 | /// Returns the pin number within a bank | 220 | /// Returns the pin number within a bank |
| 231 | #[inline] | 221 | #[inline] |
| 232 | fn pin(&self) -> u8 { | 222 | fn pin(&self) -> u8 { |
| @@ -252,8 +242,8 @@ impl AnyPin { | |||
| 252 | /// # Safety | 242 | /// # Safety |
| 253 | /// | 243 | /// |
| 254 | /// You must ensure that you’re only using one instance of this type at a time. | 244 | /// You must ensure that you’re only using one instance of this type at a time. |
| 255 | pub unsafe fn steal(pin_bank: Bank, pin_number: u8) -> Self { | 245 | pub unsafe fn steal(pin_bank: Bank, pin_number: u8) -> Peri<'static, Self> { |
| 256 | Self { pin_bank, pin_number } | 246 | Peri::new_unchecked(Self { pin_bank, pin_number }) |
| 257 | } | 247 | } |
| 258 | } | 248 | } |
| 259 | 249 | ||
| @@ -289,7 +279,10 @@ macro_rules! impl_pin { | |||
| 289 | 279 | ||
| 290 | impl From<peripherals::$name> for crate::gpio::AnyPin { | 280 | impl From<peripherals::$name> for crate::gpio::AnyPin { |
| 291 | fn from(val: peripherals::$name) -> Self { | 281 | fn from(val: peripherals::$name) -> Self { |
| 292 | crate::gpio::Pin::degrade(val) | 282 | Self { |
| 283 | pin_bank: val.pin_bank(), | ||
| 284 | pin_number: val.pin_number(), | ||
| 285 | } | ||
| 293 | } | 286 | } |
| 294 | } | 287 | } |
| 295 | }; | 288 | }; |
