Skip to content

Commit c2eab4d

Browse files
committed
spi: make Operation::DelayNs with nanosecond granularity.
1 parent 493dfd8 commit c2eab4d

File tree

9 files changed

+17
-14
lines changed

9 files changed

+17
-14
lines changed

embedded-hal-async/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1212
- delay: Rename `DelayUs` to `DelayNs`
1313
- delay: Add `DelayNs::delay_ns()`
1414
- delay: Add default impls of `delay_ms` and `delay_us` based on `delay_ns`.
15+
- spi: Rename `Operation::DelayUs` to `Operation::DelayNs`, with nanosecond precision.
1516

1617
## [v1.0.0-rc.1] - 2023-08-15
1718

embedded-hal-bus/src/spi/critical_section.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl<'a, BUS, CS> CriticalSectionDevice<'a, BUS, CS, super::NoDelay> {
3737
/// # Panics
3838
///
3939
/// The returned device will panic if you try to execute a transaction
40-
/// that contains any operations of type [`Operation::DelayUs`].
40+
/// that contains any operations of type [`Operation::DelayNs`].
4141
#[inline]
4242
pub fn new_no_delay(bus: &'a Mutex<RefCell<BUS>>, cs: CS) -> Self {
4343
Self {

embedded-hal-bus/src/spi/exclusive.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ use embedded_hal::digital::OutputPin;
55
use embedded_hal::spi::{ErrorType, Operation, SpiBus, SpiDevice};
66
#[cfg(feature = "async")]
77
use embedded_hal_async::{
8-
delay::DelayNs as AsyncDelayUs,
8+
delay::DelayNs as AsyncDelayNs,
99
spi::{SpiBus as AsyncSpiBus, SpiDevice as AsyncSpiDevice},
1010
};
1111

12+
use super::shared::transaction;
1213
use super::DeviceError;
1314

1415
/// [`SpiDevice`] implementation with exclusive access to the bus (not shared).
@@ -47,7 +48,7 @@ impl<BUS, CS> ExclusiveDevice<BUS, CS, super::NoDelay> {
4748
/// # Panics
4849
///
4950
/// The returned device will panic if you try to execute a transaction
50-
/// that contains any operations of type `Operation::DelayUs`.
51+
/// that contains any operations of type [`Operation::DelayNs`].
5152
#[inline]
5253
pub fn new_no_delay(bus: BUS, cs: CS) -> Self {
5354
Self {
@@ -84,7 +85,7 @@ impl<Word: Copy + 'static, BUS, CS, D> AsyncSpiDevice<Word> for ExclusiveDevice<
8485
where
8586
BUS: AsyncSpiBus<Word>,
8687
CS: OutputPin,
87-
D: AsyncDelayUs,
88+
D: AsyncDelayNs,
8889
{
8990
#[inline]
9091
async fn transaction(
@@ -100,10 +101,10 @@ where
100101
Operation::Write(buf) => self.bus.write(buf).await,
101102
Operation::Transfer(read, write) => self.bus.transfer(read, write).await,
102103
Operation::TransferInPlace(buf) => self.bus.transfer_in_place(buf).await,
103-
Operation::DelayUs(us) => match self.bus.flush().await {
104+
Operation::DelayNs(ns) => match self.bus.flush().await {
104105
Err(e) => Err(e),
105106
Ok(()) => {
106-
self.delay.delay_us(*us).await;
107+
self.delay.delay_ns(*ns).await;
107108
Ok(())
108109
}
109110
},

embedded-hal-bus/src/spi/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ where
4343
}
4444
}
4545

46-
/// Dummy `DelayUs` implementation that panics on use.
46+
/// Dummy [`DelayNs`](embedded_hal::delay::DelayNs) implementation that panics on use.
4747
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
4848
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
4949
pub struct NoDelay;
5050

5151
#[cold]
5252
fn no_delay_panic() {
53-
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.");
53+
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 `DelayNs` implementation.");
5454
}
5555

5656
impl embedded_hal::delay::DelayNs for NoDelay {

embedded-hal-bus/src/spi/mutex.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl<'a, BUS, CS> MutexDevice<'a, BUS, CS, super::NoDelay> {
3535
/// # Panics
3636
///
3737
/// The returned device will panic if you try to execute a transaction
38-
/// that contains any operations of type `Operation::DelayUs`.
38+
/// that contains any operations of type [`Operation::DelayNs`].
3939
#[inline]
4040
pub fn new_no_delay(bus: &'a Mutex<BUS>, cs: CS) -> Self {
4141
Self {

embedded-hal-bus/src/spi/refcell.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl<'a, BUS, CS> RefCellDevice<'a, BUS, CS, super::NoDelay> {
3434
/// # Panics
3535
///
3636
/// The returned device will panic if you try to execute a transaction
37-
/// that contains any operations of type `Operation::DelayUs`.
37+
/// that contains any operations of type [`Operation::DelayNs`].
3838
#[inline]
3939
pub fn new_no_delay(bus: &'a RefCell<BUS>, cs: CS) -> Self {
4040
Self {

embedded-hal-bus/src/spi/shared.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ where
2525
Operation::Write(buf) => bus.write(buf),
2626
Operation::Transfer(read, write) => bus.transfer(read, write),
2727
Operation::TransferInPlace(buf) => bus.transfer_in_place(buf),
28-
Operation::DelayUs(us) => {
28+
Operation::DelayNs(ns) => {
2929
bus.flush()?;
30-
delay.delay_us(*us);
30+
delay.delay_ns(*ns);
3131
Ok(())
3232
}
3333
});

embedded-hal/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1414
- delay: Add `DelayNs::delay_ns()`
1515
- delay: Add default impls of `delay_ms` and `delay_us` based on `delay_ns`.
1616
- delay: Make the default impl of `delay_ms` more efficient, it now does less calls to the underlying `delay_ns` (previously `delay_us`).
17+
- spi: Rename `Operation::DelayUs` to `Operation::DelayNs`, with nanosecond precision.
1718

1819
## [v1.0.0-rc.1] - 2023-08-15
1920

embedded-hal/src/spi.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,8 @@ pub enum Operation<'a, Word: 'static> {
324324
///
325325
/// Equivalent to [`SpiBus::transfer_in_place`].
326326
TransferInPlace(&'a mut [Word]),
327-
/// Delay for at least the specified number of microseconds.
328-
DelayUs(u32),
327+
/// Delay for at least the specified number of nanoseconds.
328+
DelayNs(u32),
329329
}
330330

331331
/// SPI device trait.

0 commit comments

Comments
 (0)