From 4634316749c41dd5d8cc2f316033c9098369ed2f Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Wed, 29 Nov 2023 16:37:07 +0100 Subject: [PATCH] Update embedded-(hal,io,nal). --- cyw43/Cargo.toml | 2 +- embassy-embedded-hal/Cargo.toml | 4 ++-- .../src/shared_bus/asynch/spi.rs | 20 +++++++++++++------ .../src/shared_bus/blocking/spi.rs | 20 +++++++++---------- embassy-embedded-hal/src/shared_bus/mod.rs | 6 +++--- embassy-net-adin1110/Cargo.toml | 8 ++++---- embassy-net-adin1110/src/lib.rs | 8 ++++++-- embassy-net-enc28j60/Cargo.toml | 4 ++-- embassy-net-esp-hosted/Cargo.toml | 4 ++-- embassy-net-ppp/Cargo.toml | 2 +- embassy-net-wiznet/Cargo.toml | 4 ++-- embassy-net/Cargo.toml | 4 ++-- embassy-nrf/Cargo.toml | 6 +++--- embassy-rp/Cargo.toml | 8 ++++---- embassy-stm32/Cargo.toml | 8 ++++---- embassy-sync/Cargo.toml | 2 +- embassy-time/CHANGELOG.md | 4 ++-- embassy-time/Cargo.toml | 4 ++-- embassy-time/src/delay.rs | 20 +++++++++++++------ embassy-time/src/duration.rs | 9 +++++++++ embassy-time/src/lib.rs | 1 + embassy-time/src/timer.rs | 9 +++++++++ examples/nrf52840/Cargo.toml | 8 ++++---- examples/nrf5340/Cargo.toml | 2 +- examples/rp/Cargo.toml | 8 ++++---- examples/std/Cargo.toml | 4 ++-- examples/stm32f4/Cargo.toml | 2 +- examples/stm32f7/Cargo.toml | 2 +- examples/stm32h5/Cargo.toml | 8 ++++---- examples/stm32h7/Cargo.toml | 8 ++++---- examples/stm32l0/Cargo.toml | 2 +- examples/stm32l4/Cargo.toml | 8 ++++---- examples/stm32l5/Cargo.toml | 2 +- tests/nrf/Cargo.toml | 6 +++--- tests/rp/Cargo.toml | 8 ++++---- tests/stm32/Cargo.toml | 4 ++-- 36 files changed, 134 insertions(+), 95 deletions(-) diff --git a/cyw43/Cargo.toml b/cyw43/Cargo.toml index 789e3ab0..3e37a8cd 100644 --- a/cyw43/Cargo.toml +++ b/cyw43/Cargo.toml @@ -23,7 +23,7 @@ cortex-m = "0.7.6" cortex-m-rt = "0.7.0" futures = { version = "0.3.17", default-features = false, features = ["async-await", "cfg-target-has-atomic", "unstable"] } -embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-rc.1" } +embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-rc.2" } num_enum = { version = "0.5.7", default-features = false } [package.metadata.embassy_docs] diff --git a/embassy-embedded-hal/Cargo.toml b/embassy-embedded-hal/Cargo.toml index 11e47acb..52ecd5c7 100644 --- a/embassy-embedded-hal/Cargo.toml +++ b/embassy-embedded-hal/Cargo.toml @@ -25,8 +25,8 @@ embassy-time = { version = "0.1.5", path = "../embassy-time", optional = true } embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = [ "unproven", ] } -embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.1" } -embedded-hal-async = { version = "=1.0.0-rc.1", optional = true } +embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2" } +embedded-hal-async = { version = "=1.0.0-rc.2", optional = true } embedded-storage = "0.3.0" embedded-storage-async = { version = "0.4.0", optional = true } nb = "1.0.0" diff --git a/embassy-embedded-hal/src/shared_bus/asynch/spi.rs b/embassy-embedded-hal/src/shared_bus/asynch/spi.rs index 17d5f367..b4f53c62 100644 --- a/embassy-embedded-hal/src/shared_bus/asynch/spi.rs +++ b/embassy-embedded-hal/src/shared_bus/asynch/spi.rs @@ -63,6 +63,10 @@ where CS: OutputPin, { async fn transaction(&mut self, operations: &mut [spi::Operation<'_, u8>]) -> Result<(), Self::Error> { + if cfg!(not(feature = "time")) && operations.iter().any(|op| matches!(op, Operation::DelayNs(_))) { + return Err(SpiDeviceError::DelayNotSupported); + } + let mut bus = self.bus.lock().await; self.cs.set_low().map_err(SpiDeviceError::Cs)?; @@ -74,12 +78,12 @@ where Operation::Transfer(read, write) => bus.transfer(read, write).await, Operation::TransferInPlace(buf) => bus.transfer_in_place(buf).await, #[cfg(not(feature = "time"))] - Operation::DelayUs(us) => return Err(SpiDeviceError::DelayUsNotSupported), + Operation::DelayNs(_) => unreachable!(), #[cfg(feature = "time")] - Operation::DelayUs(us) => match bus.flush().await { + Operation::DelayNs(ns) => match bus.flush().await { Err(e) => Err(e), Ok(()) => { - embassy_time::Timer::after_micros(*us as _).await; + embassy_time::Timer::after_nanos(*ns as _).await; Ok(()) } }, @@ -137,6 +141,10 @@ where CS: OutputPin, { async fn transaction(&mut self, operations: &mut [spi::Operation<'_, u8>]) -> Result<(), Self::Error> { + if cfg!(not(feature = "time")) && operations.iter().any(|op| matches!(op, Operation::DelayNs(_))) { + return Err(SpiDeviceError::DelayNotSupported); + } + let mut bus = self.bus.lock().await; bus.set_config(&self.config).map_err(|_| SpiDeviceError::Config)?; self.cs.set_low().map_err(SpiDeviceError::Cs)?; @@ -149,12 +157,12 @@ where Operation::Transfer(read, write) => bus.transfer(read, write).await, Operation::TransferInPlace(buf) => bus.transfer_in_place(buf).await, #[cfg(not(feature = "time"))] - Operation::DelayUs(us) => return Err(SpiDeviceError::DelayUsNotSupported), + Operation::DelayNs(_) => unreachable!(), #[cfg(feature = "time")] - Operation::DelayUs(us) => match bus.flush().await { + Operation::DelayNs(ns) => match bus.flush().await { Err(e) => Err(e), Ok(()) => { - embassy_time::Timer::after_micros(*us as _).await; + embassy_time::Timer::after_nanos(*ns as _).await; Ok(()) } }, diff --git a/embassy-embedded-hal/src/shared_bus/blocking/spi.rs b/embassy-embedded-hal/src/shared_bus/blocking/spi.rs index 2b67862e..59b65bfb 100644 --- a/embassy-embedded-hal/src/shared_bus/blocking/spi.rs +++ b/embassy-embedded-hal/src/shared_bus/blocking/spi.rs @@ -55,8 +55,8 @@ where CS: OutputPin, { fn transaction(&mut self, operations: &mut [Operation<'_, u8>]) -> Result<(), Self::Error> { - if cfg!(not(feature = "time")) && operations.iter().any(|op| matches!(op, Operation::DelayUs(_))) { - return Err(SpiDeviceError::DelayUsNotSupported); + if cfg!(not(feature = "time")) && operations.iter().any(|op| matches!(op, Operation::DelayNs(_))) { + return Err(SpiDeviceError::DelayNotSupported); } self.bus.lock(|bus| { @@ -69,10 +69,10 @@ where Operation::Transfer(read, write) => bus.transfer(read, write), Operation::TransferInPlace(buf) => bus.transfer_in_place(buf), #[cfg(not(feature = "time"))] - Operation::DelayUs(_) => unreachable!(), + Operation::DelayNs(_) => unreachable!(), #[cfg(feature = "time")] - Operation::DelayUs(us) => { - embassy_time::block_for(embassy_time::Duration::from_micros(*us as _)); + Operation::DelayNs(ns) => { + embassy_time::block_for(embassy_time::Duration::from_nanos(*ns as _)); Ok(()) } }); @@ -165,8 +165,8 @@ where CS: OutputPin, { fn transaction(&mut self, operations: &mut [Operation<'_, u8>]) -> Result<(), Self::Error> { - if cfg!(not(feature = "time")) && operations.iter().any(|op| matches!(op, Operation::DelayUs(_))) { - return Err(SpiDeviceError::DelayUsNotSupported); + if cfg!(not(feature = "time")) && operations.iter().any(|op| matches!(op, Operation::DelayNs(_))) { + return Err(SpiDeviceError::DelayNotSupported); } self.bus.lock(|bus| { @@ -180,10 +180,10 @@ where Operation::Transfer(read, write) => bus.transfer(read, write), Operation::TransferInPlace(buf) => bus.transfer_in_place(buf), #[cfg(not(feature = "time"))] - Operation::DelayUs(_) => unreachable!(), + Operation::DelayNs(_) => unreachable!(), #[cfg(feature = "time")] - Operation::DelayUs(us) => { - embassy_time::block_for(embassy_time::Duration::from_micros(*us as _)); + Operation::DelayNs(ns) => { + embassy_time::block_for(embassy_time::Duration::from_nanos(*ns as _)); Ok(()) } }); diff --git a/embassy-embedded-hal/src/shared_bus/mod.rs b/embassy-embedded-hal/src/shared_bus/mod.rs index b0159ac0..ab96df13 100644 --- a/embassy-embedded-hal/src/shared_bus/mod.rs +++ b/embassy-embedded-hal/src/shared_bus/mod.rs @@ -39,8 +39,8 @@ pub enum SpiDeviceError { Spi(BUS), /// Setting the value of the Chip Select (CS) pin failed. Cs(CS), - /// DelayUs operations are not supported when the `time` Cargo feature is not enabled. - DelayUsNotSupported, + /// Delay operations are not supported when the `time` Cargo feature is not enabled. + DelayNotSupported, /// The SPI bus could not be configured. Config, } @@ -54,7 +54,7 @@ where match self { Self::Spi(e) => e.kind(), Self::Cs(_) => spi::ErrorKind::Other, - Self::DelayUsNotSupported => spi::ErrorKind::Other, + Self::DelayNotSupported => spi::ErrorKind::Other, Self::Config => spi::ErrorKind::Other, } } diff --git a/embassy-net-adin1110/Cargo.toml b/embassy-net-adin1110/Cargo.toml index 3f016160..3dbbee44 100644 --- a/embassy-net-adin1110/Cargo.toml +++ b/embassy-net-adin1110/Cargo.toml @@ -13,16 +13,16 @@ edition = "2021" heapless = "0.8" defmt = { version = "0.3", optional = true } log = { version = "0.4", default-features = false, optional = true } -embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.1" } -embedded-hal-async = { version = "=1.0.0-rc.1" } -embedded-hal-bus = { version = "=0.1.0-rc.1", features = ["async"] } +embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2" } +embedded-hal-async = { version = "=1.0.0-rc.2" } +embedded-hal-bus = { version = "=0.1.0-rc.2", features = ["async"] } embassy-net-driver-channel = { version = "0.2.0", path = "../embassy-net-driver-channel" } embassy-time = { version = "0.1.5", path = "../embassy-time" } embassy-futures = { version = "0.1.0", path = "../embassy-futures" } bitfield = "0.14.0" [dev-dependencies] -embedded-hal-mock = { version = "=0.10.0-rc.1", features = ["embedded-hal-async", "eh1"] } +embedded-hal-mock = { git = "https://github.com/Dirbaio/embedded-hal-mock", rev = "c5c4dca18e043e6386aee02173f61a65fea3981e", features = ["embedded-hal-async", "eh1"] } crc = "3.0.1" env_logger = "0.10" critical-section = { version = "1.1.2", features = ["std"] } diff --git a/embassy-net-adin1110/src/lib.rs b/embassy-net-adin1110/src/lib.rs index 331c596d..e4a3cb20 100644 --- a/embassy-net-adin1110/src/lib.rs +++ b/embassy-net-adin1110/src/lib.rs @@ -729,7 +729,7 @@ mod tests { use core::convert::Infallible; use embedded_hal_1::digital::{ErrorType, OutputPin}; - use embedded_hal_async::delay::DelayUs; + use embedded_hal_async::delay::DelayNs; use embedded_hal_bus::spi::ExclusiveDevice; use embedded_hal_mock::common::Generic; use embedded_hal_mock::eh1::spi::{Mock as SpiMock, Transaction as SpiTransaction}; @@ -760,7 +760,11 @@ mod tests { // see https://github.com/rust-embedded/embedded-hal/pull/462#issuecomment-1560014426 struct MockDelay {} - impl DelayUs for MockDelay { + impl DelayNs for MockDelay { + async fn delay_ns(&mut self, _ns: u32) { + todo!() + } + async fn delay_us(&mut self, _us: u32) { todo!() } diff --git a/embassy-net-enc28j60/Cargo.toml b/embassy-net-enc28j60/Cargo.toml index ea2ed1f7..eda699d9 100644 --- a/embassy-net-enc28j60/Cargo.toml +++ b/embassy-net-enc28j60/Cargo.toml @@ -8,8 +8,8 @@ license = "MIT OR Apache-2.0" edition = "2021" [dependencies] -embedded-hal = { version = "1.0.0-rc.1" } -embedded-hal-async = { version = "=1.0.0-rc.1" } +embedded-hal = { version = "1.0.0-rc.2" } +embedded-hal-async = { version = "=1.0.0-rc.2" } embassy-net-driver = { version = "0.2.0", path = "../embassy-net-driver" } embassy-time = { version = "0.1.5", path = "../embassy-time" } embassy-futures = { version = "0.1.0", path = "../embassy-futures" } diff --git a/embassy-net-esp-hosted/Cargo.toml b/embassy-net-esp-hosted/Cargo.toml index e86be445..6b325c80 100644 --- a/embassy-net-esp-hosted/Cargo.toml +++ b/embassy-net-esp-hosted/Cargo.toml @@ -12,8 +12,8 @@ embassy-sync = { version = "0.4.0", path = "../embassy-sync"} embassy-futures = { version = "0.1.0", path = "../embassy-futures"} embassy-net-driver-channel = { version = "0.2.0", path = "../embassy-net-driver-channel"} -embedded-hal = { version = "1.0.0-rc.1" } -embedded-hal-async = { version = "=1.0.0-rc.1" } +embedded-hal = { version = "1.0.0-rc.2" } +embedded-hal-async = { version = "=1.0.0-rc.2" } noproto = { git="https://github.com/embassy-rs/noproto", rev = "f5e6d1f325b6ad4e344f60452b09576e24671f62", default-features = false, features = ["derive"] } #noproto = { version = "0.1", path = "/home/dirbaio/noproto", default-features = false, features = ["derive"] } diff --git a/embassy-net-ppp/Cargo.toml b/embassy-net-ppp/Cargo.toml index 273dccbc..7119ebd5 100644 --- a/embassy-net-ppp/Cargo.toml +++ b/embassy-net-ppp/Cargo.toml @@ -15,7 +15,7 @@ log = ["dep:log", "ppproto/log"] defmt = { version = "0.3", optional = true } log = { version = "0.4.14", optional = true } -embedded-io-async = { version = "0.6.0" } +embedded-io-async = { version = "0.6.1" } embassy-net-driver-channel = { version = "0.2.0", path = "../embassy-net-driver-channel" } embassy-futures = { version = "0.1.0", path = "../embassy-futures" } ppproto = { version = "0.1.2"} diff --git a/embassy-net-wiznet/Cargo.toml b/embassy-net-wiznet/Cargo.toml index 0cc086b7..187f3e29 100644 --- a/embassy-net-wiznet/Cargo.toml +++ b/embassy-net-wiznet/Cargo.toml @@ -8,8 +8,8 @@ license = "MIT OR Apache-2.0" edition = "2021" [dependencies] -embedded-hal = { version = "1.0.0-rc.1" } -embedded-hal-async = { version = "=1.0.0-rc.1" } +embedded-hal = { version = "1.0.0-rc.2" } +embedded-hal-async = { version = "=1.0.0-rc.2" } embassy-net-driver-channel = { version = "0.2.0", path = "../embassy-net-driver-channel" } embassy-time = { version = "0.1.5", path = "../embassy-time" } embassy-futures = { version = "0.1.0", path = "../embassy-futures" } diff --git a/embassy-net/Cargo.toml b/embassy-net/Cargo.toml index ef66078c..fe8344f5 100644 --- a/embassy-net/Cargo.toml +++ b/embassy-net/Cargo.toml @@ -54,7 +54,7 @@ smoltcp = { git = "https://github.com/smoltcp-rs/smoltcp.git", rev = "b57e2f9e70 embassy-net-driver = { version = "0.2.0", path = "../embassy-net-driver" } embassy-time = { version = "0.1.5", path = "../embassy-time" } embassy-sync = { version = "0.4.0", path = "../embassy-sync" } -embedded-io-async = { version = "0.6.0", optional = true } +embedded-io-async = { version = "0.6.1", optional = true } managed = { version = "0.8.0", default-features = false, features = [ "map" ] } heapless = { version = "0.8", default-features = false } @@ -63,4 +63,4 @@ generic-array = { version = "0.14.4", default-features = false } stable_deref_trait = { version = "1.2.0", default-features = false } futures = { version = "0.3.17", default-features = false, features = [ "async-await" ] } atomic-pool = "1.0" -embedded-nal-async = { version = "0.7", optional = true } +embedded-nal-async = { version = "0.7.1", optional = true } diff --git a/embassy-nrf/Cargo.toml b/embassy-nrf/Cargo.toml index 60e03d85..a75a94f0 100644 --- a/embassy-nrf/Cargo.toml +++ b/embassy-nrf/Cargo.toml @@ -101,10 +101,10 @@ embassy-embedded-hal = {version = "0.1.0", path = "../embassy-embedded-hal" } embassy-usb-driver = {version = "0.1.0", path = "../embassy-usb-driver", optional=true } embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["unproven"] } -embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.1", optional = true} -embedded-hal-async = { version = "=1.0.0-rc.1", optional = true} +embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2", optional = true} +embedded-hal-async = { version = "=1.0.0-rc.2", optional = true} embedded-io = { version = "0.6.0" } -embedded-io-async = { version = "0.6.0", optional = true } +embedded-io-async = { version = "0.6.1", optional = true } defmt = { version = "0.3", optional = true } log = { version = "0.4.14", optional = true } diff --git a/embassy-rp/Cargo.toml b/embassy-rp/Cargo.toml index eb79cfd3..35ea77f0 100644 --- a/embassy-rp/Cargo.toml +++ b/embassy-rp/Cargo.toml @@ -76,7 +76,7 @@ critical-section = "1.1" futures = { version = "0.3.17", default-features = false, features = ["async-await"] } chrono = { version = "0.4", default-features = false, optional = true } embedded-io = { version = "0.6.0" } -embedded-io-async = { version = "0.6.0", optional = true } +embedded-io-async = { version = "0.6.1", optional = true } embedded-storage = { version = "0.3" } embedded-storage-async = { version = "0.4.0", optional = true } rand_core = "0.6.4" @@ -85,9 +85,9 @@ fixed = "1.23.1" rp-pac = { version = "6" } embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["unproven"] } -embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.1", optional = true} -embedded-hal-async = { version = "=1.0.0-rc.1", optional = true} -embedded-hal-nb = { version = "=1.0.0-rc.1", optional = true} +embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2", optional = true} +embedded-hal-async = { version = "=1.0.0-rc.2", optional = true} +embedded-hal-nb = { version = "=1.0.0-rc.2", optional = true} pio-proc = {version= "0.2" } pio = {version= "0.2.1" } diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml index 292902ac..535357fc 100644 --- a/embassy-stm32/Cargo.toml +++ b/embassy-stm32/Cargo.toml @@ -42,9 +42,9 @@ embassy-usb-driver = {version = "0.1.0", path = "../embassy-usb-driver", optiona embassy-executor = { version = "0.3.3", path = "../embassy-executor", optional = true } embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["unproven"] } -embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.1", optional = true} -embedded-hal-async = { version = "=1.0.0-rc.1", optional = true} -embedded-hal-nb = { version = "=1.0.0-rc.1", optional = true} +embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2", optional = true} +embedded-hal-async = { version = "=1.0.0-rc.2", optional = true} +embedded-hal-nb = { version = "=1.0.0-rc.2", optional = true} embedded-storage = "0.3.0" embedded-storage-async = { version = "0.4.0", optional = true } @@ -65,7 +65,7 @@ nb = "1.0.0" stm32-fmc = "0.3.0" cfg-if = "1.0.0" embedded-io = { version = "0.6.0" } -embedded-io-async = { version = "0.6.0", optional = true } +embedded-io-async = { version = "0.6.1", optional = true } chrono = { version = "^0.4", default-features = false, optional = true} bit_field = "0.10.2" document-features = "0.2.7" diff --git a/embassy-sync/Cargo.toml b/embassy-sync/Cargo.toml index e395389a..ffcd13d9 100644 --- a/embassy-sync/Cargo.toml +++ b/embassy-sync/Cargo.toml @@ -35,7 +35,7 @@ futures-util = { version = "0.3.17", default-features = false } critical-section = "1.1" heapless = "0.8" cfg-if = "1.0.0" -embedded-io-async = { version = "0.6.0", optional = true } +embedded-io-async = { version = "0.6.1", optional = true } [dev-dependencies] futures-executor = { version = "0.3.17", features = [ "thread-pool" ] } diff --git a/embassy-time/CHANGELOG.md b/embassy-time/CHANGELOG.md index 1421d76a..9625b890 100644 --- a/embassy-time/CHANGELOG.md +++ b/embassy-time/CHANGELOG.md @@ -22,8 +22,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## 0.1.3 - 2023-08-28 -- Update `embedded-hal-async` to `1.0.0-rc.1` -- Update `embedded-hal v1` to `1.0.0-rc.1` +- Update `embedded-hal-async` to `1.0.0-rc.2` +- Update `embedded-hal v1` to `1.0.0-rc.2` ## 0.1.2 - 2023-07-05 diff --git a/embassy-time/Cargo.toml b/embassy-time/Cargo.toml index 3cabb237..570e0efa 100644 --- a/embassy-time/Cargo.toml +++ b/embassy-time/Cargo.toml @@ -242,8 +242,8 @@ defmt = { version = "0.3", optional = true } log = { version = "0.4.14", optional = true } embedded-hal-02 = { package = "embedded-hal", version = "0.2.6" } -embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.1", optional = true} -embedded-hal-async = { version = "=1.0.0-rc.1", optional = true} +embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2", optional = true} +embedded-hal-async = { version = "=1.0.0-rc.2", optional = true} futures-util = { version = "0.3.17", default-features = false } critical-section = "1.1" diff --git a/embassy-time/src/delay.rs b/embassy-time/src/delay.rs index be962747..aab56b1f 100644 --- a/embassy-time/src/delay.rs +++ b/embassy-time/src/delay.rs @@ -18,7 +18,11 @@ pub struct Delay; mod eh1 { use super::*; - impl embedded_hal_1::delay::DelayUs for Delay { + impl embedded_hal_1::delay::DelayNs for Delay { + fn delay_ns(&mut self, ns: u32) { + block_for(Duration::from_nanos(ns as u64)) + } + fn delay_us(&mut self, us: u32) { block_for(Duration::from_micros(us as u64)) } @@ -34,13 +38,17 @@ mod eha { use super::*; use crate::Timer; - impl embedded_hal_async::delay::DelayUs for Delay { - async fn delay_us(&mut self, micros: u32) { - Timer::after_micros(micros as _).await + impl embedded_hal_async::delay::DelayNs for Delay { + async fn delay_ns(&mut self, ns: u32) { + Timer::after_nanos(ns as _).await } - async fn delay_ms(&mut self, millis: u32) { - Timer::after_millis(millis as _).await + async fn delay_us(&mut self, us: u32) { + Timer::after_micros(us as _).await + } + + async fn delay_ms(&mut self, ms: u32) { + Timer::after_millis(ms as _).await } } } diff --git a/embassy-time/src/duration.rs b/embassy-time/src/duration.rs index 8366455b..647d208e 100644 --- a/embassy-time/src/duration.rs +++ b/embassy-time/src/duration.rs @@ -2,6 +2,7 @@ use core::fmt; use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign}; use super::{GCD_1K, GCD_1M, TICK_HZ}; +use crate::GCD_1G; #[derive(Debug, Default, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] @@ -61,6 +62,14 @@ impl Duration { } } + /// Creates a duration from the specified number of nanoseconds, rounding up. + /// NOTE: Delays this small may be inaccurate. + pub const fn from_nanos(micros: u64) -> Duration { + Duration { + ticks: div_ceil(micros * (TICK_HZ / GCD_1G), 1_000_000_000 / GCD_1G), + } + } + /// Creates a duration from the specified number of seconds, rounding down. pub const fn from_secs_floor(secs: u64) -> Duration { Duration { ticks: secs * TICK_HZ } diff --git a/embassy-time/src/lib.rs b/embassy-time/src/lib.rs index a90368d5..a0f6e382 100644 --- a/embassy-time/src/lib.rs +++ b/embassy-time/src/lib.rs @@ -52,6 +52,7 @@ const fn gcd(a: u64, b: u64) -> u64 { pub(crate) const GCD_1K: u64 = gcd(TICK_HZ, 1_000); pub(crate) const GCD_1M: u64 = gcd(TICK_HZ, 1_000_000); +pub(crate) const GCD_1G: u64 = gcd(TICK_HZ, 1_000_000_000); #[cfg(feature = "defmt-timestamp-uptime")] defmt::timestamp! {"{=u64:us}", Instant::now().as_micros() } diff --git a/embassy-time/src/timer.rs b/embassy-time/src/timer.rs index ee2423da..574d715d 100644 --- a/embassy-time/src/timer.rs +++ b/embassy-time/src/timer.rs @@ -74,6 +74,15 @@ impl Timer { Self::after(Duration::from_ticks(ticks)) } + /// Expire after the specified number of nanoseconds. + /// + /// This method is a convenience wrapper for calling `Timer::after(Duration::from_nanos())`. + /// For more details, refer to [`Timer::after()`] and [`Duration::from_nanos()`]. + #[inline] + pub fn after_nanos(nanos: u64) -> Self { + Self::after(Duration::from_nanos(nanos)) + } + /// Expire after the specified number of microseconds. /// /// This method is a convenience wrapper for calling `Timer::after(Duration::from_micros())`. diff --git a/examples/nrf52840/Cargo.toml b/examples/nrf52840/Cargo.toml index 88e8d58d..d9b22a4d 100644 --- a/examples/nrf52840/Cargo.toml +++ b/examples/nrf52840/Cargo.toml @@ -32,7 +32,7 @@ embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defm embassy-net = { version = "0.2.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet"], optional = true } embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"], optional = true } embedded-io = { version = "0.6.0", features = ["defmt-03"] } -embedded-io-async = { version = "0.6.0", optional = true, features = ["defmt-03"] } +embedded-io-async = { version = "0.6.1", optional = true, features = ["defmt-03"] } embassy-net-esp-hosted = { version = "0.1.0", path = "../../embassy-net-esp-hosted", features = ["defmt"], optional = true } embassy-net-enc28j60 = { version = "0.1.0", path = "../../embassy-net-enc28j60", features = ["defmt"], optional = true } @@ -49,9 +49,9 @@ rand = { version = "0.8.4", default-features = false } embedded-storage = "0.3.0" usbd-hid = "0.6.0" serde = { version = "1.0.136", default-features = false } -embedded-hal = { version = "1.0.0-rc.1" } -embedded-hal-async = { version = "1.0.0-rc.1", optional = true } -embedded-hal-bus = { version = "0.1.0-rc.1" } +embedded-hal = { version = "1.0.0-rc.2" } +embedded-hal-async = { version = "1.0.0-rc.2", optional = true } +embedded-hal-bus = { version = "0.1.0-rc.2" } num-integer = { version = "0.1.45", default-features = false } microfft = "0.5.0" diff --git a/examples/nrf5340/Cargo.toml b/examples/nrf5340/Cargo.toml index 032ec980..25ae9749 100644 --- a/examples/nrf5340/Cargo.toml +++ b/examples/nrf5340/Cargo.toml @@ -37,7 +37,7 @@ embassy-net = { version = "0.2.0", path = "../../embassy-net", features = [ embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = [ "defmt", ] } -embedded-io-async = { version = "0.6.0" } +embedded-io-async = { version = "0.6.1" } defmt = "0.3" defmt-rtt = "0.4" diff --git a/examples/rp/Cargo.toml b/examples/rp/Cargo.toml index 1012a8b5..e0e0d8a7 100644 --- a/examples/rp/Cargo.toml +++ b/examples/rp/Cargo.toml @@ -38,10 +38,10 @@ smart-leds = "0.3.0" heapless = "0.8" usbd-hid = "0.6.1" -embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.1" } -embedded-hal-async = "1.0.0-rc.1" -embedded-hal-bus = { version = "0.1.0-rc.1", features = ["async"] } -embedded-io-async = { version = "0.6.0", features = ["defmt-03"] } +embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2" } +embedded-hal-async = "1.0.0-rc.2" +embedded-hal-bus = { version = "0.1.0-rc.2", features = ["async"] } +embedded-io-async = { version = "0.6.1", features = ["defmt-03"] } embedded-storage = { version = "0.3" } static_cell = { version = "2", features = ["nightly"]} portable-atomic = { version = "1.5", features = ["critical-section"] } diff --git a/examples/std/Cargo.toml b/examples/std/Cargo.toml index 75ed74b5..2a59fd69 100644 --- a/examples/std/Cargo.toml +++ b/examples/std/Cargo.toml @@ -11,8 +11,8 @@ embassy-time = { version = "0.1.5", path = "../../embassy-time", features = ["lo embassy-net = { version = "0.2.0", path = "../../embassy-net", features=[ "std", "nightly", "log", "medium-ethernet", "medium-ip", "tcp", "udp", "dns", "dhcpv4", "proto-ipv6"] } embassy-net-tuntap = { version = "0.1.0", path = "../../embassy-net-tuntap" } embassy-net-ppp = { version = "0.1.0", path = "../../embassy-net-ppp", features = ["log"]} -embedded-io-async = { version = "0.6.0" } -embedded-io-adapters = { version = "0.6.0", features = ["futures-03"] } +embedded-io-async = { version = "0.6.1" } +embedded-io-adapters = { version = "0.6.1", features = ["futures-03"] } critical-section = { version = "1.1", features = ["std"] } async-io = "1.6.0" diff --git a/examples/stm32f4/Cargo.toml b/examples/stm32f4/Cargo.toml index 772d873c..8cee6d23 100644 --- a/examples/stm32f4/Cargo.toml +++ b/examples/stm32f4/Cargo.toml @@ -20,7 +20,7 @@ cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-sing cortex-m-rt = "0.7.0" embedded-hal = "0.2.6" embedded-io = { version = "0.6.0" } -embedded-io-async = { version = "0.6.0" } +embedded-io-async = { version = "0.6.1" } panic-probe = { version = "0.3", features = ["print-defmt"] } futures = { version = "0.3.17", default-features = false, features = ["async-await"] } heapless = { version = "0.8", default-features = false } diff --git a/examples/stm32f7/Cargo.toml b/examples/stm32f7/Cargo.toml index d418f813..8fe2f289 100644 --- a/examples/stm32f7/Cargo.toml +++ b/examples/stm32f7/Cargo.toml @@ -11,7 +11,7 @@ embassy-sync = { version = "0.4.0", path = "../../embassy-sync", features = ["de embassy-executor = { version = "0.3.3", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } embassy-time = { version = "0.1.5", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } embassy-net = { version = "0.2.0", path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet"] } -embedded-io-async = { version = "0.6.0" } +embedded-io-async = { version = "0.6.1" } embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } defmt = "0.3" diff --git a/examples/stm32h5/Cargo.toml b/examples/stm32h5/Cargo.toml index e8d17cee..db34005a 100644 --- a/examples/stm32h5/Cargo.toml +++ b/examples/stm32h5/Cargo.toml @@ -11,7 +11,7 @@ embassy-sync = { version = "0.4.0", path = "../../embassy-sync", features = ["de embassy-executor = { version = "0.3.3", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } embassy-time = { version = "0.1.5", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] } embassy-net = { version = "0.2.0", path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet", "proto-ipv6"] } -embedded-io-async = { version = "0.6.0" } +embedded-io-async = { version = "0.6.1" } embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } defmt = "0.3" @@ -20,9 +20,9 @@ defmt-rtt = "0.4" cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } cortex-m-rt = "0.7.0" embedded-hal = "0.2.6" -embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.1" } -embedded-hal-async = { version = "=1.0.0-rc.1" } -embedded-nal-async = { version = "0.7" } +embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2" } +embedded-hal-async = { version = "=1.0.0-rc.2" } +embedded-nal-async = { version = "0.7.1" } panic-probe = { version = "0.3", features = ["print-defmt"] } futures = { version = "0.3.17", default-features = false, features = ["async-await"] } heapless = { version = "0.8", default-features = false } diff --git a/examples/stm32h7/Cargo.toml b/examples/stm32h7/Cargo.toml index 05523d00..2fe88dfa 100644 --- a/examples/stm32h7/Cargo.toml +++ b/examples/stm32h7/Cargo.toml @@ -11,7 +11,7 @@ embassy-sync = { version = "0.4.0", path = "../../embassy-sync", features = ["de embassy-executor = { version = "0.3.3", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } embassy-time = { version = "0.1.5", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] } embassy-net = { version = "0.2.0", path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet", "proto-ipv6", "dns"] } -embedded-io-async = { version = "0.6.0" } +embedded-io-async = { version = "0.6.1" } embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } defmt = "0.3" @@ -20,9 +20,9 @@ defmt-rtt = "0.4" cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } cortex-m-rt = "0.7.0" embedded-hal = "0.2.6" -embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.1" } -embedded-hal-async = { version = "=1.0.0-rc.1" } -embedded-nal-async = { version = "0.7" } +embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2" } +embedded-hal-async = { version = "=1.0.0-rc.2" } +embedded-nal-async = { version = "0.7.1" } panic-probe = { version = "0.3", features = ["print-defmt"] } futures = { version = "0.3.17", default-features = false, features = ["async-await"] } heapless = { version = "0.8", default-features = false } diff --git a/examples/stm32l0/Cargo.toml b/examples/stm32l0/Cargo.toml index 2ba58c3d..15f7afe9 100644 --- a/examples/stm32l0/Cargo.toml +++ b/examples/stm32l0/Cargo.toml @@ -20,7 +20,7 @@ defmt-rtt = "0.4" embedded-storage = "0.3.0" embedded-io = { version = "0.6.0" } -embedded-io-async = { version = "0.6.0", optional = true } +embedded-io-async = { version = "0.6.1", optional = true } cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } cortex-m-rt = "0.7.0" diff --git a/examples/stm32l4/Cargo.toml b/examples/stm32l4/Cargo.toml index f4eaf647..350e6e26 100644 --- a/examples/stm32l4/Cargo.toml +++ b/examples/stm32l4/Cargo.toml @@ -15,7 +15,7 @@ embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defm embassy-net-adin1110 = { version = "0.2.0", path = "../../embassy-net-adin1110" } embassy-net = { version = "0.2.0", path = "../../embassy-net", features = ["defmt", "nightly", "udp", "tcp", "dhcpv4", "medium-ethernet"] } embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } -embedded-io-async = { version = "0.6.0", features = ["defmt-03"] } +embedded-io-async = { version = "0.6.1", features = ["defmt-03"] } embedded-io = { version = "0.6.0", features = ["defmt-03"] } defmt = "0.3" @@ -24,9 +24,9 @@ defmt-rtt = "0.4" cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } cortex-m-rt = "0.7.0" embedded-hal = "0.2.6" -embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.1" } -embedded-hal-async = { version = "=1.0.0-rc.1" } -embedded-hal-bus = { version = "=0.1.0-rc.1", features = ["async"] } +embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2" } +embedded-hal-async = { version = "=1.0.0-rc.2" } +embedded-hal-bus = { version = "=0.1.0-rc.2", features = ["async"] } panic-probe = { version = "0.3", features = ["print-defmt"] } futures = { version = "0.3.17", default-features = false, features = ["async-await"] } heapless = { version = "0.8", default-features = false } diff --git a/examples/stm32l5/Cargo.toml b/examples/stm32l5/Cargo.toml index 1b9b026f..7bca51ad 100644 --- a/examples/stm32l5/Cargo.toml +++ b/examples/stm32l5/Cargo.toml @@ -25,7 +25,7 @@ embedded-hal = "0.2.6" futures = { version = "0.3.17", default-features = false, features = ["async-await"] } heapless = { version = "0.8", default-features = false } rand_core = { version = "0.6.3", default-features = false } -embedded-io-async = { version = "0.6.0" } +embedded-io-async = { version = "0.6.1" } static_cell = { version = "2", features = ["nightly"]} [profile.release] diff --git a/tests/nrf/Cargo.toml b/tests/nrf/Cargo.toml index fd756881..70bb17c1 100644 --- a/tests/nrf/Cargo.toml +++ b/tests/nrf/Cargo.toml @@ -12,12 +12,12 @@ embassy-sync = { version = "0.4.0", path = "../../embassy-sync", features = ["de embassy-executor = { version = "0.3.3", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "task-arena-size-16384", "integrated-timers"] } embassy-time = { version = "0.1.5", path = "../../embassy-time", features = ["defmt", "nightly", "unstable-traits", "defmt-timestamp-uptime"] } embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nightly", "unstable-traits", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac"] } -embedded-io-async = { version = "0.6.0", features = ["defmt-03"] } +embedded-io-async = { version = "0.6.1", features = ["defmt-03"] } embassy-net = { version = "0.2.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", "nightly"] } embassy-net-esp-hosted = { version = "0.1.0", path = "../../embassy-net-esp-hosted", features = ["defmt"] } embassy-net-enc28j60 = { version = "0.1.0", path = "../../embassy-net-enc28j60", features = ["defmt"] } -embedded-hal-async = { version = "1.0.0-rc.1" } -embedded-hal-bus = { version = "0.1.0-rc.1", features = ["async"] } +embedded-hal-async = { version = "1.0.0-rc.2" } +embedded-hal-bus = { version = "0.1.0-rc.2", features = ["async"] } static_cell = { version = "2", features = [ "nightly" ] } perf-client = { path = "../perf-client" } diff --git a/tests/rp/Cargo.toml b/tests/rp/Cargo.toml index fc434a02..d69bd795 100644 --- a/tests/rp/Cargo.toml +++ b/tests/rp/Cargo.toml @@ -24,12 +24,12 @@ defmt-rtt = "0.4" cortex-m = { version = "0.7.6" } cortex-m-rt = "0.7.0" embedded-hal = "0.2.6" -embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.1" } -embedded-hal-async = { version = "=1.0.0-rc.1" } -embedded-hal-bus = { version = "=0.1.0-rc.1", features = ["async"] } +embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2" } +embedded-hal-async = { version = "=1.0.0-rc.2" } +embedded-hal-bus = { version = "=0.1.0-rc.2", features = ["async"] } panic-probe = { version = "0.3.0", features = ["print-defmt"] } futures = { version = "0.3.17", default-features = false, features = ["async-await"] } -embedded-io-async = { version = "0.6.0" } +embedded-io-async = { version = "0.6.1" } embedded-storage = { version = "0.3" } static_cell = { version = "2", features = ["nightly"]} portable-atomic = { version = "1.5", features = ["critical-section"] } diff --git a/tests/stm32/Cargo.toml b/tests/stm32/Cargo.toml index 8c2cfdf5..ba72c642 100644 --- a/tests/stm32/Cargo.toml +++ b/tests/stm32/Cargo.toml @@ -63,8 +63,8 @@ defmt-rtt = "0.4" cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } cortex-m-rt = "0.7.0" embedded-hal = "0.2.6" -embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.1" } -embedded-hal-async = { version = "=1.0.0-rc.1" } +embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.2" } +embedded-hal-async = { version = "=1.0.0-rc.2" } micromath = "2.0.0" panic-probe = { version = "0.3.0", features = ["print-defmt"] } rand_core = { version = "0.6", default-features = false }