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
13use crate::epd2in9::RefreshMode;
14
15pub mod buffer;
16pub mod epd2in9;
17
18mod log;
19
20#[derive(Debug, Copy, Clone, PartialEq)]
21pub enum Error {
22 InvalidArgument,
23}
24
25#[allow(async_fn_in_trait)]
26pub trait Epd<HW>
27where
28 HW: EpdHw,
29{
30 type RefreshMode;
31 type Command;
32 type Buffer;
33
34 fn new_buffer(&self) -> Self::Buffer;
36
37 fn width(&self) -> u32;
38
39 fn height(&self) -> u32;
40
41 async fn init(&mut self, spi: &mut HW::Spi, mode: RefreshMode) -> Result<(), HW::Error>;
43
44 async fn set_refresh_mode(
46 &mut self,
47 spi: &mut HW::Spi,
48 mode: Self::RefreshMode,
49 ) -> Result<(), HW::Error>;
50
51 async fn reset(&mut self) -> Result<(), HW::Error>;
53
54 async fn sleep(&mut self, spi: &mut HW::Spi) -> Result<(), HW::Error>;
56
57 async fn wake(&mut self, spi: &mut HW::Spi) -> Result<(), HW::Error>;
59
60 async fn display_buffer(
62 &mut self,
63 spi: &mut HW::Spi,
64 buffer: &Self::Buffer,
65 ) -> Result<(), HW::Error>;
66
67 async fn set_window(&mut self, spi: &mut HW::Spi, shape: Rectangle) -> Result<(), HW::Error>;
70
71 async fn set_cursor(
73 &mut self,
74 spi: &mut HW::Spi,
75 position: Point,
76 ) -> Result<(), <HW as EpdHw>::Error>;
77
78 async fn write_image(&mut self, spi: &mut HW::Spi, image: &[u8]) -> Result<(), HW::Error>;
80
81 async fn update_display(&mut self, spi: &mut HW::Spi) -> Result<(), HW::Error>;
91
92 async fn send(
94 &mut self,
95 spi: &mut HW::Spi,
96 command: Self::Command,
97 data: &[u8],
98 ) -> Result<(), HW::Error>;
99
100 async fn wait_if_busy(&mut self) -> Result<(), HW::Error>;
103}
104
105pub trait EpdHw {
107 type Spi: SpiBus;
108 type Cs: OutputPin;
109 type Dc: OutputPin;
110 type Reset: OutputPin;
111 type Busy: InputPin + Wait;
112 type Delay: DelayNs;
113 type Error: CoreError
114 + From<<Self::Spi as SpiErrorType>::Error>
115 + From<<Self::Cs as PinErrorType>::Error>
116 + From<<Self::Dc as PinErrorType>::Error>
117 + From<<Self::Reset as PinErrorType>::Error>
118 + From<<Self::Busy as PinErrorType>::Error>
119 + From<Error>;
120
121 fn cs(&mut self) -> &mut Self::Cs;
122 fn dc(&mut self) -> &mut Self::Dc;
123 fn reset(&mut self) -> &mut Self::Reset;
124 fn busy(&mut self) -> &mut Self::Busy;
125 fn delay(&mut self) -> &mut Self::Delay;
126}