diff options
| author | Dario Nieuwenhuis <[email protected]> | 2021-12-14 13:23:40 +0100 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2021-12-14 13:23:40 +0100 |
| commit | 153b1bbdbfc38b7973b27c05589514bee993e690 (patch) | |
| tree | 4c289c0da1dede60214a85ce6b7262c06cfc75d9 /embassy-nrf/src/gpio.rs | |
| parent | ff82c76935d86b7444e6abc7296c4c3e09261484 (diff) | |
nrf/gpiote: remove PortInput, move impls to Input.
Diffstat (limited to 'embassy-nrf/src/gpio.rs')
| -rw-r--r-- | embassy-nrf/src/gpio.rs | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/embassy-nrf/src/gpio.rs b/embassy-nrf/src/gpio.rs index 91b2e585a..190d8470f 100644 --- a/embassy-nrf/src/gpio.rs +++ b/embassy-nrf/src/gpio.rs | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | #![macro_use] | 1 | #![macro_use] |
| 2 | 2 | ||
| 3 | use core::convert::Infallible; | 3 | use core::convert::Infallible; |
| 4 | use core::future::Future; | ||
| 4 | use core::hint::unreachable_unchecked; | 5 | use core::hint::unreachable_unchecked; |
| 5 | use core::marker::PhantomData; | 6 | use core::marker::PhantomData; |
| 6 | 7 | ||
| @@ -72,6 +73,54 @@ impl<'d, T: Pin> InputPin for Input<'d, T> { | |||
| 72 | } | 73 | } |
| 73 | } | 74 | } |
| 74 | 75 | ||
| 76 | #[cfg(feature = "gpiote")] | ||
| 77 | impl<'d, T: Pin> embassy::traits::gpio::WaitForHigh for Input<'d, T> { | ||
| 78 | #[rustfmt::skip] | ||
| 79 | type Future<'a> where Self: 'a = impl Future<Output=()> + Unpin + 'a; | ||
| 80 | |||
| 81 | fn wait_for_high<'a>(&'a mut self) -> Self::Future<'a> { | ||
| 82 | self.pin.conf().modify(|_, w| w.sense().high()); | ||
| 83 | |||
| 84 | crate::gpiote::PortInputFuture { | ||
| 85 | pin_port: self.pin.pin_port(), | ||
| 86 | phantom: PhantomData, | ||
| 87 | } | ||
| 88 | } | ||
| 89 | } | ||
| 90 | |||
| 91 | #[cfg(feature = "gpiote")] | ||
| 92 | impl<'d, T: Pin> embassy::traits::gpio::WaitForLow for Input<'d, T> { | ||
| 93 | #[rustfmt::skip] | ||
| 94 | type Future<'a> where Self: 'a = impl Future<Output=()> + Unpin + 'a; | ||
| 95 | |||
| 96 | fn wait_for_low<'a>(&'a mut self) -> Self::Future<'a> { | ||
| 97 | self.pin.conf().modify(|_, w| w.sense().low()); | ||
| 98 | |||
| 99 | crate::gpiote::PortInputFuture { | ||
| 100 | pin_port: self.pin.pin_port(), | ||
| 101 | phantom: PhantomData, | ||
| 102 | } | ||
| 103 | } | ||
| 104 | } | ||
| 105 | |||
| 106 | #[cfg(feature = "gpiote")] | ||
| 107 | impl<'d, T: Pin> embassy::traits::gpio::WaitForAnyEdge for Input<'d, T> { | ||
| 108 | #[rustfmt::skip] | ||
| 109 | type Future<'a> where Self: 'a = impl Future<Output=()> + Unpin + 'a; | ||
| 110 | |||
| 111 | fn wait_for_any_edge<'a>(&'a mut self) -> Self::Future<'a> { | ||
| 112 | if self.is_high().ok().unwrap() { | ||
| 113 | self.pin.conf().modify(|_, w| w.sense().low()); | ||
| 114 | } else { | ||
| 115 | self.pin.conf().modify(|_, w| w.sense().high()); | ||
| 116 | } | ||
| 117 | crate::gpiote::PortInputFuture { | ||
| 118 | pin_port: self.pin.pin_port(), | ||
| 119 | phantom: PhantomData, | ||
| 120 | } | ||
| 121 | } | ||
| 122 | } | ||
| 123 | |||
| 75 | /// Digital input or output level. | 124 | /// Digital input or output level. |
| 76 | #[derive(Debug, Eq, PartialEq)] | 125 | #[derive(Debug, Eq, PartialEq)] |
| 77 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 126 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| @@ -277,6 +326,54 @@ impl<'d, T: Pin> StatefulOutputPin for FlexPin<'d, T> { | |||
| 277 | } | 326 | } |
| 278 | } | 327 | } |
| 279 | 328 | ||
| 329 | #[cfg(feature = "gpiote")] | ||
| 330 | impl<'d, T: Pin> embassy::traits::gpio::WaitForHigh for FlexPin<'d, T> { | ||
| 331 | #[rustfmt::skip] | ||
| 332 | type Future<'a> where Self: 'a = impl Future<Output=()> + Unpin + 'a; | ||
| 333 | |||
| 334 | fn wait_for_high<'a>(&'a mut self) -> Self::Future<'a> { | ||
| 335 | self.pin.conf().modify(|_, w| w.sense().high()); | ||
| 336 | |||
| 337 | crate::gpiote::PortInputFuture { | ||
| 338 | pin_port: self.pin.pin_port(), | ||
| 339 | phantom: PhantomData, | ||
| 340 | } | ||
| 341 | } | ||
| 342 | } | ||
| 343 | |||
| 344 | #[cfg(feature = "gpiote")] | ||
| 345 | impl<'d, T: Pin> embassy::traits::gpio::WaitForLow for FlexPin<'d, T> { | ||
| 346 | #[rustfmt::skip] | ||
| 347 | type Future<'a> where Self: 'a = impl Future<Output=()> + Unpin + 'a; | ||
| 348 | |||
| 349 | fn wait_for_low<'a>(&'a mut self) -> Self::Future<'a> { | ||
| 350 | self.pin.conf().modify(|_, w| w.sense().low()); | ||
| 351 | |||
| 352 | crate::gpiote::PortInputFuture { | ||
| 353 | pin_port: self.pin.pin_port(), | ||
| 354 | phantom: PhantomData, | ||
| 355 | } | ||
| 356 | } | ||
| 357 | } | ||
| 358 | |||
| 359 | #[cfg(feature = "gpiote")] | ||
| 360 | impl<'d, T: Pin> embassy::traits::gpio::WaitForAnyEdge for FlexPin<'d, T> { | ||
| 361 | #[rustfmt::skip] | ||
| 362 | type Future<'a> where Self: 'a = impl Future<Output=()> + Unpin + 'a; | ||
| 363 | |||
| 364 | fn wait_for_any_edge<'a>(&'a mut self) -> Self::Future<'a> { | ||
| 365 | if self.is_high().ok().unwrap() { | ||
| 366 | self.pin.conf().modify(|_, w| w.sense().low()); | ||
| 367 | } else { | ||
| 368 | self.pin.conf().modify(|_, w| w.sense().high()); | ||
| 369 | } | ||
| 370 | crate::gpiote::PortInputFuture { | ||
| 371 | pin_port: self.pin.pin_port(), | ||
| 372 | phantom: PhantomData, | ||
| 373 | } | ||
| 374 | } | ||
| 375 | } | ||
| 376 | |||
| 280 | pub(crate) mod sealed { | 377 | pub(crate) mod sealed { |
| 281 | use super::*; | 378 | use super::*; |
| 282 | 379 | ||
