use embedded_hal_async::delay::DelayNs;
use crate::{bus::BusRead, ColorFormat, DisplayBus, DisplayError};
pub mod initseq;
pub mod reset;
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum Orientation {
Deg0,
Deg90,
Deg180,
Deg270,
}
impl Orientation {
pub fn is_transposed(&self) -> bool {
matches!(self, Orientation::Deg90 | Orientation::Deg270)
}
pub fn is_inverted(&self) -> bool {
matches!(self, Orientation::Deg180 | Orientation::Deg270)
}
}
#[allow(async_fn_in_trait)]
pub trait Panel<B: DisplayBus> {
const CMD_LEN: usize;
const PIXEL_WRITE_CMD: [u8; 4];
fn width(&self) -> u16;
fn height(&self) -> u16;
fn size(&self) -> (u16, u16) {
(self.width(), self.height())
}
fn x_alignment(&self) -> u16 {
1
}
fn y_alignment(&self) -> u16 {
1
}
async fn init<D: DelayNs>(&mut self, bus: &mut B, delay: D) -> Result<(), B::Error>;
async fn set_window(
&mut self,
bus: &mut B,
x0: u16,
y0: u16,
x1: u16,
y1: u16,
) -> Result<(), DisplayError<B::Error>>;
async fn set_full_window(&mut self, bus: &mut B) -> Result<(), DisplayError<B::Error>> {
self.set_window(bus, 0, 0, self.width() - 1, self.height() - 1)
.await
}
async fn check_id(&mut self, bus: &mut B) -> Result<bool, DisplayError<B::Error>>
where
B: BusRead,
{
let _ = bus;
Err(DisplayError::Unsupported)
}
async fn set_orientation(
&mut self,
bus: &mut B,
orientation: Orientation,
) -> Result<(), DisplayError<B::Error>> {
let _ = (bus, orientation);
Err(DisplayError::Unsupported)
}
async fn set_color_format(
&mut self,
bus: &mut B,
color_format: ColorFormat,
) -> Result<(), DisplayError<B::Error>>;
}
#[allow(async_fn_in_trait)]
pub trait PanelSetBrightness<B: DisplayBus>: Panel<B> {
async fn set_brightness(
&mut self,
bus: &mut B,
brightness: u8,
) -> Result<(), DisplayError<B::Error>>;
}