Skip to content

Commit

Permalink
Remove background_color and clear_frame
Browse files Browse the repository at this point in the history
Resolves #100

I did find one display which was using `background_color` for stuff other than `clear_frame` - the epd5in16f was using it to set the border color. For now, I've replaced it with a `set_border_color` method which is only on that display. It should eventually be replaced by a proper method on `WaveshareDisplay`, but I don't have any hardware which supports border colors that I can test with.
  • Loading branch information
Liamolucko committed Apr 18, 2022
1 parent b99a07c commit 19df3e8
Show file tree
Hide file tree
Showing 16 changed files with 35 additions and 504 deletions.
24 changes: 0 additions & 24 deletions src/epd1in54/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ pub use crate::epd1in54::graphics::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 @@ -170,7 +168,6 @@ where

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

Expand Down Expand Up @@ -249,27 +246,6 @@ where
Ok(())
}

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

// clear the ram with the background color
let color = self.background_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
40 changes: 5 additions & 35 deletions src/epd1in54b/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ pub use self::graphics::Display1in54b;
/// 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 @@ -149,9 +148,8 @@ where
delay: &mut DELAY,
) -> Result<Self, SPI::Error> {
let interface = DisplayInterface::new(cs, busy, dc, rst);
let color = DEFAULT_BACKGROUND_COLOR;

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

epd.init(spi, delay)?;

Expand Down Expand Up @@ -182,14 +180,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 @@ -217,12 +207,12 @@ where

//NOTE: Example code has a delay here

// Clear the read layer
let color = self.color.get_byte_value();
let nbits = WIDTH * (HEIGHT / 8);
// Clear the red layer
let color = 0xff;
let nbytes = WIDTH * (HEIGHT / 8);

self.interface.cmd(spi, Command::DataStartTransmission2)?;
self.interface.data_x_times(spi, color, nbits)?;
self.interface.data_x_times(spi, color, nbytes)?;

//NOTE: Example code has a delay here
Ok(())
Expand Down Expand Up @@ -258,26 +248,6 @@ where
Ok(())
}

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

let color = DEFAULT_BACKGROUND_COLOR.get_byte_value();

// Clear the black
self.interface.cmd(spi, Command::DataStartTransmission1)?;

// Uses 2 bits per pixel
self.interface
.data_x_times(spi, color, 2 * (WIDTH * HEIGHT / 8))?;

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

fn set_lut(
&mut self,
spi: &mut SPI,
Expand Down
29 changes: 2 additions & 27 deletions src/epd1in54c/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ pub use self::graphics::Display1in54c;
/// 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 @@ -132,9 +131,8 @@ where
delay: &mut DELAY,
) -> Result<Self, SPI::Error> {
let interface = DisplayInterface::new(cs, busy, dc, rst);
let color = DEFAULT_BACKGROUND_COLOR;

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

epd.init(spi, delay)?;

Expand All @@ -155,14 +153,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 @@ -180,7 +170,7 @@ where
self.update_achromatic_frame(spi, buffer)?;

// Clear the chromatic layer
let color = self.color.get_byte_value();
let color = 0xff;

self.command(spi, Command::DataStartTransmission2)?;
self.interface.data_x_times(spi, color, NUM_DISPLAY_BITS)?;
Expand Down Expand Up @@ -220,21 +210,6 @@ where
Ok(())
}

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

// Clear the black
self.command(spi, Command::DataStartTransmission1)?;
self.interface.data_x_times(spi, color, NUM_DISPLAY_BITS)?;

// Clear the chromatic
self.command(spi, Command::DataStartTransmission2)?;
self.interface.data_x_times(spi, color, NUM_DISPLAY_BITS)?;

Ok(())
}

fn set_lut(
&mut self,
_spi: &mut SPI,
Expand Down
39 changes: 0 additions & 39 deletions src/epd2in13_v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ pub struct Epd2in13<SPI, CS, BUSY, DC, RST, DELAY> {

sleep_mode: DeepSleepMode,

/// Background Color
background_color: Color,
refresh: RefreshLut,
}

Expand Down Expand Up @@ -172,7 +170,6 @@ where
let mut epd = Epd2in13 {
interface: DisplayInterface::new(cs, busy, dc, rst),
sleep_mode: DeepSleepMode::Mode1,
background_color: DEFAULT_BACKGROUND_COLOR,
refresh: RefreshLut::Full,
};

Expand Down Expand Up @@ -299,42 +296,6 @@ where
Ok(())
}

fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
let color = self.background_color.get_byte_value();

self.set_ram_area(spi, 0, 0, WIDTH - 1, HEIGHT - 1)?;
self.set_ram_address_counters(spi, 0, 0)?;

self.command(spi, Command::WriteRam)?;
self.interface.data_x_times(
spi,
color,
buffer_len(WIDTH as usize, HEIGHT as usize) as u32,
)?;

// Always keep the base buffer equals to current if not doing partial refresh.
if self.refresh == RefreshLut::Full {
self.set_ram_area(spi, 0, 0, WIDTH - 1, HEIGHT - 1)?;
self.set_ram_address_counters(spi, 0, 0)?;

self.command(spi, Command::WriteRamRed)?;
self.interface.data_x_times(
spi,
color,
buffer_len(WIDTH as usize, HEIGHT as usize) as u32,
)?;
}
Ok(())
}

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

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

fn width(&self) -> u32 {
WIDTH
}
Expand Down
32 changes: 2 additions & 30 deletions src/epd2in13bc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ pub use self::graphics::Display2in13bc;
/// Epd2in13bc driver
pub struct Epd2in13bc<SPI, CS, BUSY, DC, RST, DELAY> {
interface: DisplayInterface<SPI, CS, BUSY, DC, RST, DELAY>,
color: TriColor,
}

impl<SPI, CS, BUSY, DC, RST, DELAY> InternalWiAdditions<SPI, CS, BUSY, DC, RST, DELAY>
Expand Down Expand Up @@ -201,9 +200,8 @@ where
delay: &mut DELAY,
) -> Result<Self, SPI::Error> {
let interface = DisplayInterface::new(cs, busy, dc, rst);
let color = DEFAULT_BACKGROUND_COLOR;

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

epd.init(spi, delay)?;

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

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

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

fn width(&self) -> u32 {
WIDTH
}
Expand All @@ -258,7 +248,7 @@ where
self.interface.data(spi, buffer)?;

// Clear the chromatic layer
let color = self.color.get_byte_value();
let color = 0xff;

self.interface.cmd(spi, Command::DataStartTransmission2)?;
self.interface.data_x_times(spi, color, NUM_DISPLAY_BITS)?;
Expand Down Expand Up @@ -298,24 +288,6 @@ where
Ok(())
}

fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
self.send_resolution(spi)?;

let color = DEFAULT_BACKGROUND_COLOR.get_byte_value();

// Clear the black
self.interface.cmd(spi, Command::DataStartTransmission1)?;

self.interface.data_x_times(spi, color, NUM_DISPLAY_BITS)?;

// Clear the chromatic
self.interface.cmd(spi, Command::DataStartTransmission2)?;
self.interface.data_x_times(spi, color, NUM_DISPLAY_BITS)?;

self.wait_until_idle();
Ok(())
}

fn set_lut(
&mut self,
_spi: &mut SPI,
Expand Down
33 changes: 2 additions & 31 deletions src/epd2in7b/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ pub use self::graphics::Display2in7b;
pub struct Epd2in7b<SPI, CS, BUSY, DC, RST, DELAY> {
/// Connection Interface
interface: DisplayInterface<SPI, CS, BUSY, DC, RST, DELAY>,
/// Background Color
color: Color,
}

impl<SPI, CS, BUSY, DC, RST, DELAY> InternalWiAdditions<SPI, CS, BUSY, DC, RST, DELAY>
Expand Down Expand Up @@ -128,9 +126,8 @@ where
delay: &mut DELAY,
) -> Result<Self, SPI::Error> {
let interface = DisplayInterface::new(cs, busy, dc, rst);
let color = DEFAULT_BACKGROUND_COLOR;

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

epd.init(spi, delay)?;

Expand Down Expand Up @@ -164,8 +161,7 @@ where

// Clear chromatic layer since we won't be using it here
self.interface.cmd(spi, Command::DataStartTransmission2)?;
self.interface
.data_x_times(spi, !self.color.get_byte_value(), WIDTH * HEIGHT / 8)?;
self.interface.data_x_times(spi, 0x00, WIDTH * HEIGHT / 8)?;

self.interface.cmd(spi, Command::DataStop)?;
Ok(())
Expand Down Expand Up @@ -215,31 +211,6 @@ where
Ok(())
}

fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
self.wait_until_idle();

let color_value = self.color.get_byte_value();
self.interface.cmd(spi, Command::DataStartTransmission1)?;
self.interface
.data_x_times(spi, color_value, WIDTH * HEIGHT / 8)?;

self.interface.cmd(spi, Command::DataStop)?;

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

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
Loading

0 comments on commit 19df3e8

Please sign in to comment.