Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove background color but not clear_frame #134

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/epd1in54_no_graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ fn main() -> Result<(), std::io::Error> {
let mut epd = Epd1in54::new(&mut spi, cs_pin, busy, dc, rst, &mut delay, Some(5))?;

// Clear the full screen
epd.clear_frame(&mut spi, &mut delay)?;
epd.clear_frame(&mut spi, &mut delay, Color::White)?;
epd.display_frame(&mut spi, &mut delay)?;

// Speeddemo
Expand All @@ -83,7 +83,7 @@ fn main() -> Result<(), std::io::Error> {
}

// Clear the full screen
epd.clear_frame(&mut spi, &mut delay)?;
epd.clear_frame(&mut spi, &mut delay, Color::White)?;
epd.display_frame(&mut spi, &mut delay)?;

// Draw some squares
Expand Down
2 changes: 1 addition & 1 deletion examples/epd2in13_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ fn main() -> Result<(), std::io::Error> {
epd2in13
.set_refresh(&mut spi, &mut delay, RefreshLut::Quick)
.unwrap();
epd2in13.clear_frame(&mut spi, &mut delay).unwrap();
epd2in13.clear_frame(&mut spi, &mut delay, Color::White).unwrap();

// a moving `Hello World!`
let limit = 10;
Expand Down
2 changes: 1 addition & 1 deletion examples/epd4in2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ fn main() -> Result<(), std::io::Error> {
epd4in2
.set_lut(&mut spi, &mut delay, Some(RefreshLut::Quick))
.unwrap();
epd4in2.clear_frame(&mut spi, &mut delay).unwrap();
epd4in2.clear_frame(&mut spi, &mut delay, Color::White).unwrap();
for i in 0..limit {
//println!("Moving Hello World. Loop {} from {}", (i + 1), limit);

Expand Down
4 changes: 2 additions & 2 deletions examples/epd4in2_variable_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use embedded_graphics::{
use embedded_hal::prelude::*;
use epd_waveshare::{
color::*,
epd4in2::{self, Epd4in2},
epd4in2::Epd4in2,
graphics::{DisplayRotation, VarDisplay},
prelude::*,
};
Expand Down Expand Up @@ -69,7 +69,7 @@ fn main() -> Result<(), std::io::Error> {

let (x, y, width, height) = (50, 50, 250, 250);

let mut buffer = [epd4in2::DEFAULT_BACKGROUND_COLOR.get_byte_value(); 62500]; //250*250
let mut buffer = [Color::White.get_byte_value(); 62500]; //250*250
let mut display = VarDisplay::new(width, height, &mut buffer, false).unwrap();
display.set_rotation(DisplayRotation::Rotate0);
draw_text(&mut display, "Rotate 0!", 5, 50);
Expand Down
23 changes: 7 additions & 16 deletions src/epd1in54/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@
pub const WIDTH: u32 = 200;
/// Height of the display
pub const HEIGHT: u32 = 200;
/// Default Background Color
pub const DEFAULT_BACKGROUND_COLOR: Color = Color::White;
//const DPI: u16 = 184;
const IS_BUSY_LOW: bool = false;

Expand Down Expand Up @@ -84,8 +82,6 @@ pub type Display1in54 = crate::graphics::Display<
pub struct Epd1in54<SPI, CS, BUSY, DC, RST, DELAY> {
/// SPI
interface: DisplayInterface<SPI, CS, BUSY, DC, RST, DELAY>,
/// Color
background_color: Color,
/// Refresh LUT
refresh: RefreshLut,
}
Expand Down Expand Up @@ -177,7 +173,6 @@ where

let mut epd = Epd1in54 {
interface,
background_color: DEFAULT_BACKGROUND_COLOR,
refresh: RefreshLut::Full,
};

Expand Down Expand Up @@ -257,27 +252,24 @@ where
Ok(())
}

fn clear_frame(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
fn clear_frame(
&mut self,
spi: &mut SPI,
delay: &mut DELAY,
color: Self::DisplayColor,
) -> Result<(), SPI::Error> {
self.wait_until_idle(spi, delay)?;
self.use_full_frame(spi, delay)?;

// clear the ram with the background color
let color = self.background_color.get_byte_value();
let color = color.get_byte_value();

self.interface.cmd(spi, Command::WriteRam)?;
self.interface
.data_x_times(spi, color, WIDTH / 8 * HEIGHT)?;
Ok(())
}

fn set_background_color(&mut self, background_color: Color) {
self.background_color = background_color;
}

fn background_color(&self) -> &Color {
&self.background_color
}

fn set_lut(
&mut self,
spi: &mut SPI,
Expand Down Expand Up @@ -400,6 +392,5 @@ mod tests {
fn epd_size() {
assert_eq!(WIDTH, 200);
assert_eq!(HEIGHT, 200);
assert_eq!(DEFAULT_BACKGROUND_COLOR, Color::White);
}
}
23 changes: 7 additions & 16 deletions src/epd1in54_v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
pub const WIDTH: u32 = 200;
/// Height of the display
pub const HEIGHT: u32 = 200;
/// Default Background Color
pub const DEFAULT_BACKGROUND_COLOR: Color = Color::White;
const IS_BUSY_LOW: bool = false;

use embedded_hal::{
Expand All @@ -33,8 +31,6 @@ pub use crate::epd1in54::Display1in54;
pub struct Epd1in54<SPI, CS, BUSY, DC, RST, DELAY> {
/// SPI
interface: DisplayInterface<SPI, CS, BUSY, DC, RST, DELAY>,
/// Color
background_color: Color,

/// Refresh LUT
refresh: RefreshLut,
Expand Down Expand Up @@ -122,7 +118,6 @@ where

let mut epd = Epd1in54 {
interface,
background_color: DEFAULT_BACKGROUND_COLOR,
refresh: RefreshLut::Full,
};

Expand Down Expand Up @@ -205,12 +200,17 @@ where
Ok(())
}

fn clear_frame(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
fn clear_frame(
&mut self,
spi: &mut SPI,
delay: &mut DELAY,
color: Self::DisplayColor,
) -> Result<(), SPI::Error> {
self.wait_until_idle(spi, delay)?;
self.use_full_frame(spi, delay)?;

// clear the ram with the background color
let color = self.background_color.get_byte_value();
let color = color.get_byte_value();

self.interface.cmd(spi, Command::WriteRam)?;
self.interface
Expand All @@ -221,14 +221,6 @@ where
Ok(())
}

fn set_background_color(&mut self, background_color: Color) {
self.background_color = background_color;
}

fn background_color(&self) -> &Color {
&self.background_color
}

fn set_lut(
&mut self,
spi: &mut SPI,
Expand Down Expand Up @@ -386,6 +378,5 @@ mod tests {
fn epd_size() {
assert_eq!(WIDTH, 200);
assert_eq!(HEIGHT, 200);
assert_eq!(DEFAULT_BACKGROUND_COLOR, Color::White);
}
}
26 changes: 9 additions & 17 deletions src/epd1in54b/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ use crate::epd1in54b::constants::*;
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;

use crate::color::Color;
Expand All @@ -42,7 +40,6 @@ pub type Display1in54b = crate::graphics::Display<
/// Epd1in54b driver
pub struct Epd1in54b<SPI, CS, BUSY, DC, RST, DELAY> {
interface: DisplayInterface<SPI, CS, BUSY, DC, RST, DELAY>,
color: Color,
}

impl<SPI, CS, BUSY, DC, RST, DELAY> InternalWiAdditions<SPI, CS, BUSY, DC, RST, DELAY>
Expand Down Expand Up @@ -164,9 +161,8 @@ where
delay_us: Option<u32>,
) -> Result<Self, SPI::Error> {
let interface = DisplayInterface::new(cs, busy, dc, rst, delay_us);
let color = DEFAULT_BACKGROUND_COLOR;

let mut epd = Epd1in54b { interface, color };
let mut epd = Epd1in54b { interface };

epd.init(spi, delay)?;

Expand Down Expand Up @@ -197,14 +193,6 @@ where
self.init(spi, delay)
}

fn set_background_color(&mut self, color: Color) {
self.color = color;
}

fn background_color(&self) -> &Color {
&self.color
}

fn width(&self) -> u32 {
WIDTH
}
Expand Down Expand Up @@ -233,7 +221,7 @@ where
//NOTE: Example code has a delay here

// Clear the read layer
let color = self.color.get_byte_value();
let color = Color::White.get_byte_value();
let nbits = WIDTH * (HEIGHT / 8);

self.interface.cmd(spi, Command::DataStartTransmission2)?;
Expand Down Expand Up @@ -274,11 +262,16 @@ where
Ok(())
}

fn clear_frame(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
fn clear_frame(
&mut self,
spi: &mut SPI,
delay: &mut DELAY,
color: Self::DisplayColor,
) -> Result<(), SPI::Error> {
self.wait_until_idle(spi, delay)?;
self.send_resolution(spi)?;

let color = DEFAULT_BACKGROUND_COLOR.get_byte_value();
let color = color.get_byte_value();
Comment on lines -281 to +274

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be used for both the black and white layer and the chromatic layer - since we're only clearing to black or white, the chromatic layer should always be left as white.


// Clear the black
self.interface.cmd(spi, Command::DataStartTransmission1)?;
Expand Down Expand Up @@ -381,6 +374,5 @@ mod tests {
fn epd_size() {
assert_eq!(WIDTH, 200);
assert_eq!(HEIGHT, 200);
assert_eq!(DEFAULT_BACKGROUND_COLOR, Color::White);
}
}
25 changes: 9 additions & 16 deletions src/epd1in54c/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ use crate::traits::{
pub const WIDTH: u32 = 152;
/// Height of epd1in54 in pixels
pub const HEIGHT: u32 = 152;
/// Default Background Color (white)
pub const DEFAULT_BACKGROUND_COLOR: Color = Color::White;
const IS_BUSY_LOW: bool = true;
const NUM_DISPLAY_BITS: u32 = WIDTH * HEIGHT / 8;

Expand All @@ -39,7 +37,6 @@ pub type Display1in54c = crate::graphics::Display<
/// Epd1in54c driver
pub struct Epd1in54c<SPI, CS, BUSY, DC, RST, DELAY> {
interface: DisplayInterface<SPI, CS, BUSY, DC, RST, DELAY>,
color: Color,
}

impl<SPI, CS, BUSY, DC, RST, DELAY> InternalWiAdditions<SPI, CS, BUSY, DC, RST, DELAY>
Expand Down Expand Up @@ -146,9 +143,8 @@ where
delay_us: Option<u32>,
) -> Result<Self, SPI::Error> {
let interface = DisplayInterface::new(cs, busy, dc, rst, delay_us);
let color = DEFAULT_BACKGROUND_COLOR;

let mut epd = Epd1in54c { interface, color };
let mut epd = Epd1in54c { interface };

epd.init(spi, delay)?;

Expand All @@ -169,14 +165,6 @@ where
self.init(spi, delay)
}

fn set_background_color(&mut self, color: Color) {
self.color = color;
}

fn background_color(&self) -> &Color {
&self.color
}

fn width(&self) -> u32 {
WIDTH
}
Expand All @@ -194,7 +182,7 @@ where
self.update_achromatic_frame(spi, delay, buffer)?;

// Clear the chromatic layer
let color = self.color.get_byte_value();
let color = Color::White.get_byte_value();

self.command(spi, Command::DataStartTransmission2)?;
self.interface.data_x_times(spi, color, NUM_DISPLAY_BITS)?;
Expand Down Expand Up @@ -235,9 +223,14 @@ where
Ok(())
}

fn clear_frame(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
fn clear_frame(
&mut self,
spi: &mut SPI,
delay: &mut DELAY,
color: Self::DisplayColor,
) -> Result<(), SPI::Error> {
self.wait_until_idle(spi, delay)?;
let color = DEFAULT_BACKGROUND_COLOR.get_byte_value();
let color = color.get_byte_value();

// Clear the black
self.command(spi, Command::DataStartTransmission1)?;
Expand Down
Loading