mirror of
https://github.com/Anshorei/epd-waveshare.git
synced 2026-10-04 06:16:42 +00:00
Update/Include new update_and_display trait
This commit is contained in:
+13
-15
@@ -175,21 +175,19 @@ where
|
||||
}
|
||||
|
||||
fn sleep(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
|
||||
self.wait_until_idle();
|
||||
// 0x00 for Normal mode (Power on Reset), 0x01 for Deep Sleep Mode
|
||||
//TODO: is 0x00 needed here or would 0x01 be even more efficient?
|
||||
self.interface
|
||||
.cmd_with_data(spi, Command::DEEP_SLEEP_MODE, &[0x00])?;
|
||||
|
||||
self.wait_until_idle();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn update_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> {
|
||||
self.wait_until_idle();
|
||||
self.use_full_frame(spi)?;
|
||||
self.interface
|
||||
.cmd_with_data(spi, Command::WRITE_RAM, buffer)?;
|
||||
|
||||
self.wait_until_idle();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -203,17 +201,17 @@ where
|
||||
width: u32,
|
||||
height: u32,
|
||||
) -> Result<(), SPI::Error> {
|
||||
self.wait_until_idle();
|
||||
self.set_ram_area(spi, x, y, x + width, y + height)?;
|
||||
self.set_ram_counter(spi, x, y)?;
|
||||
|
||||
self.interface
|
||||
.cmd_with_data(spi, Command::WRITE_RAM, buffer)?;
|
||||
|
||||
self.wait_until_idle();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn display_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
|
||||
self.wait_until_idle();
|
||||
// enable clock signal, enable cp, display pattern -> 0xC4 (tested with the arduino version)
|
||||
//TODO: test control_1 or control_2 with default value 0xFF (from the datasheet)
|
||||
self.interface
|
||||
@@ -223,12 +221,17 @@ where
|
||||
// MASTER Activation should not be interupted to avoid currption of panel images
|
||||
// therefore a terminate command is send
|
||||
self.interface.cmd(spi, Command::NOP)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
self.wait_until_idle();
|
||||
fn update_and_display_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> {
|
||||
self.update_frame(spi, buffer)?;
|
||||
self.display_frame(spi)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn clear_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
|
||||
self.wait_until_idle();
|
||||
self.use_full_frame(spi)?;
|
||||
|
||||
// clear the ram with the background color
|
||||
@@ -237,8 +240,6 @@ where
|
||||
self.interface.cmd(spi, Command::WRITE_RAM)?;
|
||||
self.interface
|
||||
.data_x_times(spi, color, WIDTH / 8 * HEIGHT)?;
|
||||
|
||||
self.wait_until_idle();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -297,6 +298,7 @@ where
|
||||
end_x: u32,
|
||||
end_y: u32,
|
||||
) -> Result<(), SPI::Error> {
|
||||
self.wait_until_idle();
|
||||
assert!(start_x < end_x);
|
||||
assert!(start_y < end_y);
|
||||
|
||||
@@ -319,8 +321,6 @@ where
|
||||
(end_y >> 8) as u8,
|
||||
],
|
||||
)?;
|
||||
|
||||
self.wait_until_idle();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -330,6 +330,7 @@ where
|
||||
x: u32,
|
||||
y: u32,
|
||||
) -> Result<(), SPI::Error> {
|
||||
self.wait_until_idle();
|
||||
// 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
|
||||
@@ -341,18 +342,15 @@ where
|
||||
Command::SET_RAM_Y_ADDRESS_COUNTER,
|
||||
&[y as u8, (y >> 8) as u8],
|
||||
)?;
|
||||
|
||||
self.wait_until_idle();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn set_lut_helper(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> {
|
||||
self.wait_until_idle();
|
||||
assert!(buffer.len() == 30);
|
||||
|
||||
self.interface
|
||||
.cmd_with_data(spi, Command::WRITE_LUT_REGISTER, buffer)?;
|
||||
|
||||
self.wait_until_idle();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user