diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7959974..15aeec0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,7 +9,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Changed
- [breaking-change] Replace serial-rs with the serialport-rs crate. `Serial::open` now needs a baud-rate argument as well.
-- Updated to `embedded-hal` `1.0.0-alpha.10` release ([API changes](https://github.com/rust-embedded/embedded-hal/blob/master/embedded-hal/CHANGELOG.md#v100-alpha10---2023-04-04))
+- Updated to `embedded-hal` `1.0.0-alpha.11` release ([API changes](https://github.com/rust-embedded/embedded-hal/blob/master/embedded-hal/CHANGELOG.md#v100-alpha11---2023-07-04))
+- Updated to `spidev` `0.5.2` release([API changes](https://github.com/rust-embedded/rust-spidev/blob/master/CHANGELOG.md#052--2023-08-02))
## [v0.4.0-alpha.3] - 2022-08-04
diff --git a/Cargo.toml b/Cargo.toml
index 1de3a72..e3658c3 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -22,14 +22,14 @@ spi = ["spidev"]
default = [ "gpio_cdev", "gpio_sysfs", "i2c", "spi" ]
[dependencies]
-embedded-hal = "=1.0.0-alpha.10"
-embedded-hal-nb = "=1.0.0-alpha.2"
+embedded-hal = "=1.0.0-alpha.11"
+embedded-hal-nb = "=1.0.0-alpha.3"
gpio-cdev = { version = "0.5.1", optional = true }
sysfs_gpio = { version = "0.6.1", optional = true }
i2cdev = { version = "0.5.1", optional = true }
nb = "1"
serialport = { version = "4.2.0", default-features = false }
-spidev = { version = "0.5.1", optional = true }
+spidev = { version = "0.5.2", optional = true }
nix = "0.23.1"
[dev-dependencies]
diff --git a/src/serial.rs b/src/serial.rs
index 8b81354..35ead87 100644
--- a/src/serial.rs
+++ b/src/serial.rs
@@ -81,6 +81,7 @@ impl fmt::Display for SerialError {
impl std::error::Error for SerialError {}
impl embedded_hal::serial::Error for SerialError {
+ #[allow(clippy::match_single_binding)]
fn kind(&self) -> embedded_hal::serial::ErrorKind {
use embedded_hal::serial::ErrorKind::*;
// TODO: match any errors here if we can find any that are relevant
diff --git a/src/spi.rs b/src/spi.rs
index 4a55ace..8da6a76 100644
--- a/src/spi.rs
+++ b/src/spi.rs
@@ -10,13 +10,16 @@ use std::path::Path;
/// Newtype around [`spidev::Spidev`] that implements the `embedded-hal` traits
///
-/// [`spidev::Spidev`]: https://docs.rs/spidev/0.5.0/spidev/struct.Spidev.html
+/// [Delay operations][delay] are capped to 65535 microseconds.
+///
+/// [`spidev::Spidev`]: https://docs.rs/spidev/0.5.2/spidev/struct.Spidev.html
+/// [delay]: embedded_hal::spi::Operation::DelayUs
pub struct Spidev(pub spidev::Spidev);
impl Spidev {
/// See [`spidev::Spidev::open`][0] for details.
///
- /// [0]: https://docs.rs/spidev/0.5.0/spidev/struct.Spidev.html#method.open
+ /// [0]: https://docs.rs/spidev/0.5.2/spidev/struct.Spidev.html#method.open
pub fn open
(path: P) -> Result
where
P: AsRef,
@@ -42,36 +45,24 @@ impl ops::DerefMut for Spidev {
mod embedded_hal_impl {
use super::*;
use embedded_hal::spi::ErrorType;
- use embedded_hal::spi::{
- Operation as SpiOperation, SpiBus, SpiBusFlush, SpiBusRead, SpiBusWrite, SpiDevice,
- SpiDeviceRead, SpiDeviceWrite,
- };
+ use embedded_hal::spi::{Operation as SpiOperation, SpiBus, SpiDevice};
use spidev::SpidevTransfer;
+ use std::convert::TryInto;
use std::io::{Read, Write};
impl ErrorType for Spidev {
type Error = SPIError;
}
- impl SpiBusFlush for Spidev {
- fn flush(&mut self) -> Result<(), Self::Error> {
- self.0.flush().map_err(|err| SPIError { err })
- }
- }
-
- impl SpiBusRead for Spidev {
+ impl SpiBus for Spidev {
fn read(&mut self, words: &mut [u8]) -> Result<(), Self::Error> {
self.0.read_exact(words).map_err(|err| SPIError { err })
}
- }
- impl SpiBusWrite for Spidev {
fn write(&mut self, words: &[u8]) -> Result<(), Self::Error> {
self.0.write_all(words).map_err(|err| SPIError { err })
}
- }
- impl SpiBus for Spidev {
fn transfer(&mut self, read: &mut [u8], write: &[u8]) -> Result<(), Self::Error> {
self.0
.transfer(&mut SpidevTransfer::read_write(write, read))
@@ -84,37 +75,19 @@ mod embedded_hal_impl {
.transfer(&mut SpidevTransfer::read_write(&tx, words))
.map_err(|err| SPIError { err })
}
- }
-
- impl SpiDeviceRead for Spidev {
- fn read_transaction(&mut self, operations: &mut [&mut [u8]]) -> Result<(), Self::Error> {
- let mut transfers: Vec<_> = operations
- .iter_mut()
- .map(|op| SpidevTransfer::read(op))
- .collect();
- self.0
- .transfer_multiple(&mut transfers)
- .map_err(|err| SPIError { err })?;
- self.flush()?;
- Ok(())
- }
- }
- impl SpiDeviceWrite for Spidev {
- fn write_transaction(&mut self, operations: &[&[u8]]) -> Result<(), Self::Error> {
- let mut transfers: Vec<_> = operations
- .iter()
- .map(|op| SpidevTransfer::write(op))
- .collect();
- self.0
- .transfer_multiple(&mut transfers)
- .map_err(|err| SPIError { err })?;
- self.flush()?;
- Ok(())
+ fn flush(&mut self) -> Result<(), Self::Error> {
+ self.0.flush().map_err(|err| SPIError { err })
}
}
impl SpiDevice for Spidev {
+ ///Perform a transaction against the device. [Read more][transaction]
+ ///
+ /// [Delay operations][delay] are capped to 65535 microseconds.
+ ///
+ /// [transaction]: SpiDevice::transaction
+ /// [delay]: SpiOperation::DelayUs
fn transaction(
&mut self,
operations: &mut [SpiOperation<'_, u8>],
@@ -132,6 +105,9 @@ mod embedded_hal_impl {
};
SpidevTransfer::read_write(tx, buf)
}
+ SpiOperation::DelayUs(us) => {
+ SpidevTransfer::delay((*us).try_into().unwrap_or(u16::MAX))
+ }
})
.collect();
self.0
@@ -163,6 +139,7 @@ impl From for SPIError {
}
impl embedded_hal::spi::Error for SPIError {
+ #[allow(clippy::match_single_binding)]
fn kind(&self) -> embedded_hal::spi::ErrorKind {
use embedded_hal::spi::ErrorKind;
// TODO: match any errors here if we can find any that are relevant