use crate::color::Color;
use core::marker::Sized;
use embedded_hal::{
blocking::{delay::*, spi::Write},
digital::v2::*,
};
pub(crate) trait Command {
fn address(self) -> u8;
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum RefreshLUT {
FULL,
QUICK,
}
impl Default for RefreshLUT {
fn default() -> Self {
RefreshLUT::FULL
}
}
pub(crate) trait InternalWiAdditions<SPI, CS, BUSY, DC, RST>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
{
fn init<DELAY: DelayMs<u8>>(
&mut self,
spi: &mut SPI,
delay: &mut DELAY,
) -> Result<(), SPI::Error>;
}
pub trait WaveshareThreeColorDisplay<SPI, CS, BUSY, DC, RST>:
WaveshareDisplay<SPI, CS, BUSY, DC, RST>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
{
fn update_color_frame(
&mut self,
spi: &mut SPI,
black: &[u8],
chromatic: &[u8],
) -> Result<(), SPI::Error>;
fn update_achromatic_frame(&mut self, spi: &mut SPI, black: &[u8]) -> Result<(), SPI::Error>;
fn update_chromatic_frame(&mut self, spi: &mut SPI, chromatic: &[u8])
-> Result<(), SPI::Error>;
}
pub trait WaveshareDisplay<SPI, CS, BUSY, DC, RST>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
{
fn new<DELAY: DelayMs<u8>>(
spi: &mut SPI,
cs: CS,
busy: BUSY,
dc: DC,
rst: RST,
delay: &mut DELAY,
) -> Result<Self, SPI::Error>
where
Self: Sized;
fn sleep(&mut self, spi: &mut SPI) -> Result<(), SPI::Error>;
fn wake_up<DELAY: DelayMs<u8>>(
&mut self,
spi: &mut SPI,
delay: &mut DELAY,
) -> Result<(), SPI::Error>;
fn set_background_color(&mut self, color: Color);
fn background_color(&self) -> &Color;
fn width(&self) -> u32;
fn height(&self) -> u32;
fn update_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error>;
fn update_partial_frame(
&mut self,
spi: &mut SPI,
buffer: &[u8],
x: u32,
y: u32,
width: u32,
height: u32,
) -> Result<(), SPI::Error>;
fn display_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error>;
fn update_and_display_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error>;
fn clear_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error>;
fn set_lut(
&mut self,
spi: &mut SPI,
refresh_rate: Option<RefreshLUT>,
) -> Result<(), SPI::Error>;
fn is_busy(&self) -> bool;
}