From b76d026f20771dba4e19b122d1f971770f612120 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Wo=C5=BAniak?= Date: Mon, 14 Oct 2024 12:36:50 +0200 Subject: [PATCH] Fast update done --- epd-waveshare/src/epd3in7/constants.rs | 14 +++++++++ epd-waveshare/src/epd3in7/mod.rs | 38 ++++-------------------- src/apps/maze_game.rs | 40 +++++++++++++++----------- src/apps/mod.rs | 1 + src/epaper.rs | 22 ++++++++++++++ src/main.rs | 2 +- 6 files changed, 66 insertions(+), 51 deletions(-) diff --git a/epd-waveshare/src/epd3in7/constants.rs b/epd-waveshare/src/epd3in7/constants.rs index bbfbf0c..ee3b3c3 100644 --- a/epd-waveshare/src/epd3in7/constants.rs +++ b/epd-waveshare/src/epd3in7/constants.rs @@ -15,6 +15,7 @@ pub(crate) const LUT_1GRAY_GC: [u8; 105] = [ // This LUT updates only the pixels that have changed. pub(crate) const LUT_1GRAY_DU: [u8; 105] = [ + /* 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //1 0x01, 0x2A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //2 0x0A, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //3 @@ -25,5 +26,18 @@ pub(crate) const LUT_1GRAY_DU: [u8; 105] = [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //8 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //9 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //10 + 0x22, 0x22, 0x22, 0x22, 0x22,*/ + // + // + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //1 + 0x01, 0x2A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 2 + 0x0A, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //3 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 4 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //5 + 0x00, 0x00, 0x05, 0x05, 0x00, 0x05, 0x03, 0x05, 0x05, 0x00, // 6 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //7 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //8 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //9 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //10 0x22, 0x22, 0x22, 0x22, 0x22, ]; diff --git a/epd-waveshare/src/epd3in7/mod.rs b/epd-waveshare/src/epd3in7/mod.rs index 71a51c5..7fd8b2c 100644 --- a/epd-waveshare/src/epd3in7/mod.rs +++ b/epd-waveshare/src/epd3in7/mod.rs @@ -143,6 +143,7 @@ where } } +#[allow(dead_code)] impl EPD3in7 where SPI: SpiDevice, @@ -320,41 +321,12 @@ where spi: &mut SPI, delay: &mut DELAY, buffer: &[u8], - x: u32, - y: u32, + start_x: u32, + start_y: u32, width: u32, height: u32, ) -> Result<(), SPI::Error> { - let i = &mut self.interface; - i.cmd(spi, Command::SetRamXAddressStartEndPosition); - i.data(spi, &[(x >> 8) as u8])?; - let tmp = x & 0xf8; - i.data(spi, &[tmp as u8])?; // x should be the multiple of 8, the last 3 bit will always be ignored - let tmp = tmp + width - 1; - i.data(spi, &[(tmp >> 8) as u8])?; - i.data(spi, &[(tmp | 0x07) as u8])?; - - i.cmd(spi, Command::SetRamYAddressStartEndPosition); - i.data(spi, &[(y >> 8) as u8])?; - i.data(spi, &[y as u8])?; - i.data(spi, &[((y + height - 1) >> 8) as u8])?; - i.data(spi, &[(y + height - 1) as u8])?; - - i.cmd_with_data(spi, Command::WriteRam, buffer); - - //load lut 2 - i.cmd_with_data(spi, Command::WriteLutRegister, &LUT_1GRAY_DU); - - i.cmd(spi, Command::DisplayUpdateSequence); - i.wait_until_idle(delay, IS_BUSY_LOW); - /* - self.wait_until_idle(spi, delay)?; - self.set_ram_area(spi, delay, x, y, x + width, y + height)?; - self.set_ram_counter(spi, delay, x, y)?; - - self.interface - .cmd_with_data(spi, Command::WriteRam, buffer)?; - */ + // broken beyond repart Ok(()) } @@ -407,7 +379,7 @@ where } fn wait_until_idle(&mut self, _spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> { - self.interface.wait_until_idle(delay, IS_BUSY_LOW); + self.interface.wait_until_idle(delay, IS_BUSY_LOW).unwrap(); Ok(()) } } diff --git a/src/apps/maze_game.rs b/src/apps/maze_game.rs index 3a2eaea..64d540c 100644 --- a/src/apps/maze_game.rs +++ b/src/apps/maze_game.rs @@ -116,27 +116,33 @@ impl App for MazeGame { self.draw_walls(ctx); self.draw_player(ctx);*/ // FIXME: Partial update - let Some(old) = &self.old_player else { + let Some(_old) = &self.old_player else { self.draw_walls(ctx); self.draw_player(ctx); return; }; - ctx.epaper.partial_update( - *old, - Size { - width: 1, - height: 1, - }, - &[Color::White as u8], - ); - ctx.epaper.partial_update( - self.player, - Size { - width: 1, - height: 1, - }, - &[Color::Black as u8], - ); + + ctx.epaper.fast_update(); + ctx.epaper.clear_frame(); + self.draw_walls(ctx); + self.draw_player(ctx); + ctx.epaper.full_update(); + // ctx.epaper.partial_update( + // *old, + // Size { + // width: 1, + // height: 1, + // }, + // &[Color::White as u8], + // ); + // ctx.epaper.partial_update( + // self.player, + // Size { + // width: 1, + // height: 1, + // }, + // &[Color::Black as u8], + // ); } fn update(&mut self, ctx: &mut Context) -> Option { diff --git a/src/apps/mod.rs b/src/apps/mod.rs index 81662b0..1c1f779 100644 --- a/src/apps/mod.rs +++ b/src/apps/mod.rs @@ -39,6 +39,7 @@ impl Default for Application { impl Application { pub fn draw(&self, ctx: &mut Context, full: bool) { if full { + ctx.epaper.slow_update(); ctx.epaper.full_erase(); } match self { diff --git a/src/epaper.rs b/src/epaper.rs index 76cb484..bf747f0 100644 --- a/src/epaper.rs +++ b/src/epaper.rs @@ -142,6 +142,17 @@ impl<'d> Epaper<'d> { log::info!("Clearing display DONE"); } + pub fn fast_update(&mut self) { + self.driver + .set_lut(&mut self.spi, &mut self.delay, Some(RefreshLut::Quick)) + .unwrap(); + } + pub fn slow_update(&mut self) { + self.driver + .set_lut(&mut self.spi, &mut self.delay, Some(RefreshLut::Full)) + .unwrap(); + } + pub fn print_welcome(&mut self) { // draw white on black background let style = MonoTextStyleBuilder::new() @@ -183,4 +194,15 @@ impl<'d> Epaper<'d> { size.height, ); } + pub fn partial_update_buffer(&mut self, pos: Point, size: Size) { + let _ = self.driver.update_partial_frame( + &mut self.spi, + &mut self.delay, + self.display.buffer(), + pos.x as u32, + pos.y as u32, + size.width, + size.height, + ); + } } diff --git a/src/main.rs b/src/main.rs index 399c585..c41c85f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -94,7 +94,7 @@ fn main() -> ! { loop { ctx.button_pressed = kbd.pressed(); if ctx.button_pressed.is_some() { - ctx.epaper.clear_frame(); + // ctx.epaper.clear_frame(); log::info!("Wake up!"); app.update_and_draw(&mut ctx, &mut trng); }