display_driver/bus/
simple.rs1use super::*;
2
3#[allow(async_fn_in_trait)]
4pub trait SimpleDisplayBus: ErrorType {
14 async fn write_cmds(&mut self, cmd: &[u8]) -> Result<(), Self::Error>;
18
19 async fn write_data(&mut self, data: &[u8]) -> Result<(), Self::Error>;
23
24 async fn write_cmd_with_params(
26 &mut self,
27 cmd: &[u8],
28 params: &[u8],
29 ) -> Result<(), Self::Error> {
30 self.write_cmds(cmd).await?;
31 self.write_data(params).await
32 }
33
34 fn set_reset(&mut self, reset: bool) -> Result<(), DisplayError<Self::Error>> {
40 let _ = reset;
41 Err(DisplayError::Unsupported)
42 }
43}
44
45impl<T: SimpleDisplayBus> BusBytesIo for T {
46 async fn write_cmd_bytes(&mut self, cmd: &[u8]) -> Result<(), Self::Error> {
47 T::write_cmd(self, cmd).await
48 }
49
50 async fn write_data_bytes(&mut self, data: &[u8]) -> Result<(), Self::Error> {
51 T::write_data(self, data).await
52 }
53}
54
55impl<T: SimpleDisplayBus> DisplayBus for T {
56 async fn write_cmd(&mut self, cmd: &[u8]) -> Result<(), Self::Error> {
57 T::write_cmds(self, cmd).await
58 }
59
60 async fn write_cmd_with_params(
61 &mut self,
62 cmd: &[u8],
63 params: &[u8],
64 ) -> Result<(), Self::Error> {
65 T::write_cmd_with_params(self, cmd, params).await
66 }
67
68 async fn write_pixels(
69 &mut self,
70 cmd: &[u8],
71 data: &[u8],
72 _metadata: Metadata,
73 ) -> Result<(), DisplayError<Self::Error>> {
74 T::write_cmd_with_params(self, cmd, data)
75 .await
76 .map_err(DisplayError::BusError)
77 }
78
79 fn set_reset(&mut self, reset: bool) -> Result<(), DisplayError<Self::Error>> {
80 T::set_reset(self, reset)
81 }
82}