File tree Expand file tree Collapse file tree 2 files changed +35
-6
lines changed Expand file tree Collapse file tree 2 files changed +35
-6
lines changed Original file line number Diff line number Diff line change 5
5
//! The `Delay` trait provides an asynchronous delay abstraction and it's meant to be used either
6
6
//! to build higher-level abstractions like I/O timeouts or by itself.
7
7
8
- use core:: future:: Future ;
8
+ use core:: { future:: Future , time :: Duration } ;
9
9
10
10
/// Asynchronously wait a duration of time.
11
11
pub trait Delay {
@@ -17,11 +17,8 @@ pub trait Delay {
17
17
where
18
18
Self : ' a ;
19
19
20
- /// The unit of time used by this delay timer.
21
- type Time ;
22
-
23
20
/// Returns a future that will resolve when `duration` has passed.
24
21
/// It is not guaranteed that _exactly_ `duration` will pass, but it will
25
22
/// be `duration` or longer.
26
- fn delay < ' a > ( & mut self , duration : impl Into < Self :: Time > ) -> Self :: DelayFuture < ' a > ;
23
+ fn delay < ' a > ( & mut self , duration : Duration ) -> Self :: DelayFuture < ' a > ;
27
24
}
Original file line number Diff line number Diff line change 2
2
3
3
use core:: future:: Future ;
4
4
5
+ use crate :: blocking:: digital:: InputPin ;
6
+
5
7
/// Asynchronously wait for a pin to become high or low.
6
- pub trait AsyncInputPin {
8
+ ///
9
+ /// # Examples
10
+ /// ```rust
11
+ /// # use embedded_hal::futures::digital::AsyncInputPin;
12
+ /// /// Asynchronously wait until the `ready_pin` becomes high.
13
+ /// async fn wait_until_ready<P>(ready_pin: &P)
14
+ /// where
15
+ /// P: AsyncInputPin,
16
+ /// {
17
+ /// ready_pin.until_high().await
18
+ /// }
19
+ /// ```
20
+ ///
21
+ /// ```rust,ignore
22
+ /// # use embedded_hal::futures::digital::AsyncInputPin;
23
+ /// # use embedded_hal::futures::delay::Delay;
24
+ /// # use core::time::Duration;
25
+ /// /// Wait until the `ready_pin` is high or timeout after 1 millisecond.
26
+ /// /// Returns true is the pin became high or false if it timed-out.
27
+ /// async fn wait_until_ready_or_timeout<P, D>(ready_pin: &P, delay: &mut D) -> bool
28
+ /// where
29
+ /// P: AsyncInputPin,
30
+ /// D: Delay,
31
+ /// {
32
+ /// futures::select_biased! {
33
+ /// _ => ready_pin.until_high() => true,
34
+ /// _ => delay.delay(Duration::from_millis(1)) => false,
35
+ /// }
36
+ /// }
37
+ /// ```
38
+ pub trait AsyncInputPin : InputPin {
7
39
/// The future returned by the `until_high` function.
8
40
type UntilHighFuture < ' a > : Future < Output =( ) > + ' a ;
9
41
You can’t perform that action at this time.
0 commit comments