embedded_hal_async/
delay.rs
1pub trait DelayNs {
5 async fn delay_ns(&mut self, ns: u32);
8
9 async fn delay_us(&mut self, mut us: u32) {
12 while us > 4_294_967 {
13 us -= 4_294_967;
14 self.delay_ns(4_294_967_000).await;
15 }
16 self.delay_ns(us * 1_000).await;
17 }
18
19 #[inline]
22 async fn delay_ms(&mut self, mut ms: u32) {
23 while ms > 4294 {
24 ms -= 4294;
25 self.delay_ns(4_294_000_000).await;
26 }
27 self.delay_ns(ms * 1_000_000).await;
28 }
29}
30
31impl<T> DelayNs for &mut T
32where
33 T: DelayNs + ?Sized,
34{
35 #[inline]
36 async fn delay_ns(&mut self, ns: u32) {
37 T::delay_ns(self, ns).await;
38 }
39
40 #[inline]
41 async fn delay_us(&mut self, us: u32) {
42 T::delay_us(self, us).await;
43 }
44
45 #[inline]
46 async fn delay_ms(&mut self, ms: u32) {
47 T::delay_ms(self, ms).await;
48 }
49}