From 19df3e868acd63c3d2a7a6362499577c38901f2c Mon Sep 17 00:00:00 2001 From: Liam Murphy Date: Sat, 9 Apr 2022 10:06:26 +1000 Subject: [PATCH 1/3] Remove `background_color` and `clear_frame` 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. --- src/epd1in54/mod.rs | 24 ----------------- src/epd1in54b/mod.rs | 40 ++++----------------------- src/epd1in54c/mod.rs | 29 ++------------------ src/epd2in13_v2/mod.rs | 39 --------------------------- src/epd2in13bc/mod.rs | 32 ++-------------------- src/epd2in7b/mod.rs | 33 ++--------------------- src/epd2in9/mod.rs | 24 ----------------- src/epd2in9_v2/mod.rs | 38 -------------------------- src/epd2in9bc/mod.rs | 32 ++-------------------- src/epd4in2/mod.rs | 60 +---------------------------------------- src/epd5in65f/mod.rs | 40 +++++++++++---------------- src/epd5in83b_v2/mod.rs | 28 ++----------------- src/epd7in5/mod.rs | 24 +---------------- src/epd7in5_hd/mod.rs | 32 +--------------------- src/epd7in5_v2/mod.rs | 42 +---------------------------- src/traits.rs | 22 --------------- 16 files changed, 35 insertions(+), 504 deletions(-) diff --git a/src/epd1in54/mod.rs b/src/epd1in54/mod.rs index 0598de34..6a99f2c2 100644 --- a/src/epd1in54/mod.rs +++ b/src/epd1in54/mod.rs @@ -78,8 +78,6 @@ pub use crate::epd1in54::graphics::Display1in54; pub struct Epd1in54 { /// SPI interface: DisplayInterface, - /// Color - background_color: Color, /// Refresh LUT refresh: RefreshLut, } @@ -170,7 +168,6 @@ where let mut epd = Epd1in54 { interface, - background_color: DEFAULT_BACKGROUND_COLOR, refresh: RefreshLut::Full, }; @@ -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, diff --git a/src/epd1in54b/mod.rs b/src/epd1in54b/mod.rs index 6150c9cc..f4dcc795 100644 --- a/src/epd1in54b/mod.rs +++ b/src/epd1in54b/mod.rs @@ -35,7 +35,6 @@ pub use self::graphics::Display1in54b; /// Epd1in54b driver pub struct Epd1in54b { interface: DisplayInterface, - color: Color, } impl InternalWiAdditions @@ -149,9 +148,8 @@ where delay: &mut DELAY, ) -> Result { 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)?; @@ -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 } @@ -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(()) @@ -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, diff --git a/src/epd1in54c/mod.rs b/src/epd1in54c/mod.rs index 802b131b..b43f461b 100644 --- a/src/epd1in54c/mod.rs +++ b/src/epd1in54c/mod.rs @@ -33,7 +33,6 @@ pub use self::graphics::Display1in54c; /// Epd1in54c driver pub struct Epd1in54c { interface: DisplayInterface, - color: Color, } impl InternalWiAdditions @@ -132,9 +131,8 @@ where delay: &mut DELAY, ) -> Result { 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)?; @@ -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 } @@ -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)?; @@ -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, diff --git a/src/epd2in13_v2/mod.rs b/src/epd2in13_v2/mod.rs index 8368d56f..ee58f3e5 100644 --- a/src/epd2in13_v2/mod.rs +++ b/src/epd2in13_v2/mod.rs @@ -51,8 +51,6 @@ pub struct Epd2in13 { sleep_mode: DeepSleepMode, - /// Background Color - background_color: Color, refresh: RefreshLut, } @@ -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, }; @@ -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 } diff --git a/src/epd2in13bc/mod.rs b/src/epd2in13bc/mod.rs index 6c201177..19d9fa49 100644 --- a/src/epd2in13bc/mod.rs +++ b/src/epd2in13bc/mod.rs @@ -89,7 +89,6 @@ pub use self::graphics::Display2in13bc; /// Epd2in13bc driver pub struct Epd2in13bc { interface: DisplayInterface, - color: TriColor, } impl InternalWiAdditions @@ -201,9 +200,8 @@ where delay: &mut DELAY, ) -> Result { 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)?; @@ -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 } @@ -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)?; @@ -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, diff --git a/src/epd2in7b/mod.rs b/src/epd2in7b/mod.rs index 972d7858..4136d582 100644 --- a/src/epd2in7b/mod.rs +++ b/src/epd2in7b/mod.rs @@ -38,8 +38,6 @@ pub use self::graphics::Display2in7b; pub struct Epd2in7b { /// Connection Interface interface: DisplayInterface, - /// Background Color - color: Color, } impl InternalWiAdditions @@ -128,9 +126,8 @@ where delay: &mut DELAY, ) -> Result { 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)?; @@ -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(()) @@ -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 } diff --git a/src/epd2in9/mod.rs b/src/epd2in9/mod.rs index fc1ed549..bdfee7e0 100644 --- a/src/epd2in9/mod.rs +++ b/src/epd2in9/mod.rs @@ -75,8 +75,6 @@ pub use crate::epd2in9::graphics::Display2in9; pub struct Epd2in9 { /// SPI interface: DisplayInterface, - /// Color - background_color: Color, /// Refresh LUT refresh: RefreshLut, } @@ -163,7 +161,6 @@ where let mut epd = Epd2in9 { interface, - background_color: DEFAULT_BACKGROUND_COLOR, refresh: RefreshLut::Full, }; @@ -245,27 +242,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, diff --git a/src/epd2in9_v2/mod.rs b/src/epd2in9_v2/mod.rs index 16e3864a..9b114fd4 100644 --- a/src/epd2in9_v2/mod.rs +++ b/src/epd2in9_v2/mod.rs @@ -98,8 +98,6 @@ pub use crate::epd2in9_v2::graphics::Display2in9; pub struct Epd2in9 { /// SPI interface: DisplayInterface, - /// Color - background_color: Color, /// Refresh LUT refresh: RefreshLut, } @@ -176,7 +174,6 @@ where let mut epd = Epd2in9 { interface, - background_color: DEFAULT_BACKGROUND_COLOR, refresh: RefreshLut::Full, }; @@ -249,27 +246,6 @@ where Ok(()) } - fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> { - self.wait_until_idle(); - - // 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)?; - self.interface.cmd(spi, Command::WriteRam2)?; - self.interface.data_x_times(spi, color, WIDTH / 8 * HEIGHT) - } - - 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, @@ -469,20 +445,6 @@ where //TODO supported by display? unimplemented!() } - - /// Partial quick refresh not supported yet - #[allow(unused)] - fn clear_partial_frame( - &mut self, - spi: &mut SPI, - x: u32, - y: u32, - width: u32, - height: u32, - ) -> Result<(), SPI::Error> { - //TODO supported by display? - unimplemented!() - } } #[cfg(test)] diff --git a/src/epd2in9bc/mod.rs b/src/epd2in9bc/mod.rs index 783fab6f..a4ce9b7c 100644 --- a/src/epd2in9bc/mod.rs +++ b/src/epd2in9bc/mod.rs @@ -92,7 +92,6 @@ pub use self::graphics::Display2in9bc; /// Epd2in9bc driver pub struct Epd2in9bc { interface: DisplayInterface, - color: Color, } impl InternalWiAdditions @@ -204,9 +203,8 @@ where delay: &mut DELAY, ) -> Result { let interface = DisplayInterface::new(cs, busy, dc, rst); - let color = DEFAULT_BACKGROUND_COLOR; - let mut epd = Epd2in9bc { interface, color }; + let mut epd = Epd2in9bc { interface }; epd.init(spi, delay)?; @@ -234,14 +232,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 } @@ -261,7 +251,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)?; @@ -301,24 +291,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, diff --git a/src/epd4in2/mod.rs b/src/epd4in2/mod.rs index 900d20d4..d359772c 100644 --- a/src/epd4in2/mod.rs +++ b/src/epd4in2/mod.rs @@ -84,8 +84,6 @@ pub use self::graphics::Display4in2; pub struct Epd4in2 { /// Connection Interface interface: DisplayInterface, - /// Background Color - color: Color, /// Refresh LUT refresh: RefreshLut, } @@ -165,11 +163,9 @@ where delay: &mut DELAY, ) -> Result { let interface = DisplayInterface::new(cs, busy, dc, rst); - let color = DEFAULT_BACKGROUND_COLOR; let mut epd = Epd4in2 { interface, - color, refresh: RefreshLut::Full, }; @@ -208,7 +204,7 @@ where _delay: &mut DELAY, ) -> Result<(), SPI::Error> { self.wait_until_idle(); - let color_value = self.color.get_byte_value(); + let color_value = 0xff; self.interface.cmd(spi, Command::DataStartTransmission1)?; self.interface @@ -282,30 +278,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_value = self.color.get_byte_value(); - - self.interface.cmd(spi, Command::DataStartTransmission1)?; - self.interface - .data_x_times(spi, color_value, WIDTH / 8 * HEIGHT)?; - - self.interface.cmd(spi, Command::DataStartTransmission2)?; - self.interface - .data_x_times(spi, color_value, WIDTH / 8 * HEIGHT)?; - Ok(()) - } - - fn set_background_color(&mut self, color: Color) { - self.color = color; - } - - fn background_color(&self) -> &Color { - &self.color - } - fn width(&self) -> u32 { WIDTH } @@ -556,36 +528,6 @@ where self.interface.cmd(spi, Command::PartialOut)?; Ok(()) } - - fn clear_partial_frame( - &mut self, - spi: &mut SPI, - x: u32, - y: u32, - width: u32, - height: u32, - ) -> Result<(), SPI::Error> { - self.wait_until_idle(); - self.send_resolution(spi)?; - - let color_value = self.color.get_byte_value(); - - self.interface.cmd(spi, Command::PartialIn)?; - self.interface.cmd(spi, Command::PartialWindow)?; - - self.shift_display(spi, x, y, width, height)?; - - self.interface.cmd(spi, Command::DataStartTransmission1)?; - self.interface - .data_x_times(spi, color_value, width / 8 * height)?; - - self.interface.cmd(spi, Command::DataStartTransmission2)?; - self.interface - .data_x_times(spi, color_value, width / 8 * height)?; - - self.interface.cmd(spi, Command::PartialOut)?; - Ok(()) - } } #[cfg(test)] diff --git a/src/epd5in65f/mod.rs b/src/epd5in65f/mod.rs index 3199e381..2eb4483f 100644 --- a/src/epd5in65f/mod.rs +++ b/src/epd5in65f/mod.rs @@ -36,8 +36,7 @@ const IS_BUSY_LOW: bool = true; pub struct Epd5in65f { /// Connection Interface interface: DisplayInterface, - /// Background Color - color: OctColor, + border_color: OctColor, } impl InternalWiAdditions @@ -93,9 +92,11 @@ where delay: &mut DELAY, ) -> Result { let interface = DisplayInterface::new(cs, busy, dc, rst); - let color = DEFAULT_BACKGROUND_COLOR; - let mut epd = Epd5in65f { interface, color }; + let mut epd = Epd5in65f { + interface, + border_color: DEFAULT_BACKGROUND_COLOR, + }; epd.init(spi, delay)?; @@ -158,25 +159,6 @@ where Ok(()) } - fn clear_frame(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> { - let bg = OctColor::colors_byte(self.color, self.color); - self.wait_busy_high(); - self.update_vcom(spi)?; - self.send_resolution(spi)?; - self.command(spi, Command::DataStartTransmission1)?; - self.interface.data_x_times(spi, bg, WIDTH * HEIGHT / 2)?; - self.display_frame(spi, delay)?; - Ok(()) - } - - fn set_background_color(&mut self, color: OctColor) { - self.color = color; - } - - fn background_color(&self) -> &OctColor { - &self.color - } - fn width(&self) -> u32 { WIDTH } @@ -242,10 +224,20 @@ where } fn update_vcom(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { - let bg_color = (self.color.get_nibble() & 0b111) << 5; + let bg_color = (self.border_color.get_nibble() & 0b111) << 5; self.cmd_with_data(spi, Command::VcomAndDataIntervalSetting, &[0x17 | bg_color])?; Ok(()) } + + /// Set the outer border of the display to the chosen color. + /// + /// This will be applied on the next call to `update_frame`. + pub fn set_border_color(&mut self, color: OctColor) { + // FIXME: this is completely inconsistent with the other implementations of this (epd2in13bc and epd2in9bc), + // which immediately run `Command::VcomAndDataIntervalSetting`, + // but I don't have this hardware and I don't want to mess with the implementation without testing it. + self.border_color = color; + } } #[cfg(test)] diff --git a/src/epd5in83b_v2/mod.rs b/src/epd5in83b_v2/mod.rs index f7ad3570..8e8c645a 100644 --- a/src/epd5in83b_v2/mod.rs +++ b/src/epd5in83b_v2/mod.rs @@ -38,8 +38,6 @@ const NUM_DISPLAY_BITS: u32 = WIDTH * HEIGHT / 8; pub struct Epd5in83 { /// Connection Interface interface: DisplayInterface, - /// Background Color - color: Color, } impl InternalWiAdditions @@ -145,9 +143,8 @@ where delay: &mut DELAY, ) -> Result { let interface = DisplayInterface::new(cs, busy, dc, rst); - let color = DEFAULT_BACKGROUND_COLOR; - let mut epd = Epd5in83 { interface, color }; + let mut epd = Epd5in83 { interface }; epd.init(spi, delay)?; @@ -166,14 +163,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 } @@ -190,7 +179,7 @@ where ) -> Result<(), SPI::Error> { self.wait_until_idle(); self.update_achromatic_frame(spi, buffer)?; - 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)?; Ok(()) @@ -261,19 +250,6 @@ where Ok(()) } - fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> { - self.wait_until_idle(); - - // The Waveshare controllers all implement clear using 0x33 - self.command(spi, Command::DataStartTransmission1)?; - self.interface.data_x_times(spi, 0xFF, NUM_DISPLAY_BITS)?; - - self.command(spi, Command::DataStartTransmission2)?; - self.interface.data_x_times(spi, 0x00, NUM_DISPLAY_BITS)?; - - Ok(()) - } - fn set_lut( &mut self, _spi: &mut SPI, diff --git a/src/epd7in5/mod.rs b/src/epd7in5/mod.rs index 582061f7..182706f8 100644 --- a/src/epd7in5/mod.rs +++ b/src/epd7in5/mod.rs @@ -36,8 +36,6 @@ const IS_BUSY_LOW: bool = true; pub struct Epd7in5 { /// Connection Interface interface: DisplayInterface, - /// Background Color - color: Color, } impl InternalWiAdditions @@ -116,9 +114,8 @@ where delay: &mut DELAY, ) -> Result { let interface = DisplayInterface::new(cs, busy, dc, rst); - let color = DEFAULT_BACKGROUND_COLOR; - let mut epd = Epd7in5 { interface, color }; + let mut epd = Epd7in5 { interface }; epd.init(spi, delay)?; @@ -188,25 +185,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)?; - - // The Waveshare controllers all implement clear using 0x33 - self.command(spi, Command::DataStartTransmission1)?; - self.interface - .data_x_times(spi, 0x33, WIDTH / 8 * HEIGHT * 4)?; - Ok(()) - } - - fn set_background_color(&mut self, color: Color) { - self.color = color; - } - - fn background_color(&self) -> &Color { - &self.color - } - fn width(&self) -> u32 { WIDTH } diff --git a/src/epd7in5_hd/mod.rs b/src/epd7in5_hd/mod.rs index d4f49837..ebe82303 100644 --- a/src/epd7in5_hd/mod.rs +++ b/src/epd7in5_hd/mod.rs @@ -39,8 +39,6 @@ const IS_BUSY_LOW: bool = false; pub struct Epd7in5 { /// Connection Interface interface: DisplayInterface, - /// Background Color - color: Color, } impl InternalWiAdditions @@ -116,9 +114,8 @@ where delay: &mut DELAY, ) -> Result { let interface = DisplayInterface::new(cs, busy, dc, rst); - let color = DEFAULT_BACKGROUND_COLOR; - let mut epd = Epd7in5 { interface, color }; + let mut epd = Epd7in5 { interface }; epd.init(spi, delay)?; @@ -177,33 +174,6 @@ where Ok(()) } - fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> { - let pixel_count = WIDTH * HEIGHT / 8; - let background_color_byte = self.color.get_byte_value(); - - self.wait_until_idle(); - self.cmd_with_data(spi, Command::SetRamYAc, &[0x00, 0x00])?; - - for cmd in &[Command::WriteRamBw, Command::WriteRamRed] { - self.command(spi, *cmd)?; - self.interface - .data_x_times(spi, background_color_byte, pixel_count)?; - } - - self.cmd_with_data(spi, Command::DisplayUpdateControl2, &[0xF7])?; - self.command(spi, Command::MasterActivation)?; - self.wait_until_idle(); - Ok(()) - } - - fn set_background_color(&mut self, color: Color) { - self.color = color; - } - - fn background_color(&self) -> &Color { - &self.color - } - fn width(&self) -> u32 { WIDTH } diff --git a/src/epd7in5_v2/mod.rs b/src/epd7in5_v2/mod.rs index 3ee95af3..9269169f 100644 --- a/src/epd7in5_v2/mod.rs +++ b/src/epd7in5_v2/mod.rs @@ -40,8 +40,6 @@ const IS_BUSY_LOW: bool = true; pub struct Epd7in5 { /// Connection Interface interface: DisplayInterface, - /// Background Color - color: Color, } impl InternalWiAdditions @@ -98,9 +96,8 @@ where delay: &mut DELAY, ) -> Result { let interface = DisplayInterface::new(cs, busy, dc, rst); - let color = DEFAULT_BACKGROUND_COLOR; - let mut epd = Epd7in5 { interface, color }; + let mut epd = Epd7in5 { interface }; epd.init(spi, delay)?; @@ -159,28 +156,6 @@ where Ok(()) } - fn clear_frame(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> { - self.wait_until_idle(spi, delay)?; - self.send_resolution(spi)?; - - self.command(spi, Command::DataStartTransmission1)?; - self.interface.data_x_times(spi, 0x00, WIDTH * HEIGHT / 8)?; - - self.command(spi, Command::DataStartTransmission2)?; - self.interface.data_x_times(spi, 0x00, WIDTH * HEIGHT / 8)?; - - self.command(spi, Command::DisplayRefresh)?; - Ok(()) - } - - fn set_background_color(&mut self, color: Color) { - self.color = color; - } - - fn background_color(&self) -> &Color { - &self.color - } - fn width(&self) -> u32 { WIDTH } @@ -215,10 +190,6 @@ where self.interface.cmd(spi, command) } - fn send_data(&mut self, spi: &mut SPI, data: &[u8]) -> Result<(), SPI::Error> { - self.interface.data(spi, data) - } - fn cmd_with_data( &mut self, spi: &mut SPI, @@ -235,17 +206,6 @@ where } Ok(()) } - - fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { - let w = self.width(); - let h = self.height(); - - self.command(spi, Command::TconResolution)?; - self.send_data(spi, &[(w >> 8) as u8])?; - self.send_data(spi, &[w as u8])?; - self.send_data(spi, &[(h >> 8) as u8])?; - self.send_data(spi, &[h as u8]) - } } #[cfg(test)] diff --git a/src/traits.rs b/src/traits.rs index a74c2a23..c140189f 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -161,12 +161,6 @@ where /// Also reintialises the device if necessary. fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error>; - /// Sets the backgroundcolor for various commands like [clear_frame](WaveshareDisplay::clear_frame) - fn set_background_color(&mut self, color: Self::DisplayColor); - - /// Get current background color - fn background_color(&self) -> &Self::DisplayColor; - /// Get the width of the display fn width(&self) -> u32; @@ -209,11 +203,6 @@ where delay: &mut DELAY, ) -> Result<(), SPI::Error>; - /// Clears the frame buffer on the EPD with the declared background color - /// - /// The background color can be changed with [`WaveshareDisplay::set_background_color`] - fn clear_frame(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error>; - /// Trait for using various Waveforms from different LUTs /// E.g. for partial refreshes /// @@ -338,15 +327,4 @@ where width: u32, height: u32, ) -> Result<(), SPI::Error>; - - /// Clears the partial frame buffer on the EPD with the declared background color - /// The background color can be changed with [`WaveshareDisplay::set_background_color`] - fn clear_partial_frame( - &mut self, - spi: &mut SPI, - x: u32, - y: u32, - width: u32, - height: u32, - ) -> Result<(), SPI::Error>; } From fe58fc50f8a7e96a77bfedd8f3b18713b7e09f9c Mon Sep 17 00:00:00 2001 From: Liam Murphy Date: Mon, 18 Apr 2022 13:34:17 +1000 Subject: [PATCH 2/3] Update examples --- examples/epd1in54_no_graphics.rs | 20 +++++++++++++++++--- examples/epd2in13_v2.rs | 1 - examples/epd4in2.rs | 1 - 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/examples/epd1in54_no_graphics.rs b/examples/epd1in54_no_graphics.rs index 4eecbcd1..c83ad518 100644 --- a/examples/epd1in54_no_graphics.rs +++ b/examples/epd1in54_no_graphics.rs @@ -1,7 +1,11 @@ #![deny(warnings)] use embedded_hal::prelude::*; -use epd_waveshare::{epd1in54::Epd1in54, prelude::*}; +use epd_waveshare::{ + buffer_len, + epd1in54::{Epd1in54, HEIGHT, WIDTH}, + prelude::*, +}; use linux_embedded_hal::{ spidev::{self, SpidevOptions}, sysfs_gpio::Direction, @@ -12,6 +16,8 @@ use linux_embedded_hal::{ // needs to be run with sudo because of some sysfs_gpio permission problems and follow-up timing problems // see https://github.com/rust-embedded/rust-sysfs-gpio/issues/5 and follow-up issues +const BUFFER_LEN: usize = buffer_len(WIDTH as usize, HEIGHT as usize); + fn main() -> Result<(), std::io::Error> { // Configure SPI // SPI settings are from eink-waveshare-rs documenation @@ -61,7 +67,11 @@ fn main() -> Result<(), std::io::Error> { let mut epd = Epd1in54::new(&mut spi, cs_pin, busy, dc, rst, &mut delay)?; // Clear the full screen - epd.clear_frame(&mut spi, &mut delay)?; + epd.update_frame( + &mut spi, + &[Color::White.get_byte_value(); BUFFER_LEN], + &mut delay, + )?; epd.display_frame(&mut spi, &mut delay)?; // Speeddemo @@ -75,7 +85,11 @@ fn main() -> Result<(), std::io::Error> { } // Clear the full screen - epd.clear_frame(&mut spi, &mut delay)?; + epd.update_frame( + &mut spi, + &[Color::White.get_byte_value(); BUFFER_LEN], + &mut delay, + )?; epd.display_frame(&mut spi, &mut delay)?; // Draw some squares diff --git a/examples/epd2in13_v2.rs b/examples/epd2in13_v2.rs index 3e58ac1e..f60adb9e 100644 --- a/examples/epd2in13_v2.rs +++ b/examples/epd2in13_v2.rs @@ -126,7 +126,6 @@ fn main() -> Result<(), std::io::Error> { epd2in13 .set_refresh(&mut spi, &mut delay, RefreshLut::Quick) .unwrap(); - epd2in13.clear_frame(&mut spi, &mut delay).unwrap(); // a moving `Hello World!` let limit = 10; diff --git a/examples/epd4in2.rs b/examples/epd4in2.rs index 729e03ce..d12e73c0 100644 --- a/examples/epd4in2.rs +++ b/examples/epd4in2.rs @@ -128,7 +128,6 @@ fn main() -> Result<(), std::io::Error> { // a moving `Hello World!` let limit = 10; epd4in2.set_lut(&mut spi, Some(RefreshLut::Quick)).unwrap(); - epd4in2.clear_frame(&mut spi, &mut delay).unwrap(); for i in 0..limit { //println!("Moving Hello World. Loop {} from {}", (i + 1), limit); From 9424e00939552bf5a78d0e3a5ca3960712e71032 Mon Sep 17 00:00:00 2001 From: Liam Murphy Date: Mon, 18 Apr 2022 14:00:18 +1000 Subject: [PATCH 3/3] Fix epd1in54_v2 --- src/epd1in54_v2/mod.rs | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/src/epd1in54_v2/mod.rs b/src/epd1in54_v2/mod.rs index 1e6156c4..b1c8b26a 100644 --- a/src/epd1in54_v2/mod.rs +++ b/src/epd1in54_v2/mod.rs @@ -33,8 +33,6 @@ pub use crate::epd1in54::graphics::Display1in54; pub struct Epd1in54 { /// SPI interface: DisplayInterface, - /// Color - background_color: Color, /// Refresh LUT refresh: RefreshLut, @@ -121,7 +119,6 @@ where let mut epd = Epd1in54 { interface, - background_color: DEFAULT_BACKGROUND_COLOR, refresh: RefreshLut::Full, }; @@ -203,30 +200,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)?; - self.interface.cmd(spi, Command::WriteRam2)?; - 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,