diff --git a/embassy-embedded-hal/Cargo.toml b/embassy-embedded-hal/Cargo.toml index e89179740a..af0ba256a3 100644 --- a/embassy-embedded-hal/Cargo.toml +++ b/embassy-embedded-hal/Cargo.toml @@ -24,7 +24,10 @@ features = ["std"] [features] std = [] time = ["dep:embassy-time"] -default = ["time"] +default = ["time", "embedded-hal-02"] + +#! Support legacy for embedded hal 0.2 traits +embedded-hal-02 = ["dep:embedded-hal-02"] [dependencies] embassy-futures = { version = "0.1.0", path = "../embassy-futures" } @@ -32,8 +35,8 @@ embassy-sync = { version = "0.5.0", path = "../embassy-sync" } embassy-time = { version = "0.3.0", 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" } +], optional = true } +embedded-hal = "1.0" embedded-hal-async = { version = "1.0" } embedded-storage = "0.3.1" embedded-storage-async = { version = "0.4.1" } diff --git a/embassy-embedded-hal/src/adapter/blocking_async.rs b/embassy-embedded-hal/src/adapter/blocking_async.rs index bafc31583d..043d2ede74 100644 --- a/embassy-embedded-hal/src/adapter/blocking_async.rs +++ b/embassy-embedded-hal/src/adapter/blocking_async.rs @@ -1,5 +1,3 @@ -use embedded_hal_02::blocking; - /// Wrapper that implements async traits using blocking implementations. /// /// This allows driver writers to depend on the async traits while still supporting embedded-hal peripheral implementations. @@ -17,92 +15,181 @@ impl BlockingAsync { Self { wrapped } } } +#[cfg(feature = "embedded-hal-02")] +mod embedded_hal_02 { + use embedded_hal_02::blocking; + + use super::BlockingAsync; + // + // I2C implementations + // + impl embedded_hal::i2c::ErrorType for BlockingAsync + where + E: embedded_hal::i2c::Error + 'static, + T: blocking::i2c::WriteRead + blocking::i2c::Read + blocking::i2c::Write, + { + type Error = E; + } -// -// I2C implementations -// -impl embedded_hal_1::i2c::ErrorType for BlockingAsync -where - E: embedded_hal_1::i2c::Error + 'static, - T: blocking::i2c::WriteRead + blocking::i2c::Read + blocking::i2c::Write, -{ - type Error = E; -} + impl embedded_hal_async::i2c::I2c for BlockingAsync + where + E: embedded_hal::i2c::Error + 'static, + T: blocking::i2c::WriteRead + blocking::i2c::Read + blocking::i2c::Write, + { + async fn read(&mut self, address: u8, read: &mut [u8]) -> Result<(), Self::Error> { + self.wrapped.read(address, read) + } -impl embedded_hal_async::i2c::I2c for BlockingAsync -where - E: embedded_hal_1::i2c::Error + 'static, - T: blocking::i2c::WriteRead + blocking::i2c::Read + blocking::i2c::Write, -{ - async fn read(&mut self, address: u8, read: &mut [u8]) -> Result<(), Self::Error> { - self.wrapped.read(address, read) - } + async fn write(&mut self, address: u8, write: &[u8]) -> Result<(), Self::Error> { + self.wrapped.write(address, write) + } + + async fn write_read(&mut self, address: u8, write: &[u8], read: &mut [u8]) -> Result<(), Self::Error> { + self.wrapped.write_read(address, write, read) + } - async fn write(&mut self, address: u8, write: &[u8]) -> Result<(), Self::Error> { - self.wrapped.write(address, write) + async fn transaction( + &mut self, + address: u8, + operations: &mut [embedded_hal::i2c::Operation<'_>], + ) -> Result<(), Self::Error> { + let _ = address; + let _ = operations; + todo!() + } } - async fn write_read(&mut self, address: u8, write: &[u8], read: &mut [u8]) -> Result<(), Self::Error> { - self.wrapped.write_read(address, write, read) + // + // SPI implementatinos + // + + impl embedded_hal_async::spi::ErrorType for BlockingAsync + where + E: embedded_hal::spi::Error, + T: blocking::spi::Transfer + blocking::spi::Write, + { + type Error = E; } - async fn transaction( - &mut self, - address: u8, - operations: &mut [embedded_hal_1::i2c::Operation<'_>], - ) -> Result<(), Self::Error> { - let _ = address; - let _ = operations; - todo!() + impl embedded_hal_async::spi::SpiBus for BlockingAsync + where + E: embedded_hal::spi::Error + 'static, + T: blocking::spi::Transfer + blocking::spi::Write, + { + async fn flush(&mut self) -> Result<(), Self::Error> { + Ok(()) + } + + async fn write(&mut self, data: &[u8]) -> Result<(), Self::Error> { + self.wrapped.write(data)?; + Ok(()) + } + + async fn read(&mut self, data: &mut [u8]) -> Result<(), Self::Error> { + self.wrapped.transfer(data)?; + Ok(()) + } + + async fn transfer(&mut self, read: &mut [u8], write: &[u8]) -> Result<(), Self::Error> { + // Ensure we write the expected bytes + for i in 0..core::cmp::min(read.len(), write.len()) { + read[i] = write[i].clone(); + } + self.wrapped.transfer(read)?; + Ok(()) + } + + async fn transfer_in_place(&mut self, data: &mut [u8]) -> Result<(), Self::Error> { + self.wrapped.transfer(data)?; + Ok(()) + } } } +#[cfg(not(feature = "embedded-hal-02"))] +mod embedded_hal { + use super::BlockingAsync; + + // + // I2C implementations + // + impl embedded_hal::i2c::ErrorType for BlockingAsync + where + E: embedded_hal::i2c::Error + 'static, + T: embedded_hal::i2c::I2c + embedded_hal_async::i2c::ErrorType, + { + type Error = E; + } -// -// SPI implementatinos -// + impl embedded_hal_async::i2c::I2c for BlockingAsync + where + E: embedded_hal::i2c::Error + 'static, + T: embedded_hal::i2c::I2c + embedded_hal_async::i2c::ErrorType, + { + async fn read(&mut self, address: u8, read: &mut [u8]) -> Result<(), Self::Error> { + self.wrapped.read(address, read) + } -impl embedded_hal_async::spi::ErrorType for BlockingAsync -where - E: embedded_hal_1::spi::Error, - T: blocking::spi::Transfer + blocking::spi::Write, -{ - type Error = E; -} + async fn write(&mut self, address: u8, write: &[u8]) -> Result<(), Self::Error> { + self.wrapped.write(address, write) + } -impl embedded_hal_async::spi::SpiBus for BlockingAsync -where - E: embedded_hal_1::spi::Error + 'static, - T: blocking::spi::Transfer + blocking::spi::Write, -{ - async fn flush(&mut self) -> Result<(), Self::Error> { - Ok(()) - } + async fn write_read(&mut self, address: u8, write: &[u8], read: &mut [u8]) -> Result<(), Self::Error> { + self.wrapped.write_read(address, write, read) + } - async fn write(&mut self, data: &[u8]) -> Result<(), Self::Error> { - self.wrapped.write(data)?; - Ok(()) + async fn transaction( + &mut self, + address: u8, + operations: &mut [embedded_hal::i2c::Operation<'_>], + ) -> Result<(), Self::Error> { + let _ = address; + let _ = operations; + todo!() + } } - async fn read(&mut self, data: &mut [u8]) -> Result<(), Self::Error> { - self.wrapped.transfer(data)?; - Ok(()) + // + // SPI implementatinos + // + + impl embedded_hal_async::spi::ErrorType for BlockingAsync + where + E: embedded_hal::spi::Error, + T: embedded_hal::spi::SpiBus + embedded_hal_async::spi::ErrorType, + { + type Error = E; } - async fn transfer(&mut self, read: &mut [u8], write: &[u8]) -> Result<(), Self::Error> { - // Ensure we write the expected bytes - for i in 0..core::cmp::min(read.len(), write.len()) { - read[i] = write[i].clone(); + impl embedded_hal_async::spi::SpiBus for BlockingAsync + where + E: embedded_hal::spi::Error + 'static, + T: embedded_hal::spi::SpiBus + embedded_hal_async::spi::ErrorType, + { + async fn flush(&mut self) -> Result<(), Self::Error> { + Ok(()) } - self.wrapped.transfer(read)?; - Ok(()) - } - async fn transfer_in_place(&mut self, data: &mut [u8]) -> Result<(), Self::Error> { - self.wrapped.transfer(data)?; - Ok(()) + async fn write(&mut self, data: &[u8]) -> Result<(), Self::Error> { + self.wrapped.write(data)?; + Ok(()) + } + + async fn read(&mut self, data: &mut [u8]) -> Result<(), Self::Error> { + self.wrapped.read(data)?; + Ok(()) + } + + async fn transfer(&mut self, read: &mut [u8], write: &[u8]) -> Result<(), Self::Error> { + self.wrapped.transfer(read, write)?; + Ok(()) + } + + async fn transfer_in_place(&mut self, data: &mut [u8]) -> Result<(), Self::Error> { + self.wrapped.transfer_in_place(data)?; + Ok(()) + } } } - /// NOR flash wrapper use embedded_storage::nor_flash::{ErrorType, MultiwriteNorFlash, NorFlash, ReadNorFlash}; use embedded_storage_async::nor_flash::{ diff --git a/embassy-embedded-hal/src/adapter/yielding_async.rs b/embassy-embedded-hal/src/adapter/yielding_async.rs index fe9c9c3418..363ab51bc7 100644 --- a/embassy-embedded-hal/src/adapter/yielding_async.rs +++ b/embassy-embedded-hal/src/adapter/yielding_async.rs @@ -18,9 +18,9 @@ impl YieldingAsync { // // I2C implementations // -impl embedded_hal_1::i2c::ErrorType for YieldingAsync +impl embedded_hal::i2c::ErrorType for YieldingAsync where - T: embedded_hal_1::i2c::ErrorType, + T: embedded_hal::i2c::ErrorType, { type Error = T::Error; } @@ -50,7 +50,7 @@ where async fn transaction( &mut self, address: u8, - operations: &mut [embedded_hal_1::i2c::Operation<'_>], + operations: &mut [embedded_hal::i2c::Operation<'_>], ) -> Result<(), Self::Error> { self.wrapped.transaction(address, operations).await?; yield_now().await; diff --git a/embassy-embedded-hal/src/shared_bus/asynch/spi.rs b/embassy-embedded-hal/src/shared_bus/asynch/spi.rs index 9890f218d1..1009b915cb 100644 --- a/embassy-embedded-hal/src/shared_bus/asynch/spi.rs +++ b/embassy-embedded-hal/src/shared_bus/asynch/spi.rs @@ -27,8 +27,8 @@ use embassy_sync::blocking_mutex::raw::RawMutex; use embassy_sync::mutex::Mutex; -use embedded_hal_1::digital::OutputPin; -use embedded_hal_1::spi::Operation; +use embedded_hal::digital::OutputPin; +use embedded_hal::spi::Operation; use embedded_hal_async::spi; use crate::shared_bus::SpiDeviceError; diff --git a/embassy-embedded-hal/src/shared_bus/blocking/i2c.rs b/embassy-embedded-hal/src/shared_bus/blocking/i2c.rs index 627767c8a1..5512ae1a67 100644 --- a/embassy-embedded-hal/src/shared_bus/blocking/i2c.rs +++ b/embassy-embedded-hal/src/shared_bus/blocking/i2c.rs @@ -19,7 +19,7 @@ use core::cell::RefCell; use embassy_sync::blocking_mutex::raw::RawMutex; use embassy_sync::blocking_mutex::Mutex; -use embedded_hal_1::i2c::{ErrorType, I2c, Operation}; +use embedded_hal::i2c::{ErrorType, I2c, Operation}; use crate::shared_bus::I2cDeviceError; use crate::SetConfig; @@ -75,45 +75,53 @@ where } } -impl<'a, M, BUS, E> embedded_hal_02::blocking::i2c::Write for I2cDevice<'_, M, BUS> -where - M: RawMutex, - BUS: embedded_hal_02::blocking::i2c::Write, -{ - type Error = I2cDeviceError; +#[cfg(feature = "embedded-hal-02")] +mod embedded_hal_02 { + use embassy_sync::blocking_mutex::raw::RawMutex; - fn write<'w>(&mut self, addr: u8, bytes: &'w [u8]) -> Result<(), Self::Error> { - self.bus - .lock(|bus| bus.borrow_mut().write(addr, bytes).map_err(I2cDeviceError::I2c)) - } -} + use super::I2cDevice; + use crate::shared_bus::I2cDeviceError; -impl<'a, M, BUS, E> embedded_hal_02::blocking::i2c::Read for I2cDevice<'_, M, BUS> -where - M: RawMutex, - BUS: embedded_hal_02::blocking::i2c::Read, -{ - type Error = I2cDeviceError; + impl<'a, M, BUS, E> embedded_hal_02::blocking::i2c::Write for I2cDevice<'_, M, BUS> + where + M: RawMutex, + BUS: embedded_hal_02::blocking::i2c::Write, + { + type Error = I2cDeviceError; - fn read<'w>(&mut self, addr: u8, bytes: &'w mut [u8]) -> Result<(), Self::Error> { - self.bus - .lock(|bus| bus.borrow_mut().read(addr, bytes).map_err(I2cDeviceError::I2c)) + fn write<'w>(&mut self, addr: u8, bytes: &'w [u8]) -> Result<(), Self::Error> { + self.bus + .lock(|bus| bus.borrow_mut().write(addr, bytes).map_err(I2cDeviceError::I2c)) + } } -} -impl<'a, M, BUS, E> embedded_hal_02::blocking::i2c::WriteRead for I2cDevice<'_, M, BUS> -where - M: RawMutex, - BUS: embedded_hal_02::blocking::i2c::WriteRead, -{ - type Error = I2cDeviceError; + impl<'a, M, BUS, E> embedded_hal_02::blocking::i2c::Read for I2cDevice<'_, M, BUS> + where + M: RawMutex, + BUS: embedded_hal_02::blocking::i2c::Read, + { + type Error = I2cDeviceError; + + fn read<'w>(&mut self, addr: u8, bytes: &'w mut [u8]) -> Result<(), Self::Error> { + self.bus + .lock(|bus| bus.borrow_mut().read(addr, bytes).map_err(I2cDeviceError::I2c)) + } + } - fn write_read<'w>(&mut self, addr: u8, bytes: &'w [u8], buffer: &'w mut [u8]) -> Result<(), Self::Error> { - self.bus.lock(|bus| { - bus.borrow_mut() - .write_read(addr, bytes, buffer) - .map_err(I2cDeviceError::I2c) - }) + impl<'a, M, BUS, E> embedded_hal_02::blocking::i2c::WriteRead for I2cDevice<'_, M, BUS> + where + M: RawMutex, + BUS: embedded_hal_02::blocking::i2c::WriteRead, + { + type Error = I2cDeviceError; + + fn write_read<'w>(&mut self, addr: u8, bytes: &'w [u8], buffer: &'w mut [u8]) -> Result<(), Self::Error> { + self.bus.lock(|bus| { + bus.borrow_mut() + .write_read(addr, bytes, buffer) + .map_err(I2cDeviceError::I2c) + }) + } } } diff --git a/embassy-embedded-hal/src/shared_bus/blocking/spi.rs b/embassy-embedded-hal/src/shared_bus/blocking/spi.rs index 801899f9fb..d995125112 100644 --- a/embassy-embedded-hal/src/shared_bus/blocking/spi.rs +++ b/embassy-embedded-hal/src/shared_bus/blocking/spi.rs @@ -21,8 +21,8 @@ use core::cell::RefCell; use embassy_sync::blocking_mutex::raw::RawMutex; use embassy_sync::blocking_mutex::Mutex; -use embedded_hal_1::digital::OutputPin; -use embedded_hal_1::spi::{self, Operation, SpiBus}; +use embedded_hal::digital::OutputPin; +use embedded_hal::spi::{self, Operation, SpiBus}; use crate::shared_bus::SpiDeviceError; use crate::SetConfig; @@ -48,7 +48,7 @@ where type Error = SpiDeviceError; } -impl embedded_hal_1::spi::SpiDevice for SpiDevice<'_, M, BUS, CS> +impl embedded_hal::spi::SpiDevice for SpiDevice<'_, M, BUS, CS> where M: RawMutex, BUS: SpiBus, @@ -90,44 +90,53 @@ where } } -impl<'d, M, BUS, CS, BusErr, CsErr> embedded_hal_02::blocking::spi::Transfer for SpiDevice<'_, M, BUS, CS> -where - M: RawMutex, - BUS: embedded_hal_02::blocking::spi::Transfer, - CS: OutputPin, -{ - type Error = SpiDeviceError; - fn transfer<'w>(&mut self, words: &'w mut [u8]) -> Result<&'w [u8], Self::Error> { - self.bus.lock(|bus| { - let mut bus = bus.borrow_mut(); - self.cs.set_low().map_err(SpiDeviceError::Cs)?; - let op_res = bus.transfer(words); - let cs_res = self.cs.set_high(); - let op_res = op_res.map_err(SpiDeviceError::Spi)?; - cs_res.map_err(SpiDeviceError::Cs)?; - Ok(op_res) - }) +#[cfg(feature = "embedded-hal-02")] +mod embedded_hal_02 { + use embassy_sync::blocking_mutex::raw::RawMutex; + use embedded_hal_02::digital::v2::OutputPin; + + use super::SpiDevice; + use crate::shared_bus::SpiDeviceError; + + impl<'d, M, BUS, CS, BusErr, CsErr> embedded_hal_02::blocking::spi::Transfer for SpiDevice<'_, M, BUS, CS> + where + M: RawMutex, + BUS: embedded_hal_02::blocking::spi::Transfer, + CS: OutputPin, + { + type Error = SpiDeviceError; + fn transfer<'w>(&mut self, words: &'w mut [u8]) -> Result<&'w [u8], Self::Error> { + self.bus.lock(|bus| { + let mut bus = bus.borrow_mut(); + self.cs.set_low().map_err(SpiDeviceError::Cs)?; + let op_res = bus.transfer(words); + let cs_res = self.cs.set_high(); + let op_res = op_res.map_err(SpiDeviceError::Spi)?; + cs_res.map_err(SpiDeviceError::Cs)?; + Ok(op_res) + }) + } } -} -impl<'d, M, BUS, CS, BusErr, CsErr> embedded_hal_02::blocking::spi::Write for SpiDevice<'_, M, BUS, CS> -where - M: RawMutex, - BUS: embedded_hal_02::blocking::spi::Write, - CS: OutputPin, -{ - type Error = SpiDeviceError; - - fn write(&mut self, words: &[u8]) -> Result<(), Self::Error> { - self.bus.lock(|bus| { - let mut bus = bus.borrow_mut(); - self.cs.set_low().map_err(SpiDeviceError::Cs)?; - let op_res = bus.write(words); - let cs_res = self.cs.set_high(); - let op_res = op_res.map_err(SpiDeviceError::Spi)?; - cs_res.map_err(SpiDeviceError::Cs)?; - Ok(op_res) - }) + impl<'d, M, BUS, CS, BusErr, CsErr> embedded_hal_02::blocking::spi::Write for SpiDevice<'_, M, BUS, CS> + where + M: RawMutex, + BUS: embedded_hal_02::blocking::spi::Write, + CS: OutputPin, + { + type Error = SpiDeviceError; + + fn write(&mut self, words: &[u8]) -> Result<(), Self::Error> { + self.bus.lock(|bus| { + let mut bus = bus.borrow_mut(); + self.cs.set_low().map_err(SpiDeviceError::Cs)?; + let op_res = bus.write(words); + let cs_res = self.cs.set_high(); + let op_res = op_res.map_err(SpiDeviceError::Spi)?; + cs_res.map_err(SpiDeviceError::Cs)?; + Ok(op_res) + }) + } } } @@ -163,7 +172,7 @@ where type Error = SpiDeviceError; } -impl embedded_hal_1::spi::SpiDevice for SpiDeviceWithConfig<'_, M, BUS, CS> +impl embedded_hal::spi::SpiDevice for SpiDeviceWithConfig<'_, M, BUS, CS> where M: RawMutex, BUS: SpiBus + SetConfig, diff --git a/embassy-embedded-hal/src/shared_bus/mod.rs b/embassy-embedded-hal/src/shared_bus/mod.rs index d835306bc5..19df92316c 100644 --- a/embassy-embedded-hal/src/shared_bus/mod.rs +++ b/embassy-embedded-hal/src/shared_bus/mod.rs @@ -1,7 +1,7 @@ //! Shared bus implementations use core::fmt::Debug; -use embedded_hal_1::{i2c, spi}; +use embedded_hal::{i2c, spi}; pub mod asynch; pub mod blocking; diff --git a/embassy-time/CHANGELOG.md b/embassy-time/CHANGELOG.md index df093949fa..266a32337c 100644 --- a/embassy-time/CHANGELOG.md +++ b/embassy-time/CHANGELOG.md @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +- Put `embedded-hal v0.2` dependency behind a feature flag. + ## 0.3.0 - 2024-01-11 - Update `embedded-hal-async` to `1.0.0` diff --git a/embassy-time/Cargo.toml b/embassy-time/Cargo.toml index ca7ad2d09a..bc6221c81f 100644 --- a/embassy-time/Cargo.toml +++ b/embassy-time/Cargo.toml @@ -24,6 +24,7 @@ target = "x86_64-unknown-linux-gnu" features = ["defmt", "std"] [features] +default = ["embedded-hal-02"] std = ["tick-hz-1_000_000", "critical-section/std"] wasm = ["dep:wasm-bindgen", "dep:js-sys", "dep:wasm-timer", "tick-hz-1_000_000"] @@ -40,6 +41,9 @@ mock-driver = ["tick-hz-1_000_000"] ## To use this you must have a time driver provided. generic-queue = [] +#! Support legacy for embedded hal 0.2 traits +embedded-hal-02 = ["dep:embedded-hal-02"] + #! The following features set how many timers are used for the generic queue. At most one #! `generic-queue-*` feature can be enabled. If none is enabled, a default of 64 timers is used. #! @@ -404,8 +408,8 @@ embassy-time-queue-driver = { version = "0.1.0", path = "../embassy-time-queue-d 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" } +embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", optional = true } +embedded-hal = "1.0" embedded-hal-async = { version = "1.0" } futures-util = { version = "0.3.17", default-features = false } diff --git a/embassy-time/src/delay.rs b/embassy-time/src/delay.rs index f77859d4af..9e822fdc97 100644 --- a/embassy-time/src/delay.rs +++ b/embassy-time/src/delay.rs @@ -16,7 +16,7 @@ pub fn block_for(duration: Duration) { #[derive(Clone)] pub struct Delay; -impl embedded_hal_1::delay::DelayNs for Delay { +impl embedded_hal::delay::DelayNs for Delay { fn delay_ns(&mut self, ns: u32) { block_for(Duration::from_nanos(ns as u64)) } @@ -43,39 +43,43 @@ impl embedded_hal_async::delay::DelayNs for Delay { Timer::after_millis(ms as _).await } } +#[cfg(feature = "embedded-hal-02")] +mod embedded_hal_02 { + use crate::{block_for, Delay, Duration}; -impl embedded_hal_02::blocking::delay::DelayMs for Delay { - fn delay_ms(&mut self, ms: u8) { - block_for(Duration::from_millis(ms as u64)) + impl embedded_hal_02::blocking::delay::DelayMs for Delay { + fn delay_ms(&mut self, ms: u8) { + block_for(Duration::from_millis(ms as u64)) + } } -} -impl embedded_hal_02::blocking::delay::DelayMs for Delay { - fn delay_ms(&mut self, ms: u16) { - block_for(Duration::from_millis(ms as u64)) + impl embedded_hal_02::blocking::delay::DelayMs for Delay { + fn delay_ms(&mut self, ms: u16) { + block_for(Duration::from_millis(ms as u64)) + } } -} -impl embedded_hal_02::blocking::delay::DelayMs for Delay { - fn delay_ms(&mut self, ms: u32) { - block_for(Duration::from_millis(ms as u64)) + impl embedded_hal_02::blocking::delay::DelayMs for Delay { + fn delay_ms(&mut self, ms: u32) { + block_for(Duration::from_millis(ms as u64)) + } } -} -impl embedded_hal_02::blocking::delay::DelayUs for Delay { - fn delay_us(&mut self, us: u8) { - block_for(Duration::from_micros(us as u64)) + impl embedded_hal_02::blocking::delay::DelayUs for Delay { + fn delay_us(&mut self, us: u8) { + block_for(Duration::from_micros(us as u64)) + } } -} -impl embedded_hal_02::blocking::delay::DelayUs for Delay { - fn delay_us(&mut self, us: u16) { - block_for(Duration::from_micros(us as u64)) + impl embedded_hal_02::blocking::delay::DelayUs for Delay { + fn delay_us(&mut self, us: u16) { + block_for(Duration::from_micros(us as u64)) + } } -} -impl embedded_hal_02::blocking::delay::DelayUs for Delay { - fn delay_us(&mut self, us: u32) { - block_for(Duration::from_micros(us as u64)) + impl embedded_hal_02::blocking::delay::DelayUs for Delay { + fn delay_us(&mut self, us: u32) { + block_for(Duration::from_micros(us as u64)) + } } }