mirror of
https://github.com/Anshorei/epd-waveshare.git
synced 2026-10-03 22:06:43 +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:
+39
-10
@@ -1,40 +1,69 @@
|
||||
use crate::epd2in9::{DEFAULT_BACKGROUND_COLOR, HEIGHT, WIDTH};
|
||||
use crate::graphics::{Display, DisplayRotation};
|
||||
use crate::prelude::*;
|
||||
use embedded_graphics::prelude::*;
|
||||
|
||||
/// Full size buffer for use with the 2in9 EPD
|
||||
/// Display with Fullsize buffer for use with the 2in9 EPD
|
||||
///
|
||||
/// Can also be manuall constructed:
|
||||
/// `buffer: [DEFAULT_BACKGROUND_COLOR.get_byte_value(); WIDTH / 8 * HEIGHT]`
|
||||
pub struct Buffer2in9 {
|
||||
pub buffer: [u8; WIDTH as usize * HEIGHT as usize / 8],
|
||||
pub struct Display2in9 {
|
||||
buffer: [u8; WIDTH as usize * HEIGHT as usize / 8],
|
||||
rotation: DisplayRotation,
|
||||
}
|
||||
|
||||
impl Default for Buffer2in9 {
|
||||
impl Default for Display2in9 {
|
||||
fn default() -> Self {
|
||||
Buffer2in9 {
|
||||
Display2in9 {
|
||||
buffer: [DEFAULT_BACKGROUND_COLOR.get_byte_value();
|
||||
WIDTH as usize * HEIGHT as usize / 8],
|
||||
rotation: DisplayRotation::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drawing<Color> for Display2in9 {
|
||||
fn draw<T>(&mut self, item_pixels: T)
|
||||
where
|
||||
T: Iterator<Item = Pixel<Color>>,
|
||||
{
|
||||
self.draw_helper(WIDTH, HEIGHT, item_pixels);
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Display2in9 {
|
||||
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::graphics::Display;
|
||||
|
||||
// test buffer length
|
||||
#[test]
|
||||
fn graphics_size() {
|
||||
let mut buffer = Buffer2in9::default();
|
||||
let display = Display::new(WIDTH, HEIGHT, &mut buffer.buffer);
|
||||
let display = Display2in9::default();
|
||||
assert_eq!(display.buffer().len(), 4736);
|
||||
}
|
||||
|
||||
// test default background color on all bytes
|
||||
#[test]
|
||||
fn graphics_default() {
|
||||
let mut buffer = Buffer2in9::default();
|
||||
let display = Display::new(WIDTH, HEIGHT, &mut buffer.buffer);
|
||||
let display = Display2in9::default();
|
||||
for &byte in display.buffer() {
|
||||
assert_eq!(byte, DEFAULT_BACKGROUND_COLOR.get_byte_value());
|
||||
}
|
||||
|
||||
+14
-7
@@ -4,19 +4,19 @@
|
||||
//!
|
||||
//! # Example for the 2.9 in E-Ink Display
|
||||
//!
|
||||
//! ```ignore
|
||||
//! ```rust,ignore
|
||||
//! use epd_waveshare::{
|
||||
//! epd2in9::{EPD2in9, Buffer2in9},
|
||||
//! 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)?;
|
||||
//! let mut epd = EPD2in9::new(&mut spi, cs_pin, busy_in, dc, rst, &mut delay).unwrap();
|
||||
//!
|
||||
//! // Use display graphics
|
||||
//! let mut buffer = Buffer2in9::default();
|
||||
//! let mut display = Display::new(epd.width(), epd.height(), &mut buffer.buffer);
|
||||
//! let mut display = Display2in9::default();
|
||||
//!
|
||||
//! // Write some hello world in the screenbuffer
|
||||
//! display.draw(
|
||||
@@ -38,6 +38,7 @@
|
||||
pub const WIDTH: u32 = 128;
|
||||
pub const HEIGHT: u32 = 296;
|
||||
pub const DEFAULT_BACKGROUND_COLOR: Color = Color::White;
|
||||
const IS_BUSY_LOW: bool = false;
|
||||
|
||||
use embedded_hal::{
|
||||
blocking::{delay::*, spi::Write},
|
||||
@@ -55,8 +56,10 @@ use crate::traits::*;
|
||||
|
||||
use crate::interface::DisplayInterface;
|
||||
|
||||
#[cfg(feature = "graphics")]
|
||||
mod graphics;
|
||||
pub use crate::epd2in9::graphics::Buffer2in9;
|
||||
#[cfg(feature = "graphics")]
|
||||
pub use crate::epd2in9::graphics::Display2in9;
|
||||
|
||||
/// EPD2in9 driver
|
||||
///
|
||||
@@ -247,6 +250,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> EPD2in9<SPI, CS, BUSY, DC, RST>
|
||||
@@ -258,7 +265,7 @@ where
|
||||
RST: OutputPin,
|
||||
{
|
||||
fn wait_until_idle(&mut self) {
|
||||
self.interface.wait_until_idle(false);
|
||||
self.interface.wait_until_idle(IS_BUSY_LOW);
|
||||
}
|
||||
|
||||
fn use_full_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
|
||||
|
||||
Reference in New Issue
Block a user