use super::*;
#[allow(async_fn_in_trait)]
pub trait SimpleDisplayBus: ErrorType {
async fn write_cmds(&mut self, cmd: &[u8]) -> Result<(), Self::Error>;
async fn write_data(&mut self, data: &[u8]) -> Result<(), Self::Error>;
async fn write_cmd_with_params(
&mut self,
cmd: &[u8],
params: &[u8],
) -> Result<(), Self::Error> {
self.write_cmds(cmd).await?;
self.write_data(params).await
}
fn set_reset(&mut self, reset: bool) -> Result<(), DisplayError<Self::Error>> {
let _ = reset;
Err(DisplayError::Unsupported)
}
}
impl<T: SimpleDisplayBus> BusBytesIo for T {
async fn write_cmd_bytes(&mut self, cmd: &[u8]) -> Result<(), Self::Error> {
T::write_cmd(self, cmd).await
}
async fn write_data_bytes(&mut self, data: &[u8]) -> Result<(), Self::Error> {
T::write_data(self, data).await
}
}
impl<T: SimpleDisplayBus> DisplayBus for T {
async fn write_cmd(&mut self, cmd: &[u8]) -> Result<(), Self::Error> {
T::write_cmds(self, cmd).await
}
async fn write_cmd_with_params(
&mut self,
cmd: &[u8],
params: &[u8],
) -> Result<(), Self::Error> {
T::write_cmd_with_params(self, cmd, params).await
}
async fn write_pixels(
&mut self,
cmd: &[u8],
data: &[u8],
_metadata: Metadata,
) -> Result<(), DisplayError<Self::Error>> {
T::write_cmd_with_params(self, cmd, data)
.await
.map_err(DisplayError::BusError)
}
fn set_reset(&mut self, reset: bool) -> Result<(), DisplayError<Self::Error>> {
T::set_reset(self, reset)
}
}