#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum DmxUartDriverError<E> {
TimeoutError,
DriverError(E),
}
impl<E: core::fmt::Display> core::fmt::Display for DmxUartDriverError<E> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
DmxUartDriverError::TimeoutError => write!(f, "timeout error occurred"),
DmxUartDriverError::DriverError(error) => error.fmt(f),
}
}
}
#[cfg(feature = "std")]
impl<E: core::fmt::Display + core::fmt::Debug> std::error::Error for DmxUartDriverError<E> {}
impl<E> From<E> for DmxUartDriverError<E> {
fn from(value: E) -> Self {
Self::DriverError(value)
}
}
pub trait DmxUartDriver {
type DriverError;
}
pub trait DmxRecvUartDriver: DmxUartDriver {
fn read_frames(
&mut self,
buffer: &mut [u8],
timeout_us: u32,
) -> Result<usize, DmxUartDriverError<Self::DriverError>>;
fn read_frames_no_break(
&mut self,
buffer: &mut [u8],
timeout_us: u32,
) -> Result<usize, DmxUartDriverError<Self::DriverError>>;
}
pub trait DmxRespUartDriver: DmxUartDriver {
fn write_frames(
&mut self,
buffer: &[u8],
) -> Result<usize, DmxUartDriverError<Self::DriverError>>;
fn write_frames_no_break(
&mut self,
buffer: &[u8],
) -> Result<usize, DmxUartDriverError<Self::DriverError>>;
}