mirror of
https://github.com/Anshorei/epd-waveshare.git
synced 2026-10-04 06:16:42 +00:00
Various improvements (#25)
- Added is_busy to Waveshare_Interface - Added IS_BUSY_LOW const for all supported epds - Added is_busy to DisplayInterface - moved width, height and default_background_color directly to epd4in2 module - Added VarDisplay (a variable buffersize display/graphic driver) - Removed all Buffers (Buffer1in54,...) and instead made specialised Displays (Display1in54,...) with included Buffers - Updated and added more examples - Cargo fmt/clippy - Improved Docs/Readmes
This commit is contained in:
+42
-17
@@ -1,44 +1,73 @@
|
||||
use crate::epd1in54::{DEFAULT_BACKGROUND_COLOR, HEIGHT, WIDTH};
|
||||
use crate::graphics::{Display, DisplayRotation};
|
||||
use crate::prelude::*;
|
||||
use embedded_graphics::prelude::*;
|
||||
|
||||
/// Full size buffer for use with the 1in54 EPD
|
||||
///
|
||||
/// Can also be manuall constructed:
|
||||
/// `buffer: [DEFAULT_BACKGROUND_COLOR.get_byte_value(); WIDTH / 8 * HEIGHT]`
|
||||
pub struct Buffer1in54BlackWhite {
|
||||
pub buffer: [u8; WIDTH as usize * HEIGHT as usize / 8],
|
||||
pub struct Display1in54 {
|
||||
buffer: [u8; WIDTH as usize * HEIGHT as usize / 8],
|
||||
rotation: DisplayRotation,
|
||||
}
|
||||
|
||||
impl Default for Buffer1in54BlackWhite {
|
||||
impl Default for Display1in54 {
|
||||
fn default() -> Self {
|
||||
Buffer1in54BlackWhite {
|
||||
Display1in54 {
|
||||
buffer: [DEFAULT_BACKGROUND_COLOR.get_byte_value();
|
||||
WIDTH as usize * HEIGHT as usize / 8],
|
||||
rotation: DisplayRotation::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drawing<Color> for Display1in54 {
|
||||
fn draw<T>(&mut self, item_pixels: T)
|
||||
where
|
||||
T: Iterator<Item = Pixel<Color>>,
|
||||
{
|
||||
self.draw_helper(WIDTH, HEIGHT, item_pixels);
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Display1in54 {
|
||||
fn buffer(&self) -> &[u8] {
|
||||
&self.buffer
|
||||
}
|
||||
|
||||
fn get_mut_buffer(&mut self) -> &mut [u8] {
|
||||
&mut self.buffer
|
||||
}
|
||||
|
||||
fn set_rotation(&mut self, rotation: DisplayRotation) {
|
||||
self.rotation = rotation;
|
||||
}
|
||||
|
||||
fn rotation(&self) -> DisplayRotation {
|
||||
self.rotation
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::color::Color;
|
||||
use crate::graphics::{Display, DisplayRotation};
|
||||
use embedded_graphics::coord::Coord;
|
||||
use embedded_graphics::prelude::*;
|
||||
use embedded_graphics::primitives::Line;
|
||||
|
||||
// test buffer length
|
||||
#[test]
|
||||
fn graphics_size() {
|
||||
let mut display1in54 = Buffer1in54BlackWhite::default();
|
||||
let display = Display::new(WIDTH, HEIGHT, &mut display1in54.buffer);
|
||||
let display = Display1in54::default();
|
||||
assert_eq!(display.buffer().len(), 5000);
|
||||
}
|
||||
|
||||
// test default background color on all bytes
|
||||
#[test]
|
||||
fn graphics_default() {
|
||||
let mut display1in54 = Buffer1in54BlackWhite::default();
|
||||
let display = Display::new(WIDTH, HEIGHT, &mut display1in54.buffer);
|
||||
let display = Display1in54::default();
|
||||
for &byte in display.buffer() {
|
||||
assert_eq!(byte, DEFAULT_BACKGROUND_COLOR.get_byte_value());
|
||||
}
|
||||
@@ -46,8 +75,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn graphics_rotation_0() {
|
||||
let mut display1in54 = Buffer1in54BlackWhite::default();
|
||||
let mut display = Display::new(WIDTH, HEIGHT, &mut display1in54.buffer);
|
||||
let mut display = Display1in54::default();
|
||||
display.draw(
|
||||
Line::new(Coord::new(0, 0), Coord::new(7, 0))
|
||||
.with_stroke(Some(Color::Black))
|
||||
@@ -65,8 +93,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn graphics_rotation_90() {
|
||||
let mut display1in54 = Buffer1in54BlackWhite::default();
|
||||
let mut display = Display::new(WIDTH, HEIGHT, &mut display1in54.buffer);
|
||||
let mut display = Display1in54::default();
|
||||
display.set_rotation(DisplayRotation::Rotate90);
|
||||
display.draw(
|
||||
Line::new(Coord::new(0, 192), Coord::new(0, 199))
|
||||
@@ -85,8 +112,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn graphics_rotation_180() {
|
||||
let mut display1in54 = Buffer1in54BlackWhite::default();
|
||||
let mut display = Display::new(WIDTH, HEIGHT, &mut display1in54.buffer);
|
||||
let mut display = Display1in54::default();
|
||||
display.set_rotation(DisplayRotation::Rotate180);
|
||||
display.draw(
|
||||
Line::new(Coord::new(192, 199), Coord::new(199, 199))
|
||||
@@ -108,8 +134,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn graphics_rotation_270() {
|
||||
let mut display1in54 = Buffer1in54BlackWhite::default();
|
||||
let mut display = Display::new(WIDTH, HEIGHT, &mut display1in54.buffer);
|
||||
let mut display = Display1in54::default();
|
||||
display.set_rotation(DisplayRotation::Rotate270);
|
||||
display.draw(
|
||||
Line::new(Coord::new(199, 0), Coord::new(199, 7))
|
||||
|
||||
+14
-7
@@ -2,19 +2,19 @@
|
||||
//!
|
||||
//! # Example for the 1.54 in E-Ink Display
|
||||
//!
|
||||
//! ```ignore
|
||||
//! ```rust,ignore
|
||||
//! use epd_waveshare::{
|
||||
//! epd1in54::{EPD1in54, Buffer1in54},
|
||||
//! epd1in54::{EPD1in54, Display1in54},
|
||||
//! graphics::{Display, DisplayRotation},
|
||||
//! prelude::*,
|
||||
//! };
|
||||
//! use embedded_graphics::Drawing;
|
||||
//!
|
||||
//! // Setup EPD
|
||||
//! let mut epd = EPD1in54::new(&mut spi, cs_pin, busy_in, dc, rst, &mut delay)?;
|
||||
//! let mut epd = EPD1in54::new(&mut spi, cs_pin, busy_in, dc, rst, &mut delay).unwrap();
|
||||
//!
|
||||
//! // Use display graphics
|
||||
//! let mut buffer = Buffer1in54::default();
|
||||
//! let mut display = Display::new(epd.width(), epd.height(), &mut buffer.buffer);
|
||||
//! let mut display = Display1in54::default();
|
||||
//!
|
||||
//! // Write some hello world in the screenbuffer
|
||||
//! display.draw(
|
||||
@@ -37,6 +37,7 @@ pub const WIDTH: u32 = 200;
|
||||
pub const HEIGHT: u32 = 200;
|
||||
//const DPI: u16 = 184;
|
||||
pub const DEFAULT_BACKGROUND_COLOR: Color = Color::White;
|
||||
const IS_BUSY_LOW: bool = false;
|
||||
|
||||
use embedded_hal::{
|
||||
blocking::{delay::*, spi::Write},
|
||||
@@ -54,8 +55,10 @@ use crate::traits::{RefreshLUT, WaveshareDisplay};
|
||||
|
||||
use crate::interface::DisplayInterface;
|
||||
|
||||
#[cfg(feature = "graphics")]
|
||||
mod graphics;
|
||||
pub use crate::epd1in54::graphics::Buffer1in54BlackWhite as Buffer1in54;
|
||||
#[cfg(feature = "graphics")]
|
||||
pub use crate::epd1in54::graphics::Display1in54;
|
||||
|
||||
/// EPD1in54 driver
|
||||
///
|
||||
@@ -248,6 +251,10 @@ where
|
||||
RefreshLUT::QUICK => self.set_lut_helper(spi, &LUT_PARTIAL_UPDATE),
|
||||
}
|
||||
}
|
||||
|
||||
fn is_busy(&self) -> bool {
|
||||
self.interface.is_busy(IS_BUSY_LOW)
|
||||
}
|
||||
}
|
||||
|
||||
impl<SPI, CS, BUSY, DC, RST> EPD1in54<SPI, CS, BUSY, DC, RST>
|
||||
@@ -259,7 +266,7 @@ where
|
||||
RST: OutputPin,
|
||||
{
|
||||
fn wait_until_idle(&mut self) {
|
||||
self.interface.wait_until_idle(false);
|
||||
self.interface.wait_until_idle(IS_BUSY_LOW);
|
||||
}
|
||||
|
||||
pub(crate) fn use_full_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
|
||||
|
||||
Reference in New Issue
Block a user