#[cfg(feature = "display-interface")]
mod display_interface_impl;
pub mod qspi_flash;
pub use qspi_flash::QspiFlashBus;
pub mod simple;
pub use simple::SimpleDisplayBus;
use crate::{Area, DisplayError, SolidColor};
pub trait ErrorType {
type Error: core::fmt::Debug;
}
#[derive(Debug, Clone, Copy, Default)]
pub struct FrameControl {
pub first: bool,
pub last: bool,
}
impl FrameControl {
pub fn new_standalone() -> Self {
Self {
first: true,
last: true,
}
}
pub fn new_first() -> Self {
Self {
first: true,
last: false,
}
}
pub fn new_last() -> Self {
Self {
first: false,
last: true,
}
}
}
#[derive(Clone, Copy, Debug)]
pub struct Metadata {
pub area: Option<Area>,
pub frame_control: FrameControl,
}
impl Metadata {
pub fn new_full_screen(w: u16, h: u16) -> Self {
Self {
area: Some(Area::from_origin(w, h)),
frame_control: FrameControl {
first: true,
last: true,
},
}
}
pub fn new_continue_stream() -> Self {
Self {
area: None,
frame_control: FrameControl {
first: false,
last: false,
},
}
}
pub fn new_from_parts(area: Option<Area>, frame_control: FrameControl) -> Self {
Self {
area,
frame_control,
}
}
}
#[allow(async_fn_in_trait)]
pub trait DisplayBus: ErrorType {
async fn write_cmd(&mut self, cmd: &[u8]) -> Result<(), Self::Error>;
async fn write_cmd_with_params(&mut self, cmd: &[u8], params: &[u8])
-> Result<(), Self::Error>;
async fn write_pixels(
&mut self,
cmd: &[u8],
data: &[u8],
metadata: Metadata,
) -> Result<(), DisplayError<Self::Error>>;
fn set_reset(&mut self, reset: bool) -> Result<(), DisplayError<Self::Error>> {
let _ = reset;
Err(DisplayError::Unsupported)
}
}
#[allow(async_fn_in_trait)]
pub trait BusHardwareFill: DisplayBus {
async fn fill_solid(
&mut self,
cmd: &[u8],
color: SolidColor,
area: Area,
) -> Result<(), DisplayError<Self::Error>>;
}
#[allow(async_fn_in_trait)]
pub trait BusRead: DisplayBus {
async fn read_data(
&mut self,
cmd: &[u8],
params: &[u8],
buffer: &mut [u8],
) -> Result<(), DisplayError<Self::Error>> {
let (_, _, _) = (cmd, params, buffer);
Err(DisplayError::Unsupported)
}
}
#[allow(async_fn_in_trait)]
pub trait BusBytesIo: DisplayBus {
async fn write_cmd_bytes(&mut self, cmd: &[u8]) -> Result<(), Self::Error>;
async fn write_data_bytes(&mut self, data: &[u8]) -> Result<(), Self::Error>;
}