1#[derive(Debug, Copy, Clone, Eq, PartialEq)]
2pub enum CanError {
3 Overrun,
5 Bit,
9 Stuff,
11 Crc,
14 Form,
16 Acknowledge,
18 BusOff,
20 BusPassive,
22 BusWarning,
24 Timeout,
26}
27
28impl core::fmt::Display for CanError {
29 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
30 match self {
31 Self::Overrun => write!(f, "The peripheral receive buffer was overrun"),
32 Self::Bit => write!(f, "Bit value that is monitored differs from the bit value sent"),
33 Self::Stuff => write!(f, "Sixth consecutive equal bits detected"),
34 Self::Crc => write!(f, "Calculated CRC sequence does not equal the received one"),
35 Self::Form => write!(f, "A fixed-form bit field contains one or more illegal bits"),
36 Self::Acknowledge => write!(f, "Transmitted frame was not acknowledged"),
37 Self::BusOff => write!(f, "The peripheral is in Bus Off mode"),
38 Self::BusPassive => write!(f, "The peripheral is in Bus Passive mode"),
39 Self::BusWarning => write!(f, "A peripheral error counter has reached the Warning threshold"),
40 Self::Timeout => write!(f, "Operation timed out"),
41 }
42 }
43}
44
45impl Into<embedded_can::ErrorKind> for CanError {
46 fn into(self) -> embedded_can::ErrorKind {
47 match self {
48 Self::Overrun => embedded_can::ErrorKind::Overrun,
49 Self::Bit => embedded_can::ErrorKind::Bit,
50 Self::Stuff => embedded_can::ErrorKind::Stuff,
51 Self::Crc => embedded_can::ErrorKind::Crc,
52 Self::Form => embedded_can::ErrorKind::Form,
53 Self::Acknowledge => embedded_can::ErrorKind::Acknowledge,
54 Self::BusOff => embedded_can::ErrorKind::Other,
55 Self::BusPassive => embedded_can::ErrorKind::Other,
56 Self::BusWarning => embedded_can::ErrorKind::Other,
57 Self::Timeout => embedded_can::ErrorKind::Other,
58 }
59 }
60}
61
62impl embedded_can::Error for CanError {
63 fn kind(&self) -> embedded_can::ErrorKind {
64 (*self).into()
65 }
66}
67
68#[derive(PartialEq)]
69pub enum CanMode {
70 Normal,
71 Silent,
72 Loopback,
73 SilentLoopback,
74}
75
76pub(crate) struct CanModeRegs {
77 pub(crate) lbkm: bool,
79 pub(crate) silm: bool,
81}
82
83impl CanMode {
84 pub(crate) fn regs(&self) -> CanModeRegs {
85 match self {
86 CanMode::Normal => CanModeRegs {
87 lbkm: false,
88 silm: false,
89 },
90 CanMode::Silent => CanModeRegs {
91 lbkm: false,
92 silm: true,
93 },
94 CanMode::Loopback => CanModeRegs {
95 lbkm: true,
96 silm: false,
97 },
98 CanMode::SilentLoopback => CanModeRegs { lbkm: true, silm: true },
99 }
100 }
101}
102
103#[derive(Copy, Clone)]
104pub enum CanFifo {
105 Fifo0,
106 Fifo1,
107}
108
109impl CanFifo {
110 pub(crate) fn val(&self) -> usize {
111 match self {
112 CanFifo::Fifo0 => 0,
113 CanFifo::Fifo1 => 1,
114 }
115 }
116
117 pub(crate) fn val_bool(&self) -> bool {
118 match self {
119 CanFifo::Fifo0 => false,
120 CanFifo::Fifo1 => true,
121 }
122 }
123}
124
125#[derive(Debug)]
126pub enum TxStatus {
127 Sent,
129 TimeoutError,
131 ArbitrationError,
133 OtherError,
135}