epd_waveshare_async/
lib.rs1#![no_std]
2
3use core::error::Error as CoreError;
4
5use embedded_graphics::{
6 prelude::{DrawTarget, Point},
7 primitives::Rectangle,
8};
9use embedded_hal::digital::{ErrorType as PinErrorType, InputPin, OutputPin};
10use embedded_hal_async::{
11 delay::DelayNs,
12 digital::Wait,
13 spi::{ErrorType as SpiErrorType, SpiDevice},
14};
15
16pub mod buffer;
17pub mod epd2in9;
18
19mod log;
20
21#[allow(async_fn_in_trait)]
22pub trait Epd<HW>
23where
24 HW: EpdHw,
25{
26 type RefreshMode;
27 type Buffer: DrawTarget;
28
29 fn new_buffer(&self) -> Self::Buffer;
31
32 fn width(&self) -> u32;
33
34 fn height(&self) -> u32;
35
36 async fn init(&mut self, spi: &mut HW::Spi, mode: Self::RefreshMode) -> Result<(), HW::Error>;
38
39 async fn set_refresh_mode(
41 &mut self,
42 spi: &mut HW::Spi,
43 mode: Self::RefreshMode,
44 ) -> Result<(), HW::Error>;
45
46 async fn reset(&mut self) -> Result<(), HW::Error>;
48
49 async fn sleep(&mut self, spi: &mut HW::Spi) -> Result<(), HW::Error>;
51
52 async fn wake(&mut self, spi: &mut HW::Spi) -> Result<(), HW::Error>;
54
55 async fn display_buffer(
57 &mut self,
58 spi: &mut HW::Spi,
59 buffer: &Self::Buffer,
60 ) -> Result<(), HW::Error>;
61
62 async fn set_window(&mut self, spi: &mut HW::Spi, shape: Rectangle) -> Result<(), HW::Error>;
65
66 async fn set_cursor(
68 &mut self,
69 spi: &mut HW::Spi,
70 position: Point,
71 ) -> Result<(), <HW as EpdHw>::Error>;
72
73 async fn write_image(&mut self, spi: &mut HW::Spi, image: &[u8]) -> Result<(), HW::Error>;
76
77 async fn update_display(&mut self, spi: &mut HW::Spi) -> Result<(), HW::Error>;
87}
88
89pub trait EpdHw {
91 type Spi: SpiDevice;
92 type Dc: OutputPin;
93 type Reset: OutputPin;
94 type Busy: InputPin + Wait;
95 type Delay: DelayNs;
96 type Error: CoreError
97 + From<<Self::Spi as SpiErrorType>::Error>
98 + From<<Self::Dc as PinErrorType>::Error>
99 + From<<Self::Reset as PinErrorType>::Error>
100 + From<<Self::Busy as PinErrorType>::Error>;
101
102 fn dc(&mut self) -> &mut Self::Dc;
103 fn reset(&mut self) -> &mut Self::Reset;
104 fn busy(&mut self) -> &mut Self::Busy;
105 fn delay(&mut self) -> &mut Self::Delay;
106}