diff --git a/examples/epd1in54_no_graphics.rs b/examples/epd1in54_no_graphics.rs index 4782622..4eecbcd 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 3fc7472..3ee0e8c 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 b986828..dffc083 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 554c707..fe36f7e 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 315899b..e5d97bd 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(()) //!# } //!``` @@ -71,29 +71,25 @@ mod graphics; 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: @@ -139,14 +135,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 { @@ -157,7 +154,7 @@ where HEIGHT } - fn new>( + fn new( spi: &mut SPI, cs: CS, busy: BUSY, @@ -178,15 +175,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? @@ -195,7 +188,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 @@ -222,7 +220,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) @@ -236,13 +234,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)?; @@ -282,16 +285,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); } 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 0f871ba..6150c9c 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, @@ -131,17 +129,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, @@ -159,7 +158,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::VcomAndDataIntervalSetting, &[0x17])?; //border floating @@ -179,11 +178,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) } @@ -203,7 +198,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)?; @@ -241,19 +241,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::DisplayRefresh)?; 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)?; @@ -301,13 +306,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) @@ -327,7 +333,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); } fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { diff --git a/src/epd1in54c/mod.rs b/src/epd1in54c/mod.rs index 6ff0508..802b131 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::PowerOff)?; @@ -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::DisplayRefresh)?; 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); } 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 4705c1f..8368d56 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); @@ -153,17 +150,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, @@ -182,15 +180,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... @@ -208,7 +202,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)?; @@ -265,7 +264,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, @@ -285,9 +284,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)?; @@ -295,7 +299,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)?; @@ -357,13 +361,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. @@ -387,7 +392,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, @@ -555,7 +560,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); } } diff --git a/src/epd2in7b/mod.rs b/src/epd2in7b/mod.rs index cbe07fe..972d785 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::VcomAndDataIntervalSetting, &[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::DataStartTransmission1)?; self.send_buffer_helper(spi, buffer)?; @@ -199,19 +198,24 @@ where self.interface.cmd(spi, Command::DataStop) } - 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::DisplayRefresh)?; 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::DisplayRefresh)?; 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(); @@ -263,14 +267,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, @@ -316,13 +321,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) @@ -351,7 +357,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); } /// Refresh display for partial frame diff --git a/src/epd2in9/mod.rs b/src/epd2in9/mod.rs index 8658789..0feec3d 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(()) //!# } //!``` @@ -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(); @@ -135,14 +132,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 { @@ -153,7 +151,7 @@ where HEIGHT } - fn new>( + fn new( spi: &mut SPI, cs: CS, busy: BUSY, @@ -174,7 +172,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) @@ -183,17 +181,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)?; @@ -221,7 +220,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) @@ -235,13 +234,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)?; @@ -281,16 +285,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); } 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 ff8face..37280f3 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(()) //!# } //!``` @@ -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, @@ -186,17 +184,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, @@ -214,7 +213,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, @@ -231,11 +230,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) } @@ -255,7 +250,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::DataStartTransmission1)?; self.interface.data(spi, &buffer)?; @@ -283,20 +283,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::DisplayRefresh)?; 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(); @@ -327,13 +332,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) @@ -353,7 +359,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); } fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { diff --git a/src/epd4in2/mod.rs b/src/epd4in2/mod.rs index 2f75539..983172f 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(()) //!# } //!``` @@ -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::VcomAndDataIntervalSetting, &[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(); @@ -266,19 +265,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::DisplayRefresh)?; 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::DisplayRefresh)?; 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)?; @@ -338,13 +342,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) @@ -364,7 +369,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); } fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { @@ -434,14 +439,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 9f94930..869fe2a 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::DeepSleep, &[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::DataStartTransmission1, 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::PowerOn)?; 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::DataStartTransmission1)?; 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); } fn wait_busy_low(&mut self) { - self.interface.wait_until_idle(false) + 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 c93bf1e..582061f 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::PowerOff)?; 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::DataStartTransmission1)?; 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::DisplayRefresh)?; 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::DisplayRefresh)?; 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); } 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 b3ab5de..3ee95af 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::BoosterSoftStart, &[0x17, 0x17, 0x27, 0x17])?; self.cmd_with_data(spi, Command::PowerSetting, &[0x07, 0x17, 0x3F, 0x3F])?; self.command(spi, Command::PowerOn)?; - self.wait_until_idle(); + self.wait_until_idle(spi, delay)?; self.cmd_with_data(spi, Command::PanelSetting, &[0x1F])?; self.cmd_with_data(spi, Command::PllControl, &[0x06])?; self.cmd_with_data(spi, Command::TconResolution, &[0x03, 0x20, 0x01, 0xE0])?; self.cmd_with_data(spi, Command::DualSpi, &[0x00])?; self.cmd_with_data(spi, Command::TconSetting, &[0x22])?; self.cmd_with_data(spi, Command::VcomAndDataIntervalSetting, &[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::PowerOff)?; - self.wait_until_idle(); + self.wait_until_idle(spi, delay)?; self.cmd_with_data(spi, Command::DeepSleep, &[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::DataStartTransmission2, 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::DisplayRefresh)?; 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::DisplayRefresh)?; 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::DataStartTransmission1)?; @@ -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,12 @@ 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> { + while self.interface.is_busy(IS_BUSY_LOW) { + self.interface.cmd(spi, Command::GetStatus)?; + delay.delay_ms(20); + } + Ok(()) } fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { diff --git a/src/interface.rs b/src/interface.rs index 4ba1eb3..8d59a91 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, @@ -127,13 +131,12 @@ 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); - + // //tested: worked without the delay for all tested devices + // //self.delay_ms(1); 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); + // //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); } } @@ -162,7 +165,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/lib.rs b/src/lib.rs index b96e6fe..2b4dea4 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 7c21c10..94446f2 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 /// @@ -119,28 +117,29 @@ 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(()) ///# } ///``` -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 + /// 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