Update I2C implementation of embedded-hal 1.x to 1.0.0-alpha.6

This commit is contained in:
Jan Niehusmann 2021-11-19 21:41:30 +00:00
parent 76aff05cec
commit 0f3bb8e88c
2 changed files with 26 additions and 1 deletions

View file

@ -79,6 +79,31 @@ pub enum Error {
AddressReserved(u16),
}
#[cfg(feature = "eh1_0_alpha")]
impl eh1_0_alpha::i2c::Error for Error {
fn kind(&self) -> eh1_0_alpha::i2c::ErrorKind {
match &self {
Error::Abort(v) if v & 1<<12 != 0 // ARB_LOST
=> eh1_0_alpha::i2c::ErrorKind::ArbitrationLoss,
Error::Abort(v) if v & 1<<7 != 0 // ABRT_SBYTE_ACKDET
=> eh1_0_alpha::i2c::ErrorKind::Bus,
Error::Abort(v) if v & 1<<6 != 0 // ABRT_HS_ACKDET
=> eh1_0_alpha::i2c::ErrorKind::Bus,
Error::Abort(v) if v & 1<<4 != 0 // ABRT_GCALL_NOACK
=> eh1_0_alpha::i2c::ErrorKind::NoAcknowledge(eh1_0_alpha::i2c::NoAcknowledgeSource::Address),
Error::Abort(v) if v & 1<<3 != 0 // ABRT_TXDATA_NOACK
=> eh1_0_alpha::i2c::ErrorKind::NoAcknowledge(eh1_0_alpha::i2c::NoAcknowledgeSource::Data),
Error::Abort(v) if v & 1<<2 != 0 // ABRT_10ADDR2_NOACK
=> eh1_0_alpha::i2c::ErrorKind::NoAcknowledge(eh1_0_alpha::i2c::NoAcknowledgeSource::Address),
Error::Abort(v) if v & 1<<1 != 0 // ABRT_10ADDR1_NOACK
=> eh1_0_alpha::i2c::ErrorKind::NoAcknowledge(eh1_0_alpha::i2c::NoAcknowledgeSource::Address),
Error::Abort(v) if v & 1<<0 != 0 // ABRT_7B_ADDR_NOACK
=> eh1_0_alpha::i2c::ErrorKind::NoAcknowledge(eh1_0_alpha::i2c::NoAcknowledgeSource::Address),
_ => eh1_0_alpha::i2c::ErrorKind::Other,
}
}
}
/// SCL pin
pub trait SclPin<I2C>: Sealed {}

View file

@ -278,7 +278,7 @@ impl<T: Deref<Target = Block>, PINS> Write for I2C<T, PINS, Controller> {
impl<T: Deref<Target = Block>, PINS> eh1::Write for I2C<T, PINS, Controller> {
type Error = Error;
fn write(&mut self, addr: u8, bytes: &[u8]) -> Result<(), Error> {
fn write(&mut self, addr: u8, bytes: &[u8]) -> Result<(), Self::Error> {
Write::write(self, addr, bytes)
}
}