1use embassy_time::{Duration, Timer};
2use embedded_hal::digital::{Error, ErrorKind, ErrorType};
3use embedded_hal_async::digital::Wait;
4
5pub struct TimeOutWait {
8 pub timeout: Duration,
9}
10
11#[derive(Debug)]
13pub struct TimeoutWaitError;
14
15impl Error for TimeoutWaitError {
17 fn kind(&self) -> ErrorKind {
18 ErrorKind::Other
19 }
20}
21
22impl ErrorType for TimeOutWait { type Error = TimeoutWaitError; }
24
25impl Default for TimeOutWait {
27 #[inline]
28 fn default() -> Self {
29 Self::new(Duration::from_millis(100))
30 }
31}
32
33impl TimeOutWait {
35 #[inline]
37 pub fn new(timeout: Duration) -> Self {
38 Self { timeout }
39 }
40}
41
42impl Wait for TimeOutWait {
44 async fn wait_for_high(&mut self) -> Result<(), Self::Error> {
45 Timer::after(self.timeout).await;
46 Ok(())
47 }
48
49 async fn wait_for_low(&mut self) -> Result<(), Self::Error> {
50 Timer::after(self.timeout).await;
51 Ok(())
52 }
53
54 async fn wait_for_rising_edge(&mut self) -> Result<(), Self::Error> {
55 Timer::after(self.timeout).await;
56 Ok(())
57 }
58
59 async fn wait_for_falling_edge(&mut self) -> Result<(), Self::Error> {
60 Timer::after(self.timeout).await;
61 Ok(())
62 }
63
64 async fn wait_for_any_edge(&mut self) -> Result<(), Self::Error> {
65 Timer::after(self.timeout).await;
66 Ok(())
67 }
68}