Trying to make partial update

This commit is contained in:
Adrian Woźniak 2024-10-04 16:34:48 +02:00
parent a340c9083a
commit 91f3382b15
4 changed files with 106 additions and 7 deletions

View File

@ -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(())
}
}

View File

@ -143,6 +143,71 @@ where
}
}
impl<SPI, BUSY, DC, RST, DELAY> EPD3in7<SPI, BUSY, DC, RST, DELAY>
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<SPI, BUSY, DC, RST, DELAY> WaveshareDisplay<SPI, BUSY, DC, RST, DELAY>
for EPD3in7<SPI, BUSY, DC, RST, DELAY>
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(())
}

View File

@ -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<Action> {

View File

@ -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) {