From c2ceb78540f32a9ff3608e9dc54173e2a2c3fb04 Mon Sep 17 00:00:00 2001 From: Diego Barrios Romero Date: Tue, 13 Jul 2021 23:02:08 +0200 Subject: [PATCH 1/7] Raise MSRV to Rust 1.40.0 --- .github/bors.toml | 4 ++-- .github/workflows/ci.yml | 2 +- .github/workflows/test.yml | 2 +- README.md | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/bors.toml b/.github/bors.toml index cd9fa23ed..19e66e614 100644 --- a/.github/bors.toml +++ b/.github/bors.toml @@ -5,8 +5,8 @@ status = [ "ci-linux (stable, x86_64-unknown-linux-gnu)", "ci-linux (stable, thumbv6m-none-eabi)", "ci-linux (stable, thumbv7m-none-eabi)", - "ci-linux (1.35.0, x86_64-unknown-linux-gnu)", + "ci-linux (1.40.0, x86_64-unknown-linux-gnu)", "ci-linux-test (stable)", - "ci-linux-test (1.36.0, x86_64-unknown-linux-gnu)", + "ci-linux-test (1.40.0, x86_64-unknown-linux-gnu)", "fmt", ] diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 946f35b09..11153d04f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,7 @@ jobs: include: # Test MSRV - - rust: 1.35.0 + - rust: 1.40.0 TARGET: x86_64-unknown-linux-gnu # Test nightly but don't fail diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7f10361ed..1a49c83c4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,7 +16,7 @@ jobs: rust: [stable] include: - - rust: 1.36.0 # Higher than the MSRV due to dependencies. + - rust: 1.40.0 TARGET: x86_64-unknown-linux-gnu # Test nightly but don't fail diff --git a/README.md b/README.md index 5fc04539d..3d4df0664 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ [![crates.io](https://img.shields.io/crates/d/embedded-hal.svg)](https://crates.io/crates/embedded-hal) [![crates.io](https://img.shields.io/crates/v/embedded-hal.svg)](https://crates.io/crates/embedded-hal) [![Documentation](https://docs.rs/embedded-hal/badge.svg)](https://docs.rs/embedded-hal) -![Minimum Supported Rust Version](https://img.shields.io/badge/rustc-1.35+-blue.svg) +![Minimum Supported Rust Version](https://img.shields.io/badge/rustc-1.40+-blue.svg) # `embedded-hal` @@ -108,7 +108,7 @@ As stated before, `embedded-hal` `-alpha` versions are _not guaranteed_ to be co ## Minimum Supported Rust Version (MSRV) -This crate is guaranteed to compile on stable Rust 1.35 and up. It *might* +This crate is guaranteed to compile on stable Rust 1.40 and up. It *might* compile with older versions but that may change in any new patch release. ## License From d0bd316ebc8616e05d7fba4d979fa845e98a8d76 Mon Sep 17 00:00:00 2001 From: Diego Barrios Romero Date: Tue, 31 Aug 2021 21:43:53 +0200 Subject: [PATCH 2/7] Add error traits for communication interfaces --- CHANGELOG.md | 4 +++ src/fmt.rs | 3 +- src/i2c.rs | 82 ++++++++++++++++++++++++++++++++++-------- src/lib.rs | 31 ++++++---------- src/serial/blocking.rs | 2 +- src/serial/mod.rs | 55 ++++++++++++++++++++++++++++ src/serial/nb.rs | 4 +-- src/spi/blocking.rs | 8 ++--- src/spi/mod.rs | 60 +++++++++++++++++++++++++++++++ src/spi/nb.rs | 2 +- 10 files changed, 207 insertions(+), 44 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 495576757..a268cf32d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Added - Added `IoPin` trait for pins that can change between being inputs or outputs dynamically. +- `Error` traits for SPI, I2C and Serial traits. The error types used in those must + implement these `Error` traits, which implies providing a conversion to a common + set of error kinds. Generic drivers using these interfaces can then convert the errors + to this common set to act upon them. - Added `Debug` to all spi mode types. - Add impls of all traits for references (`&T` or `&mut T` depending on the trait) when `T` implements the trait. diff --git a/src/fmt.rs b/src/fmt.rs index 220c55e09..8d5c141ea 100644 --- a/src/fmt.rs +++ b/src/fmt.rs @@ -3,7 +3,8 @@ //! TODO write example of usage use core::fmt::{Result, Write}; -impl Write for dyn crate::serial::nb::Write + '_ +impl Write + for dyn crate::serial::nb::Write + '_ where Word: From, { diff --git a/src/i2c.rs b/src/i2c.rs index 1466b7f33..2215643da 100644 --- a/src/i2c.rs +++ b/src/i2c.rs @@ -26,13 +26,13 @@ //! Here is an example of an embedded-hal implementation of the `Write` trait //! for both modes: //! ``` -//! # use embedded_hal::i2c::{SevenBitAddress, TenBitAddress, blocking::Write}; +//! # use embedded_hal::i2c::{ErrorKind, SevenBitAddress, TenBitAddress, blocking::Write}; //! /// I2C0 hardware peripheral which supports both 7-bit and 10-bit addressing. //! pub struct I2c0; //! //! impl Write for I2c0 //! { -//! # type Error = (); +//! # type Error = ErrorKind; //! # //! fn write(&mut self, addr: u8, output: &[u8]) -> Result<(), Self::Error> { //! // ... @@ -42,7 +42,7 @@ //! //! impl Write for I2c0 //! { -//! # type Error = (); +//! # type Error = ErrorKind; //! # //! fn write(&mut self, addr: u16, output: &[u8]) -> Result<(), Self::Error> { //! // ... @@ -56,14 +56,14 @@ //! For demonstration purposes the address mode parameter has been omitted in this example. //! //! ``` -//! # use embedded_hal::i2c::blocking::WriteRead; +//! # use embedded_hal::i2c::{blocking::WriteRead, Error}; //! const ADDR: u8 = 0x15; //! # const TEMP_REGISTER: u8 = 0x1; //! pub struct TemperatureSensorDriver { //! i2c: I2C, //! } //! -//! impl TemperatureSensorDriver +//! impl TemperatureSensorDriver //! where //! I2C: WriteRead, //! { @@ -79,14 +79,14 @@ //! ### Device driver compatible only with 10-bit addresses //! //! ``` -//! # use embedded_hal::i2c::{TenBitAddress, blocking::WriteRead}; +//! # use embedded_hal::i2c::{Error, TenBitAddress, blocking::WriteRead}; //! const ADDR: u16 = 0x158; //! # const TEMP_REGISTER: u8 = 0x1; //! pub struct TemperatureSensorDriver { //! i2c: I2C, //! } //! -//! impl TemperatureSensorDriver +//! impl TemperatureSensorDriver //! where //! I2C: WriteRead, //! { @@ -101,6 +101,58 @@ use crate::private; +/// I2C error +pub trait Error: core::fmt::Debug { + /// Convert error to a generic I2C error kind + /// + /// By using this method, I2C errors freely defined by HAL implementations + /// can be converted to a set of generic I2C errors upon which generic + /// code can act. + fn kind(&self) -> ErrorKind; +} + +/// I2C error kind +/// +/// This represents a common set of I2C operation errors. HAL implementations are +/// free to define more specific or additional error types. However, by providing +/// a mapping to these common I2C errors, generic code can still react to them. +#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] +#[non_exhaustive] +pub enum ErrorKind { + /// An unspecific bus error occurred + Bus, + /// The arbitration was lost, e.g. electrical problems with the clock signal + ArbitrationLoss, + /// A bus operation was not acknowledged, e.g. due to the addressed device not being available on + /// the bus or the device not being ready to process requests at the moment + NoAcknowledge, + /// The peripheral receive buffer was overrun + Overrun, + /// A different error occurred. The original error may contain more information. + Other, +} + +impl Error for ErrorKind { + fn kind(&self) -> ErrorKind { + *self + } +} + +impl core::fmt::Display for ErrorKind { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Self::Bus => write!(f, "An unspecific bus error occurred"), + Self::ArbitrationLoss => write!(f, "The arbitration was lost"), + Self::NoAcknowledge => write!(f, "A bus operation was not acknowledged"), + Self::Overrun => write!(f, "The peripheral receive buffer was overrun"), + Self::Other => write!( + f, + "A different error occurred. The original error may contain more information" + ), + } + } +} + /// Address mode (7-bit / 10-bit) /// /// Note: This trait is sealed and should not be implemented outside of this crate. @@ -119,12 +171,12 @@ impl AddressMode for TenBitAddress {} /// Blocking I2C traits pub mod blocking { - use super::{AddressMode, SevenBitAddress}; + use super::{AddressMode, Error, SevenBitAddress}; /// Blocking read pub trait Read { /// Error type - type Error: core::fmt::Debug; + type Error: Error; /// Reads enough bytes from slave with `address` to fill `buffer` /// @@ -158,7 +210,7 @@ pub mod blocking { /// Blocking write pub trait Write { /// Error type - type Error: core::fmt::Debug; + type Error: Error; /// Writes bytes to slave with address `address` /// @@ -190,7 +242,7 @@ pub mod blocking { /// Blocking write (iterator version) pub trait WriteIter { /// Error type - type Error: core::fmt::Debug; + type Error: Error; /// Writes bytes to slave with address `address` /// @@ -216,7 +268,7 @@ pub mod blocking { /// Blocking write + read pub trait WriteRead { /// Error type - type Error: core::fmt::Debug; + type Error: Error; /// Writes bytes to slave with address `address` and then reads enough bytes to fill `buffer` *in a /// single transaction* @@ -264,7 +316,7 @@ pub mod blocking { /// Blocking write (iterator version) + read pub trait WriteIterRead { /// Error type - type Error: core::fmt::Debug; + type Error: Error; /// Writes bytes to slave with address `address` and then reads enough bytes to fill `buffer` *in a /// single transaction* @@ -314,7 +366,7 @@ pub mod blocking { /// This allows combining operations within an I2C transaction. pub trait Transactional { /// Error type - type Error: core::fmt::Debug; + type Error: Error; /// Execute the provided operations on the I2C bus. /// @@ -353,7 +405,7 @@ pub mod blocking { /// This allows combining operation within an I2C transaction. pub trait TransactionalIter { /// Error type - type Error: core::fmt::Debug; + type Error: Error; /// Execute the provided operations on the I2C bus (iterator version). /// diff --git a/src/lib.rs b/src/lib.rs index f1582259e..37e6335f1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -143,24 +143,16 @@ //! // convenience type alias //! pub type Serial1 = Serial; //! -//! /// Serial interface error -//! #[derive(Debug)] -//! pub enum Error { -//! /// Buffer overrun -//! Overrun, -//! // omitted: other error variants -//! } -//! //! impl hal::serial::nb::Read for Serial { -//! type Error = Error; +//! type Error = hal::serial::ErrorKind; //! -//! fn read(&mut self) -> nb::Result { +//! fn read(&mut self) -> nb::Result { //! // read the status register //! let isr = self.usart.sr.read(); //! //! if isr.ore().bit_is_set() { //! // Error: Buffer overrun -//! Err(nb::Error::Other(Error::Overrun)) +//! Err(nb::Error::Other(Self::Error::Overrun)) //! } //! // omitted: checks for other errors //! else if isr.rxne().bit_is_set() { @@ -174,14 +166,14 @@ //! } //! //! impl hal::serial::nb::Write for Serial { -//! type Error = Error; +//! type Error = hal::serial::ErrorKind; //! -//! fn write(&mut self, byte: u8) -> nb::Result<(), Error> { +//! fn write(&mut self, byte: u8) -> nb::Result<(), Self::Error> { //! // Similar to the `read` implementation //! # Ok(()) //! } //! -//! fn flush(&mut self) -> nb::Result<(), Error> { +//! fn flush(&mut self) -> nb::Result<(), Self::Error> { //! // Similar to the `read` implementation //! # Ok(()) //! } @@ -327,12 +319,11 @@ //! use embedded_hal as hal; //! use hal::nb; //! -//! use hal::serial::nb::Write; -//! use ::core::convert::Infallible; +//! use hal::serial::{ErrorKind, nb::Write}; //! //! fn flush(serial: &mut S, cb: &mut CircularBuffer) //! where -//! S: hal::serial::nb::Write, +//! S: hal::serial::nb::Write, //! { //! loop { //! if let Some(byte) = cb.peek() { @@ -397,9 +388,9 @@ //! # } //! # struct Serial1; //! # impl hal::serial::nb::Write for Serial1 { -//! # type Error = Infallible; -//! # fn write(&mut self, _: u8) -> nb::Result<(), Infallible> { Err(::nb::Error::WouldBlock) } -//! # fn flush(&mut self) -> nb::Result<(), Infallible> { Err(::nb::Error::WouldBlock) } +//! # type Error = ErrorKind; +//! # fn write(&mut self, _: u8) -> nb::Result<(), Self::Error> { Err(::nb::Error::WouldBlock) } +//! # fn flush(&mut self) -> nb::Result<(), Self::Error> { Err(::nb::Error::WouldBlock) } //! # } //! # struct CircularBuffer; //! # impl CircularBuffer { diff --git a/src/serial/blocking.rs b/src/serial/blocking.rs index df9bc8e90..4b2900a0f 100644 --- a/src/serial/blocking.rs +++ b/src/serial/blocking.rs @@ -7,7 +7,7 @@ /// Write half of a serial interface (blocking variant) pub trait Write { /// The type of error that can occur when writing - type Error: core::fmt::Debug; + type Error: crate::serial::Error; /// Writes a slice, blocking until everything has been written /// diff --git a/src/serial/mod.rs b/src/serial/mod.rs index cdb6e5f1c..e33f45773 100644 --- a/src/serial/mod.rs +++ b/src/serial/mod.rs @@ -2,3 +2,58 @@ pub mod blocking; pub mod nb; + +/// Serial error +pub trait Error: core::fmt::Debug { + /// Convert error to a generic serial error kind + /// + /// By using this method, serial errors freely defined by HAL implementations + /// can be converted to a set of generic serial errors upon which generic + /// code can act. + fn kind(&self) -> ErrorKind; +} + +/// Serial error kind +/// +/// This represents a common set of serial operation errors. HAL implementations are +/// free to define more specific or additional error types. However, by providing +/// a mapping to these common serial errors, generic code can still react to them. +#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] +#[non_exhaustive] +pub enum ErrorKind { + /// The peripheral receive buffer was overrun. + Overrun, + /// Received data does not conform to the peripheral configuration. + /// Can be caused by a misconfigured device on either end of the serial line. + FrameFormat, + /// Parity check failed. + Parity, + /// Serial line is too noisy to read valid data. + Noise, + /// A different error occurred. The original error may contain more information. + Other, +} + +impl Error for ErrorKind { + fn kind(&self) -> ErrorKind { + *self + } +} + +impl core::fmt::Display for ErrorKind { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Self::Overrun => write!(f, "The peripheral receive buffer was overrun"), + Self::Parity => write!(f, "Parity check failed"), + Self::Noise => write!(f, "Serial line is too noisy to read valid data"), + Self::FrameFormat => write!( + f, + "Received data does not conform to the peripheral configuration" + ), + Self::Other => write!( + f, + "A different error occurred. The original error may contain more information" + ), + } + } +} diff --git a/src/serial/nb.rs b/src/serial/nb.rs index d11475ea5..13a845d10 100644 --- a/src/serial/nb.rs +++ b/src/serial/nb.rs @@ -6,7 +6,7 @@ /// This can be encoded in this trait via the `Word` type parameter. pub trait Read { /// Read error - type Error: core::fmt::Debug; + type Error: crate::serial::Error; /// Reads a single word from the serial interface fn read(&mut self) -> nb::Result; @@ -23,7 +23,7 @@ impl, Word> Read for &mut T { /// Write half of a serial interface pub trait Write { /// Write error - type Error: core::fmt::Debug; + type Error: crate::serial::Error; /// Writes a single word to the serial interface fn write(&mut self, word: Word) -> nb::Result<(), Self::Error>; diff --git a/src/spi/blocking.rs b/src/spi/blocking.rs index 8cc4c1107..b98207277 100644 --- a/src/spi/blocking.rs +++ b/src/spi/blocking.rs @@ -7,7 +7,7 @@ /// Blocking transfer pub trait Transfer { /// Error type - type Error: core::fmt::Debug; + type Error: crate::spi::Error; /// Writes and reads simultaneously. The contents of `words` are /// written to the slave, and the received words are stored into the same @@ -26,7 +26,7 @@ impl, W> Transfer for &mut T { /// Blocking write pub trait Write { /// Error type - type Error: core::fmt::Debug; + type Error: crate::spi::Error; /// Writes `words` to the slave, ignoring all the incoming words fn write(&mut self, words: &[W]) -> Result<(), Self::Error>; @@ -43,7 +43,7 @@ impl, W> Write for &mut T { /// Blocking write (iterator version) pub trait WriteIter { /// Error type - type Error: core::fmt::Debug; + type Error: crate::spi::Error; /// Writes `words` to the slave, ignoring all the incoming words fn write_iter(&mut self, words: WI) -> Result<(), Self::Error> @@ -77,7 +77,7 @@ pub enum Operation<'a, W: 'static> { /// as part of a single SPI transaction pub trait Transactional { /// Associated error type - type Error: core::fmt::Debug; + type Error: crate::spi::Error; /// Execute the provided transactions fn exec<'a>(&mut self, operations: &mut [Operation<'a, W>]) -> Result<(), Self::Error>; diff --git a/src/spi/mod.rs b/src/spi/mod.rs index 0a99e9379..f62c4a834 100644 --- a/src/spi/mod.rs +++ b/src/spi/mod.rs @@ -53,3 +53,63 @@ pub const MODE_3: Mode = Mode { polarity: Polarity::IdleHigh, phase: Phase::CaptureOnSecondTransition, }; + +/// SPI error +pub trait Error: core::fmt::Debug { + /// Convert error to a generic SPI error kind + /// + /// By using this method, SPI errors freely defined by HAL implementations + /// can be converted to a set of generic SPI errors upon which generic + /// code can act. + fn kind(&self) -> ErrorKind; +} + +/// SPI error kind +/// +/// This represents a common set of SPI operation errors. HAL implementations are +/// free to define more specific or additional error types. However, by providing +/// a mapping to these common SPI errors, generic code can still react to them. +#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] +#[non_exhaustive] +pub enum ErrorKind { + /// An unspecific bus error occurred + Bus, + /// The peripheral receive buffer was overrun + Overrun, + /// Multiple devices on the SPI bus are trying across each other, e.g. in a multi-master setup + ModeFault, + /// CRC does not match the received data + Crc, + /// Received data does not conform to the peripheral configuration + FrameFormat, + /// A different error occurred. The original error may contain more information. + Other, +} + +impl Error for ErrorKind { + fn kind(&self) -> ErrorKind { + *self + } +} + +impl core::fmt::Display for ErrorKind { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Self::Bus => write!(f, "An unspecific bus error occurred"), + Self::Overrun => write!(f, "The peripheral receive buffer was overrun"), + Self::ModeFault => write!( + f, + "Multiple devices on the SPI bus are trying across each other" + ), + Self::Crc => write!(f, "CRC does not match the received data"), + Self::FrameFormat => write!( + f, + "Received data does not conform to the peripheral configuration" + ), + Self::Other => write!( + f, + "A different error occurred. The original error may contain more information" + ), + } + } +} diff --git a/src/spi/nb.rs b/src/spi/nb.rs index 675d15d81..c7d377ef9 100644 --- a/src/spi/nb.rs +++ b/src/spi/nb.rs @@ -18,7 +18,7 @@ /// `Word` types to allow operation in both modes. pub trait FullDuplex { /// An enumeration of SPI errors - type Error: core::fmt::Debug; + type Error: crate::spi::Error; /// Reads the word stored in the shift register /// From 5531e5626f18845897d3b72d1ebb3e82f2f32412 Mon Sep 17 00:00:00 2001 From: Diego Barrios Romero Date: Thu, 2 Sep 2021 22:31:43 +0200 Subject: [PATCH 3/7] Improve documentation of I2C bus error --- src/i2c.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/i2c.rs b/src/i2c.rs index 2215643da..281e6fd02 100644 --- a/src/i2c.rs +++ b/src/i2c.rs @@ -119,7 +119,7 @@ pub trait Error: core::fmt::Debug { #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] #[non_exhaustive] pub enum ErrorKind { - /// An unspecific bus error occurred + /// Bus error occurred. e.g. A START or a STOP condition is detected and is not located after a multiple of 9 SCL clock pulses. Bus, /// The arbitration was lost, e.g. electrical problems with the clock signal ArbitrationLoss, @@ -141,7 +141,7 @@ impl Error for ErrorKind { impl core::fmt::Display for ErrorKind { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match self { - Self::Bus => write!(f, "An unspecific bus error occurred"), + Self::Bus => write!(f, "Bus error occurred"), Self::ArbitrationLoss => write!(f, "The arbitration was lost"), Self::NoAcknowledge => write!(f, "A bus operation was not acknowledged"), Self::Overrun => write!(f, "The peripheral receive buffer was overrun"), From 40b571da8a0e955eb3037d650d883d1431b63771 Mon Sep 17 00:00:00 2001 From: Diego Barrios Romero Date: Thu, 2 Sep 2021 22:33:10 +0200 Subject: [PATCH 4/7] Remove SPI unspecific bus error --- src/spi/mod.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/spi/mod.rs b/src/spi/mod.rs index f62c4a834..c9760d4cf 100644 --- a/src/spi/mod.rs +++ b/src/spi/mod.rs @@ -72,8 +72,6 @@ pub trait Error: core::fmt::Debug { #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] #[non_exhaustive] pub enum ErrorKind { - /// An unspecific bus error occurred - Bus, /// The peripheral receive buffer was overrun Overrun, /// Multiple devices on the SPI bus are trying across each other, e.g. in a multi-master setup @@ -95,7 +93,6 @@ impl Error for ErrorKind { impl core::fmt::Display for ErrorKind { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match self { - Self::Bus => write!(f, "An unspecific bus error occurred"), Self::Overrun => write!(f, "The peripheral receive buffer was overrun"), Self::ModeFault => write!( f, From 596ba882cb792cab7ed5e144a7f8e69162204eb2 Mon Sep 17 00:00:00 2001 From: Diego Barrios Romero Date: Fri, 17 Sep 2021 15:07:56 +0200 Subject: [PATCH 5/7] Improve SPI mode fault documentation --- src/spi/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/spi/mod.rs b/src/spi/mod.rs index c9760d4cf..d6966849a 100644 --- a/src/spi/mod.rs +++ b/src/spi/mod.rs @@ -74,7 +74,7 @@ pub trait Error: core::fmt::Debug { pub enum ErrorKind { /// The peripheral receive buffer was overrun Overrun, - /// Multiple devices on the SPI bus are trying across each other, e.g. in a multi-master setup + /// Multiple devices on the SPI bus are trying to drive the slave select pin, e.g. in a multi-master setup ModeFault, /// CRC does not match the received data Crc, @@ -96,7 +96,7 @@ impl core::fmt::Display for ErrorKind { Self::Overrun => write!(f, "The peripheral receive buffer was overrun"), Self::ModeFault => write!( f, - "Multiple devices on the SPI bus are trying across each other" + "Multiple devices on the SPI bus are trying to drive the slave select pin" ), Self::Crc => write!(f, "CRC does not match the received data"), Self::FrameFormat => write!( From 1f4fea94bd0d2e07c26187086a92dfcbd38971b6 Mon Sep 17 00:00:00 2001 From: Diego Barrios Romero Date: Mon, 4 Oct 2021 11:18:26 +0200 Subject: [PATCH 6/7] Remove SPI ErrorKind::Crc variant --- src/spi/mod.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/spi/mod.rs b/src/spi/mod.rs index d6966849a..c367e70d8 100644 --- a/src/spi/mod.rs +++ b/src/spi/mod.rs @@ -76,8 +76,6 @@ pub enum ErrorKind { Overrun, /// Multiple devices on the SPI bus are trying to drive the slave select pin, e.g. in a multi-master setup ModeFault, - /// CRC does not match the received data - Crc, /// Received data does not conform to the peripheral configuration FrameFormat, /// A different error occurred. The original error may contain more information. @@ -98,7 +96,6 @@ impl core::fmt::Display for ErrorKind { f, "Multiple devices on the SPI bus are trying to drive the slave select pin" ), - Self::Crc => write!(f, "CRC does not match the received data"), Self::FrameFormat => write!( f, "Received data does not conform to the peripheral configuration" From d870969f0234f1ad2bc809be520bf5b2c3673e8c Mon Sep 17 00:00:00 2001 From: Diego Barrios Romero Date: Mon, 4 Oct 2021 11:18:58 +0200 Subject: [PATCH 7/7] Split I2C ErrorKind::NoAcknowledge into NoAcknowledgeAddress and NoAcknowledgeData --- src/i2c.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/i2c.rs b/src/i2c.rs index 281e6fd02..0dbda4256 100644 --- a/src/i2c.rs +++ b/src/i2c.rs @@ -123,9 +123,10 @@ pub enum ErrorKind { Bus, /// The arbitration was lost, e.g. electrical problems with the clock signal ArbitrationLoss, - /// A bus operation was not acknowledged, e.g. due to the addressed device not being available on - /// the bus or the device not being ready to process requests at the moment - NoAcknowledge, + /// The device did not acknowledge its address. The device may be missing. + NoAcknowledgeAddress, + /// The device did not acknowled the data. It may not be ready to process requests at the moment. + NoAcknowledgeData, /// The peripheral receive buffer was overrun Overrun, /// A different error occurred. The original error may contain more information. @@ -143,7 +144,8 @@ impl core::fmt::Display for ErrorKind { match self { Self::Bus => write!(f, "Bus error occurred"), Self::ArbitrationLoss => write!(f, "The arbitration was lost"), - Self::NoAcknowledge => write!(f, "A bus operation was not acknowledged"), + Self::NoAcknowledgeAddress => write!(f, "The device did not acknowledge its address"), + Self::NoAcknowledgeData => write!(f, "The device did not acknowledge the data"), Self::Overrun => write!(f, "The peripheral receive buffer was overrun"), Self::Other => write!( f,