Skip to main content

scd41_embedded/
error.rs

1use embedded_hal::i2c as ehal;
2
3/// Driver error.
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum Error<E> {
6    /// Underlying I2C bus error.
7    I2c(E),
8    /// CRC mismatch in a sensor response word.
9    Crc,
10    /// Response had an unexpected length.
11    UnexpectedResponse,
12    /// Parameter out of range or invalid for the given command.
13    InvalidInput,
14}
15
16impl<E> From<E> for Error<E> {
17    fn from(e: E) -> Self {
18        Self::I2c(e)
19    }
20}
21
22impl<E> ehal::Error for Error<E>
23where
24    E: ehal::Error,
25{
26    fn kind(&self) -> ehal::ErrorKind {
27        match self {
28            Self::I2c(e) => e.kind(),
29            Self::Crc | Self::UnexpectedResponse | Self::InvalidInput => ehal::ErrorKind::Other,
30        }
31    }
32}