diff --git a/embedded-hal-async/CHANGELOG.md b/embedded-hal-async/CHANGELOG.md index 043d704d9..af7908ed2 100644 --- a/embedded-hal-async/CHANGELOG.md +++ b/embedded-hal-async/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - delay: Rename `DelayUs` to `BasicDelay` - delay: Add `BasicDelay::delay_ns()` - delay: Add default impls of `delay_ms` and `delay_us` based on `delay_ns`. +- spi: Rename `Operation::DelayUs` to `Operation::DelayNs`, with microsecond precision. ## [v1.0.0-rc.1] - 2023-08-15 diff --git a/embedded-hal-bus/src/spi/critical_section.rs b/embedded-hal-bus/src/spi/critical_section.rs index 26d2f1cf6..391a093dc 100644 --- a/embedded-hal-bus/src/spi/critical_section.rs +++ b/embedded-hal-bus/src/spi/critical_section.rs @@ -37,7 +37,7 @@ impl<'a, BUS, CS> CriticalSectionDevice<'a, BUS, CS, super::NoDelay> { /// # Panics /// /// The returned device will panic if you try to execute a transaction - /// that contains any operations of type [`Operation::DelayUs`]. + /// that contains any operations of type [`Operation::DelayNs`]. #[inline] pub fn new_no_delay(bus: &'a Mutex>, cs: CS) -> Self { Self { diff --git a/embedded-hal-bus/src/spi/exclusive.rs b/embedded-hal-bus/src/spi/exclusive.rs index 9a31a3311..0ae8580cb 100644 --- a/embedded-hal-bus/src/spi/exclusive.rs +++ b/embedded-hal-bus/src/spi/exclusive.rs @@ -5,10 +5,11 @@ use embedded_hal::digital::OutputPin; use embedded_hal::spi::{ErrorType, Operation, SpiBus, SpiDevice}; #[cfg(feature = "async")] use embedded_hal_async::{ - delay::BasicDelay as AsyncDelayUs, + delay::BasicDelay as AsyncBasicDelay, spi::{SpiBus as AsyncSpiBus, SpiDevice as AsyncSpiDevice}, }; +use super::shared::transaction; use super::DeviceError; /// [`SpiDevice`] implementation with exclusive access to the bus (not shared). @@ -47,7 +48,7 @@ impl ExclusiveDevice { /// # Panics /// /// The returned device will panic if you try to execute a transaction - /// that contains any operations of type `Operation::DelayUs`. + /// that contains any operations of type [`Operation::DelayNs`]. #[inline] pub fn new_no_delay(bus: BUS, cs: CS) -> Self { Self { @@ -84,7 +85,7 @@ impl AsyncSpiDevice for ExclusiveDevice< where BUS: AsyncSpiBus, CS: OutputPin, - D: AsyncDelayUs, + D: AsyncBasicDelay, { #[inline] async fn transaction( @@ -100,10 +101,10 @@ where Operation::Write(buf) => self.bus.write(buf).await, Operation::Transfer(read, write) => self.bus.transfer(read, write).await, Operation::TransferInPlace(buf) => self.bus.transfer_in_place(buf).await, - Operation::DelayUs(us) => match self.bus.flush().await { + Operation::DelayNs(ns) => match self.bus.flush().await { Err(e) => Err(e), Ok(()) => { - self.delay.delay_us(*us).await; + self.delay.delay_ns(*ns).await; Ok(()) } }, diff --git a/embedded-hal-bus/src/spi/mod.rs b/embedded-hal-bus/src/spi/mod.rs index 7fe23cd00..73c2a86ad 100644 --- a/embedded-hal-bus/src/spi/mod.rs +++ b/embedded-hal-bus/src/spi/mod.rs @@ -43,14 +43,14 @@ where } } -/// Dummy `DelayUs` implementation that panics on use. +/// Dummy [`BasicDelay`](embedded_hal::delay::BasicDelay) implementation that panics on use. #[derive(Copy, Clone, Eq, PartialEq, Debug)] #[cfg_attr(feature = "defmt-03", derive(defmt::Format))] pub struct NoDelay; #[cold] fn no_delay_panic() { - panic!("You've tried to execute a SPI transaction containing a `Operation::Delay` in a `SpiDevice` created with `new_no_delay()`. Create it with `new()` instead, passing a `DelayUs` implementation."); + panic!("You've tried to execute a SPI transaction containing a `Operation::DelayNs` in a `SpiDevice` created with `new_no_delay()`. Create it with `new()` instead, passing a `BasicDelay` implementation."); } impl embedded_hal::delay::BasicDelay for NoDelay { diff --git a/embedded-hal-bus/src/spi/mutex.rs b/embedded-hal-bus/src/spi/mutex.rs index d8c497ecc..0f516c321 100644 --- a/embedded-hal-bus/src/spi/mutex.rs +++ b/embedded-hal-bus/src/spi/mutex.rs @@ -35,7 +35,7 @@ impl<'a, BUS, CS> MutexDevice<'a, BUS, CS, super::NoDelay> { /// # Panics /// /// The returned device will panic if you try to execute a transaction - /// that contains any operations of type `Operation::DelayUs`. + /// that contains any operations of type [`Operation::DelayNs`]. #[inline] pub fn new_no_delay(bus: &'a Mutex, cs: CS) -> Self { Self { diff --git a/embedded-hal-bus/src/spi/refcell.rs b/embedded-hal-bus/src/spi/refcell.rs index 108564dd9..4b5a4452b 100644 --- a/embedded-hal-bus/src/spi/refcell.rs +++ b/embedded-hal-bus/src/spi/refcell.rs @@ -34,7 +34,7 @@ impl<'a, BUS, CS> RefCellDevice<'a, BUS, CS, super::NoDelay> { /// # Panics /// /// The returned device will panic if you try to execute a transaction - /// that contains any operations of type `Operation::DelayUs`. + /// that contains any operations of type [`Operation::DelayNs`]. #[inline] pub fn new_no_delay(bus: &'a RefCell, cs: CS) -> Self { Self { diff --git a/embedded-hal-bus/src/spi/shared.rs b/embedded-hal-bus/src/spi/shared.rs index a07187a39..ad99a8173 100644 --- a/embedded-hal-bus/src/spi/shared.rs +++ b/embedded-hal-bus/src/spi/shared.rs @@ -25,9 +25,9 @@ where Operation::Write(buf) => bus.write(buf), Operation::Transfer(read, write) => bus.transfer(read, write), Operation::TransferInPlace(buf) => bus.transfer_in_place(buf), - Operation::DelayUs(us) => { + Operation::DelayNs(ns) => { bus.flush()?; - delay.delay_us(*us); + delay.delay_ns(*ns); Ok(()) } }); diff --git a/embedded-hal/CHANGELOG.md b/embedded-hal/CHANGELOG.md index 53fa9a6f0..04ffb9145 100644 --- a/embedded-hal/CHANGELOG.md +++ b/embedded-hal/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - delay: Add `BasicDelay::delay_ns()` - delay: Add default impls of `delay_ms` and `delay_us` based on `delay_ns`. - delay: Make the default impl of `delay_ms` more efficient, it now does less calls to the underlying `delay_ns` (previously `delay_us`). +- spi: Rename `Operation::DelayUs` to `Operation::DelayNs`, with microsecond precision. ## [v1.0.0-rc.1] - 2023-08-15 diff --git a/embedded-hal/src/spi.rs b/embedded-hal/src/spi.rs index c8c8224fd..ca61269e7 100644 --- a/embedded-hal/src/spi.rs +++ b/embedded-hal/src/spi.rs @@ -324,8 +324,8 @@ pub enum Operation<'a, Word: 'static> { /// /// Equivalent to [`SpiBus::transfer_in_place`]. TransferInPlace(&'a mut [Word]), - /// Delay for at least the specified number of microseconds. - DelayUs(u32), + /// Delay for at least the specified number of nanoseconds. + DelayNs(u32), } /// SPI device trait.