Skip to content

Commit

Permalink
Also implement delay_us and delay_ms.
Browse files Browse the repository at this point in the history
  • Loading branch information
reitermarkus committed Jan 24, 2024
1 parent 4cab71b commit b80b2f8
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/delay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,27 @@ impl DelayNs for Delay {
fn delay_ns(&mut self, n: u32) {
thread::sleep(Duration::from_nanos(n.into()));
}

fn delay_us(&mut self, n: u32) {
thread::sleep(Duration::from_micros(n.into()));
}

fn delay_ms(&mut self, n: u32) {
thread::sleep(Duration::from_millis(n.into()));
}
}

#[cfg(feature = "async-tokio")]
impl embedded_hal_async::delay::DelayNs for Delay {
async fn delay_ns(&mut self, n: u32) {
tokio::time::sleep(Duration::from_nanos(n.into())).await;
}

async fn delay_us(&mut self, n: u32) {
tokio::time::sleep(Duration::from_micros(n.into())).await;
}

async fn delay_ms(&mut self, n: u32) {
tokio::time::sleep(Duration::from_millis(n.into())).await;
}
}

0 comments on commit b80b2f8

Please sign in to comment.