dmx_rdm/
dmx_uart_driver.rs1#[derive(Debug)]
2#[cfg_attr(feature = "defmt", derive(defmt::Format))]
3pub enum DmxUartDriverError<E> {
4 TimeoutError,
8 DriverError(E),
10}
11
12impl<E: core::fmt::Display> core::fmt::Display for DmxUartDriverError<E> {
13 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
14 match self {
15 DmxUartDriverError::TimeoutError => write!(f, "timeout error occurred"),
16 DmxUartDriverError::DriverError(error) => error.fmt(f),
17 }
18 }
19}
20
21#[cfg(feature = "std")]
22impl<E: core::fmt::Display + core::fmt::Debug> std::error::Error for DmxUartDriverError<E> {}
23
24impl<E> From<E> for DmxUartDriverError<E> {
25 fn from(value: E) -> Self {
26 Self::DriverError(value)
27 }
28}
29
30pub trait DmxUartDriver {
31 type DriverError;
32}
33
34pub trait DmxRecvUartDriver: DmxUartDriver {
38 fn read_frames(
41 &mut self,
42 buffer: &mut [u8],
43 timeout_us: u32,
44 ) -> Result<usize, DmxUartDriverError<Self::DriverError>>;
45
46 fn read_frames_no_break(
49 &mut self,
50 buffer: &mut [u8],
51 timeout_us: u32,
52 ) -> Result<usize, DmxUartDriverError<Self::DriverError>>;
53}
54
55pub trait DmxRespUartDriver: DmxUartDriver {
59 fn write_frames(
62 &mut self,
63 buffer: &[u8],
64 ) -> Result<usize, DmxUartDriverError<Self::DriverError>>;
65
66 fn write_frames_no_break(
69 &mut self,
70 buffer: &[u8],
71 ) -> Result<usize, DmxUartDriverError<Self::DriverError>>;
72}