Skip to content

Commit

Permalink
Implement e-hal DelayUs on AsyncTimer
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmarkov committed Sep 8, 2023
1 parent 84bebaa commit 8c6f9d6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@ default = ["std", "use_serde", "use_strum", "use_numenum", "log"]

std = ["alloc", "embedded-io/std", "embedded-io-async?/std", "serde/std", "strum?/std", "num_enum?/std"]
alloc = ["embedded-io/alloc", "embedded-io-async?/alloc", "serde/alloc", "defmt?/alloc"]
nightly = ["embedded-io-async"]
nightly = ["embedded-io-async", "embedded-hal-async"]
experimental = []
use_serde = ["enumset/serde", "no-std-net/serde", "heapless/serde"]
use_strum = ["strum", "strum_macros"]
use_numenum = ["num_enum"]
defmt = ["dep:defmt", "heapless/defmt", "heapless/defmt-impl", "embedded-io/defmt-03", "embedded-io-async?/defmt-03"]
defmt = ["dep:defmt", "heapless/defmt", "heapless/defmt-impl", "embedded-io/defmt-03", "embedded-io-async?/defmt-03", "embedded-hal-async?/defmt-03"]

[dependencies]
heapless = { version = "0.7" }
embedded-io = { version = "0.5", default-features = false }
embedded-io-async = { version = "0.5", default-features = false, optional = true }
embedded-hal-async = { version = "=1.0.0-rc.1", default-features = false, optional = true }
log = { version = "0.4", default-features = false, optional = true }
no-std-net = { version = "0.5", default-features = false }
serde = { version = "1", default-features = false, features = ["derive"] }
Expand Down
17 changes: 17 additions & 0 deletions src/utils/asyncify/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,21 @@ mod async_traits_impl {
AsyncTimerService::timer(self)
}
}

impl<T> embedded_hal_async::delay::DelayUs for AsyncTimer<T>
where
T: crate::timer::OnceTimer + Send + 'static,
{
async fn delay_us(&mut self, us: u32) {
AsyncTimer::after(self, Duration::from_micros(us as _))
.await
.unwrap();
}

async fn delay_ms(&mut self, ms: u32) {
AsyncTimer::after(self, Duration::from_millis(ms as _))
.await
.unwrap();
}
}
}

0 comments on commit 8c6f9d6

Please sign in to comment.