Mainly improved Documenation
parent
1dfea538b7
commit
409676423d
|
|
@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|||
- Update and integrate a few important examples and remove the others
|
||||
- Add update_and_display_frame to the main trait, fixes #38
|
||||
- Also improve position of busy_wait (#30) once more
|
||||
- Fixed all doc tests
|
||||
- Some more documentation improvements
|
||||
|
||||
<!-- ## [v0.3.2] - 2019-04-04 -->
|
||||
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ epd.display_frame(&mut spi)?;
|
|||
| [4.2 Inch B/W (A)](https://www.waveshare.com/product/4.2inch-e-paper-module.htm) | Black, White | ✕ | Not officially [[2](#2-42-inch-e-ink-blackwhite---partial-refresh)] | ✔ | ✔ |
|
||||
| [1.54 Inch B/W (A)](https://www.waveshare.com/1.54inch-e-Paper-Module.htm) | Black, White | ✕ | ✔ | ✔ | ✔ |
|
||||
| [2.13 Inch B/W (A)](https://www.waveshare.com/product/2.13inch-e-paper-hat.htm) | Black, White | ✕ | ✔ | | |
|
||||
| [2.9 Inch B/W (A)](https://www.waveshare.com/product/2.9inch-e-paper-module.htm) | Black, White | ✕ | ✔ | ✔ | ✔ [[3](#3-29-inch-e-ink-blackwhite---tests)] |
|
||||
| [2.9 Inch B/W (A)](https://www.waveshare.com/product/2.9inch-e-paper-module.htm) | Black, White | ✕ | ✔ | ✔ | ✔ |
|
||||
| [1.54 Inch B/W/R (B)](https://www.waveshare.com/product/modules/oleds-lcds/e-paper/1.54inch-e-paper-module-b.htm) | Black, White, Red | ✕ | ✕ | ✔ | ✔ |
|
||||
|
||||
### [1]: 7.5 Inch B/W V2 (A)
|
||||
|
|
@ -62,10 +62,6 @@ Out of the Box the original driver from Waveshare only supports full updates.
|
|||
That means: Be careful with the quick refresh updates: <br>
|
||||
It's possible with this driver but might lead to ghosting / burn-in effects therefore it's hidden behind a feature.
|
||||
|
||||
### [3]: 2.9 Inch E-Ink Black/White - Tests
|
||||
|
||||
Since my 2.9 Inch Display has some blurring issues I am not absolutly sure if everything was working correctly as it should :-)
|
||||
|
||||
### Interface
|
||||
|
||||
| Interface | Description |
|
||||
|
|
|
|||
|
|
@ -2,37 +2,51 @@
|
|||
//!
|
||||
//! # Example for the 1.54 in E-Ink Display
|
||||
//!
|
||||
//! ```rust,no_run
|
||||
//! use epd_waveshare::{
|
||||
//! epd1in54::{EPD1in54, Display1in54},
|
||||
//! graphics::{Display, DisplayRotation},
|
||||
//! prelude::*,
|
||||
//! };
|
||||
//! use embedded_graphics::Drawing;
|
||||
//!```rust, no_run
|
||||
//!# use embedded_hal_mock::*;
|
||||
//!# fn main() -> Result<(), MockError> {
|
||||
//!use embedded_graphics::{
|
||||
//! pixelcolor::BinaryColor::On as Black, prelude::*, primitives::Line, style::PrimitiveStyle,
|
||||
//!};
|
||||
//!use epd_waveshare::{epd1in54::*, prelude::*};
|
||||
//!#
|
||||
//!# let expectations = [];
|
||||
//!# let mut spi = spi::Mock::new(&expectations);
|
||||
//!# let expectations = [];
|
||||
//!# let cs_pin = pin::Mock::new(&expectations);
|
||||
//!# let busy_in = pin::Mock::new(&expectations);
|
||||
//!# let dc = pin::Mock::new(&expectations);
|
||||
//!# let rst = pin::Mock::new(&expectations);
|
||||
//!# let mut delay = delay::MockNoop::new();
|
||||
//!
|
||||
//! // Setup EPD
|
||||
//! let mut epd = EPD1in54::new(&mut spi, cs_pin, busy_in, dc, rst, &mut delay).unwrap();
|
||||
//!// Setup EPD
|
||||
//!let mut epd = EPD1in54::new(&mut spi, cs_pin, busy_in, dc, rst, &mut delay)?;
|
||||
//!
|
||||
//! // Use display graphics
|
||||
//! let mut display = Display1in54::default();
|
||||
//!// Use display graphics from embedded-graphics
|
||||
//!let mut display = Display1in54::default();
|
||||
//!
|
||||
//! // Write some hello world in the screenbuffer
|
||||
//! let _ = Line::new(Point::new(0, 120), Point::new(0, 295))
|
||||
//! .into_styled(PrimitiveStyle::with_stroke(BinaryColor::On, 1))
|
||||
//!// Use embedded graphics for drawing a line
|
||||
//!let _ = Line::new(Point::new(0, 120), Point::new(0, 295))
|
||||
//! .into_styled(PrimitiveStyle::with_stroke(Black, 1))
|
||||
//! .draw(&mut display);
|
||||
//!
|
||||
//! // Display updated frame
|
||||
//! epd.update_frame(&mut spi, &display.buffer()).unwrap();
|
||||
//! epd.display_frame(&mut spi).expect("display frame new graphics");
|
||||
//!epd.update_frame(&mut spi, &display.buffer())?;
|
||||
//!epd.display_frame(&mut spi)?;
|
||||
//!
|
||||
//! // Set the EPD to sleep
|
||||
//! epd.sleep(&mut spi).expect("sleep");
|
||||
//! ```
|
||||
//!// Set the EPD to sleep
|
||||
//!epd.sleep(&mut spi)?;
|
||||
//!# Ok(())
|
||||
//!# }
|
||||
//!```
|
||||
|
||||
/// Width of the display
|
||||
pub const WIDTH: u32 = 200;
|
||||
/// Height of the display
|
||||
pub const HEIGHT: u32 = 200;
|
||||
//const DPI: u16 = 184;
|
||||
/// Default Background Color
|
||||
pub const DEFAULT_BACKGROUND_COLOR: Color = Color::White;
|
||||
//const DPI: u16 = 184;
|
||||
const IS_BUSY_LOW: bool = false;
|
||||
|
||||
use embedded_hal::{
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@ use crate::graphics::{Display, DisplayRotation};
|
|||
use embedded_graphics::pixelcolor::BinaryColor;
|
||||
use embedded_graphics::prelude::*;
|
||||
|
||||
/// Full size buffer for use with the 1in54 EPD
|
||||
///
|
||||
/// Can also be manually constructed and be used together with VarDisplay
|
||||
pub struct Display1in54b {
|
||||
buffer: [u8; WIDTH as usize * HEIGHT as usize / 8],
|
||||
rotation: DisplayRotation,
|
||||
|
|
|
|||
|
|
@ -14,8 +14,11 @@ use crate::traits::{
|
|||
mod constants;
|
||||
use crate::epd1in54b::constants::*;
|
||||
|
||||
/// Width of epd1in54 in pixels
|
||||
pub const WIDTH: u32 = 200;
|
||||
/// Height of epd1in54 in pixels
|
||||
pub const HEIGHT: u32 = 200;
|
||||
/// Default Background Color (white)
|
||||
pub const DEFAULT_BACKGROUND_COLOR: Color = Color::White;
|
||||
const IS_BUSY_LOW: bool = true;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,42 +1,51 @@
|
|||
//! A simple Driver for the Waveshare 2.9" E-Ink Display via SPI
|
||||
//!
|
||||
//! Untested!
|
||||
//!
|
||||
//! # Example for the 2.9 in E-Ink Display
|
||||
//!
|
||||
//! ```rust,ignore
|
||||
//! use epd_waveshare::{
|
||||
//! epd2in9::{EPD2in9, Display2in9},
|
||||
//! graphics::{Display, DisplayRotation},
|
||||
//! prelude::*,
|
||||
//! };
|
||||
//! use embedded_graphics::Drawing;
|
||||
//!```rust, no_run
|
||||
//!# use embedded_hal_mock::*;
|
||||
//!# fn main() -> Result<(), MockError> {
|
||||
//!use embedded_graphics::{
|
||||
//! pixelcolor::BinaryColor::On as Black, prelude::*, primitives::Line, style::PrimitiveStyle,
|
||||
//!};
|
||||
//!use epd_waveshare::{epd2in9::*, prelude::*};
|
||||
//!#
|
||||
//!# let expectations = [];
|
||||
//!# let mut spi = spi::Mock::new(&expectations);
|
||||
//!# let expectations = [];
|
||||
//!# let cs_pin = pin::Mock::new(&expectations);
|
||||
//!# let busy_in = pin::Mock::new(&expectations);
|
||||
//!# let dc = pin::Mock::new(&expectations);
|
||||
//!# let rst = pin::Mock::new(&expectations);
|
||||
//!# let mut delay = delay::MockNoop::new();
|
||||
//!
|
||||
//! // Setup EPD
|
||||
//! let mut epd = EPD2in9::new(&mut spi, cs_pin, busy_in, dc, rst, &mut delay).unwrap();
|
||||
//!// Setup EPD
|
||||
//!let mut epd = EPD2in9::new(&mut spi, cs_pin, busy_in, dc, rst, &mut delay)?;
|
||||
//!
|
||||
//! // Use display graphics
|
||||
//! let mut display = Display2in9::default();
|
||||
//!// Use display graphics from embedded-graphics
|
||||
//!let mut display = Display2in9::default();
|
||||
//!
|
||||
//! // Write some hello world in the screenbuffer
|
||||
//! display.draw(
|
||||
//! Font6x8::render_str("Hello World!")
|
||||
//! .stroke(Some(Color::Black))
|
||||
//! .fill(Some(Color::White))
|
||||
//! .translate(Point::new(5, 50))
|
||||
//! .into_iter(),
|
||||
//! );
|
||||
//!// Use embedded graphics for drawing a line
|
||||
//!let _ = Line::new(Point::new(0, 120), Point::new(0, 295))
|
||||
//! .into_styled(PrimitiveStyle::with_stroke(Black, 1))
|
||||
//! .draw(&mut display);
|
||||
//!
|
||||
//! // Display updated frame
|
||||
//! epd.update_frame(&mut spi, &display.buffer()).unwrap();
|
||||
//! epd.display_frame(&mut spi).expect("display frame new graphics");
|
||||
//!epd.update_frame(&mut spi, &display.buffer())?;
|
||||
//!epd.display_frame(&mut spi)?;
|
||||
//!
|
||||
//! // Set the EPD to sleep
|
||||
//! epd.sleep(&mut spi).expect("sleep");
|
||||
//! ```
|
||||
//!// Set the EPD to sleep
|
||||
//!epd.sleep(&mut spi)?;
|
||||
//!# Ok(())
|
||||
//!# }
|
||||
//!```
|
||||
|
||||
/// Width of epd2in9 in pixels
|
||||
pub const WIDTH: u32 = 128;
|
||||
/// Height of epd2in9 in pixels
|
||||
pub const HEIGHT: u32 = 296;
|
||||
/// Default Background Color (white)
|
||||
pub const DEFAULT_BACKGROUND_COLOR: Color = Color::White;
|
||||
const IS_BUSY_LOW: bool = false;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,46 +1,49 @@
|
|||
//! A simple Driver for the Waveshare 4.2" E-Ink Display via SPI
|
||||
//!
|
||||
//! The other Waveshare E-Ink Displays should be added later on
|
||||
//!
|
||||
//! Build with the help of documentation/code from [Waveshare](https://www.waveshare.com/wiki/4.2inch_e-Paper_Module),
|
||||
//! [Ben Krasnows partial Refresh tips](https://benkrasnow.blogspot.de/2017/10/fast-partial-refresh-on-42-e-paper.html) and
|
||||
//! the driver documents in the `pdfs`-folder as orientation.
|
||||
//!
|
||||
//! This driver was built using [`embedded-hal`] traits.
|
||||
//!
|
||||
//! [`embedded-hal`]: https://docs.rs/embedded-hal/~0.1
|
||||
//!
|
||||
//! # Requirements
|
||||
//!
|
||||
//! ### SPI
|
||||
//!
|
||||
//! - MISO is not connected/available
|
||||
//! - SPI_MODE_0 is used (CPHL = 0, CPOL = 0)
|
||||
//! - 8 bits per word, MSB first
|
||||
//! - Max. Speed tested was 8Mhz but more should be possible
|
||||
//!
|
||||
//! ### Other....
|
||||
//!
|
||||
//! - Buffersize: Wherever a buffer is used it always needs to be of the size: `width / 8 * length`,
|
||||
//! where width and length being either the full e-ink size or the partial update window size
|
||||
//!
|
||||
//! # Examples
|
||||
//!
|
||||
//! ```ignore
|
||||
//! let mut epd4in2 = EPD4in2::new(spi, cs, busy, dc, rst, delay).unwrap();
|
||||
//!```rust, no_run
|
||||
//!# use embedded_hal_mock::*;
|
||||
//!# fn main() -> Result<(), MockError> {
|
||||
//!use embedded_graphics::{
|
||||
//! pixelcolor::BinaryColor::On as Black, prelude::*, primitives::Line, style::PrimitiveStyle,
|
||||
//!};
|
||||
//!use epd_waveshare::{epd4in2::*, prelude::*};
|
||||
//!#
|
||||
//!# let expectations = [];
|
||||
//!# let mut spi = spi::Mock::new(&expectations);
|
||||
//!# let expectations = [];
|
||||
//!# let cs_pin = pin::Mock::new(&expectations);
|
||||
//!# let busy_in = pin::Mock::new(&expectations);
|
||||
//!# let dc = pin::Mock::new(&expectations);
|
||||
//!# let rst = pin::Mock::new(&expectations);
|
||||
//!# let mut delay = delay::MockNoop::new();
|
||||
//!
|
||||
//! let mut buffer = [0u8, epd4in2.get_width() / 8 * epd4in2.get_height()];
|
||||
//!// Setup EPD
|
||||
//!let mut epd = EPD4in2::new(&mut spi, cs_pin, busy_in, dc, rst, &mut delay)?;
|
||||
//!
|
||||
//! // draw something into the buffer
|
||||
//!// Use display graphics from embedded-graphics
|
||||
//!let mut display = Display4in2::default();
|
||||
//!
|
||||
//! epd4in2.display_and_transfer_buffer(buffer, None);
|
||||
//!// Use embedded graphics for drawing a line
|
||||
//!let _ = Line::new(Point::new(0, 120), Point::new(0, 295))
|
||||
//! .into_styled(PrimitiveStyle::with_stroke(Black, 1))
|
||||
//! .draw(&mut display);
|
||||
//!
|
||||
//! // wait and look at the image
|
||||
//! // Display updated frame
|
||||
//!epd.update_frame(&mut spi, &display.buffer())?;
|
||||
//!epd.display_frame(&mut spi)?;
|
||||
//!
|
||||
//! epd4in2.clear_frame(None);
|
||||
//!
|
||||
//! epd4in2.sleep();
|
||||
//! ```
|
||||
//!// Set the EPD to sleep
|
||||
//!epd.sleep(&mut spi)?;
|
||||
//!# Ok(())
|
||||
//!# }
|
||||
//!```
|
||||
//!
|
||||
//!
|
||||
//!
|
||||
|
|
@ -58,8 +61,11 @@ use crate::traits::{InternalWiAdditions, RefreshLUT, WaveshareDisplay};
|
|||
mod constants;
|
||||
use crate::epd4in2::constants::*;
|
||||
|
||||
/// Width of the display
|
||||
pub const WIDTH: u32 = 400;
|
||||
/// Height of the display
|
||||
pub const HEIGHT: u32 = 300;
|
||||
/// Default Background Color
|
||||
pub const DEFAULT_BACKGROUND_COLOR: Color = Color::White;
|
||||
const IS_BUSY_LOW: bool = true;
|
||||
|
||||
|
|
@ -142,21 +148,6 @@ where
|
|||
DC: OutputPin,
|
||||
RST: OutputPin,
|
||||
{
|
||||
/// Creates a new driver from a SPI peripheral, CS Pin, Busy InputPin, DC
|
||||
///
|
||||
/// This already initialises the device. That means [init()](init()) isn't needed directly afterwards
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```ignore
|
||||
/// //buffer = some image data;
|
||||
///
|
||||
/// let mut epd4in2 = EPD4in2::new(spi, cs, busy, dc, rst, delay);
|
||||
///
|
||||
/// epd4in2.display_and_transfer_frame(buffer, None);
|
||||
///
|
||||
/// epd4in2.sleep();
|
||||
/// ```
|
||||
fn new<DELAY: DelayMs<u8>>(
|
||||
spi: &mut SPI,
|
||||
cs: CS,
|
||||
|
|
|
|||
|
|
@ -23,8 +23,11 @@ mod graphics;
|
|||
#[cfg(feature = "graphics")]
|
||||
pub use self::graphics::Display7in5;
|
||||
|
||||
/// Width of the display
|
||||
pub const WIDTH: u32 = 640;
|
||||
/// Height of the display
|
||||
pub const HEIGHT: u32 = 384;
|
||||
/// Default Background Color
|
||||
pub const DEFAULT_BACKGROUND_COLOR: Color = Color::White;
|
||||
const IS_BUSY_LOW: bool = true;
|
||||
|
||||
|
|
@ -105,24 +108,6 @@ where
|
|||
DC: OutputPin,
|
||||
RST: OutputPin,
|
||||
{
|
||||
/// Creates a new driver from a SPI peripheral, CS Pin, Busy InputPin, DC
|
||||
///
|
||||
/// This already initialises the device. That means [init()] isn't needed
|
||||
/// directly afterwards.
|
||||
///
|
||||
/// [init()]: InternalWiAdditions::init
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```ignore
|
||||
/// //buffer = some image data;
|
||||
///
|
||||
/// let mut epd7in5 = EPD7in5::new(spi, cs, busy, dc, rst, delay);
|
||||
///
|
||||
/// epd7in5.display_and_transfer_frame(buffer, None);
|
||||
///
|
||||
/// epd7in5.sleep();
|
||||
/// ```
|
||||
fn new<DELAY: DelayMs<u8>>(
|
||||
spi: &mut SPI,
|
||||
cs: CS,
|
||||
|
|
|
|||
|
|
@ -27,8 +27,11 @@ mod graphics;
|
|||
#[cfg(feature = "graphics")]
|
||||
pub use self::graphics::Display7in5;
|
||||
|
||||
/// Width of the display
|
||||
pub const WIDTH: u32 = 800;
|
||||
/// Height of the display
|
||||
pub const HEIGHT: u32 = 480;
|
||||
/// Default Background Color
|
||||
pub const DEFAULT_BACKGROUND_COLOR: Color = Color::White;
|
||||
const IS_BUSY_LOW: bool = true;
|
||||
|
||||
|
|
@ -87,24 +90,6 @@ where
|
|||
DC: OutputPin,
|
||||
RST: OutputPin,
|
||||
{
|
||||
/// Creates a new driver from a SPI peripheral, CS Pin, Busy InputPin, DC
|
||||
///
|
||||
/// This already initialises the device. That means [init()] isn't needed
|
||||
/// directly afterwards.
|
||||
///
|
||||
/// [init()]: InternalWiAdditions::init
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust,ignore
|
||||
/// //buffer = some image data;
|
||||
///
|
||||
/// let mut epd7in5 = EPD7in5::new(spi, cs, busy, dc, rst, delay);
|
||||
///
|
||||
/// epd7in5.update_and_display_frame(&mut spi, &buffer);
|
||||
///
|
||||
/// epd7in5.sleep();
|
||||
/// ```
|
||||
fn new<DELAY: DelayMs<u8>>(
|
||||
spi: &mut SPI,
|
||||
cs: CS,
|
||||
|
|
|
|||
|
|
@ -22,6 +22,12 @@ impl Default for DisplayRotation {
|
|||
}
|
||||
}
|
||||
|
||||
/// Necessary traits for all displays to implement for drawing
|
||||
///
|
||||
/// Adds support for:
|
||||
/// - Drawing (With the help of DrawTarget/Embedded Graphics)
|
||||
/// - Rotations
|
||||
/// - Clearing
|
||||
pub trait Display: DrawTarget<BinaryColor> {
|
||||
/// Clears the buffer of the display with the chosen background color
|
||||
fn clear_buffer(&mut self, background_color: Color) {
|
||||
|
|
@ -112,6 +118,9 @@ pub struct VarDisplay<'a> {
|
|||
}
|
||||
|
||||
impl<'a> VarDisplay<'a> {
|
||||
/// Create a new variable sized display.
|
||||
///
|
||||
/// Buffersize must be at least width / 8 * height bytes.
|
||||
pub fn new(width: u32, height: u32, buffer: &'a mut [u8]) -> VarDisplay<'a> {
|
||||
let len = buffer.len() as u32;
|
||||
assert!(width / 8 * height >= len);
|
||||
|
|
|
|||
91
src/lib.rs
91
src/lib.rs
|
|
@ -1,58 +1,66 @@
|
|||
//! A simple Driver for the Waveshare E-Ink Displays via SPI
|
||||
//! A simple Driver for the [Waveshare](https://github.com/waveshare/e-Paper) E-Ink Displays via SPI
|
||||
//!
|
||||
//! This driver was built using [`embedded-hal`] traits.
|
||||
//! - Built using [`embedded-hal`] traits.
|
||||
//! - Graphics support is added through [`embedded-graphics`]
|
||||
//!
|
||||
//! [`embedded-hal`]: https://docs.rs/embedded-hal/~0.1
|
||||
//! [`embedded-graphics`]: https://docs.rs/embedded-graphics/
|
||||
//! [`embedded-hal`]: https://docs.rs/embedded-hal
|
||||
//!
|
||||
//! # Requirements
|
||||
|
||||
//!
|
||||
//! ### SPI
|
||||
//! # Example
|
||||
//!
|
||||
//! - MISO is not connected/available
|
||||
//! - SPI_MODE_0 is used (CPHL = 0, CPOL = 0)
|
||||
//! - 8 bits per word, MSB first
|
||||
//! - Max. Speed tested by myself was 8Mhz but more should be possible (Ben Krasnow used 18Mhz with his implemenation)
|
||||
//!```rust, no_run
|
||||
//!# use embedded_hal_mock::*;
|
||||
//!# fn main() -> Result<(), MockError> {
|
||||
//!use embedded_graphics::{
|
||||
//! pixelcolor::BinaryColor::On as Black, prelude::*, primitives::Line, style::PrimitiveStyle,
|
||||
//!};
|
||||
//!use epd_waveshare::{epd1in54::*, prelude::*};
|
||||
//!#
|
||||
//!# let expectations = [];
|
||||
//!# let mut spi = spi::Mock::new(&expectations);
|
||||
//!# let expectations = [];
|
||||
//!# let cs_pin = pin::Mock::new(&expectations);
|
||||
//!# let busy_in = pin::Mock::new(&expectations);
|
||||
//!# let dc = pin::Mock::new(&expectations);
|
||||
//!# let rst = pin::Mock::new(&expectations);
|
||||
//!# let mut delay = delay::MockNoop::new();
|
||||
//!
|
||||
//! ### Other....
|
||||
//!// Setup EPD
|
||||
//!let mut epd = EPD1in54::new(&mut spi, cs_pin, busy_in, dc, rst, &mut delay)?;
|
||||
//!
|
||||
//!// Use display graphics from embedded-graphics
|
||||
//!let mut display = Display1in54::default();
|
||||
//!
|
||||
//!// Use embedded graphics for drawing a line
|
||||
//!let _ = Line::new(Point::new(0, 120), Point::new(0, 295))
|
||||
//! .into_styled(PrimitiveStyle::with_stroke(Black, 1))
|
||||
//! .draw(&mut display);
|
||||
//!
|
||||
//! // Display updated frame
|
||||
//!epd.update_frame(&mut spi, &display.buffer())?;
|
||||
//!epd.display_frame(&mut spi)?;
|
||||
//!
|
||||
//!// Set the EPD to sleep
|
||||
//!epd.sleep(&mut spi)?;
|
||||
//!# Ok(())
|
||||
//!# }
|
||||
//!```
|
||||
//!
|
||||
//! # Other information and requirements
|
||||
//!
|
||||
//! - Buffersize: Wherever a buffer is used it always needs to be of the size: `width / 8 * length`,
|
||||
//! where width and length being either the full e-ink size or the partial update window size
|
||||
//!
|
||||
//! # Examples
|
||||
//! ### SPI
|
||||
//!
|
||||
//! ```rust,ignore
|
||||
//! use epd_waveshare::{
|
||||
//! epd2in9::{EPD2in9, Display2in9},
|
||||
//! graphics::{Display, DisplayRotation},
|
||||
//! prelude::*,
|
||||
//! };
|
||||
//! use embedded_graphics::Drawing;
|
||||
//!
|
||||
//! // Setup EPD
|
||||
//! let mut epd = EPD2in9::new(&mut spi, cs_pin, busy_in, dc, rst, &mut delay).unwrap();
|
||||
//!
|
||||
//! // Use display graphics
|
||||
//! let mut display = Display2in9::default();
|
||||
//!
|
||||
//! // Write some hello world in the screenbuffer
|
||||
//! display.draw(
|
||||
//! Font6x8::render_str("Hello World!")
|
||||
//! .stroke(Some(Color::Black))
|
||||
//! .fill(Some(Color::White))
|
||||
//! .translate(Point::new(5, 50))
|
||||
//! .into_iter(),
|
||||
//! );
|
||||
//!
|
||||
//! // Display updated frame
|
||||
//! epd.update_frame(&mut spi, &display.buffer()).unwrap();
|
||||
//! epd.display_frame(&mut spi).expect("display frame new graphics");
|
||||
//!
|
||||
//! // Set the EPD to sleep
|
||||
//! epd.sleep(&mut spi).expect("sleep");
|
||||
//! ```
|
||||
//! MISO is not connected/available. SPI_MODE_0 is used (CPHL = 0, CPOL = 0) with 8 bits per word, MSB first.
|
||||
//!
|
||||
//! Maximum speed tested by myself was 8Mhz but more should be possible (Ben Krasnow used 18Mhz with his implemenation)
|
||||
//!
|
||||
#![no_std]
|
||||
#![deny(missing_docs)]
|
||||
|
||||
#[cfg(feature = "graphics")]
|
||||
pub mod graphics;
|
||||
|
|
@ -72,6 +80,7 @@ pub mod epd7in5;
|
|||
pub mod epd7in5_v2;
|
||||
pub(crate) mod type_a;
|
||||
|
||||
/// Includes everything important besides the chosen Display
|
||||
pub mod prelude {
|
||||
pub use crate::color::Color;
|
||||
pub use crate::traits::{RefreshLUT, WaveshareDisplay, WaveshareThreeColorDisplay};
|
||||
|
|
|
|||
|
|
@ -38,11 +38,11 @@ where
|
|||
/// This initialises the EPD and powers it up
|
||||
///
|
||||
/// This function is already called from
|
||||
/// - [new()](WaveshareInterface::new())
|
||||
/// - [new()](WaveshareDisplay::new())
|
||||
/// - [`wake_up`]
|
||||
///
|
||||
///
|
||||
/// This function calls [reset()](WaveshareInterface::reset()),
|
||||
/// This function calls [reset](WaveshareDisplay::reset),
|
||||
/// so you don't need to call reset your self when trying to wake your device up
|
||||
/// after setting it to sleep.
|
||||
fn init<DELAY: DelayMs<u8>>(
|
||||
|
|
@ -75,7 +75,47 @@ where
|
|||
|
||||
/// All the functions to interact with the EPDs
|
||||
///
|
||||
/// This trait includes all public functions to use the EPDS
|
||||
/// This trait includes all public functions to use the EPDs
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
///```rust, no_run
|
||||
///# use embedded_hal_mock::*;
|
||||
///# fn main() -> Result<(), MockError> {
|
||||
///use embedded_graphics::{
|
||||
/// pixelcolor::BinaryColor::On as Black, prelude::*, primitives::Line, style::PrimitiveStyle,
|
||||
///};
|
||||
///use epd_waveshare::{epd4in2::*, prelude::*};
|
||||
///#
|
||||
///# let expectations = [];
|
||||
///# let mut spi = spi::Mock::new(&expectations);
|
||||
///# let expectations = [];
|
||||
///# let cs_pin = pin::Mock::new(&expectations);
|
||||
///# let busy_in = pin::Mock::new(&expectations);
|
||||
///# let dc = pin::Mock::new(&expectations);
|
||||
///# let rst = pin::Mock::new(&expectations);
|
||||
///# let mut delay = delay::MockNoop::new();
|
||||
///
|
||||
///// Setup EPD
|
||||
///let mut epd = EPD4in2::new(&mut spi, cs_pin, busy_in, dc, rst, &mut delay)?;
|
||||
///
|
||||
///// Use display graphics from embedded-graphics
|
||||
///let mut display = Display4in2::default();
|
||||
///
|
||||
///// Use embedded graphics for drawing a line
|
||||
///let _ = Line::new(Point::new(0, 120), Point::new(0, 295))
|
||||
/// .into_styled(PrimitiveStyle::with_stroke(Black, 1))
|
||||
/// .draw(&mut display);
|
||||
///
|
||||
/// // Display updated frame
|
||||
///epd.update_frame(&mut spi, &display.buffer())?;
|
||||
///epd.display_frame(&mut spi)?;
|
||||
///
|
||||
///// Set the EPD to sleep
|
||||
///epd.sleep(&mut spi)?;
|
||||
///# Ok(())
|
||||
///# }
|
||||
///```
|
||||
pub trait WaveshareDisplay<SPI, CS, BUSY, DC, RST>
|
||||
where
|
||||
SPI: Write<u8>,
|
||||
|
|
@ -86,7 +126,7 @@ where
|
|||
{
|
||||
/// Creates a new driver from a SPI peripheral, CS Pin, Busy InputPin, DC
|
||||
///
|
||||
/// This already initialises the device. That means [init()](WaveshareInterface::init()) isn't needed directly afterwards
|
||||
/// This already initialises the device.
|
||||
fn new<DELAY: DelayMs<u8>>(
|
||||
spi: &mut SPI,
|
||||
cs: CS,
|
||||
|
|
@ -101,19 +141,18 @@ where
|
|||
/// Let the device enter deep-sleep mode to save power.
|
||||
///
|
||||
/// The deep sleep mode returns to standby with a hardware reset.
|
||||
/// But you can also use [wake_up()](WaveshareInterface::wake_up()) to awaken.
|
||||
/// But as you need to power it up once more anyway you can also just directly use [new()](WaveshareInterface::new()) for resetting
|
||||
/// and initialising which already contains the reset
|
||||
fn sleep(&mut self, spi: &mut SPI) -> Result<(), SPI::Error>;
|
||||
|
||||
/// Wakes the device up from sleep
|
||||
///
|
||||
/// Also reintialises the device if necessary.
|
||||
fn wake_up<DELAY: DelayMs<u8>>(
|
||||
&mut self,
|
||||
spi: &mut SPI,
|
||||
delay: &mut DELAY,
|
||||
) -> Result<(), SPI::Error>;
|
||||
|
||||
/// Sets the backgroundcolor for various commands like [clear_frame()](WaveshareInterface::clear_frame())
|
||||
/// Sets the backgroundcolor for various commands like [clear_frame](WaveshareDisplay::clear_frame)
|
||||
fn set_background_color(&mut self, color: Color);
|
||||
|
||||
/// Get current background color
|
||||
|
|
@ -153,7 +192,7 @@ where
|
|||
|
||||
/// Clears the frame buffer on the EPD with the declared background color
|
||||
///
|
||||
/// The background color can be changed with [`set_background_color`]
|
||||
/// The background color can be changed with [`WaveshareDisplay::set_background_color`]
|
||||
fn clear_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error>;
|
||||
|
||||
/// Trait for using various Waveforms from different LUTs
|
||||
|
|
|
|||
Loading…
Reference in New Issue