From b13a6453165e52fedb6ec2bb4969a57d80688e11 Mon Sep 17 00:00:00 2001 From: andber1 <82754113+andber1@users.noreply.github.com> Date: Mon, 18 Mar 2024 21:18:58 +0100 Subject: [PATCH] Improve SPI error messages when using embedded_hal --- src/spi/hal.rs | 35 ++++++++--------------------------- 1 file changed, 8 insertions(+), 27 deletions(-) diff --git a/src/spi/hal.rs b/src/spi/hal.rs index 7918d6cf..5c9623b8 100644 --- a/src/spi/hal.rs +++ b/src/spi/hal.rs @@ -1,5 +1,3 @@ -use std::io; - use super::{super::hal::Delay, Error, Spi}; #[cfg(feature = "embedded-hal")] @@ -113,7 +111,10 @@ impl> SimpleHalSpiDevice { } #[cfg(feature = "embedded-hal")] -impl> embedded_hal::spi::SpiDevice for SimpleHalSpiDevice { +impl> embedded_hal::spi::SpiDevice for SimpleHalSpiDevice +where + Error: From<::Error>, +{ fn transaction( &mut self, operations: &mut [embedded_hal::spi::Operation<'_, u8>], @@ -121,36 +122,16 @@ impl> embedded_hal::spi::SpiDevice for Simp for op in operations { match op { embedded_hal::spi::Operation::Read(read) => { - self.bus.read(read).map_err(|_| { - Error::Io(io::Error::new( - io::ErrorKind::Other, - "SimpleHalSpiDevice read transaction error", - )) - })?; + self.bus.read(read)?; } embedded_hal::spi::Operation::Write(write) => { - self.bus.write(write).map_err(|_| { - Error::Io(io::Error::new( - io::ErrorKind::Other, - "SimpleHalSpiDevice write transaction error", - )) - })?; + self.bus.write(write)?; } embedded_hal::spi::Operation::Transfer(read, write) => { - self.bus.transfer(read, write).map_err(|_| { - Error::Io(io::Error::new( - io::ErrorKind::Other, - "SimpleHalSpiDevice read/write transaction error", - )) - })?; + self.bus.transfer(read, write)?; } embedded_hal::spi::Operation::TransferInPlace(words) => { - self.bus.transfer_in_place(words).map_err(|_| { - Error::Io(io::Error::new( - io::ErrorKind::Other, - "SimpleHalSpiDevice in-place read/write transaction error", - )) - })?; + self.bus.transfer_in_place(words)?; } embedded_hal::spi::Operation::DelayNs(us) => { embedded_hal::delay::DelayNs::delay_us(&mut Delay::new(), *us);