#![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},
};
use crate::epd2in9::RefreshMode;
pub mod buffer;
pub mod epd2in9;
mod log;
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum Error {
InvalidArgument,
}
#[allow(async_fn_in_trait)]
pub trait Epd<HW>
where
HW: EpdHw,
{
type RefreshMode;
type Command;
type Buffer;
fn new_buffer(&self) -> Self::Buffer;
fn width(&self) -> u32;
fn height(&self) -> u32;
async fn init(&mut self, spi: &mut HW::Spi, mode: RefreshMode) -> Result<(), HW::Error>;
async fn set_refresh_mode(
&mut self,
spi: &mut HW::Spi,
mode: Self::RefreshMode,
) -> Result<(), HW::Error>;
async fn reset(&mut self) -> Result<(), HW::Error>;
async fn sleep(&mut self, spi: &mut HW::Spi) -> Result<(), HW::Error>;
async fn wake(&mut self, spi: &mut HW::Spi) -> Result<(), HW::Error>;
async fn display_buffer(
&mut self,
spi: &mut HW::Spi,
buffer: &Self::Buffer,
) -> Result<(), HW::Error>;
async fn set_window(&mut self, spi: &mut HW::Spi, shape: Rectangle) -> Result<(), HW::Error>;
async fn set_cursor(
&mut self,
spi: &mut HW::Spi,
position: Point,
) -> Result<(), <HW as EpdHw>::Error>;
async fn write_image(&mut self, spi: &mut HW::Spi, image: &[u8]) -> Result<(), HW::Error>;
async fn update_display(&mut self, spi: &mut HW::Spi) -> Result<(), HW::Error>;
async fn send(
&mut self,
spi: &mut HW::Spi,
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 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;
}