Fast update done

This commit is contained in:
Adrian Woźniak 2024-10-14 12:36:50 +02:00
parent 91f3382b15
commit b76d026f20
6 changed files with 66 additions and 51 deletions

View File

@ -15,6 +15,20 @@ 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
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,*/
//
//
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

View File

@ -143,6 +143,7 @@ where
}
}
#[allow(dead_code)]
impl<SPI, BUSY, DC, RST, DELAY> EPD3in7<SPI, BUSY, DC, RST, DELAY>
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(())
}
}

View File

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

View File

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

View File

@ -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,
);
}
}

View File

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