#![no_std]
use core::error::Error as CoreError;
use embedded_graphics::{prelude::Point, primitives::Rectangle};
use embedded_hal::digital::{ErrorType as PinErrorType, InputPin, OutputPin};
use embedded_hal_async::{
delay::DelayNs,
digital::Wait,
spi::{ErrorType as SpiErrorType, SpiBus},
};
pub mod buffer;
pub mod epd2in9;
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum Error {
InvalidArgument,
}
#[allow(async_fn_in_trait)]
pub trait Epd<HW>
where
HW: EpdHw,
{
type Command;
type Buffer;
async fn init(&mut self, lut: &[u8]) -> Result<(), HW::Error>;
async fn clear(&mut self) -> Result<(), HW::Error>;
async fn reset(&mut self) -> Result<(), HW::Error>;
async fn sleep(&mut self) -> Result<(), HW::Error>;
async fn wake(&mut self) -> Result<(), HW::Error>;
async fn display_buffer(&mut self, buffer: &Self::Buffer) -> Result<(), HW::Error>;
async fn set_window(&mut self, shape: Rectangle) -> Result<(), HW::Error>;
async fn set_cursor(&mut self, position: Point) -> Result<(), <HW as EpdHw>::Error>;
async fn write_image(&mut self, image: &[u8]) -> Result<(), HW::Error>;
async fn update_display(&mut self) -> Result<(), HW::Error>;
async fn send(&mut self, command: Self::Command, data: &[u8]) -> Result<(), HW::Error>;
async fn wait_if_busy(&mut self) -> Result<(), HW::Error>;
}
pub trait EpdHw {
type Spi: SpiBus;
type Cs: OutputPin;
type Dc: OutputPin;
type Reset: OutputPin;
type Busy: InputPin + Wait;
type Delay: DelayNs;
type Error: CoreError
+ From<<Self::Spi as SpiErrorType>::Error>
+ From<<Self::Cs as PinErrorType>::Error>
+ From<<Self::Dc as PinErrorType>::Error>
+ From<<Self::Reset as PinErrorType>::Error>
+ From<<Self::Busy as PinErrorType>::Error>
+ From<Error>;
fn spi(&mut self) -> &mut Self::Spi;
fn cs(&mut self) -> &mut Self::Cs;
fn dc(&mut self) -> &mut Self::Dc;
fn reset(&mut self) -> &mut Self::Reset;
fn busy(&mut self) -> &mut Self::Busy;
fn delay(&mut self) -> &mut Self::Delay;
}