|
|
@@ -3,7 +3,7 @@ use core::fmt::Write;
|
|
3
|
3
|
use embedded_hal::blocking::delay::DelayUs;
|
|
4
|
4
|
use embedded_hal::digital::v2::OutputPin;
|
|
5
|
5
|
use epd_waveshare::epd4in2::EPD4in2;
|
|
6
|
|
-use epd_waveshare::prelude::{DisplayStream, WaveshareDisplay};
|
|
|
6
|
+use epd_waveshare::prelude::{Color, DisplayStream, RefreshLUT, WaveshareDisplay};
|
|
7
|
7
|
use mkl25z4_hal::time::CopyableMonoTimer;
|
|
8
|
8
|
use tinygfx::color::BlackWhite::{self, Black, White};
|
|
9
|
9
|
use tinygfx::image::{MonoBitmapImage, MonoImageData};
|
|
|
@@ -15,13 +15,20 @@ use super::pins::{
|
|
15
|
15
|
DisplayBmeSpi, DisplayBusy, DisplayCs, DisplayDc, DisplayPins, DisplayPwr, DisplayRst,
|
|
16
|
16
|
};
|
|
17
|
17
|
|
|
18
|
|
-pub struct DisplayState {
|
|
19
|
|
- // TODO
|
|
|
18
|
+const FULL_REFRESH_INTERVAL: usize = 5;
|
|
|
19
|
+
|
|
|
20
|
+pub struct DisplayState {}
|
|
|
21
|
+
|
|
|
22
|
+impl DisplayState {
|
|
|
23
|
+ pub fn new() -> DisplayState {
|
|
|
24
|
+ DisplayState {}
|
|
|
25
|
+ }
|
|
20
|
26
|
}
|
|
21
|
27
|
|
|
22
|
28
|
pub struct Display {
|
|
23
|
29
|
pwr: DisplayPwr,
|
|
24
|
30
|
epd: EPD4in2<DisplayBmeSpi, DisplayCs, DisplayBusy, DisplayDc, DisplayRst>,
|
|
|
31
|
+ refresh_counter: usize,
|
|
25
|
32
|
}
|
|
26
|
33
|
|
|
27
|
34
|
impl Display {
|
|
|
@@ -40,7 +47,11 @@ impl Display {
|
|
40
|
47
|
// Disable power again.
|
|
41
|
48
|
pins.pwr.set_high().ok();
|
|
42
|
49
|
|
|
43
|
|
- Display { pwr: pins.pwr, epd }
|
|
|
50
|
+ Display {
|
|
|
51
|
+ pwr: pins.pwr,
|
|
|
52
|
+ epd,
|
|
|
53
|
+ refresh_counter: 0,
|
|
|
54
|
+ }
|
|
44
|
55
|
}
|
|
45
|
56
|
|
|
46
|
57
|
pub fn update(
|
|
|
@@ -125,8 +136,19 @@ impl Display {
|
|
125
|
136
|
});
|
|
126
|
137
|
frame.mirror_x(true);
|
|
127
|
138
|
frame.mirror_y(true);
|
|
128
|
|
- //self.epd.set_background_color(Color::Black);
|
|
129
|
139
|
let checkerboard = TinyGfxStream::new(frame);
|
|
|
140
|
+
|
|
|
141
|
+ // We perform a full update every FULL_REFRESH_INTERVAL frames.
|
|
|
142
|
+ // TODO: Proper background.
|
|
|
143
|
+ self.epd.set_background_color(Color::White);
|
|
|
144
|
+ if self.refresh_counter == 0 {
|
|
|
145
|
+ self.refresh_counter = FULL_REFRESH_INTERVAL - 1;
|
|
|
146
|
+ self.epd.set_lut(spi, Some(RefreshLUT::FULL)).unwrap();
|
|
|
147
|
+ } else {
|
|
|
148
|
+ self.refresh_counter -= 1;
|
|
|
149
|
+ self.epd.set_lut(spi, Some(RefreshLUT::QUICK)).unwrap();
|
|
|
150
|
+ }
|
|
|
151
|
+
|
|
130
|
152
|
self.epd.update_frame_stream(spi, checkerboard).unwrap();
|
|
131
|
153
|
self.epd.display_frame(spi).unwrap();
|
|
132
|
154
|
|