linux_embedded_hal/
delay.rs1use embedded_hal::delay::DelayNs;
6use std::thread;
7use std::time::Duration;
8
9pub struct Delay;
12
13impl DelayNs for Delay {
14 fn delay_ns(&mut self, n: u32) {
15 thread::sleep(Duration::from_nanos(n.into()));
16 }
17
18 fn delay_us(&mut self, n: u32) {
19 thread::sleep(Duration::from_micros(n.into()));
20 }
21
22 fn delay_ms(&mut self, n: u32) {
23 thread::sleep(Duration::from_millis(n.into()));
24 }
25}
26
27#[cfg(feature = "async-tokio")]
28impl embedded_hal_async::delay::DelayNs for Delay {
29 async fn delay_ns(&mut self, n: u32) {
30 tokio::time::sleep(Duration::from_nanos(n.into())).await;
31 }
32
33 async fn delay_us(&mut self, n: u32) {
34 tokio::time::sleep(Duration::from_micros(n.into())).await;
35 }
36
37 async fn delay_ms(&mut self, n: u32) {
38 tokio::time::sleep(Duration::from_millis(n.into())).await;
39 }
40}