epd_waveshare_async/
lib.rs1#![no_std]
2
3use core::error::Error as CoreError;
4
5use embedded_graphics::{prelude::Point, primitives::Rectangle};
6use embedded_hal::digital::{ErrorType as PinErrorType, InputPin, OutputPin};
7use embedded_hal_async::{
8 delay::DelayNs,
9 digital::Wait,
10 spi::{ErrorType as SpiErrorType, SpiBus},
11};
12
13pub mod buffer;
14pub mod epd2in9;
15
16#[derive(Debug, Copy, Clone, PartialEq)]
17pub enum Error {
18 InvalidArgument,
19}
20
21#[allow(async_fn_in_trait)]
22pub trait Epd<HW>
23where
24 HW: EpdHw,
25{
26 type Command;
27 type Buffer;
28
29 async fn init(&mut self, lut: &[u8]) -> Result<(), HW::Error>;
31
32 async fn clear(&mut self) -> Result<(), HW::Error>;
34
35 async fn reset(&mut self) -> Result<(), HW::Error>;
37
38 async fn sleep(&mut self) -> Result<(), HW::Error>;
40
41 async fn wake(&mut self) -> Result<(), HW::Error>;
43
44 async fn display_buffer(&mut self, buffer: &Self::Buffer) -> Result<(), HW::Error>;
46
47 async fn set_window(&mut self, shape: Rectangle) -> Result<(), HW::Error>;
50
51 async fn set_cursor(&mut self, position: Point) -> Result<(), <HW as EpdHw>::Error>;
53
54 async fn write_image(&mut self, image: &[u8]) -> Result<(), HW::Error>;
56
57 async fn update_display(&mut self) -> Result<(), HW::Error>;
59
60 async fn send(&mut self, command: Self::Command, data: &[u8]) -> Result<(), HW::Error>;
62
63 async fn wait_if_busy(&mut self) -> Result<(), HW::Error>;
66}
67
68pub trait EpdHw {
70 type Spi: SpiBus;
71 type Cs: OutputPin;
72 type Dc: OutputPin;
73 type Reset: OutputPin;
74 type Busy: InputPin + Wait;
75 type Delay: DelayNs;
76 type Error: CoreError
77 + From<<Self::Spi as SpiErrorType>::Error>
78 + From<<Self::Cs as PinErrorType>::Error>
79 + From<<Self::Dc as PinErrorType>::Error>
80 + From<<Self::Reset as PinErrorType>::Error>
81 + From<<Self::Busy as PinErrorType>::Error>
82 + From<Error>;
83
84 fn spi(&mut self) -> &mut Self::Spi;
85 fn cs(&mut self) -> &mut Self::Cs;
86 fn dc(&mut self) -> &mut Self::Dc;
87 fn reset(&mut self) -> &mut Self::Reset;
88 fn busy(&mut self) -> &mut Self::Busy;
89 fn delay(&mut self) -> &mut Self::Delay;
90}