From 9a1575b2ec113489fe2221679a665ebec325b61c Mon Sep 17 00:00:00 2001 From: Edwin Svensson Date: Sun, 4 Apr 2021 22:10:50 +0200 Subject: [PATCH 1/3] API change to partially fix #70 --- examples/epd1in54_no_graphics.rs | 14 +++--- examples/epd2in13_v2.rs | 14 +++--- examples/epd4in2.rs | 14 +++--- examples/epd4in2_variable_size.rs | 6 +-- src/epd1in54/mod.rs | 55 +++++++++++---------- src/epd1in54b/mod.rs | 62 +++++++++++++----------- src/epd1in54c/mod.rs | 62 +++++++++++++----------- src/epd2in13_v2/mod.rs | 59 ++++++++++++----------- src/epd2in7b/mod.rs | 60 ++++++++++++----------- src/epd2in9/mod.rs | 55 +++++++++++---------- src/epd2in9bc/mod.rs | 62 +++++++++++++----------- src/epd4in2/mod.rs | 60 ++++++++++++----------- src/epd5in65f/mod.rs | 61 +++++++++++++----------- src/epd7in5/mod.rs | 55 +++++++++++---------- src/epd7in5_v2/mod.rs | 79 ++++++++++++++++++------------- src/interface.rs | 39 +++++++++++---- src/traits.rs | 48 +++++++++++-------- 17 files changed, 451 insertions(+), 354 deletions(-) diff --git a/examples/epd1in54_no_graphics.rs b/examples/epd1in54_no_graphics.rs index 7fd30ae..40931ae 100644 --- a/examples/epd1in54_no_graphics.rs +++ b/examples/epd1in54_no_graphics.rs @@ -61,8 +61,8 @@ 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)?; - epd.display_frame(&mut spi)?; + epd.clear_frame(&mut spi, &mut delay)?; + epd.display_frame(&mut spi, &mut delay)?; // Speeddemo epd.set_lut(&mut spi, Some(RefreshLUT::QUICK))?; @@ -71,12 +71,12 @@ fn main() -> Result<(), std::io::Error> { for i in 0..number_of_runs { let offset = i * 8 % 150; epd.update_partial_frame(&mut spi, &small_buffer, 25 + offset, 25 + offset, 16, 16)?; - epd.display_frame(&mut spi)?; + epd.display_frame(&mut spi, &mut delay)?; } // Clear the full screen - epd.clear_frame(&mut spi)?; - epd.display_frame(&mut spi)?; + epd.clear_frame(&mut spi, &mut delay)?; + epd.display_frame(&mut spi, &mut delay)?; // Draw some squares let small_buffer = [Color::Black.get_byte_value(); 3200]; //160x160 @@ -89,11 +89,11 @@ fn main() -> Result<(), std::io::Error> { epd.update_partial_frame(&mut spi, &small_buffer, 96, 96, 8, 8)?; // Display updated frame - epd.display_frame(&mut spi)?; + epd.display_frame(&mut spi, &mut delay)?; delay.delay_ms(5000u16); // Set the EPD to sleep - epd.sleep(&mut spi)?; + epd.sleep(&mut spi, &mut delay)?; Ok(()) } diff --git a/examples/epd2in13_v2.rs b/examples/epd2in13_v2.rs index ac509c3..b695993 100644 --- a/examples/epd2in13_v2.rs +++ b/examples/epd2in13_v2.rs @@ -80,9 +80,9 @@ fn main() -> Result<(), std::io::Error> { display.set_rotation(DisplayRotation::Rotate270); draw_text(&mut display, "Rotate 270!", 5, 50); - epd2in13.update_frame(&mut spi, &display.buffer())?; + epd2in13.update_frame(&mut spi, &display.buffer(), &mut delay)?; epd2in13 - .display_frame(&mut spi) + .display_frame(&mut spi, &mut delay) .expect("display frame new graphics"); delay.delay_ms(5000u16); @@ -123,7 +123,7 @@ fn main() -> Result<(), std::io::Error> { epd2in13 .set_refresh(&mut spi, &mut delay, RefreshLUT::QUICK) .unwrap(); - epd2in13.clear_frame(&mut spi).unwrap(); + epd2in13.clear_frame(&mut spi, &mut delay).unwrap(); // a moving `Hello World!` let limit = 10; @@ -131,7 +131,7 @@ fn main() -> Result<(), std::io::Error> { draw_text(&mut display, " Hello World! ", 5 + i * 12, 50); epd2in13 - .update_and_display_frame(&mut spi, &display.buffer()) + .update_and_display_frame(&mut spi, &display.buffer(), &mut delay) .expect("display frame new graphics"); delay.delay_ms(1_000u16); } @@ -140,7 +140,7 @@ fn main() -> Result<(), std::io::Error> { // the screen can refresh for this kind of change (small single character) display.clear_buffer(Color::White); epd2in13 - .update_and_display_frame(&mut spi, &display.buffer()) + .update_and_display_frame(&mut spi, &display.buffer(), &mut delay) .unwrap(); let spinner = ["|", "/", "-", "\\"]; @@ -148,12 +148,12 @@ fn main() -> Result<(), std::io::Error> { display.clear_buffer(Color::White); draw_text(&mut display, spinner[i % spinner.len()], 10, 100); epd2in13 - .update_and_display_frame(&mut spi, &display.buffer()) + .update_and_display_frame(&mut spi, &display.buffer(), &mut delay) .unwrap(); } println!("Finished tests - going to sleep"); - epd2in13.sleep(&mut spi) + epd2in13.sleep(&mut spi, &mut delay) } fn draw_text(display: &mut Display2in13, text: &str, x: i32, y: i32) { diff --git a/examples/epd4in2.rs b/examples/epd4in2.rs index 04730ed..5ac80da 100644 --- a/examples/epd4in2.rs +++ b/examples/epd4in2.rs @@ -80,9 +80,9 @@ fn main() -> Result<(), std::io::Error> { display.set_rotation(DisplayRotation::Rotate270); draw_text(&mut display, "Rotate 270!", 5, 50); - epd4in2.update_frame(&mut spi, &display.buffer())?; + epd4in2.update_frame(&mut spi, &display.buffer(), &mut delay)?; epd4in2 - .display_frame(&mut spi) + .display_frame(&mut spi, &mut delay) .expect("display frame new graphics"); delay.delay_ms(5000u16); @@ -121,22 +121,24 @@ 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).unwrap(); + epd4in2.clear_frame(&mut spi, &mut delay).unwrap(); for i in 0..limit { //println!("Moving Hello World. Loop {} from {}", (i + 1), limit); draw_text(&mut display, " Hello World! ", 5 + i * 12, 50); - epd4in2.update_frame(&mut spi, &display.buffer()).unwrap(); epd4in2 - .display_frame(&mut spi) + .update_frame(&mut spi, &display.buffer(), &mut delay) + .unwrap(); + epd4in2 + .display_frame(&mut spi, &mut delay) .expect("display frame new graphics"); delay.delay_ms(1_000u16); } println!("Finished tests - going to sleep"); - epd4in2.sleep(&mut spi) + epd4in2.sleep(&mut spi, &mut delay) } fn draw_text(display: &mut Display4in2, text: &str, x: i32, y: i32) { diff --git a/examples/epd4in2_variable_size.rs b/examples/epd4in2_variable_size.rs index 6c03851..5fd8123 100644 --- a/examples/epd4in2_variable_size.rs +++ b/examples/epd4in2_variable_size.rs @@ -88,7 +88,7 @@ fn main() -> Result<(), std::io::Error> { .update_partial_frame(&mut spi, &display.buffer(), x, y, width, height) .unwrap(); epd4in2 - .display_frame(&mut spi) + .display_frame(&mut spi, &mut delay) .expect("display frame new graphics"); delay.delay_ms(5000u16); @@ -137,14 +137,14 @@ fn main() -> Result<(), std::io::Error> { .update_partial_frame(&mut spi, &display.buffer(), x, y, width, height) .unwrap(); epd4in2 - .display_frame(&mut spi) + .display_frame(&mut spi, &mut delay) .expect("display frame new graphics"); delay.delay_ms(1_000u16); } println!("Finished tests - going to sleep"); - epd4in2.sleep(&mut spi) + epd4in2.sleep(&mut spi, &mut delay) } fn draw_text(display: &mut VarDisplay, text: &str, x: i32, y: i32) { diff --git a/src/epd1in54/mod.rs b/src/epd1in54/mod.rs index 66420ea..cd2e149 100644 --- a/src/epd1in54/mod.rs +++ b/src/epd1in54/mod.rs @@ -72,28 +72,25 @@ pub use crate::epd1in54::graphics::Display1in54; /// EPD1in54 driver /// -pub struct EPD1in54 { +pub struct EPD1in54 { /// SPI - interface: DisplayInterface, + interface: DisplayInterface, /// Color background_color: Color, /// Refresh LUT refresh: RefreshLUT, } -impl EPD1in54 +impl EPD1in54 where SPI: Write, CS: OutputPin, BUSY: InputPin, DC: OutputPin, RST: OutputPin, + DELAY: DelayMs, { - fn init>( - &mut self, - spi: &mut SPI, - delay: &mut DELAY, - ) -> Result<(), SPI::Error> { + fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> { self.interface.reset(delay, 10); // 3 Databytes: @@ -142,14 +139,15 @@ where } } -impl WaveshareDisplay - for EPD1in54 +impl WaveshareDisplay + for EPD1in54 where SPI: Write, CS: OutputPin, BUSY: InputPin, DC: OutputPin, RST: OutputPin, + DELAY: DelayMs, { type DisplayColor = Color; fn width(&self) -> u32 { @@ -160,7 +158,7 @@ where HEIGHT } - fn new>( + fn new( spi: &mut SPI, cs: CS, busy: BUSY, @@ -181,15 +179,11 @@ where Ok(epd) } - fn wake_up>( - &mut self, - spi: &mut SPI, - delay: &mut DELAY, - ) -> Result<(), SPI::Error> { + fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> { self.init(spi, delay) } - fn sleep(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { + fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> { self.wait_until_idle(); // 0x00 for Normal mode (Power on Reset), 0x01 for Deep Sleep Mode //TODO: is 0x00 needed here or would 0x01 be even more efficient? @@ -198,7 +192,12 @@ where Ok(()) } - fn update_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> { + fn update_frame( + &mut self, + spi: &mut SPI, + buffer: &[u8], + _delay: &mut DELAY, + ) -> Result<(), SPI::Error> { self.wait_until_idle(); self.use_full_frame(spi)?; self.interface @@ -225,7 +224,7 @@ where Ok(()) } - fn display_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { + fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> { self.wait_until_idle(); // enable clock signal, enable cp, display pattern -> 0xC4 (tested with the arduino version) //TODO: test control_1 or control_2 with default value 0xFF (from the datasheet) @@ -239,13 +238,18 @@ where Ok(()) } - fn update_and_display_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> { - self.update_frame(spi, buffer)?; - self.display_frame(spi)?; + fn update_and_display_frame( + &mut self, + spi: &mut SPI, + buffer: &[u8], + delay: &mut DELAY, + ) -> Result<(), SPI::Error> { + self.update_frame(spi, buffer, delay)?; + self.display_frame(spi, delay)?; Ok(()) } - fn clear_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { + fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> { self.wait_until_idle(); self.use_full_frame(spi)?; @@ -285,16 +289,17 @@ where } } -impl EPD1in54 +impl EPD1in54 where SPI: Write, CS: OutputPin, BUSY: InputPin, DC: OutputPin, RST: OutputPin, + DELAY: DelayMs, { fn wait_until_idle(&mut self) { - self.interface.wait_until_idle(IS_BUSY_LOW); + let _ = self.interface.wait_until_idle(IS_BUSY_LOW, None); } pub(crate) fn use_full_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { diff --git a/src/epd1in54b/mod.rs b/src/epd1in54b/mod.rs index c14050e..c34efdc 100644 --- a/src/epd1in54b/mod.rs +++ b/src/epd1in54b/mod.rs @@ -33,25 +33,22 @@ mod graphics; pub use self::graphics::Display1in54b; /// EPD1in54b driver -pub struct EPD1in54b { - interface: DisplayInterface, +pub struct EPD1in54b { + interface: DisplayInterface, color: Color, } -impl InternalWiAdditions - for EPD1in54b +impl InternalWiAdditions + for EPD1in54b where SPI: Write, CS: OutputPin, BUSY: InputPin, DC: OutputPin, RST: OutputPin, + DELAY: DelayMs, { - fn init>( - &mut self, - spi: &mut SPI, - delay: &mut DELAY, - ) -> Result<(), SPI::Error> { + fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> { self.interface.reset(delay, 10); // set the power settings @@ -88,14 +85,15 @@ where } } -impl WaveshareThreeColorDisplay - for EPD1in54b +impl WaveshareThreeColorDisplay + for EPD1in54b where SPI: Write, CS: OutputPin, BUSY: InputPin, DC: OutputPin, RST: OutputPin, + DELAY: DelayMs, { fn update_color_frame( &mut self, @@ -133,17 +131,18 @@ where } } -impl WaveshareDisplay - for EPD1in54b +impl WaveshareDisplay + for EPD1in54b where SPI: Write, CS: OutputPin, BUSY: InputPin, DC: OutputPin, RST: OutputPin, + DELAY: DelayMs, { type DisplayColor = Color; - fn new>( + fn new( spi: &mut SPI, cs: CS, busy: BUSY, @@ -161,7 +160,7 @@ where Ok(epd) } - fn sleep(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { + fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> { self.wait_until_idle(); self.interface .cmd_with_data(spi, Command::VCOM_AND_DATA_INTERVAL_SETTING, &[0x17])?; //border floating @@ -181,11 +180,7 @@ where Ok(()) } - fn wake_up>( - &mut self, - spi: &mut SPI, - delay: &mut DELAY, - ) -> Result<(), SPI::Error> { + fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> { self.init(spi, delay) } @@ -205,7 +200,12 @@ where HEIGHT } - fn update_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> { + fn update_frame( + &mut self, + spi: &mut SPI, + buffer: &[u8], + _delay: &mut DELAY, + ) -> Result<(), SPI::Error> { self.wait_until_idle(); self.send_resolution(spi)?; @@ -245,19 +245,24 @@ where unimplemented!() } - fn display_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { + fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> { self.wait_until_idle(); self.command(spi, Command::DISPLAY_REFRESH)?; Ok(()) } - fn update_and_display_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> { - self.update_frame(spi, buffer)?; - self.display_frame(spi)?; + fn update_and_display_frame( + &mut self, + spi: &mut SPI, + buffer: &[u8], + delay: &mut DELAY, + ) -> Result<(), SPI::Error> { + self.update_frame(spi, buffer, delay)?; + self.display_frame(spi, delay)?; Ok(()) } - fn clear_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { + fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> { self.wait_until_idle(); self.send_resolution(spi)?; @@ -307,13 +312,14 @@ where } } -impl EPD1in54b +impl EPD1in54b where SPI: Write, CS: OutputPin, BUSY: InputPin, DC: OutputPin, RST: OutputPin, + DELAY: DelayMs, { fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), SPI::Error> { self.interface.cmd(spi, command) @@ -333,7 +339,7 @@ where } fn wait_until_idle(&mut self) { - self.interface.wait_until_idle(IS_BUSY_LOW) + let _ = self.interface.wait_until_idle(IS_BUSY_LOW, None); } fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { diff --git a/src/epd1in54c/mod.rs b/src/epd1in54c/mod.rs index f8bd54d..f226cfe 100644 --- a/src/epd1in54c/mod.rs +++ b/src/epd1in54c/mod.rs @@ -31,25 +31,22 @@ mod graphics; pub use self::graphics::Display1in54c; /// EPD1in54c driver -pub struct EPD1in54c { - interface: DisplayInterface, +pub struct EPD1in54c { + interface: DisplayInterface, color: Color, } -impl InternalWiAdditions - for EPD1in54c +impl InternalWiAdditions + for EPD1in54c where SPI: Write, CS: OutputPin, BUSY: InputPin, DC: OutputPin, RST: OutputPin, + DELAY: DelayMs, { - fn init>( - &mut self, - spi: &mut SPI, - delay: &mut DELAY, - ) -> Result<(), SPI::Error> { + fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> { // Based on Reference Program Code from: // https://www.waveshare.com/w/upload/a/ac/1.54inch_e-Paper_Module_C_Specification.pdf // and: @@ -76,14 +73,15 @@ where } } -impl WaveshareThreeColorDisplay - for EPD1in54c +impl WaveshareThreeColorDisplay + for EPD1in54c where SPI: Write, CS: OutputPin, BUSY: InputPin, DC: OutputPin, RST: OutputPin, + DELAY: DelayMs, { fn update_color_frame( &mut self, @@ -114,17 +112,18 @@ where } } -impl WaveshareDisplay - for EPD1in54c +impl WaveshareDisplay + for EPD1in54c where SPI: Write, CS: OutputPin, BUSY: InputPin, DC: OutputPin, RST: OutputPin, + DELAY: DelayMs, { type DisplayColor = Color; - fn new>( + fn new( spi: &mut SPI, cs: CS, busy: BUSY, @@ -142,7 +141,7 @@ where Ok(epd) } - fn sleep(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { + fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> { self.wait_until_idle(); self.command(spi, Command::POWER_OFF)?; @@ -152,11 +151,7 @@ where Ok(()) } - fn wake_up>( - &mut self, - spi: &mut SPI, - delay: &mut DELAY, - ) -> Result<(), SPI::Error> { + fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> { self.init(spi, delay) } @@ -176,7 +171,12 @@ where HEIGHT } - fn update_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> { + fn update_frame( + &mut self, + spi: &mut SPI, + buffer: &[u8], + _delay: &mut DELAY, + ) -> Result<(), SPI::Error> { self.update_achromatic_frame(spi, buffer)?; // Clear the chromatic layer @@ -201,21 +201,26 @@ where unimplemented!() } - fn display_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { + fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> { self.command(spi, Command::DISPLAY_REFRESH)?; self.wait_until_idle(); Ok(()) } - fn update_and_display_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> { - self.update_frame(spi, buffer)?; - self.display_frame(spi)?; + fn update_and_display_frame( + &mut self, + spi: &mut SPI, + buffer: &[u8], + delay: &mut DELAY, + ) -> Result<(), SPI::Error> { + self.update_frame(spi, buffer, delay)?; + self.display_frame(spi, delay)?; Ok(()) } - fn clear_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { + 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(); @@ -243,13 +248,14 @@ where } } -impl EPD1in54c +impl EPD1in54c where SPI: Write, CS: OutputPin, BUSY: InputPin, DC: OutputPin, RST: OutputPin, + DELAY: DelayMs, { fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), SPI::Error> { self.interface.cmd(spi, command) @@ -269,7 +275,7 @@ where } fn wait_until_idle(&mut self) { - self.interface.wait_until_idle(IS_BUSY_LOW) + let _ = self.interface.wait_until_idle(IS_BUSY_LOW, None); } fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { diff --git a/src/epd2in13_v2/mod.rs b/src/epd2in13_v2/mod.rs index 704d262..fe661e5 100644 --- a/src/epd2in13_v2/mod.rs +++ b/src/epd2in13_v2/mod.rs @@ -45,9 +45,9 @@ const IS_BUSY_LOW: bool = false; /// EPD2in13 (V2) driver /// -pub struct EPD2in13 { +pub struct EPD2in13 { /// Connection Interface - interface: DisplayInterface, + interface: DisplayInterface, sleep_mode: DeepSleepMode, @@ -56,20 +56,17 @@ pub struct EPD2in13 { refresh: RefreshLUT, } -impl InternalWiAdditions - for EPD2in13 +impl InternalWiAdditions + for EPD2in13 where SPI: Write, CS: OutputPin, BUSY: InputPin, DC: OutputPin, RST: OutputPin, + DELAY: DelayMs, { - fn init>( - &mut self, - spi: &mut SPI, - delay: &mut DELAY, - ) -> Result<(), SPI::Error> { + fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> { // HW reset self.interface.reset(delay, 10); @@ -157,17 +154,18 @@ where } } -impl WaveshareDisplay - for EPD2in13 +impl WaveshareDisplay + for EPD2in13 where SPI: Write, CS: OutputPin, BUSY: InputPin, DC: OutputPin, RST: OutputPin, + DELAY: DelayMs, { type DisplayColor = Color; - fn new>( + fn new( spi: &mut SPI, cs: CS, busy: BUSY, @@ -186,15 +184,11 @@ where Ok(epd) } - fn wake_up>( - &mut self, - spi: &mut SPI, - delay: &mut DELAY, - ) -> Result<(), SPI::Error> { + fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> { self.init(spi, delay) } - fn sleep(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { + fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> { self.wait_until_idle(); // All sample code enables and disables analog/clocks... @@ -212,7 +206,12 @@ where Ok(()) } - fn update_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> { + fn update_frame( + &mut self, + spi: &mut SPI, + buffer: &[u8], + _delay: &mut DELAY, + ) -> Result<(), SPI::Error> { assert!(buffer.len() == buffer_len(WIDTH as usize, HEIGHT as usize)); self.set_ram_area(spi, 0, 0, WIDTH - 1, HEIGHT - 1)?; self.set_ram_address_counters(spi, 0, 0)?; @@ -269,7 +268,7 @@ where /// Never use directly this function when using partial refresh, or also /// keep the base buffer in syncd using `set_partial_base_buffer` function. - fn display_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { + fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> { if self.refresh == RefreshLUT::FULL { self.set_display_update_control_2( spi, @@ -289,9 +288,14 @@ where Ok(()) } - fn update_and_display_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> { - self.update_frame(spi, buffer)?; - self.display_frame(spi)?; + fn update_and_display_frame( + &mut self, + spi: &mut SPI, + buffer: &[u8], + delay: &mut DELAY, + ) -> Result<(), SPI::Error> { + self.update_frame(spi, buffer, delay)?; + self.display_frame(spi, delay)?; if self.refresh == RefreshLUT::QUICK { self.set_partial_base_buffer(spi, buffer)?; @@ -299,7 +303,7 @@ where Ok(()) } - fn clear_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { + 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)?; @@ -361,13 +365,14 @@ where } } -impl EPD2in13 +impl EPD2in13 where SPI: Write, CS: OutputPin, BUSY: InputPin, DC: OutputPin, RST: OutputPin, + DELAY: DelayMs, { /// When using partial refresh, the controller uses the provided buffer for /// comparison with new buffer. @@ -391,7 +396,7 @@ where /// Sets the refresh mode. When changing mode, the screen will be /// re-initialized accordingly. - pub fn set_refresh>( + pub fn set_refresh( &mut self, spi: &mut SPI, delay: &mut DELAY, @@ -559,7 +564,7 @@ where } fn wait_until_idle(&mut self) { - self.interface.wait_until_idle(IS_BUSY_LOW) + let _ = self.interface.wait_until_idle(IS_BUSY_LOW, None); } } diff --git a/src/epd2in7b/mod.rs b/src/epd2in7b/mod.rs index 666add7..4a19aab 100644 --- a/src/epd2in7b/mod.rs +++ b/src/epd2in7b/mod.rs @@ -35,27 +35,24 @@ mod graphics; pub use self::graphics::Display2in7b; /// EPD2in7b driver -pub struct EPD2in7b { +pub struct EPD2in7b { /// Connection Interface - interface: DisplayInterface, + interface: DisplayInterface, /// Background Color color: Color, } -impl InternalWiAdditions - for EPD2in7b +impl InternalWiAdditions + for EPD2in7b where SPI: Write, CS: OutputPin, BUSY: InputPin, DC: OutputPin, RST: OutputPin, + DELAY: DelayMs, { - fn init>( - &mut self, - spi: &mut SPI, - delay: &mut DELAY, - ) -> Result<(), SPI::Error> { + fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> { // reset the device self.interface.reset(delay, 2); @@ -111,17 +108,18 @@ where } } -impl WaveshareDisplay - for EPD2in7b +impl WaveshareDisplay + for EPD2in7b where SPI: Write, CS: OutputPin, BUSY: InputPin, DC: OutputPin, RST: OutputPin, + DELAY: DelayMs, { type DisplayColor = Color; - fn new>( + fn new( spi: &mut SPI, cs: CS, busy: BUSY, @@ -139,15 +137,11 @@ where Ok(epd) } - fn wake_up>( - &mut self, - spi: &mut SPI, - delay: &mut DELAY, - ) -> Result<(), SPI::Error> { + fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> { self.init(spi, delay) } - fn sleep(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { + fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> { self.wait_until_idle(); self.interface .cmd_with_data(spi, Command::VCOM_AND_DATA_INTERVAL_SETTING, &[0xf7])?; @@ -159,7 +153,12 @@ where Ok(()) } - fn update_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> { + fn update_frame( + &mut self, + spi: &mut SPI, + buffer: &[u8], + _delay: &mut DELAY, + ) -> Result<(), SPI::Error> { self.interface .cmd(spi, Command::DATA_START_TRANSMISSION_1)?; self.send_buffer_helper(spi, buffer)?; @@ -201,19 +200,24 @@ where self.interface.cmd(spi, Command::DATA_STOP) } - fn display_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { + fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> { self.command(spi, Command::DISPLAY_REFRESH)?; self.wait_until_idle(); Ok(()) } - fn update_and_display_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> { - self.update_frame(spi, buffer)?; + fn update_and_display_frame( + &mut self, + spi: &mut SPI, + buffer: &[u8], + delay: &mut DELAY, + ) -> Result<(), SPI::Error> { + self.update_frame(spi, buffer, delay)?; self.command(spi, Command::DISPLAY_REFRESH)?; Ok(()) } - fn clear_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { + 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(); @@ -267,14 +271,15 @@ where } } -impl WaveshareThreeColorDisplay - for EPD2in7b +impl WaveshareThreeColorDisplay + for EPD2in7b where SPI: Write, CS: OutputPin, BUSY: InputPin, DC: OutputPin, RST: OutputPin, + DELAY: DelayMs, { fn update_color_frame( &mut self, @@ -322,13 +327,14 @@ where } } -impl EPD2in7b +impl EPD2in7b where SPI: Write, CS: OutputPin, BUSY: InputPin, DC: OutputPin, RST: OutputPin, + DELAY: DelayMs, { fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), SPI::Error> { self.interface.cmd(spi, command) @@ -357,7 +363,7 @@ where } fn wait_until_idle(&mut self) { - self.interface.wait_until_idle(IS_BUSY_LOW) + let _ = self.interface.wait_until_idle(IS_BUSY_LOW, None); } /// Refresh display for partial frame diff --git a/src/epd2in9/mod.rs b/src/epd2in9/mod.rs index d2fbabb..4288562 100644 --- a/src/epd2in9/mod.rs +++ b/src/epd2in9/mod.rs @@ -72,28 +72,25 @@ pub use crate::epd2in9::graphics::Display2in9; /// EPD2in9 driver /// -pub struct EPD2in9 { +pub struct EPD2in9 { /// SPI - interface: DisplayInterface, + interface: DisplayInterface, /// Color background_color: Color, /// Refresh LUT refresh: RefreshLUT, } -impl EPD2in9 +impl EPD2in9 where SPI: Write, CS: OutputPin, BUSY: InputPin, DC: OutputPin, RST: OutputPin, + DELAY: DelayMs, { - fn init>( - &mut self, - spi: &mut SPI, - delay: &mut DELAY, - ) -> Result<(), SPI::Error> { + fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> { self.interface.reset(delay, 10); self.wait_until_idle(); @@ -138,14 +135,15 @@ where } } -impl WaveshareDisplay - for EPD2in9 +impl WaveshareDisplay + for EPD2in9 where SPI: Write, CS: OutputPin, BUSY: InputPin, DC: OutputPin, RST: OutputPin, + DELAY: DelayMs, { type DisplayColor = Color; fn width(&self) -> u32 { @@ -156,7 +154,7 @@ where HEIGHT } - fn new>( + fn new( spi: &mut SPI, cs: CS, busy: BUSY, @@ -177,7 +175,7 @@ where Ok(epd) } - fn sleep(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { + fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> { self.wait_until_idle(); // 0x00 for Normal mode (Power on Reset), 0x01 for Deep Sleep Mode //TODO: is 0x00 needed here? (see also epd1in54) @@ -186,17 +184,18 @@ where Ok(()) } - fn wake_up>( - &mut self, - spi: &mut SPI, - delay: &mut DELAY, - ) -> Result<(), SPI::Error> { + fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> { self.wait_until_idle(); self.init(spi, delay)?; Ok(()) } - fn update_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> { + fn update_frame( + &mut self, + spi: &mut SPI, + buffer: &[u8], + _delay: &mut DELAY, + ) -> Result<(), SPI::Error> { self.wait_until_idle(); self.use_full_frame(spi)?; @@ -224,7 +223,7 @@ where Ok(()) } - fn display_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { + fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> { self.wait_until_idle(); // enable clock signal, enable cp, display pattern -> 0xC4 (tested with the arduino version) //TODO: test control_1 or control_2 with default value 0xFF (from the datasheet) @@ -238,13 +237,18 @@ where Ok(()) } - fn update_and_display_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> { - self.update_frame(spi, buffer)?; - self.display_frame(spi)?; + fn update_and_display_frame( + &mut self, + spi: &mut SPI, + buffer: &[u8], + delay: &mut DELAY, + ) -> Result<(), SPI::Error> { + self.update_frame(spi, buffer, delay)?; + self.display_frame(spi, delay)?; Ok(()) } - fn clear_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { + fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> { self.wait_until_idle(); self.use_full_frame(spi)?; @@ -284,16 +288,17 @@ where } } -impl EPD2in9 +impl EPD2in9 where SPI: Write, CS: OutputPin, BUSY: InputPin, DC: OutputPin, RST: OutputPin, + DELAY: DelayMs, { fn wait_until_idle(&mut self) { - self.interface.wait_until_idle(IS_BUSY_LOW); + let _ = self.interface.wait_until_idle(IS_BUSY_LOW, None); } fn use_full_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { diff --git a/src/epd2in9bc/mod.rs b/src/epd2in9bc/mod.rs index 300352c..6bfb6c4 100644 --- a/src/epd2in9bc/mod.rs +++ b/src/epd2in9bc/mod.rs @@ -90,25 +90,22 @@ mod graphics; pub use self::graphics::Display2in9bc; /// EPD2in9bc driver -pub struct EPD2in9bc { - interface: DisplayInterface, +pub struct EPD2in9bc { + interface: DisplayInterface, color: Color, } -impl InternalWiAdditions - for EPD2in9bc +impl InternalWiAdditions + for EPD2in9bc where SPI: Write, CS: OutputPin, BUSY: InputPin, DC: OutputPin, RST: OutputPin, + DELAY: DelayMs, { - fn init>( - &mut self, - spi: &mut SPI, - delay: &mut DELAY, - ) -> Result<(), SPI::Error> { + fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> { // Values taken from datasheet and sample code self.interface.reset(delay, 10); @@ -142,14 +139,15 @@ where } } -impl WaveshareThreeColorDisplay - for EPD2in9bc +impl WaveshareThreeColorDisplay + for EPD2in9bc where SPI: Write, CS: OutputPin, BUSY: InputPin, DC: OutputPin, RST: OutputPin, + DELAY: DelayMs, { fn update_color_frame( &mut self, @@ -188,17 +186,18 @@ where } } -impl WaveshareDisplay - for EPD2in9bc +impl WaveshareDisplay + for EPD2in9bc where SPI: Write, CS: OutputPin, BUSY: InputPin, DC: OutputPin, RST: OutputPin, + DELAY: DelayMs, { type DisplayColor = Color; - fn new>( + fn new( spi: &mut SPI, cs: CS, busy: BUSY, @@ -216,7 +215,7 @@ where Ok(epd) } - fn sleep(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { + fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> { // Section 8.2 from datasheet self.interface.cmd_with_data( spi, @@ -233,11 +232,7 @@ where Ok(()) } - fn wake_up>( - &mut self, - spi: &mut SPI, - delay: &mut DELAY, - ) -> Result<(), SPI::Error> { + fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> { self.init(spi, delay) } @@ -257,7 +252,12 @@ where HEIGHT } - fn update_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> { + fn update_frame( + &mut self, + spi: &mut SPI, + buffer: &[u8], + _delay: &mut DELAY, + ) -> Result<(), SPI::Error> { self.interface .cmd(spi, Command::DATA_START_TRANSMISSION_1)?; @@ -287,20 +287,25 @@ where Ok(()) } - fn display_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { + fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> { self.command(spi, Command::DISPLAY_REFRESH)?; self.wait_until_idle(); Ok(()) } - fn update_and_display_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> { - self.update_frame(spi, buffer)?; - self.display_frame(spi)?; + fn update_and_display_frame( + &mut self, + spi: &mut SPI, + buffer: &[u8], + delay: &mut DELAY, + ) -> Result<(), SPI::Error> { + self.update_frame(spi, buffer, delay)?; + self.display_frame(spi, delay)?; Ok(()) } - fn clear_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { + 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(); @@ -333,13 +338,14 @@ where } } -impl EPD2in9bc +impl EPD2in9bc where SPI: Write, CS: OutputPin, BUSY: InputPin, DC: OutputPin, RST: OutputPin, + DELAY: DelayMs, { fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), SPI::Error> { self.interface.cmd(spi, command) @@ -359,7 +365,7 @@ where } fn wait_until_idle(&mut self) { - self.interface.wait_until_idle(IS_BUSY_LOW) + let _ = self.interface.wait_until_idle(IS_BUSY_LOW, None); } fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { diff --git a/src/epd4in2/mod.rs b/src/epd4in2/mod.rs index 636b254..e48a23c 100644 --- a/src/epd4in2/mod.rs +++ b/src/epd4in2/mod.rs @@ -81,29 +81,26 @@ pub use self::graphics::Display4in2; /// EPD4in2 driver /// -pub struct EPD4in2 { +pub struct EPD4in2 { /// Connection Interface - interface: DisplayInterface, + interface: DisplayInterface, /// Background Color color: Color, /// Refresh LUT refresh: RefreshLUT, } -impl InternalWiAdditions - for EPD4in2 +impl InternalWiAdditions + for EPD4in2 where SPI: Write, CS: OutputPin, BUSY: InputPin, DC: OutputPin, RST: OutputPin, + DELAY: DelayMs, { - fn init>( - &mut self, - spi: &mut SPI, - delay: &mut DELAY, - ) -> Result<(), SPI::Error> { + fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> { // reset the device self.interface.reset(delay, 10); @@ -148,17 +145,18 @@ where } } -impl WaveshareDisplay - for EPD4in2 +impl WaveshareDisplay + for EPD4in2 where SPI: Write, CS: OutputPin, BUSY: InputPin, DC: OutputPin, RST: OutputPin, + DELAY: DelayMs, { type DisplayColor = Color; - fn new>( + fn new( spi: &mut SPI, cs: CS, busy: BUSY, @@ -180,15 +178,11 @@ where Ok(epd) } - fn wake_up>( - &mut self, - spi: &mut SPI, - delay: &mut DELAY, - ) -> Result<(), SPI::Error> { + fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> { self.init(spi, delay) } - fn sleep(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { + fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> { self.wait_until_idle(); self.interface .cmd_with_data(spi, Command::VCOM_AND_DATA_INTERVAL_SETTING, &[0x17])?; //border floating @@ -207,7 +201,12 @@ where Ok(()) } - fn update_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> { + fn update_frame( + &mut self, + spi: &mut SPI, + buffer: &[u8], + _delay: &mut DELAY, + ) -> Result<(), SPI::Error> { self.wait_until_idle(); let color_value = self.color.get_byte_value(); @@ -267,19 +266,24 @@ where Ok(()) } - fn display_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { + fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> { self.wait_until_idle(); self.command(spi, Command::DISPLAY_REFRESH)?; Ok(()) } - fn update_and_display_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> { - self.update_frame(spi, buffer)?; + fn update_and_display_frame( + &mut self, + spi: &mut SPI, + buffer: &[u8], + delay: &mut DELAY, + ) -> Result<(), SPI::Error> { + self.update_frame(spi, buffer, delay)?; self.command(spi, Command::DISPLAY_REFRESH)?; Ok(()) } - fn clear_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { + fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> { self.wait_until_idle(); self.send_resolution(spi)?; @@ -341,13 +345,14 @@ where } } -impl EPD4in2 +impl EPD4in2 where SPI: Write, CS: OutputPin, BUSY: InputPin, DC: OutputPin, RST: OutputPin, + DELAY: DelayMs, { fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), SPI::Error> { self.interface.cmd(spi, command) @@ -367,7 +372,7 @@ where } fn wait_until_idle(&mut self) { - self.interface.wait_until_idle(IS_BUSY_LOW) + let _ = self.interface.wait_until_idle(IS_BUSY_LOW, None); } fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { @@ -437,14 +442,15 @@ where } } -impl QuickRefresh - for EPD4in2 +impl QuickRefresh + for EPD4in2 where SPI: Write, CS: OutputPin, BUSY: InputPin, DC: OutputPin, RST: OutputPin, + DELAY: DelayMs, { /// To be followed immediately after by `update_old_frame`. fn update_old_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> { diff --git a/src/epd5in65f/mod.rs b/src/epd5in65f/mod.rs index d10dddc..aefb3c3 100644 --- a/src/epd5in65f/mod.rs +++ b/src/epd5in65f/mod.rs @@ -33,27 +33,24 @@ const IS_BUSY_LOW: bool = true; /// EPD5in65f driver /// -pub struct EPD5in65f { +pub struct EPD5in65f { /// Connection Interface - interface: DisplayInterface, + interface: DisplayInterface, /// Background Color color: OctColor, } -impl InternalWiAdditions - for EPD5in65f +impl InternalWiAdditions + for EPD5in65f where SPI: Write, CS: OutputPin, BUSY: InputPin, DC: OutputPin, RST: OutputPin, + DELAY: DelayMs, { - fn init>( - &mut self, - spi: &mut SPI, - delay: &mut DELAY, - ) -> Result<(), SPI::Error> { + fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> { // Reset the device self.interface.reset(delay, 2); @@ -76,17 +73,18 @@ where } } -impl WaveshareDisplay - for EPD5in65f +impl WaveshareDisplay + for EPD5in65f where SPI: Write, CS: OutputPin, BUSY: InputPin, DC: OutputPin, RST: OutputPin, + DELAY: DelayMs, { type DisplayColor = OctColor; - fn new>( + fn new( spi: &mut SPI, cs: CS, busy: BUSY, @@ -104,20 +102,21 @@ where Ok(epd) } - fn wake_up>( - &mut self, - spi: &mut SPI, - delay: &mut DELAY, - ) -> Result<(), SPI::Error> { + fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> { self.init(spi, delay) } - fn sleep(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { + fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> { self.cmd_with_data(spi, Command::DEEP_SLEEP, &[0xA5])?; Ok(()) } - fn update_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> { + fn update_frame( + &mut self, + spi: &mut SPI, + buffer: &[u8], + _delay: &mut DELAY, + ) -> Result<(), SPI::Error> { self.wait_busy_high(); self.send_resolution(spi)?; self.cmd_with_data(spi, Command::DATA_START_TRANSMISSION_1, buffer)?; @@ -136,7 +135,7 @@ where unimplemented!(); } - fn display_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { + fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> { self.wait_busy_high(); self.command(spi, Command::POWER_ON)?; self.wait_busy_high(); @@ -147,19 +146,24 @@ where Ok(()) } - fn update_and_display_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> { - self.update_frame(spi, buffer)?; - self.display_frame(spi)?; + fn update_and_display_frame( + &mut self, + spi: &mut SPI, + buffer: &[u8], + delay: &mut DELAY, + ) -> Result<(), SPI::Error> { + self.update_frame(spi, buffer, delay)?; + self.display_frame(spi, delay)?; Ok(()) } - fn clear_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { + 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.send_resolution(spi)?; self.command(spi, Command::DATA_START_TRANSMISSION_1)?; self.interface.data_x_times(spi, bg, WIDTH * HEIGHT / 2)?; - self.display_frame(spi)?; + self.display_frame(spi, delay)?; Ok(()) } @@ -192,13 +196,14 @@ where } } -impl EPD5in65f +impl EPD5in65f where SPI: Write, CS: OutputPin, BUSY: InputPin, DC: OutputPin, RST: OutputPin, + DELAY: DelayMs, { fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), SPI::Error> { self.interface.cmd(spi, command) @@ -218,10 +223,10 @@ where } fn wait_busy_high(&mut self) { - self.interface.wait_until_idle(true) + let _ = self.interface.wait_until_idle(true, None); } fn wait_busy_low(&mut self) { - self.interface.wait_until_idle(false) + let _ = self.interface.wait_until_idle(false, None); } fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { let w = self.width(); diff --git a/src/epd7in5/mod.rs b/src/epd7in5/mod.rs index 883deb3..4e2c6c4 100644 --- a/src/epd7in5/mod.rs +++ b/src/epd7in5/mod.rs @@ -33,27 +33,24 @@ const IS_BUSY_LOW: bool = true; /// EPD7in5 driver /// -pub struct EPD7in5 { +pub struct EPD7in5 { /// Connection Interface - interface: DisplayInterface, + interface: DisplayInterface, /// Background Color color: Color, } -impl InternalWiAdditions - for EPD7in5 +impl InternalWiAdditions + for EPD7in5 where SPI: Write, CS: OutputPin, BUSY: InputPin, DC: OutputPin, RST: OutputPin, + DELAY: DelayMs, { - fn init>( - &mut self, - spi: &mut SPI, - delay: &mut DELAY, - ) -> Result<(), SPI::Error> { + fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> { // Reset the device self.interface.reset(delay, 10); @@ -99,17 +96,18 @@ where } } -impl WaveshareDisplay - for EPD7in5 +impl WaveshareDisplay + for EPD7in5 where SPI: Write, CS: OutputPin, BUSY: InputPin, DC: OutputPin, RST: OutputPin, + DELAY: DelayMs, { type DisplayColor = Color; - fn new>( + fn new( spi: &mut SPI, cs: CS, busy: BUSY, @@ -127,15 +125,11 @@ where Ok(epd) } - fn wake_up>( - &mut self, - spi: &mut SPI, - delay: &mut DELAY, - ) -> Result<(), SPI::Error> { + fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> { self.init(spi, delay) } - fn sleep(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { + fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> { self.wait_until_idle(); self.command(spi, Command::POWER_OFF)?; self.wait_until_idle(); @@ -143,7 +137,12 @@ where Ok(()) } - fn update_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> { + fn update_frame( + &mut self, + spi: &mut SPI, + buffer: &[u8], + _delay: &mut DELAY, + ) -> Result<(), SPI::Error> { self.wait_until_idle(); self.command(spi, Command::DATA_START_TRANSMISSION_1)?; for byte in buffer { @@ -172,19 +171,24 @@ where unimplemented!(); } - fn display_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { + fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> { self.wait_until_idle(); self.command(spi, Command::DISPLAY_REFRESH)?; Ok(()) } - fn update_and_display_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> { - self.update_frame(spi, buffer)?; + fn update_and_display_frame( + &mut self, + spi: &mut SPI, + buffer: &[u8], + delay: &mut DELAY, + ) -> Result<(), SPI::Error> { + self.update_frame(spi, buffer, delay)?; self.command(spi, Command::DISPLAY_REFRESH)?; Ok(()) } - fn clear_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { + fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> { self.wait_until_idle(); self.send_resolution(spi)?; @@ -224,13 +228,14 @@ where } } -impl EPD7in5 +impl EPD7in5 where SPI: Write, CS: OutputPin, BUSY: InputPin, DC: OutputPin, RST: OutputPin, + DELAY: DelayMs, { fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), SPI::Error> { self.interface.cmd(spi, command) @@ -250,7 +255,7 @@ where } fn wait_until_idle(&mut self) { - self.interface.wait_until_idle(IS_BUSY_LOW) + let _ = self.interface.wait_until_idle(IS_BUSY_LOW, None); } fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { diff --git a/src/epd7in5_v2/mod.rs b/src/epd7in5_v2/mod.rs index 67f9dab..8e81b90 100644 --- a/src/epd7in5_v2/mod.rs +++ b/src/epd7in5_v2/mod.rs @@ -37,27 +37,24 @@ const IS_BUSY_LOW: bool = true; /// EPD7in5 (V2) driver /// -pub struct EPD7in5 { +pub struct EPD7in5 { /// Connection Interface - interface: DisplayInterface, + interface: DisplayInterface, /// Background Color color: Color, } -impl InternalWiAdditions - for EPD7in5 +impl InternalWiAdditions + for EPD7in5 where SPI: Write, CS: OutputPin, BUSY: InputPin, DC: OutputPin, RST: OutputPin, + DELAY: DelayMs, { - fn init>( - &mut self, - spi: &mut SPI, - delay: &mut DELAY, - ) -> Result<(), SPI::Error> { + fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> { // Reset the device self.interface.reset(delay, 2); @@ -69,29 +66,30 @@ where self.cmd_with_data(spi, Command::BOOSTER_SOFT_START, &[0x17, 0x17, 0x27, 0x17])?; self.cmd_with_data(spi, Command::POWER_SETTING, &[0x07, 0x17, 0x3F, 0x3F])?; self.command(spi, Command::POWER_ON)?; - self.wait_until_idle(); + self.wait_until_idle(spi, delay)?; self.cmd_with_data(spi, Command::PANEL_SETTING, &[0x1F])?; self.cmd_with_data(spi, Command::PLL_CONTROL, &[0x06])?; self.cmd_with_data(spi, Command::TCON_RESOLUTION, &[0x03, 0x20, 0x01, 0xE0])?; self.cmd_with_data(spi, Command::DUAL_SPI, &[0x00])?; self.cmd_with_data(spi, Command::TCON_SETTING, &[0x22])?; self.cmd_with_data(spi, Command::VCOM_AND_DATA_INTERVAL_SETTING, &[0x10, 0x07])?; - self.wait_until_idle(); + self.wait_until_idle(spi, delay)?; Ok(()) } } -impl WaveshareDisplay - for EPD7in5 +impl WaveshareDisplay + for EPD7in5 where SPI: Write, CS: OutputPin, BUSY: InputPin, DC: OutputPin, RST: OutputPin, + DELAY: DelayMs, { type DisplayColor = Color; - fn new>( + fn new( spi: &mut SPI, cs: CS, busy: BUSY, @@ -109,24 +107,25 @@ where Ok(epd) } - fn wake_up>( - &mut self, - spi: &mut SPI, - delay: &mut DELAY, - ) -> Result<(), SPI::Error> { + fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> { self.init(spi, delay) } - fn sleep(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { - self.wait_until_idle(); + fn sleep(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> { + self.wait_until_idle(spi, delay)?; self.command(spi, Command::POWER_OFF)?; - self.wait_until_idle(); + self.wait_until_idle(spi, delay)?; self.cmd_with_data(spi, Command::DEEP_SLEEP, &[0xA5])?; Ok(()) } - fn update_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> { - self.wait_until_idle(); + fn update_frame( + &mut self, + spi: &mut SPI, + buffer: &[u8], + delay: &mut DELAY, + ) -> Result<(), SPI::Error> { + self.wait_until_idle(spi, delay)?; self.cmd_with_data(spi, Command::DATA_START_TRANSMISSION_2, buffer)?; Ok(()) } @@ -143,20 +142,25 @@ where unimplemented!(); } - fn display_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { - self.wait_until_idle(); + fn display_frame(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> { + self.wait_until_idle(spi, delay)?; self.command(spi, Command::DISPLAY_REFRESH)?; Ok(()) } - fn update_and_display_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> { - self.update_frame(spi, buffer)?; + fn update_and_display_frame( + &mut self, + spi: &mut SPI, + buffer: &[u8], + delay: &mut DELAY, + ) -> Result<(), SPI::Error> { + self.update_frame(spi, buffer, delay)?; self.command(spi, Command::DISPLAY_REFRESH)?; Ok(()) } - fn clear_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { - self.wait_until_idle(); + 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::DATA_START_TRANSMISSION_1)?; @@ -198,13 +202,14 @@ where } } -impl EPD7in5 +impl EPD7in5 where SPI: Write, CS: OutputPin, BUSY: InputPin, DC: OutputPin, RST: OutputPin, + DELAY: DelayMs, { fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), SPI::Error> { self.interface.cmd(spi, command) @@ -223,8 +228,16 @@ where self.interface.cmd_with_data(spi, command, data) } - fn wait_until_idle(&mut self) { - self.interface.wait_until_idle(IS_BUSY_LOW) + fn wait_until_idle(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> { + self.interface.wait_until_idle( + IS_BUSY_LOW, + Some((spi, delay, |i, s, d| { + i.cmd(s, Command::GET_STATUS)?; + d.delay_ms(20); + Ok(()) + })), + )?; + Ok(()) } fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { diff --git a/src/interface.rs b/src/interface.rs index 58fbebb..f8a7ee5 100644 --- a/src/interface.rs +++ b/src/interface.rs @@ -7,9 +7,11 @@ use embedded_hal::{ /// The Connection Interface of all (?) Waveshare EPD-Devices /// -pub(crate) struct DisplayInterface { +pub(crate) struct DisplayInterface { /// SPI _spi: PhantomData, + /// DELAY + _delay: PhantomData, /// CS for SPI cs: CS, /// Low for busy, Wait until display is ready! @@ -20,17 +22,19 @@ pub(crate) struct DisplayInterface { rst: RST, } -impl DisplayInterface +impl DisplayInterface where SPI: Write, CS: OutputPin, BUSY: InputPin, DC: OutputPin, RST: OutputPin, + DELAY: DelayMs, { pub fn new(cs: CS, busy: BUSY, dc: DC, rst: RST) -> Self { DisplayInterface { _spi: PhantomData::default(), + _delay: PhantomData::default(), cs, busy, dc, @@ -126,15 +130,32 @@ where /// /// Most likely there was a mistake with the 2in9 busy connection /// //TODO: use the #cfg feature to make this compile the right way for the certain types - pub(crate) fn wait_until_idle(&mut self, is_busy_low: bool) { - //tested: worked without the delay for all tested devices - //self.delay_ms(1); + pub(crate) fn wait_until_idle( + &mut self, + is_busy_low: bool, + mut task: Option<( + &mut SPI, + &mut DELAY, + fn(&mut Self, &mut SPI, &mut DELAY) -> Result<(), SPI::Error>, + )>, + ) -> Result<(), SPI::Error> { + // //tested: worked without the delay for all tested devices + // //self.delay_ms(1); + // Some displays need special treatment (Only 7.5"V2 known so far) + // In those cases, a "task" is provided and run here. If note, this + // just busy waits for the display. while self.is_busy(is_busy_low) { - //tested: REMOVAL of DELAY: it's only waiting for the signal anyway and should continue work asap - //old: shorten the time? it was 100 in the beginning - //self.delay_ms(5); + match task { + // TODO: Ignore this error? + Some((ref mut spi, ref mut delay, tcb)) => tcb(self, spi, delay)?, + None => {} + } + // //tested: REMOVAL of DELAY: it's only waiting for the signal anyway and should continue work asap + // //old: shorten the time? it was 100 in the beginning + // //self.delay_ms(5); } + Ok(()) } /// Checks if device is still busy @@ -162,7 +183,7 @@ where /// The timing of keeping the reset pin low seems to be important and different per device. /// Most displays seem to require keeping it low for 10ms, but the 7in5_v2 only seems to reset /// properly with 2ms - pub(crate) fn reset>(&mut self, delay: &mut DELAY, duration: u8) { + pub(crate) fn reset(&mut self, delay: &mut DELAY, duration: u8) { let _ = self.rst.set_high(); delay.delay_ms(10); diff --git a/src/traits.rs b/src/traits.rs index d4877b5..71de7b2 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -26,13 +26,14 @@ impl Default for RefreshLUT { } } -pub(crate) trait InternalWiAdditions +pub(crate) trait InternalWiAdditions where SPI: Write, CS: OutputPin, BUSY: InputPin, DC: OutputPin, RST: OutputPin, + DELAY: DelayMs, { /// This initialises the EPD and powers it up /// @@ -44,22 +45,19 @@ where /// This function calls [reset](WaveshareDisplay::reset), /// so you don't need to call reset your self when trying to wake your device up /// after setting it to sleep. - fn init>( - &mut self, - spi: &mut SPI, - delay: &mut DELAY, - ) -> Result<(), SPI::Error>; + fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error>; } /// Functions to interact with three color panels -pub trait WaveshareThreeColorDisplay: - WaveshareDisplay +pub trait WaveshareThreeColorDisplay: + WaveshareDisplay where SPI: Write, CS: OutputPin, BUSY: InputPin, DC: OutputPin, RST: OutputPin, + DELAY: DelayMs, { /// Transmit data to the SRAM of the EPD /// @@ -127,20 +125,21 @@ where ///# Ok(()) ///# } ///``` -pub trait WaveshareDisplay +pub trait WaveshareDisplay where SPI: Write, CS: OutputPin, BUSY: InputPin, DC: OutputPin, RST: OutputPin, + DELAY: DelayMs, { /// The Color Type used by the Display type DisplayColor; /// Creates a new driver from a SPI peripheral, CS Pin, Busy InputPin, DC /// /// This already initialises the device. - fn new>( + fn new( spi: &mut SPI, cs: CS, busy: BUSY, @@ -154,16 +153,12 @@ where /// Let the device enter deep-sleep mode to save power. /// /// The deep sleep mode returns to standby with a hardware reset. - fn sleep(&mut self, spi: &mut SPI) -> Result<(), SPI::Error>; + fn sleep(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error>; /// Wakes the device up from sleep /// /// Also reintialises the device if necessary. - fn wake_up>( - &mut self, - spi: &mut SPI, - delay: &mut DELAY, - ) -> Result<(), SPI::Error>; + 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); @@ -178,7 +173,12 @@ where fn height(&self) -> u32; /// Transmit a full frame to the SRAM of the EPD - fn update_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error>; + fn update_frame( + &mut self, + spi: &mut SPI, + buffer: &[u8], + delay: &mut DELAY, + ) -> Result<(), SPI::Error>; /// Transmits partial data to the SRAM of the EPD /// @@ -198,15 +198,20 @@ where /// Displays the frame data from SRAM /// /// This function waits until the device isn`t busy anymore - fn display_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error>; + fn display_frame(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error>; /// Provide a combined update&display and save some time (skipping a busy check in between) - fn update_and_display_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error>; + fn update_and_display_frame( + &mut self, + spi: &mut SPI, + buffer: &[u8], + 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) -> Result<(), SPI::Error>; + 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 @@ -275,13 +280,14 @@ where ///# Ok(()) ///# } ///``` -pub trait QuickRefresh +pub trait QuickRefresh where SPI: Write, CS: OutputPin, BUSY: InputPin, DC: OutputPin, RST: OutputPin, + DELAY: DelayMs, { /// Updates the old frame. fn update_old_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error>; From 04476e6671c620751a8f8cf3d4496ac440efafc0 Mon Sep 17 00:00:00 2001 From: Edwin Svensson Date: Sun, 4 Apr 2021 22:26:50 +0200 Subject: [PATCH 2/3] fix tests --- src/epd1in54/mod.rs | 6 +++--- src/epd2in9/mod.rs | 6 +++--- src/epd2in9bc/mod.rs | 4 ++-- src/epd4in2/mod.rs | 6 +++--- src/lib.rs | 6 +++--- src/traits.rs | 8 ++++---- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/epd1in54/mod.rs b/src/epd1in54/mod.rs index cd2e149..d82fe21 100644 --- a/src/epd1in54/mod.rs +++ b/src/epd1in54/mod.rs @@ -31,11 +31,11 @@ //! .draw(&mut display); //! //!// Display updated frame -//!epd.update_frame(&mut spi, &display.buffer())?; -//!epd.display_frame(&mut spi)?; +//!epd.update_frame(&mut spi, &display.buffer(), &mut delay)?; +//!epd.display_frame(&mut spi, &mut delay)?; //! //!// Set the EPD to sleep -//!epd.sleep(&mut spi)?; +//!epd.sleep(&mut spi, &mut delay)?; //!# Ok(()) //!# } //!``` diff --git a/src/epd2in9/mod.rs b/src/epd2in9/mod.rs index 4288562..881f32b 100644 --- a/src/epd2in9/mod.rs +++ b/src/epd2in9/mod.rs @@ -32,11 +32,11 @@ //! .draw(&mut display); //! //! // Display updated frame -//!epd.update_frame(&mut spi, &display.buffer())?; -//!epd.display_frame(&mut spi)?; +//!epd.update_frame(&mut spi, &display.buffer(), &mut delay)?; +//!epd.display_frame(&mut spi, &mut delay)?; //! //!// Set the EPD to sleep -//!epd.sleep(&mut spi)?; +//!epd.sleep(&mut spi, &mut delay)?; //!# Ok(()) //!# } //!``` diff --git a/src/epd2in9bc/mod.rs b/src/epd2in9bc/mod.rs index 6bfb6c4..2be3e57 100644 --- a/src/epd2in9bc/mod.rs +++ b/src/epd2in9bc/mod.rs @@ -46,10 +46,10 @@ //! &mono_display.buffer(), //! &chromatic_display.buffer() //!)?; -//!epd.display_frame(&mut spi)?; +//!epd.display_frame(&mut spi, &mut delay)?; //! //!// Set the EPD to sleep -//!epd.sleep(&mut spi)?; +//!epd.sleep(&mut spi, &mut delay)?; //!# Ok(()) //!# } //!``` diff --git a/src/epd4in2/mod.rs b/src/epd4in2/mod.rs index e48a23c..119edea 100644 --- a/src/epd4in2/mod.rs +++ b/src/epd4in2/mod.rs @@ -36,11 +36,11 @@ //! .draw(&mut display); //! //! // Display updated frame -//!epd.update_frame(&mut spi, &display.buffer())?; -//!epd.display_frame(&mut spi)?; +//!epd.update_frame(&mut spi, &display.buffer(), &mut delay)?; +//!epd.display_frame(&mut spi, &mut delay)?; //! //!// Set the EPD to sleep -//!epd.sleep(&mut spi)?; +//!epd.sleep(&mut spi, &mut delay)?; //!# Ok(()) //!# } //!``` diff --git a/src/lib.rs b/src/lib.rs index 60a816e..478acd3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -39,11 +39,11 @@ //! .draw(&mut display); //! //! // Display updated frame -//!epd.update_frame(&mut spi, &display.buffer())?; -//!epd.display_frame(&mut spi)?; +//!epd.update_frame(&mut spi, &display.buffer(), &mut delay)?; +//!epd.display_frame(&mut spi, &mut delay)?; //! //!// Set the EPD to sleep -//!epd.sleep(&mut spi)?; +//!epd.sleep(&mut spi, &mut delay)?; //!# Ok(()) //!# } //!``` diff --git a/src/traits.rs b/src/traits.rs index 71de7b2..f5c1f34 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -117,11 +117,11 @@ where /// .draw(&mut display); /// /// // Display updated frame -///epd.update_frame(&mut spi, &display.buffer())?; -///epd.display_frame(&mut spi)?; +///epd.update_frame(&mut spi, &display.buffer(), &mut delay)?; +///epd.display_frame(&mut spi, &mut delay)?; /// ///// Set the EPD to sleep -///epd.sleep(&mut spi)?; +///epd.sleep(&mut spi, &mut delay)?; ///# Ok(()) ///# } ///``` @@ -134,7 +134,7 @@ where RST: OutputPin, DELAY: DelayMs, { - /// The Color Type used by the Display + /// The Color Type used by the Display type DisplayColor; /// Creates a new driver from a SPI peripheral, CS Pin, Busy InputPin, DC /// From c3a4cde81559d6c0d2c6c6aa1767a23bd0cabb61 Mon Sep 17 00:00:00 2001 From: Edwin Svensson Date: Sun, 11 Apr 2021 16:57:28 +0200 Subject: [PATCH 3/3] skip closure/task --- src/epd1in54/mod.rs | 2 +- src/epd1in54b/mod.rs | 2 +- src/epd1in54c/mod.rs | 2 +- src/epd2in13_v2/mod.rs | 2 +- src/epd2in7b/mod.rs | 2 +- src/epd2in9/mod.rs | 2 +- src/epd2in9bc/mod.rs | 2 +- src/epd4in2/mod.rs | 4 ++-- src/epd5in65f/mod.rs | 4 ++-- src/epd7in5/mod.rs | 2 +- src/epd7in5_v2/mod.rs | 12 ++++-------- src/interface.rs | 20 +------------------- src/traits.rs | 3 +-- 13 files changed, 18 insertions(+), 41 deletions(-) diff --git a/src/epd1in54/mod.rs b/src/epd1in54/mod.rs index d82fe21..2666b5a 100644 --- a/src/epd1in54/mod.rs +++ b/src/epd1in54/mod.rs @@ -299,7 +299,7 @@ where DELAY: DelayMs, { fn wait_until_idle(&mut self) { - let _ = self.interface.wait_until_idle(IS_BUSY_LOW, None); + let _ = self.interface.wait_until_idle(IS_BUSY_LOW); } pub(crate) fn use_full_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { diff --git a/src/epd1in54b/mod.rs b/src/epd1in54b/mod.rs index c34efdc..57a390d 100644 --- a/src/epd1in54b/mod.rs +++ b/src/epd1in54b/mod.rs @@ -339,7 +339,7 @@ where } fn wait_until_idle(&mut self) { - let _ = self.interface.wait_until_idle(IS_BUSY_LOW, None); + let _ = self.interface.wait_until_idle(IS_BUSY_LOW); } fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { diff --git a/src/epd1in54c/mod.rs b/src/epd1in54c/mod.rs index f226cfe..df7d728 100644 --- a/src/epd1in54c/mod.rs +++ b/src/epd1in54c/mod.rs @@ -275,7 +275,7 @@ where } fn wait_until_idle(&mut self) { - let _ = self.interface.wait_until_idle(IS_BUSY_LOW, None); + let _ = self.interface.wait_until_idle(IS_BUSY_LOW); } fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { diff --git a/src/epd2in13_v2/mod.rs b/src/epd2in13_v2/mod.rs index fe661e5..0dd798f 100644 --- a/src/epd2in13_v2/mod.rs +++ b/src/epd2in13_v2/mod.rs @@ -564,7 +564,7 @@ where } fn wait_until_idle(&mut self) { - let _ = self.interface.wait_until_idle(IS_BUSY_LOW, None); + let _ = self.interface.wait_until_idle(IS_BUSY_LOW); } } diff --git a/src/epd2in7b/mod.rs b/src/epd2in7b/mod.rs index 4a19aab..89a04e2 100644 --- a/src/epd2in7b/mod.rs +++ b/src/epd2in7b/mod.rs @@ -363,7 +363,7 @@ where } fn wait_until_idle(&mut self) { - let _ = self.interface.wait_until_idle(IS_BUSY_LOW, None); + let _ = self.interface.wait_until_idle(IS_BUSY_LOW); } /// Refresh display for partial frame diff --git a/src/epd2in9/mod.rs b/src/epd2in9/mod.rs index 881f32b..9f2f9f1 100644 --- a/src/epd2in9/mod.rs +++ b/src/epd2in9/mod.rs @@ -298,7 +298,7 @@ where DELAY: DelayMs, { fn wait_until_idle(&mut self) { - let _ = self.interface.wait_until_idle(IS_BUSY_LOW, None); + let _ = self.interface.wait_until_idle(IS_BUSY_LOW); } fn use_full_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { diff --git a/src/epd2in9bc/mod.rs b/src/epd2in9bc/mod.rs index 2be3e57..663c8dc 100644 --- a/src/epd2in9bc/mod.rs +++ b/src/epd2in9bc/mod.rs @@ -365,7 +365,7 @@ where } fn wait_until_idle(&mut self) { - let _ = self.interface.wait_until_idle(IS_BUSY_LOW, None); + let _ = self.interface.wait_until_idle(IS_BUSY_LOW); } fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { diff --git a/src/epd4in2/mod.rs b/src/epd4in2/mod.rs index 119edea..c87aa40 100644 --- a/src/epd4in2/mod.rs +++ b/src/epd4in2/mod.rs @@ -372,7 +372,7 @@ where } fn wait_until_idle(&mut self) { - let _ = self.interface.wait_until_idle(IS_BUSY_LOW, None); + let _ = self.interface.wait_until_idle(IS_BUSY_LOW); } fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { @@ -442,7 +442,7 @@ where } } -impl QuickRefresh +impl QuickRefresh for EPD4in2 where SPI: Write, diff --git a/src/epd5in65f/mod.rs b/src/epd5in65f/mod.rs index aefb3c3..7731c3e 100644 --- a/src/epd5in65f/mod.rs +++ b/src/epd5in65f/mod.rs @@ -223,10 +223,10 @@ where } fn wait_busy_high(&mut self) { - let _ = self.interface.wait_until_idle(true, None); + let _ = self.interface.wait_until_idle(true); } fn wait_busy_low(&mut self) { - let _ = self.interface.wait_until_idle(false, None); + let _ = self.interface.wait_until_idle(false); } fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { let w = self.width(); diff --git a/src/epd7in5/mod.rs b/src/epd7in5/mod.rs index 4e2c6c4..ff8ada8 100644 --- a/src/epd7in5/mod.rs +++ b/src/epd7in5/mod.rs @@ -255,7 +255,7 @@ where } fn wait_until_idle(&mut self) { - let _ = self.interface.wait_until_idle(IS_BUSY_LOW, None); + let _ = self.interface.wait_until_idle(IS_BUSY_LOW); } fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { diff --git a/src/epd7in5_v2/mod.rs b/src/epd7in5_v2/mod.rs index 8e81b90..13f1716 100644 --- a/src/epd7in5_v2/mod.rs +++ b/src/epd7in5_v2/mod.rs @@ -229,14 +229,10 @@ where } fn wait_until_idle(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> { - self.interface.wait_until_idle( - IS_BUSY_LOW, - Some((spi, delay, |i, s, d| { - i.cmd(s, Command::GET_STATUS)?; - d.delay_ms(20); - Ok(()) - })), - )?; + while self.interface.is_busy(IS_BUSY_LOW) { + self.interface.cmd(spi, Command::GET_STATUS)?; + delay.delay_ms(20); + } Ok(()) } diff --git a/src/interface.rs b/src/interface.rs index f8a7ee5..3ef967b 100644 --- a/src/interface.rs +++ b/src/interface.rs @@ -130,32 +130,14 @@ where /// /// Most likely there was a mistake with the 2in9 busy connection /// //TODO: use the #cfg feature to make this compile the right way for the certain types - pub(crate) fn wait_until_idle( - &mut self, - is_busy_low: bool, - mut task: Option<( - &mut SPI, - &mut DELAY, - fn(&mut Self, &mut SPI, &mut DELAY) -> Result<(), SPI::Error>, - )>, - ) -> Result<(), SPI::Error> { + pub(crate) fn wait_until_idle(&mut self, is_busy_low: bool) { // //tested: worked without the delay for all tested devices // //self.delay_ms(1); - - // Some displays need special treatment (Only 7.5"V2 known so far) - // In those cases, a "task" is provided and run here. If note, this - // just busy waits for the display. while self.is_busy(is_busy_low) { - match task { - // TODO: Ignore this error? - Some((ref mut spi, ref mut delay, tcb)) => tcb(self, spi, delay)?, - None => {} - } // //tested: REMOVAL of DELAY: it's only waiting for the signal anyway and should continue work asap // //old: shorten the time? it was 100 in the beginning // //self.delay_ms(5); } - Ok(()) } /// Checks if device is still busy diff --git a/src/traits.rs b/src/traits.rs index f5c1f34..5ad792a 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -280,14 +280,13 @@ where ///# Ok(()) ///# } ///``` -pub trait QuickRefresh +pub trait QuickRefresh where SPI: Write, CS: OutputPin, BUSY: InputPin, DC: OutputPin, RST: OutputPin, - DELAY: DelayMs, { /// Updates the old frame. fn update_old_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error>;