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,7 @@ pub(crate) const LUT_1GRAY_GC: [u8; 105] = [
// This LUT updates only the pixels that have changed. // This LUT updates only the pixels that have changed.
pub(crate) const LUT_1GRAY_DU: [u8; 105] = [ pub(crate) const LUT_1GRAY_DU: [u8; 105] = [
/*
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //1 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //1
0x01, 0x2A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //2 0x01, 0x2A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //2
0x0A, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //3 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, //8
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //9 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //9
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //10 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, 0x22, 0x22, 0x22, 0x22, 0x22,
]; ];

View File

@ -143,6 +143,7 @@ where
} }
} }
#[allow(dead_code)]
impl<SPI, BUSY, DC, RST, DELAY> EPD3in7<SPI, BUSY, DC, RST, DELAY> impl<SPI, BUSY, DC, RST, DELAY> EPD3in7<SPI, BUSY, DC, RST, DELAY>
where where
SPI: SpiDevice, SPI: SpiDevice,
@ -320,41 +321,12 @@ where
spi: &mut SPI, spi: &mut SPI,
delay: &mut DELAY, delay: &mut DELAY,
buffer: &[u8], buffer: &[u8],
x: u32, start_x: u32,
y: u32, start_y: u32,
width: u32, width: u32,
height: u32, height: u32,
) -> Result<(), SPI::Error> { ) -> Result<(), SPI::Error> {
let i = &mut self.interface; // broken beyond repart
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(()) Ok(())
} }
@ -407,7 +379,7 @@ where
} }
fn wait_until_idle(&mut self, _spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> { 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(()) Ok(())
} }
} }

View File

@ -116,27 +116,33 @@ impl App for MazeGame {
self.draw_walls(ctx); self.draw_walls(ctx);
self.draw_player(ctx);*/ self.draw_player(ctx);*/
// FIXME: Partial update // FIXME: Partial update
let Some(old) = &self.old_player else { let Some(_old) = &self.old_player else {
self.draw_walls(ctx); self.draw_walls(ctx);
self.draw_player(ctx); self.draw_player(ctx);
return; return;
}; };
ctx.epaper.partial_update(
*old, ctx.epaper.fast_update();
Size { ctx.epaper.clear_frame();
width: 1, self.draw_walls(ctx);
height: 1, self.draw_player(ctx);
}, ctx.epaper.full_update();
&[Color::White as u8], // ctx.epaper.partial_update(
); // *old,
ctx.epaper.partial_update( // Size {
self.player, // width: 1,
Size { // height: 1,
width: 1, // },
height: 1, // &[Color::White as u8],
}, // );
&[Color::Black 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> { fn update(&mut self, ctx: &mut Context) -> Option<Action> {

View File

@ -39,6 +39,7 @@ impl Default for Application {
impl Application { impl Application {
pub fn draw(&self, ctx: &mut Context, full: bool) { pub fn draw(&self, ctx: &mut Context, full: bool) {
if full { if full {
ctx.epaper.slow_update();
ctx.epaper.full_erase(); ctx.epaper.full_erase();
} }
match self { match self {

View File

@ -142,6 +142,17 @@ impl<'d> Epaper<'d> {
log::info!("Clearing display DONE"); 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) { pub fn print_welcome(&mut self) {
// draw white on black background // draw white on black background
let style = MonoTextStyleBuilder::new() let style = MonoTextStyleBuilder::new()
@ -183,4 +194,15 @@ impl<'d> Epaper<'d> {
size.height, 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 { loop {
ctx.button_pressed = kbd.pressed(); ctx.button_pressed = kbd.pressed();
if ctx.button_pressed.is_some() { if ctx.button_pressed.is_some() {
ctx.epaper.clear_frame(); // ctx.epaper.clear_frame();
log::info!("Wake up!"); log::info!("Wake up!");
app.update_and_draw(&mut ctx, &mut trng); app.update_and_draw(&mut ctx, &mut trng);
} }