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, SpiDevice},
11};
12
13use crate::epd2in9::RefreshMode;
14
15pub mod buffer;
16pub mod epd2in9;
17
18mod log;
19
20#[allow(async_fn_in_trait)]
21pub trait Epd<HW>
22where
23 HW: EpdHw,
24{
25 type RefreshMode;
26 type Command;
27 type Buffer;
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: 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>;
75
76 async fn update_display(&mut self, spi: &mut HW::Spi) -> Result<(), HW::Error>;
86
87 async fn send(
89 &mut self,
90 spi: &mut HW::Spi,
91 command: Self::Command,
92 data: &[u8],
93 ) -> Result<(), HW::Error>;
94
95 async fn wait_if_busy(&mut self) -> Result<(), HW::Error>;
98}
99
100pub trait EpdHw {
102 type Spi: SpiDevice;
103 type Dc: OutputPin;
104 type Reset: OutputPin;
105 type Busy: InputPin + Wait;
106 type Delay: DelayNs;
107 type Error: CoreError
108 + From<<Self::Spi as SpiErrorType>::Error>
109 + From<<Self::Dc as PinErrorType>::Error>
110 + From<<Self::Reset as PinErrorType>::Error>
111 + From<<Self::Busy as PinErrorType>::Error>;
112
113 fn dc(&mut self) -> &mut Self::Dc;
114 fn reset(&mut self) -> &mut Self::Reset;
115 fn busy(&mut self) -> &mut Self::Busy;
116 fn delay(&mut self) -> &mut Self::Delay;
117}