From 6129723c416c31593b1623bfd8976d39c2b8b97f Mon Sep 17 00:00:00 2001 From: BuggStream Date: Sun, 7 Feb 2021 23:30:44 +0100 Subject: [PATCH] Clean up and simplify code --- src/epd1in54c/command.rs | 2 +- src/epd1in54c/graphics.rs | 2 +- src/epd1in54c/mod.rs | 24 +++++++----------------- 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/src/epd1in54c/command.rs b/src/epd1in54c/command.rs index 830742f..3715030 100644 --- a/src/epd1in54c/command.rs +++ b/src/epd1in54c/command.rs @@ -1,4 +1,4 @@ -//! SPI Commands for the Waveshare 1.54" red E-Ink Display +//! SPI Commands for the Waveshare 1.54" C red or yellow E-Ink Display use crate::traits; #[allow(dead_code)] diff --git a/src/epd1in54c/graphics.rs b/src/epd1in54c/graphics.rs index 2f636da..dc66b7e 100644 --- a/src/epd1in54c/graphics.rs +++ b/src/epd1in54c/graphics.rs @@ -3,7 +3,7 @@ use crate::graphics::{Display, DisplayRotation}; use embedded_graphics::pixelcolor::BinaryColor; use embedded_graphics::prelude::*; -/// Full size buffer for use with the 1in54 EPD +/// Full size buffer for use with the 1in54c EPD /// /// Can also be manually constructed and be used together with VarDisplay pub struct Display1in54c { diff --git a/src/epd1in54c/mod.rs b/src/epd1in54c/mod.rs index d453bfe..f8bd54d 100644 --- a/src/epd1in54c/mod.rs +++ b/src/epd1in54c/mod.rs @@ -16,15 +16,12 @@ pub const WIDTH: u32 = 152; pub const HEIGHT: u32 = 152; /// Default Background Color (white) pub const DEFAULT_BACKGROUND_COLOR: Color = Color::White; - -const NUM_DISPLAY_BITS: u32 = WIDTH * HEIGHT / 8; - const IS_BUSY_LOW: bool = true; +const NUM_DISPLAY_BITS: u32 = WIDTH * HEIGHT / 8; use crate::color::Color; pub(crate) mod command; - use self::command::Command; #[cfg(feature = "graphics")] @@ -100,10 +97,8 @@ where fn update_achromatic_frame(&mut self, spi: &mut SPI, black: &[u8]) -> Result<(), SPI::Error> { self.wait_until_idle(); + self.cmd_with_data(spi, Command::DATA_START_TRANSMISSION_1, black)?; - self.interface - .cmd(spi, Command::DATA_START_TRANSMISSION_1)?; - self.interface.data(spi, black)?; Ok(()) } @@ -113,10 +108,8 @@ where chromatic: &[u8], ) -> Result<(), SPI::Error> { self.wait_until_idle(); + self.cmd_with_data(spi, Command::DATA_START_TRANSMISSION_2, chromatic)?; - self.interface - .cmd(spi, Command::DATA_START_TRANSMISSION_2)?; - self.interface.data(spi, chromatic)?; Ok(()) } } @@ -189,8 +182,7 @@ where // Clear the chromatic layer let color = self.color.get_byte_value(); - self.interface - .cmd(spi, Command::DATA_START_TRANSMISSION_2)?; + self.command(spi, Command::DATA_START_TRANSMISSION_2)?; self.interface.data_x_times(spi, color, NUM_DISPLAY_BITS)?; Ok(()) @@ -228,13 +220,11 @@ where let color = DEFAULT_BACKGROUND_COLOR.get_byte_value(); // Clear the black - self.interface - .cmd(spi, Command::DATA_START_TRANSMISSION_1)?; + self.command(spi, Command::DATA_START_TRANSMISSION_1)?; self.interface.data_x_times(spi, color, NUM_DISPLAY_BITS)?; - // Clear the red - self.interface - .cmd(spi, Command::DATA_START_TRANSMISSION_2)?; + // Clear the chromatic + self.command(spi, Command::DATA_START_TRANSMISSION_2)?; self.interface.data_x_times(spi, color, NUM_DISPLAY_BITS)?; Ok(())