1 | //! Shared bus implementations |
2 | use core::fmt::Debug; |
3 | |
4 | use embedded_hal_1::{i2c, spi}; |
5 | |
6 | pub mod asynch; |
7 | pub mod blocking; |
8 | |
9 | /// Error returned by I2C device implementations in this crate. |
10 | #[derive (Copy, Clone, Eq, PartialEq, Debug)] |
11 | #[cfg_attr (feature = "defmt" , derive(defmt::Format))] |
12 | pub enum I2cDeviceError<BUS> { |
13 | /// An operation on the inner I2C bus failed. |
14 | I2c(BUS), |
15 | /// Configuration of the inner I2C bus failed. |
16 | Config, |
17 | } |
18 | |
19 | impl<BUS> i2c::Error for I2cDeviceError<BUS> |
20 | where |
21 | BUS: i2c::Error + Debug, |
22 | { |
23 | fn kind(&self) -> i2c::ErrorKind { |
24 | match self { |
25 | Self::I2c(e: &BUS) => e.kind(), |
26 | Self::Config => i2c::ErrorKind::Other, |
27 | } |
28 | } |
29 | } |
30 | |
31 | /// Error returned by SPI device implementations in this crate. |
32 | #[derive (Copy, Clone, Eq, PartialEq, Debug)] |
33 | #[cfg_attr (feature = "defmt" , derive(defmt::Format))] |
34 | #[non_exhaustive ] |
35 | pub enum SpiDeviceError<BUS, CS> { |
36 | /// An operation on the inner SPI bus failed. |
37 | Spi(BUS), |
38 | /// Setting the value of the Chip Select (CS) pin failed. |
39 | Cs(CS), |
40 | /// Delay operations are not supported when the `time` Cargo feature is not enabled. |
41 | DelayNotSupported, |
42 | /// The SPI bus could not be configured. |
43 | Config, |
44 | } |
45 | |
46 | impl<BUS, CS> spi::Error for SpiDeviceError<BUS, CS> |
47 | where |
48 | BUS: spi::Error + Debug, |
49 | CS: Debug, |
50 | { |
51 | fn kind(&self) -> spi::ErrorKind { |
52 | match self { |
53 | Self::Spi(e: &BUS) => e.kind(), |
54 | Self::Cs(_) => spi::ErrorKind::Other, |
55 | Self::DelayNotSupported => spi::ErrorKind::Other, |
56 | Self::Config => spi::ErrorKind::Other, |
57 | } |
58 | } |
59 | } |
60 | |