use embedded_hal as hal;
use hal::blocking::i2c::{Read, Write};
use sensirion_i2c::i2c;
#[derive(Debug, PartialEq)]
#[cfg_attr(feature = "thiserror", derive(thiserror::Error))]
pub enum Error<E> {
#[cfg_attr(feature = "thiserror", error("I2C: {0}"))]
I2c(E),
#[cfg_attr(feature = "thiserror", error("CRC"))]
Crc,
#[cfg_attr(feature = "thiserror", error("Self Test"))]
SelfTest,
#[cfg_attr(feature = "thiserror", error("Not Allowed"))]
NotAllowed,
#[cfg_attr(feature = "thiserror", error("Internal"))]
Internal
}
impl<E, I2cWrite, I2cRead> From<i2c::Error<I2cWrite, I2cRead>> for Error<E>
where
I2cWrite: Write<Error = E>,
I2cRead: Read<Error = E>,
{
fn from(err: i2c::Error<I2cWrite, I2cRead>) -> Self {
match err {
i2c::Error::Crc => Error::Crc,
i2c::Error::I2cWrite(e) => Error::I2c(e),
i2c::Error::I2cRead(e) => Error::I2c(e),
}
}
}