diff options
| author | Ulf Lilleengen <[email protected]> | 2022-01-26 22:39:06 +0100 |
|---|---|---|
| committer | Ulf Lilleengen <[email protected]> | 2022-01-26 22:39:06 +0100 |
| commit | 4032fc06556312eab27488f05efe1803ade47b45 (patch) | |
| tree | 0b38343758741e5c4074e86da30867595501f9b6 /embassy-stm32/src/exti.rs | |
| parent | cd36e3f7332d08865e670ca5b515d1c6efa1bf85 (diff) | |
Support unstable-trait feature for stm32
Diffstat (limited to 'embassy-stm32/src/exti.rs')
| -rw-r--r-- | embassy-stm32/src/exti.rs | 119 |
1 files changed, 66 insertions, 53 deletions
diff --git a/embassy-stm32/src/exti.rs b/embassy-stm32/src/exti.rs index af401796c..7d974c2dc 100644 --- a/embassy-stm32/src/exti.rs +++ b/embassy-stm32/src/exti.rs | |||
| @@ -1,15 +1,10 @@ | |||
| 1 | use core::convert::Infallible; | ||
| 2 | use core::future::Future; | 1 | use core::future::Future; |
| 3 | use core::marker::PhantomData; | 2 | use core::marker::PhantomData; |
| 4 | use core::pin::Pin; | 3 | use core::pin::Pin; |
| 5 | use core::task::{Context, Poll}; | 4 | use core::task::{Context, Poll}; |
| 6 | use embassy::traits::gpio::{ | ||
| 7 | WaitForAnyEdge, WaitForFallingEdge, WaitForHigh, WaitForLow, WaitForRisingEdge, | ||
| 8 | }; | ||
| 9 | use embassy::util::Unborrow; | 5 | use embassy::util::Unborrow; |
| 10 | use embassy::waitqueue::AtomicWaker; | 6 | use embassy::waitqueue::AtomicWaker; |
| 11 | use embassy_hal_common::unsafe_impl_unborrow; | 7 | use embassy_hal_common::unsafe_impl_unborrow; |
| 12 | use embedded_hal::digital::v2::InputPin; | ||
| 13 | 8 | ||
| 14 | use crate::gpio::{AnyPin, Input, Pin as GpioPin}; | 9 | use crate::gpio::{AnyPin, Input, Pin as GpioPin}; |
| 15 | use crate::interrupt; | 10 | use crate::interrupt; |
| @@ -134,70 +129,88 @@ impl<'d, T: GpioPin> ExtiInput<'d, T> { | |||
| 134 | } | 129 | } |
| 135 | } | 130 | } |
| 136 | 131 | ||
| 137 | impl<'d, T: GpioPin> InputPin for ExtiInput<'d, T> { | 132 | mod eh02 { |
| 138 | type Error = Infallible; | 133 | use super::*; |
| 134 | use core::convert::Infallible; | ||
| 139 | 135 | ||
| 140 | fn is_high(&self) -> Result<bool, Self::Error> { | 136 | impl<'d, T: GpioPin> embedded_hal_02::digital::v2::InputPin for ExtiInput<'d, T> { |
| 141 | Ok(self.is_high()) | 137 | type Error = Infallible; |
| 142 | } | 138 | |
| 139 | fn is_high(&self) -> Result<bool, Self::Error> { | ||
| 140 | Ok(self.is_high()) | ||
| 141 | } | ||
| 143 | 142 | ||
| 144 | fn is_low(&self) -> Result<bool, Self::Error> { | 143 | fn is_low(&self) -> Result<bool, Self::Error> { |
| 145 | Ok(self.is_low()) | 144 | Ok(self.is_low()) |
| 145 | } | ||
| 146 | } | 146 | } |
| 147 | } | 147 | } |
| 148 | 148 | ||
| 149 | impl<'d, T: GpioPin> WaitForHigh for ExtiInput<'d, T> { | 149 | #[cfg(feature = "unstable-traits")] |
| 150 | type Future<'a> | 150 | mod eh1 { |
| 151 | where | 151 | use super::*; |
| 152 | Self: 'a, | 152 | use core::convert::Infallible; |
| 153 | = impl Future<Output = ()> + 'a; | 153 | use futures::FutureExt; |
| 154 | 154 | ||
| 155 | fn wait_for_high<'a>(&'a mut self) -> Self::Future<'a> { | 155 | impl<'d, T: GpioPin> embedded_hal_1::digital::ErrorType for ExtiInput<'d, T> { |
| 156 | self.wait_for_high() | 156 | type Error = Infallible; |
| 157 | } | 157 | } |
| 158 | } | ||
| 159 | 158 | ||
| 160 | impl<'d, T: GpioPin> WaitForLow for ExtiInput<'d, T> { | 159 | impl<'d, T: GpioPin> embedded_hal_1::digital::blocking::InputPin for ExtiInput<'d, T> { |
| 161 | type Future<'a> | 160 | fn is_high(&self) -> Result<bool, Self::Error> { |
| 162 | where | 161 | Ok(self.is_high()) |
| 163 | Self: 'a, | 162 | } |
| 164 | = impl Future<Output = ()> + 'a; | ||
| 165 | 163 | ||
| 166 | fn wait_for_low<'a>(&'a mut self) -> Self::Future<'a> { | 164 | fn is_low(&self) -> Result<bool, Self::Error> { |
| 167 | self.wait_for_low() | 165 | Ok(self.is_low()) |
| 166 | } | ||
| 168 | } | 167 | } |
| 169 | } | ||
| 170 | 168 | ||
| 171 | impl<'d, T: GpioPin> WaitForRisingEdge for ExtiInput<'d, T> { | 169 | impl<'d, T: GpioPin> embedded_hal_async::digital::Wait for ExtiInput<'d, T> { |
| 172 | type Future<'a> | 170 | type WaitForHighFuture<'a> |
| 173 | where | 171 | where |
| 174 | Self: 'a, | 172 | Self: 'a, |
| 175 | = impl Future<Output = ()> + 'a; | 173 | = impl Future<Output = Result<(), Self::Error>> + 'a; |
| 176 | 174 | ||
| 177 | fn wait_for_rising_edge<'a>(&'a mut self) -> Self::Future<'a> { | 175 | fn wait_for_high<'a>(&'a mut self) -> Self::WaitForHighFuture<'a> { |
| 178 | self.wait_for_rising_edge() | 176 | self.wait_for_high().map(Ok) |
| 179 | } | 177 | } |
| 180 | } | ||
| 181 | 178 | ||
| 182 | impl<'d, T: GpioPin> WaitForFallingEdge for ExtiInput<'d, T> { | 179 | type WaitForLowFuture<'a> |
| 183 | type Future<'a> | 180 | where |
| 184 | where | 181 | Self: 'a, |
| 185 | Self: 'a, | 182 | = impl Future<Output = Result<(), Self::Error>> + 'a; |
| 186 | = impl Future<Output = ()> + 'a; | ||
| 187 | 183 | ||
| 188 | fn wait_for_falling_edge<'a>(&'a mut self) -> Self::Future<'a> { | 184 | fn wait_for_low<'a>(&'a mut self) -> Self::WaitForLowFuture<'a> { |
| 189 | self.wait_for_falling_edge() | 185 | self.wait_for_low().map(Ok) |
| 190 | } | 186 | } |
| 191 | } | 187 | |
| 188 | type WaitForRisingEdgeFuture<'a> | ||
| 189 | where | ||
| 190 | Self: 'a, | ||
| 191 | = impl Future<Output = Result<(), Self::Error>> + 'a; | ||
| 192 | |||
| 193 | fn wait_for_rising_edge<'a>(&'a mut self) -> Self::WaitForRisingEdgeFuture<'a> { | ||
| 194 | self.wait_for_rising_edge().map(Ok) | ||
| 195 | } | ||
| 196 | |||
| 197 | type WaitForFallingEdgeFuture<'a> | ||
| 198 | where | ||
| 199 | Self: 'a, | ||
| 200 | = impl Future<Output = Result<(), Self::Error>> + 'a; | ||
| 192 | 201 | ||
| 193 | impl<'d, T: GpioPin> WaitForAnyEdge for ExtiInput<'d, T> { | 202 | fn wait_for_falling_edge<'a>(&'a mut self) -> Self::WaitForFallingEdgeFuture<'a> { |
| 194 | type Future<'a> | 203 | self.wait_for_falling_edge().map(Ok) |
| 195 | where | 204 | } |
| 196 | Self: 'a, | ||
| 197 | = impl Future<Output = ()> + 'a; | ||
| 198 | 205 | ||
| 199 | fn wait_for_any_edge<'a>(&'a mut self) -> Self::Future<'a> { | 206 | type WaitForAnyEdgeFuture<'a> |
| 200 | self.wait_for_any_edge() | 207 | where |
| 208 | Self: 'a, | ||
| 209 | = impl Future<Output = Result<(), Self::Error>> + 'a; | ||
| 210 | |||
| 211 | fn wait_for_any_edge<'a>(&'a mut self) -> Self::WaitForAnyEdgeFuture<'a> { | ||
| 212 | self.wait_for_any_edge().map(Ok) | ||
| 213 | } | ||
| 201 | } | 214 | } |
| 202 | } | 215 | } |
| 203 | 216 | ||
