embedded_platform/gpio/
set.rs

1//! Defines futures for setting the value of a GPIO pin.
2use core::future;
3use core::pin;
4use core::task;
5
6/// A future which sets the value of a GPIO pin.
7#[derive(Debug)]
8#[must_use = "futures do nothing unless you `.await` or poll them"]
9pub struct Set<'a, A>
10where
11    A: super::OutputPin + Unpin + ?Sized,
12{
13    pin: &'a mut A,
14    high: bool,
15}
16
17/// Creates a new [`Set`] for the provided GPIO pin, that, when polled, will drive it to the
18/// specified high or low value.
19pub fn set<A>(pin: &mut A, high: bool) -> Set<A>
20where
21    A: super::OutputPin + Unpin + ?Sized,
22{
23    Set { pin, high }
24}
25
26impl<A> future::Future for Set<'_, A>
27where
28    A: super::OutputPin + Unpin + ?Sized,
29{
30    type Output = Result<(), A::Error>;
31
32    fn poll(mut self: pin::Pin<&mut Self>, cx: &mut task::Context<'_>) -> task::Poll<Self::Output> {
33        let this = &mut *self;
34        pin::Pin::new(&mut *this.pin).poll_set(cx, this.high)
35    }
36}