Skip to content

Commit 7b911a6

Browse files
committed
async: add Delay
1 parent f422a07 commit 7b911a6

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

embedded-hal-async/src/delay.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//! Delays
2+
3+
use core::future::Future;
4+
5+
/// Microsecond delay
6+
pub trait DelayUs {
7+
/// Enumeration of errors
8+
type Error: core::fmt::Debug;
9+
10+
/// The future returned by the `delay_us` function.
11+
type DelayUsFuture<'a>: Future<Output = Result<(), Self::Error>> + 'a
12+
where
13+
Self: 'a;
14+
15+
/// Pauses execution for at minimum `us` microseconds. Pause can be longer
16+
/// if the implementation requires it due to precision/timing issues.
17+
fn delay_us(&mut self, us: u32) -> Self::DelayUsFuture<'_>;
18+
19+
/// The future returned by the `delay_ms` function.
20+
type DelayMsFuture<'a>: Future<Output = Result<(), Self::Error>> + 'a
21+
where
22+
Self: 'a;
23+
24+
/// Pauses execution for at minimum `ms` milliseconds. Pause can be longer
25+
/// if the implementation requires it due to precision/timing issues.
26+
fn delay_ms(&mut self, ms: u32) -> Self::DelayMsFuture<'_>;
27+
}
28+
29+
impl<T> DelayUs for &mut T
30+
where
31+
T: DelayUs,
32+
{
33+
type Error = T::Error;
34+
35+
type DelayUsFuture<'a>
36+
where
37+
Self: 'a,
38+
= T::DelayUsFuture<'a>;
39+
40+
fn delay_us(&mut self, us: u32) -> Self::DelayUsFuture<'_> {
41+
T::delay_us(self, us)
42+
}
43+
44+
type DelayMsFuture<'a>
45+
where
46+
Self: 'a,
47+
= T::DelayMsFuture<'a>;
48+
49+
fn delay_ms(&mut self, ms: u32) -> Self::DelayMsFuture<'_> {
50+
T::delay_ms(self, ms)
51+
}
52+
}

embedded-hal-async/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@
1010
#![deny(missing_docs)]
1111
#![no_std]
1212
#![feature(generic_associated_types)]
13+
14+
pub mod delay;

0 commit comments

Comments
 (0)