1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use core::future::Future;
use core::pin::Pin;

/// Wait for a pin to become high.
pub trait WaitForHigh {
    type Future<'a>: Future<Output = ()> + 'a;

    /// Wait for a pin to become high.
    ///
    /// If the pin is already high, the future completes immediately.
    /// Otherwise, it completes when it becomes high.
    fn wait_for_high<'a>(&'a mut self) -> Self::Future<'a>;
}

/// Wait for a pin to become low.
pub trait WaitForLow {
    type Future<'a>: Future<Output = ()> + 'a;

    /// Wait for a pin to become low.
    ///
    /// If the pin is already low, the future completes immediately.
    /// Otherwise, it completes when it becomes low.
    fn wait_for_low<'a>(&'a mut self) -> Self::Future<'a>;
}

/// Wait for a rising edge (transition from low to high)
pub trait WaitForRisingEdge {
    type Future<'a>: Future<Output = ()> + 'a;

    /// Wait for a rising edge (transition from low to high)
    fn wait_for_rising_edge<'a>(&'a mut self) -> Self::Future<'a>;
}

/// Wait for a falling edge (transition from high to low)
pub trait WaitForFallingEdge {
    type Future<'a>: Future<Output = ()> + 'a;

    /// Wait for a falling edge (transition from high to low)
    fn wait_for_falling_edge<'a>(&'a mut self) -> Self::Future<'a>;
}

/// Wait for any edge (any transition, high to low or low to high)
pub trait WaitForAnyEdge {
    type Future<'a>: Future<Output = ()> + 'a;

    /// Wait for any edge (any transition, high to low or low to high)
    fn wait_for_any_edge<'a>(&'a mut self) -> Self::Future<'a>;
}