WOrking on partial refresh

This commit is contained in:
Adrian Woźniak 2024-10-03 16:25:41 +02:00
parent 021a611df2
commit a340c9083a
2 changed files with 7 additions and 24 deletions

View File

@ -260,29 +260,12 @@ where
width: u32, width: u32,
height: u32, height: u32,
) -> Result<(), SPI::Error> { ) -> Result<(), SPI::Error> {
let i = &mut self.interface; self.wait_until_idle(spi, delay)?;
i.cmd(spi, Command::SetRamXAddressStartEndPosition); self.set_ram_area(spi, delay, x, y, x + width, y + height)?;
i.data(spi, &[(x >> 8) as u8])?; self.set_ram_counter(spi, delay, x, y)?;
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.interface
.cmd_with_data(spi, Command::WriteRam, buffer)?;
Ok(()) Ok(())
} }

View File

@ -27,7 +27,7 @@ impl MazeGame {
impl MazeGame { impl MazeGame {
const X_OFFSET: i32 = 4; const X_OFFSET: i32 = 4;
const Y_OFFSET: i32 = 4; const Y_OFFSET: i32 = 4;
const CELL_SIZE: i32 = 6; const CELL_SIZE: i32 = 10;
fn player_pos(&self) -> (u16, u16) { fn player_pos(&self) -> (u16, u16) {
(self.player.x as u16, self.player.y as u16) (self.player.x as u16, self.player.y as u16)
@ -72,7 +72,7 @@ impl MazeGame {
(self.player.x * Self::CELL_SIZE) + Self::X_OFFSET + 1, (self.player.x * Self::CELL_SIZE) + Self::X_OFFSET + 1,
(self.player.y * Self::CELL_SIZE) + Self::Y_OFFSET + 1, (self.player.y * Self::CELL_SIZE) + Self::Y_OFFSET + 1,
), ),
Size::new(4, 4), Size::new((Self::CELL_SIZE - 2) as u32, (Self::CELL_SIZE - 2) as u32),
) )
.draw_styled(&player_style, &mut ctx.epaper.display) .draw_styled(&player_style, &mut ctx.epaper.display)
.unwrap(); .unwrap();