Added support for partial window tracking
This commit is contained in:
parent
185f700741
commit
05e927d0a8
1 changed files with 132 additions and 9 deletions
131
src/lib.rs
131
src/lib.rs
|
|
@ -58,9 +58,10 @@ impl Frame {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct DoubleFrame {
|
pub struct DoubleFrame<PartialWindow> {
|
||||||
old: Frame,
|
old: Frame,
|
||||||
new: Frame,
|
new: Frame,
|
||||||
|
partial_window: PartialWindow,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum PixelColour {
|
pub enum PixelColour {
|
||||||
|
|
@ -68,13 +69,126 @@ pub enum PixelColour {
|
||||||
White = 1,
|
White = 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DoubleFrame {
|
pub trait ApplyParitalWindow: private::Sealed {
|
||||||
|
fn apply<
|
||||||
|
BusyPin: InputPin,
|
||||||
|
ResetPin: OutputPin,
|
||||||
|
DcPin: OutputPin,
|
||||||
|
Spi: SpiDevice,
|
||||||
|
Delay: DelayNs,
|
||||||
|
>(
|
||||||
|
&self,
|
||||||
|
display: &mut EPaperDisplay<BusyPin, ResetPin, DcPin, Spi, Delay>,
|
||||||
|
);
|
||||||
|
|
||||||
|
fn update_partial_window(&mut self, min_x: u16, max_x: u16, min_y: u16, max_y: u16);
|
||||||
|
|
||||||
|
fn reset_partial_window(&mut self);
|
||||||
|
}
|
||||||
|
|
||||||
|
mod private {
|
||||||
|
pub(super) trait Sealed {}
|
||||||
|
|
||||||
|
impl Sealed for super::NoPartialWindow {}
|
||||||
|
|
||||||
|
impl Sealed for super::AutomaticPartialWindow {}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct NoPartialWindow;
|
||||||
|
|
||||||
|
impl ApplyParitalWindow for NoPartialWindow {
|
||||||
|
fn apply<
|
||||||
|
BusyPin: InputPin,
|
||||||
|
ResetPin: OutputPin,
|
||||||
|
DcPin: OutputPin,
|
||||||
|
Spi: SpiDevice,
|
||||||
|
Delay: DelayNs,
|
||||||
|
>(
|
||||||
|
&self,
|
||||||
|
_display: &mut EPaperDisplay<BusyPin, ResetPin, DcPin, Spi, Delay>,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update_partial_window(&mut self, _min_x: u16, _max_x: u16, _min_y: u16, _max_y: u16) {}
|
||||||
|
|
||||||
|
fn reset_partial_window(&mut self) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct AutomaticPartialWindow {
|
||||||
|
min_x: u16,
|
||||||
|
max_x: u16,
|
||||||
|
min_y: u16,
|
||||||
|
max_y: u16,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ApplyParitalWindow for AutomaticPartialWindow {
|
||||||
|
fn apply<
|
||||||
|
BusyPin: InputPin,
|
||||||
|
ResetPin: OutputPin,
|
||||||
|
DcPin: OutputPin,
|
||||||
|
Spi: SpiDevice,
|
||||||
|
Delay: DelayNs,
|
||||||
|
>(
|
||||||
|
&self,
|
||||||
|
display: &mut EPaperDisplay<BusyPin, ResetPin, DcPin, Spi, Delay>,
|
||||||
|
) {
|
||||||
|
let hrst = self.min_x as u8 & 0b11111000;
|
||||||
|
let hred = self.max_x as u8 | 0b111;
|
||||||
|
let vrst = self.min_y & 0x1FF;
|
||||||
|
let vred = self.max_y & 0x1FF;
|
||||||
|
display.write_command(0x90);
|
||||||
|
display.write_data(hrst);
|
||||||
|
display.write_data(hred);
|
||||||
|
display.write_data((vrst >> 8) as u8);
|
||||||
|
display.write_data((vrst & 0xFF) as u8);
|
||||||
|
display.write_data((vred >> 8) as u8);
|
||||||
|
display.write_data((vred & 0xFF) as u8);
|
||||||
|
display.write_data(0x00);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update_partial_window(&mut self, min_x: u16, max_x: u16, min_y: u16, max_y: u16) {
|
||||||
|
self.min_x = core::cmp::min(self.min_x, min_x);
|
||||||
|
self.max_x = core::cmp::max(self.max_x, max_x);
|
||||||
|
self.min_y = core::cmp::min(self.min_y, min_y);
|
||||||
|
self.max_y = core::cmp::max(self.max_y, max_y);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn reset_partial_window(&mut self) {
|
||||||
|
*self = AutomaticPartialWindow {
|
||||||
|
min_x: EPD_WIDTH as u16,
|
||||||
|
max_x: 0,
|
||||||
|
min_y: EPD_HEIGHT as u16,
|
||||||
|
max_y: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DoubleFrame<NoPartialWindow> {
|
||||||
pub fn new(old: Frame, new: Frame) -> Self {
|
pub fn new(old: Frame, new: Frame) -> Self {
|
||||||
Self { old, new }
|
Self {
|
||||||
|
old,
|
||||||
|
new,
|
||||||
|
partial_window: NoPartialWindow,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_pixel(&mut self, x: usize, y: usize, colour: PixelColour) {
|
pub fn draw_pixel(&mut self, x: usize, y: usize, colour: PixelColour) {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DoubleFrame<AutomaticPartialWindow> {
|
||||||
|
pub fn new_with_automatic_partial_window(old: Frame, new: Frame) -> Self {
|
||||||
|
Self {
|
||||||
|
old,
|
||||||
|
new,
|
||||||
|
partial_window: AutomaticPartialWindow {
|
||||||
|
min_x: EPD_WIDTH as u16,
|
||||||
|
max_x: 0,
|
||||||
|
min_y: EPD_HEIGHT as u16,
|
||||||
|
max_y: 0,
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -158,7 +272,8 @@ impl<BusyPin: InputPin, ResetPin: OutputPin, DcPin: OutputPin, Spi: SpiDevice, D
|
||||||
self.wait_for_display();
|
self.wait_for_display();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_full_frame(&mut self, double_frame: &mut DoubleFrame) {
|
pub fn draw_full_frame<PartialWindow: ApplyParitalWindow>(&mut self, double_frame: &mut DoubleFrame<PartialWindow>) {
|
||||||
|
double_frame.partial_window.apply(self);
|
||||||
self.write_command(0x10);
|
self.write_command(0x10);
|
||||||
for byte in double_frame.old.0 {
|
for byte in double_frame.old.0 {
|
||||||
self.write_data(byte);
|
self.write_data(byte);
|
||||||
|
|
@ -183,4 +298,12 @@ impl<BusyPin: InputPin, ResetPin: OutputPin, DcPin: OutputPin, Spi: SpiDevice, D
|
||||||
self.write_command(0x07);
|
self.write_command(0x07);
|
||||||
self.write_data(0xA5);
|
self.write_data(0xA5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn enable_partial_mode(&mut self) {
|
||||||
|
self.write_command(0x91);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn disable_partial_mode(&mut self) {
|
||||||
|
self.write_command(0x92);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue