diff options
| author | Dario Nieuwenhuis <[email protected]> | 2022-07-23 15:13:47 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2022-07-23 15:13:47 +0200 |
| commit | 709df0dc1dfff577fb79bbc2f67ea84670072456 (patch) | |
| tree | 4a54aee47c0d3881b9e0bc809e075728cee8eeae /embassy-nrf/src/gpiote.rs | |
| parent | 19d1ef0e29fdd0bf0407cbe37c388e8a87e7ddfe (diff) | |
nrf: replace PhantomData usages with PeripheralRef.
Diffstat (limited to 'embassy-nrf/src/gpiote.rs')
| -rw-r--r-- | embassy-nrf/src/gpiote.rs | 42 |
1 files changed, 16 insertions, 26 deletions
diff --git a/embassy-nrf/src/gpiote.rs b/embassy-nrf/src/gpiote.rs index e89d01685..cef80ae0a 100644 --- a/embassy-nrf/src/gpiote.rs +++ b/embassy-nrf/src/gpiote.rs | |||
| @@ -1,10 +1,9 @@ | |||
| 1 | use core::convert::Infallible; | 1 | use core::convert::Infallible; |
| 2 | use core::future::Future; | 2 | use core::future::Future; |
| 3 | use core::marker::PhantomData; | ||
| 4 | use core::task::{Context, Poll}; | 3 | use core::task::{Context, Poll}; |
| 5 | 4 | ||
| 6 | use embassy::waitqueue::AtomicWaker; | 5 | use embassy::waitqueue::AtomicWaker; |
| 7 | use embassy_hal_common::impl_peripheral; | 6 | use embassy_hal_common::{impl_peripheral, Peripheral, PeripheralRef}; |
| 8 | use futures::future::poll_fn; | 7 | use futures::future::poll_fn; |
| 9 | 8 | ||
| 10 | use crate::gpio::sealed::Pin as _; | 9 | use crate::gpio::sealed::Pin as _; |
| @@ -301,16 +300,22 @@ impl<'d, C: Channel, T: GpioPin> OutputChannel<'d, C, T> { | |||
| 301 | // ======================= | 300 | // ======================= |
| 302 | 301 | ||
| 303 | pub(crate) struct PortInputFuture<'a> { | 302 | pub(crate) struct PortInputFuture<'a> { |
| 304 | pin_port: u8, | 303 | pin: PeripheralRef<'a, AnyPin>, |
| 305 | phantom: PhantomData<&'a mut AnyPin>, | 304 | } |
| 305 | |||
| 306 | impl<'a> PortInputFuture<'a> { | ||
| 307 | fn new(pin: impl Peripheral<P = impl GpioPin> + 'a) -> Self { | ||
| 308 | Self { | ||
| 309 | pin: pin.into_ref().map_into(), | ||
| 310 | } | ||
| 311 | } | ||
| 306 | } | 312 | } |
| 307 | 313 | ||
| 308 | impl<'a> Unpin for PortInputFuture<'a> {} | 314 | impl<'a> Unpin for PortInputFuture<'a> {} |
| 309 | 315 | ||
| 310 | impl<'a> Drop for PortInputFuture<'a> { | 316 | impl<'a> Drop for PortInputFuture<'a> { |
| 311 | fn drop(&mut self) { | 317 | fn drop(&mut self) { |
| 312 | let pin = unsafe { AnyPin::steal(self.pin_port) }; | 318 | self.pin.conf().modify(|_, w| w.sense().disabled()); |
| 313 | pin.conf().modify(|_, w| w.sense().disabled()); | ||
| 314 | } | 319 | } |
| 315 | } | 320 | } |
| 316 | 321 | ||
| @@ -318,10 +323,9 @@ impl<'a> Future for PortInputFuture<'a> { | |||
| 318 | type Output = (); | 323 | type Output = (); |
| 319 | 324 | ||
| 320 | fn poll(self: core::pin::Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { | 325 | fn poll(self: core::pin::Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { |
| 321 | PORT_WAKERS[self.pin_port as usize].register(cx.waker()); | 326 | PORT_WAKERS[self.pin.pin_port() as usize].register(cx.waker()); |
| 322 | 327 | ||
| 323 | let pin = unsafe { AnyPin::steal(self.pin_port) }; | 328 | if self.pin.conf().read().sense().is_disabled() { |
| 324 | if pin.conf().read().sense().is_disabled() { | ||
| 325 | Poll::Ready(()) | 329 | Poll::Ready(()) |
| 326 | } else { | 330 | } else { |
| 327 | Poll::Pending | 331 | Poll::Pending |
| @@ -354,22 +358,12 @@ impl<'d, T: GpioPin> Input<'d, T> { | |||
| 354 | impl<'d, T: GpioPin> Flex<'d, T> { | 358 | impl<'d, T: GpioPin> Flex<'d, T> { |
| 355 | pub async fn wait_for_high(&mut self) { | 359 | pub async fn wait_for_high(&mut self) { |
| 356 | self.pin.conf().modify(|_, w| w.sense().high()); | 360 | self.pin.conf().modify(|_, w| w.sense().high()); |
| 357 | 361 | PortInputFuture::new(&mut self.pin).await | |
| 358 | PortInputFuture { | ||
| 359 | pin_port: self.pin.pin_port(), | ||
| 360 | phantom: PhantomData, | ||
| 361 | } | ||
| 362 | .await | ||
| 363 | } | 362 | } |
| 364 | 363 | ||
| 365 | pub async fn wait_for_low(&mut self) { | 364 | pub async fn wait_for_low(&mut self) { |
| 366 | self.pin.conf().modify(|_, w| w.sense().low()); | 365 | self.pin.conf().modify(|_, w| w.sense().low()); |
| 367 | 366 | PortInputFuture::new(&mut self.pin).await | |
| 368 | PortInputFuture { | ||
| 369 | pin_port: self.pin.pin_port(), | ||
| 370 | phantom: PhantomData, | ||
| 371 | } | ||
| 372 | .await | ||
| 373 | } | 367 | } |
| 374 | 368 | ||
| 375 | pub async fn wait_for_rising_edge(&mut self) { | 369 | pub async fn wait_for_rising_edge(&mut self) { |
| @@ -388,11 +382,7 @@ impl<'d, T: GpioPin> Flex<'d, T> { | |||
| 388 | } else { | 382 | } else { |
| 389 | self.pin.conf().modify(|_, w| w.sense().high()); | 383 | self.pin.conf().modify(|_, w| w.sense().high()); |
| 390 | } | 384 | } |
| 391 | PortInputFuture { | 385 | PortInputFuture::new(&mut self.pin).await |
| 392 | pin_port: self.pin.pin_port(), | ||
| 393 | phantom: PhantomData, | ||
| 394 | } | ||
| 395 | .await | ||
| 396 | } | 386 | } |
| 397 | } | 387 | } |
| 398 | 388 | ||
