epd_waveshare/
lib.rs

1//! A simple Driver for the [Waveshare](https://github.com/waveshare/e-Paper) E-Ink Displays via SPI
2//!
3//! - Built using [`embedded-hal`] traits.
4//! - Graphics support is added through [`embedded-graphics`]
5//!
6//! [`embedded-graphics`]: https://docs.rs/embedded-graphics/
7//! [`embedded-hal`]: https://docs.rs/embedded-hal
8//!
9
10//!
11//! # Example
12//!
13//!```rust, no_run
14//!# use embedded_hal_mock::eh1::*;
15//!# fn main() -> Result<(), embedded_hal::spi::ErrorKind> {
16//!use embedded_graphics::{
17//!    pixelcolor::BinaryColor::On as Black, prelude::*, primitives::{Line, PrimitiveStyle},
18//!};
19//!use epd_waveshare::{epd1in54::*, prelude::*};
20//!#
21//!# let expectations = [];
22//!# let mut spi = spi::Mock::new(&expectations);
23//!# let expectations = [];
24//!# let cs_pin = digital::Mock::new(&expectations);
25//!# let busy_in = digital::Mock::new(&expectations);
26//!# let dc = digital::Mock::new(&expectations);
27//!# let rst = digital::Mock::new(&expectations);
28//!# let mut delay = delay::NoopDelay::new();
29//!
30//!// Setup EPD
31//!let mut epd = Epd1in54::new(&mut spi, busy_in, dc, rst, &mut delay, None)?;
32//!
33//!// Use display graphics from embedded-graphics
34//!let mut display = Display1in54::default();
35//!
36//!// Use embedded graphics for drawing a line
37//!
38//!let _ = Line::new(Point::new(0, 120), Point::new(0, 295))
39//!    .into_styled(PrimitiveStyle::with_stroke(Color::Black, 1))
40//!    .draw(&mut display);
41//!
42//!    // Display updated frame
43//!epd.update_frame(&mut spi, &display.buffer(), &mut delay)?;
44//!epd.display_frame(&mut spi, &mut delay)?;
45//!
46//!// Set the EPD to sleep
47//!epd.sleep(&mut spi, &mut delay)?;
48//!# Ok(())
49//!# }
50//!```
51//!
52//! # Other information and requirements
53//!
54//! - Buffersize: Wherever a buffer is used it always needs to be of the size: `width / 8 * length`,
55//!   where width and length being either the full e-ink size or the partial update window size
56//!
57//! ### SPI
58//!
59//! MISO is not connected/available. SPI_MODE_0 is used (CPHL = 0, CPOL = 0) with 8 bits per word, MSB first.
60//!
61//! Maximum speed tested by myself was 8Mhz but more should be possible (Ben Krasnow used 18Mhz with his implemenation)
62//!
63#![no_std]
64#![deny(missing_docs)]
65
66#[cfg(feature = "graphics")]
67pub mod graphics;
68
69mod traits;
70
71pub mod color;
72
73/// Interface for the physical connection between display and the controlling device
74mod interface;
75
76pub mod epd1in54;
77pub mod epd1in54_v2;
78pub mod epd1in54b;
79pub mod epd1in54c;
80pub mod epd2in13_v2;
81pub mod epd2in13bc;
82pub mod epd2in66b;
83pub mod epd2in7b;
84pub mod epd2in9;
85pub mod epd2in9_v2;
86pub mod epd2in9bc;
87pub mod epd2in9d;
88pub mod epd3in7;
89pub mod epd4in2;
90pub mod epd5in65f;
91pub mod epd5in83_v2;
92pub mod epd5in83b_v2;
93pub mod epd7in3f;
94pub mod epd7in5;
95pub mod epd7in5_hd;
96pub mod epd7in5_v2;
97pub mod epd7in5b_v2;
98pub use epd7in5b_v2 as epd7in5b_v3;
99
100pub(crate) mod type_a;
101
102/// Includes everything important besides the chosen Display
103pub mod prelude {
104    pub use crate::color::{Color, OctColor, TriColor};
105    pub use crate::traits::{
106        QuickRefresh, RefreshLut, WaveshareDisplay, WaveshareThreeColorDisplay,
107    };
108
109    pub use crate::SPI_MODE;
110
111    #[cfg(feature = "graphics")]
112    pub use crate::graphics::{Display, DisplayRotation};
113}
114
115/// Computes the needed buffer length. Takes care of rounding up in case width
116/// is not divisible by 8.
117///
118///  unused
119///  bits        width
120/// <----><------------------------>
121/// \[XXXXX210\]\[76543210\]...\[76543210\] ^
122/// \[XXXXX210\]\[76543210\]...\[76543210\] | height
123/// \[XXXXX210\]\[76543210\]...\[76543210\] v
124pub const fn buffer_len(width: usize, height: usize) -> usize {
125    (width + 7) / 8 * height
126}
127
128use embedded_hal::spi::{Mode, Phase, Polarity};
129
130/// SPI mode -
131/// For more infos see [Requirements: SPI](index.html#spi)
132pub const SPI_MODE: Mode = Mode {
133    phase: Phase::CaptureOnFirstTransition,
134    polarity: Polarity::IdleLow,
135};