diff --git a/Cargo.toml b/Cargo.toml index 4ca6a61..d60ebcb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] } diff --git a/src/utils/asyncify/timer.rs b/src/utils/asyncify/timer.rs index 2e9844f..c80a96a 100644 --- a/src/utils/asyncify/timer.rs +++ b/src/utils/asyncify/timer.rs @@ -234,4 +234,21 @@ mod async_traits_impl { AsyncTimerService::timer(self) } } + + impl embedded_hal_async::delay::DelayUs for AsyncTimer + 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(); + } + } }