56 lines
1.4 KiB
Rust
Raw Normal View History

//! Shared bus implementations
2022-07-10 00:49:46 +02:00
use core::fmt::Debug;
use embedded_hal_1::{i2c, spi};
2022-07-10 00:05:57 +02:00
#[cfg(feature = "nightly")]
pub mod asynch;
pub mod blocking;
2022-07-10 00:05:57 +02:00
2022-07-19 07:57:39 +02:00
/// Error returned by I2C device implementations in this crate.
2022-07-10 00:05:57 +02:00
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
2022-07-18 20:01:39 +02:00
pub enum I2cDeviceError<BUS> {
2022-07-19 07:57:39 +02:00
/// An operation on the inner I2C bus failed.
2022-07-10 00:05:57 +02:00
I2c(BUS),
}
2022-07-18 20:01:39 +02:00
impl<BUS> i2c::Error for I2cDeviceError<BUS>
2022-07-10 00:49:46 +02:00
where
BUS: i2c::Error + Debug,
{
fn kind(&self) -> i2c::ErrorKind {
match self {
Self::I2c(e) => e.kind(),
}
}
}
2022-07-19 07:57:39 +02:00
/// Error returned by SPI device implementations in this crate.
2022-07-10 00:05:57 +02:00
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
2023-07-04 19:53:06 +02:00
#[non_exhaustive]
2022-07-18 20:01:39 +02:00
pub enum SpiDeviceError<BUS, CS> {
2022-07-19 07:57:39 +02:00
/// An operation on the inner SPI bus failed.
2022-07-10 00:05:57 +02:00
Spi(BUS),
2022-07-19 07:57:39 +02:00
/// Setting the value of the Chip Select (CS) pin failed.
2022-07-10 00:05:57 +02:00
Cs(CS),
2023-07-04 19:53:06 +02:00
/// DelayUs operations are not supported when the `time` Cargo feature is not enabled.
DelayUsNotSupported,
2022-07-10 00:05:57 +02:00
}
2022-07-10 00:49:46 +02:00
2022-07-18 20:01:39 +02:00
impl<BUS, CS> spi::Error for SpiDeviceError<BUS, CS>
2022-07-10 00:49:46 +02:00
where
BUS: spi::Error + Debug,
CS: Debug,
{
fn kind(&self) -> spi::ErrorKind {
match self {
Self::Spi(e) => e.kind(),
Self::Cs(_) => spi::ErrorKind::Other,
2023-07-04 19:53:06 +02:00
Self::DelayUsNotSupported => spi::ErrorKind::Other,
2022-07-10 00:49:46 +02:00
}
}
}