aboutsummaryrefslogtreecommitdiff
path: root/embassy-nxp/src
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2025-03-26 16:01:37 +0100
committerDario Nieuwenhuis <[email protected]>2025-03-27 15:18:06 +0100
commitd41eeeae79388f219bf6a84e2f7bde9f6b532516 (patch)
tree678b6fc732216e529dc38e6f65b72a309917ac32 /embassy-nxp/src
parent9edf5b7f049f95742b60b041e4443967d8a6b708 (diff)
Remove Peripheral trait, rename PeripheralRef->Peri.
Diffstat (limited to 'embassy-nxp/src')
-rw-r--r--embassy-nxp/src/gpio.rs35
-rw-r--r--embassy-nxp/src/lib.rs2
-rw-r--r--embassy-nxp/src/pint.rs18
3 files changed, 24 insertions, 31 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 @@
1use embassy_hal_internal::impl_peripheral; 1use embassy_hal_internal::{impl_peripheral, PeripheralType};
2 2
3use crate::pac_utils::*; 3use crate::pac_utils::*;
4use crate::{peripherals, Peripheral, PeripheralRef}; 4use crate::{peripherals, Peri};
5 5
6pub(crate) fn init() { 6pub(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> {
45impl<'d> Output<'d> { 45impl<'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> {
90impl<'d> Input<'d> { 90impl<'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).
126pub struct Flex<'d> { 126pub struct Flex<'d> {
127 pub(crate) pin: PeripheralRef<'d, AnyPin>, 127 pub(crate) pin: Peri<'d, AnyPin>,
128} 128}
129 129
130impl<'d> Flex<'d> { 130impl<'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)]
221pub trait Pin: Peripheral<P = Self> + Into<AnyPin> + SealedPin + Sized + 'static { 219pub 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 };
diff --git a/embassy-nxp/src/lib.rs b/embassy-nxp/src/lib.rs
index 80fdecb2e..ad2056c06 100644
--- a/embassy-nxp/src/lib.rs
+++ b/embassy-nxp/src/lib.rs
@@ -4,7 +4,7 @@ pub mod gpio;
4mod pac_utils; 4mod pac_utils;
5pub mod pint; 5pub mod pint;
6 6
7pub use embassy_hal_internal::{into_ref, Peripheral, PeripheralRef}; 7pub use embassy_hal_internal::Peri;
8pub use lpc55_pac as pac; 8pub use lpc55_pac as pac;
9 9
10/// Initialize the `embassy-nxp` HAL with the provided configuration. 10/// Initialize the `embassy-nxp` HAL with the provided configuration.
diff --git a/embassy-nxp/src/pint.rs b/embassy-nxp/src/pint.rs
index 809be4bff..8d6dc1277 100644
--- a/embassy-nxp/src/pint.rs
+++ b/embassy-nxp/src/pint.rs
@@ -5,12 +5,12 @@ use core::pin::Pin as FuturePin;
5use core::task::{Context, Poll}; 5use core::task::{Context, Poll};
6 6
7use critical_section::Mutex; 7use critical_section::Mutex;
8use embassy_hal_internal::{Peripheral, PeripheralRef};
9use embassy_sync::waitqueue::AtomicWaker; 8use embassy_sync::waitqueue::AtomicWaker;
10 9
11use crate::gpio::{self, AnyPin, Level, SealedPin}; 10use crate::gpio::{self, AnyPin, Level, SealedPin};
12use crate::pac::interrupt; 11use crate::pac::interrupt;
13use crate::pac_utils::*; 12use crate::pac_utils::*;
13use crate::Peri;
14 14
15struct PinInterrupt { 15struct PinInterrupt {
16 assigned: bool, 16 assigned: bool,
@@ -107,14 +107,14 @@ pub(crate) fn init() {
107#[must_use = "futures do nothing unless you `.await` or poll them"] 107#[must_use = "futures do nothing unless you `.await` or poll them"]
108struct InputFuture<'d> { 108struct InputFuture<'d> {
109 #[allow(dead_code)] 109 #[allow(dead_code)]
110 pin: PeripheralRef<'d, AnyPin>, 110 pin: Peri<'d, AnyPin>,
111 interrupt_number: usize, 111 interrupt_number: usize,
112} 112}
113 113
114impl<'d> InputFuture<'d> { 114impl<'d> InputFuture<'d> {
115 /// Create a new input future. Returns None if all interrupts are in use. 115 /// Create a new input future. Returns None if all interrupts are in use.
116 fn new(pin: impl Peripheral<P = impl gpio::Pin> + 'd, interrupt_on: InterruptOn) -> Option<Self> { 116 fn new(pin: Peri<'d, impl gpio::Pin>, interrupt_on: InterruptOn) -> Option<Self> {
117 let pin = pin.into_ref().map_into(); 117 let pin = pin.into();
118 let interrupt_number = next_available_interrupt()?; 118 let interrupt_number = next_available_interrupt()?;
119 119
120 // Clear interrupt, just in case 120 // Clear interrupt, just in case
@@ -344,35 +344,35 @@ impl gpio::Flex<'_> {
344 /// Wait for a falling or rising edge on the pin. You can have at most 8 pins waiting. If you 344 /// Wait for a falling or rising edge on the pin. You can have at most 8 pins waiting. If you
345 /// try to wait for more than 8 pins, this function will return `None`. 345 /// try to wait for more than 8 pins, this function will return `None`.
346 pub async fn wait_for_any_edge(&mut self) -> Option<()> { 346 pub async fn wait_for_any_edge(&mut self) -> Option<()> {
347 InputFuture::new(&mut self.pin, InterruptOn::Edge(Edge::Both))?.await; 347 InputFuture::new(self.pin.reborrow(), InterruptOn::Edge(Edge::Both))?.await;
348 Some(()) 348 Some(())
349 } 349 }
350 350
351 /// Wait for a falling edge on the pin. You can have at most 8 pins waiting. If you try to wait 351 /// Wait for a falling edge on the pin. You can have at most 8 pins waiting. If you try to wait
352 /// for more than 8 pins, this function will return `None`. 352 /// for more than 8 pins, this function will return `None`.
353 pub async fn wait_for_falling_edge(&mut self) -> Option<()> { 353 pub async fn wait_for_falling_edge(&mut self) -> Option<()> {
354 InputFuture::new(&mut self.pin, InterruptOn::Edge(Edge::Falling))?.await; 354 InputFuture::new(self.pin.reborrow(), InterruptOn::Edge(Edge::Falling))?.await;
355 Some(()) 355 Some(())
356 } 356 }
357 357
358 /// Wait for a rising edge on the pin. You can have at most 8 pins waiting. If you try to wait 358 /// Wait for a rising edge on the pin. You can have at most 8 pins waiting. If you try to wait
359 /// for more than 8 pins, this function will return `None`. 359 /// for more than 8 pins, this function will return `None`.
360 pub async fn wait_for_rising_edge(&mut self) -> Option<()> { 360 pub async fn wait_for_rising_edge(&mut self) -> Option<()> {
361 InputFuture::new(&mut self.pin, InterruptOn::Edge(Edge::Rising))?.await; 361 InputFuture::new(self.pin.reborrow(), InterruptOn::Edge(Edge::Rising))?.await;
362 Some(()) 362 Some(())
363 } 363 }
364 364
365 /// Wait for a low level on the pin. You can have at most 8 pins waiting. If you try to wait for 365 /// Wait for a low level on the pin. You can have at most 8 pins waiting. If you try to wait for
366 /// more than 8 pins, this function will return `None`. 366 /// more than 8 pins, this function will return `None`.
367 pub async fn wait_for_low(&mut self) -> Option<()> { 367 pub async fn wait_for_low(&mut self) -> Option<()> {
368 InputFuture::new(&mut self.pin, InterruptOn::Level(Level::Low))?.await; 368 InputFuture::new(self.pin.reborrow(), InterruptOn::Level(Level::Low))?.await;
369 Some(()) 369 Some(())
370 } 370 }
371 371
372 /// Wait for a high level on the pin. You can have at most 8 pins waiting. If you try to wait for 372 /// Wait for a high level on the pin. You can have at most 8 pins waiting. If you try to wait for
373 /// more than 8 pins, this function will return `None`. 373 /// more than 8 pins, this function will return `None`.
374 pub async fn wait_for_high(&mut self) -> Option<()> { 374 pub async fn wait_for_high(&mut self) -> Option<()> {
375 InputFuture::new(&mut self.pin, InterruptOn::Level(Level::High))?.await; 375 InputFuture::new(self.pin.reborrow(), InterruptOn::Level(Level::High))?.await;
376 Some(()) 376 Some(())
377 } 377 }
378} 378}