stm32f1xx_hal/i2c/
common.rs1#[derive(Clone, Copy, Debug, Eq, PartialEq)]
2pub enum Address {
3 Seven(u8),
4 Ten(u16),
5}
6
7impl From<u8> for Address {
8 fn from(value: u8) -> Self {
9 Self::Seven(value)
10 }
11}
12
13impl From<u16> for Address {
14 fn from(value: u16) -> Self {
15 Self::Ten(value)
16 }
17}
18
19pub use embedded_hal::i2c::NoAcknowledgeSource;
20
21#[derive(Debug, Eq, PartialEq, Copy, Clone)]
22#[non_exhaustive]
23pub enum Error {
24 Overrun,
26 NoAcknowledge(NoAcknowledgeSource),
28 Timeout,
29 Bus,
32 Crc,
33 ArbitrationLoss,
35 }
38
39impl Error {
40 pub(crate) fn nack_addr(self) -> Self {
41 match self {
42 Error::NoAcknowledge(NoAcknowledgeSource::Unknown) => {
43 Error::NoAcknowledge(NoAcknowledgeSource::Address)
44 }
45 e => e,
46 }
47 }
48 pub(crate) fn nack_data(self) -> Self {
49 match self {
50 Error::NoAcknowledge(NoAcknowledgeSource::Unknown) => {
51 Error::NoAcknowledge(NoAcknowledgeSource::Data)
52 }
53 e => e,
54 }
55 }
56}
57
58use embedded_hal::i2c::ErrorKind;
59impl embedded_hal::i2c::Error for Error {
60 fn kind(&self) -> ErrorKind {
61 match *self {
62 Self::Overrun => ErrorKind::Overrun,
63 Self::Bus => ErrorKind::Bus,
64 Self::ArbitrationLoss => ErrorKind::ArbitrationLoss,
65 Self::NoAcknowledge(nack) => ErrorKind::NoAcknowledge(nack),
66 Self::Crc | Self::Timeout => ErrorKind::Other,
67 }
68 }
69}
70
71pub(crate) type Hal1Operation<'a> = embedded_hal::i2c::Operation<'a>;
72pub(crate) type Hal02Operation<'a> = embedded_hal_02::blocking::i2c::Operation<'a>;