diff --git a/epd-waveshare/src/epd1in54/mod.rs b/epd-waveshare/src/epd1in54/mod.rs index 4a4514e..b97837e 100644 --- a/epd-waveshare/src/epd1in54/mod.rs +++ b/epd-waveshare/src/epd1in54/mod.rs @@ -289,7 +289,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); + let _ = self.interface.wait_until_idle(delay, IS_BUSY_LOW); Ok(()) } } diff --git a/epd-waveshare/src/epd3in7/mod.rs b/epd-waveshare/src/epd3in7/mod.rs index 507f5b1..71a51c5 100644 --- a/epd-waveshare/src/epd3in7/mod.rs +++ b/epd-waveshare/src/epd3in7/mod.rs @@ -143,6 +143,71 @@ where } } +impl EPD3in7 +where + SPI: SpiDevice, + BUSY: InputPin, + DC: OutputPin, + RST: OutputPin, + DELAY: DelayNs, +{ + pub(crate) fn set_ram_area( + &mut self, + spi: &mut SPI, + delay: &mut DELAY, + start_x: u32, + start_y: u32, + end_x: u32, + end_y: u32, + ) -> Result<(), SPI::Error> { + self.wait_until_idle(spi, delay)?; + assert!(start_x < end_x); + assert!(start_y < end_y); + + // x is positioned in bytes, so the last 3 bits which show the position inside a byte in the ram + // aren't relevant + self.interface.cmd_with_data( + spi, + Command::SetRamXAddressStartEndPosition, + &[(start_x >> 3) as u8, (end_x >> 3) as u8], + )?; + + // 2 Databytes: A[7:0] & 0..A[8] for each - start and end + self.interface.cmd_with_data( + spi, + Command::SetRamYAddressStartEndPosition, + &[ + start_y as u8, + (start_y >> 8) as u8, + end_y as u8, + (end_y >> 8) as u8, + ], + )?; + Ok(()) + } + + pub(crate) fn set_ram_counter( + &mut self, + spi: &mut SPI, + delay: &mut DELAY, + x: u32, + y: u32, + ) -> Result<(), SPI::Error> { + self.wait_until_idle(spi, delay)?; + // x is positioned in bytes, so the last 3 bits which show the position inside a byte in the ram + // aren't relevant + self.interface + .cmd_with_data(spi, Command::SetRamXAddressCounter, &[(x >> 3) as u8])?; + + // 2 Databytes: A[7:0] & 0..A[8] + self.interface.cmd_with_data( + spi, + Command::SetRamYAddressCounter, + &[y as u8, (y >> 8) as u8], + )?; + Ok(()) + } +} impl WaveshareDisplay for EPD3in7 where @@ -260,12 +325,36 @@ where 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)?; + */ Ok(()) } diff --git a/src/apps/maze_game.rs b/src/apps/maze_game.rs index 12718d9..3a2eaea 100644 --- a/src/apps/maze_game.rs +++ b/src/apps/maze_game.rs @@ -112,10 +112,11 @@ impl App for MazeGame { } fn draw(&self, ctx: &mut Context) { + /* self.draw_walls(ctx); - self.draw_player(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; @@ -123,12 +124,19 @@ impl App for MazeGame { ctx.epaper.partial_update( *old, Size { - width: 0, - height: 0, + width: 1, + height: 1, }, &[Color::White as u8], ); - self.draw_player(ctx);*/ + 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 8897fd4..81662b0 100644 --- a/src/apps/mod.rs +++ b/src/apps/mod.rs @@ -45,7 +45,9 @@ impl Application { Self::Menu(menu) => menu.draw(ctx), Self::Maze(maze) => maze.draw(ctx), }; - ctx.epaper.full_update(); + if full { + ctx.epaper.full_update(); + } } pub fn update_and_draw(&mut self, ctx: &mut Context, trng: &mut Trng) {