Skip to content

Commit 9a1575b

Browse files
committed
API change to partially fix #70
1 parent a252d07 commit 9a1575b

File tree

17 files changed

+451
-354
lines changed

17 files changed

+451
-354
lines changed

examples/epd1in54_no_graphics.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ fn main() -> Result<(), std::io::Error> {
6161
let mut epd = EPD1in54::new(&mut spi, cs_pin, busy, dc, rst, &mut delay)?;
6262

6363
// Clear the full screen
64-
epd.clear_frame(&mut spi)?;
65-
epd.display_frame(&mut spi)?;
64+
epd.clear_frame(&mut spi, &mut delay)?;
65+
epd.display_frame(&mut spi, &mut delay)?;
6666

6767
// Speeddemo
6868
epd.set_lut(&mut spi, Some(RefreshLUT::QUICK))?;
@@ -71,12 +71,12 @@ fn main() -> Result<(), std::io::Error> {
7171
for i in 0..number_of_runs {
7272
let offset = i * 8 % 150;
7373
epd.update_partial_frame(&mut spi, &small_buffer, 25 + offset, 25 + offset, 16, 16)?;
74-
epd.display_frame(&mut spi)?;
74+
epd.display_frame(&mut spi, &mut delay)?;
7575
}
7676

7777
// Clear the full screen
78-
epd.clear_frame(&mut spi)?;
79-
epd.display_frame(&mut spi)?;
78+
epd.clear_frame(&mut spi, &mut delay)?;
79+
epd.display_frame(&mut spi, &mut delay)?;
8080

8181
// Draw some squares
8282
let small_buffer = [Color::Black.get_byte_value(); 3200]; //160x160
@@ -89,11 +89,11 @@ fn main() -> Result<(), std::io::Error> {
8989
epd.update_partial_frame(&mut spi, &small_buffer, 96, 96, 8, 8)?;
9090

9191
// Display updated frame
92-
epd.display_frame(&mut spi)?;
92+
epd.display_frame(&mut spi, &mut delay)?;
9393
delay.delay_ms(5000u16);
9494

9595
// Set the EPD to sleep
96-
epd.sleep(&mut spi)?;
96+
epd.sleep(&mut spi, &mut delay)?;
9797

9898
Ok(())
9999
}

examples/epd2in13_v2.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ fn main() -> Result<(), std::io::Error> {
8080
display.set_rotation(DisplayRotation::Rotate270);
8181
draw_text(&mut display, "Rotate 270!", 5, 50);
8282

83-
epd2in13.update_frame(&mut spi, &display.buffer())?;
83+
epd2in13.update_frame(&mut spi, &display.buffer(), &mut delay)?;
8484
epd2in13
85-
.display_frame(&mut spi)
85+
.display_frame(&mut spi, &mut delay)
8686
.expect("display frame new graphics");
8787
delay.delay_ms(5000u16);
8888

@@ -123,15 +123,15 @@ fn main() -> Result<(), std::io::Error> {
123123
epd2in13
124124
.set_refresh(&mut spi, &mut delay, RefreshLUT::QUICK)
125125
.unwrap();
126-
epd2in13.clear_frame(&mut spi).unwrap();
126+
epd2in13.clear_frame(&mut spi, &mut delay).unwrap();
127127

128128
// a moving `Hello World!`
129129
let limit = 10;
130130
for i in 0..limit {
131131
draw_text(&mut display, " Hello World! ", 5 + i * 12, 50);
132132

133133
epd2in13
134-
.update_and_display_frame(&mut spi, &display.buffer())
134+
.update_and_display_frame(&mut spi, &display.buffer(), &mut delay)
135135
.expect("display frame new graphics");
136136
delay.delay_ms(1_000u16);
137137
}
@@ -140,20 +140,20 @@ fn main() -> Result<(), std::io::Error> {
140140
// the screen can refresh for this kind of change (small single character)
141141
display.clear_buffer(Color::White);
142142
epd2in13
143-
.update_and_display_frame(&mut spi, &display.buffer())
143+
.update_and_display_frame(&mut spi, &display.buffer(), &mut delay)
144144
.unwrap();
145145

146146
let spinner = ["|", "/", "-", "\\"];
147147
for i in 0..10 {
148148
display.clear_buffer(Color::White);
149149
draw_text(&mut display, spinner[i % spinner.len()], 10, 100);
150150
epd2in13
151-
.update_and_display_frame(&mut spi, &display.buffer())
151+
.update_and_display_frame(&mut spi, &display.buffer(), &mut delay)
152152
.unwrap();
153153
}
154154

155155
println!("Finished tests - going to sleep");
156-
epd2in13.sleep(&mut spi)
156+
epd2in13.sleep(&mut spi, &mut delay)
157157
}
158158

159159
fn draw_text(display: &mut Display2in13, text: &str, x: i32, y: i32) {

examples/epd4in2.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ fn main() -> Result<(), std::io::Error> {
8080
display.set_rotation(DisplayRotation::Rotate270);
8181
draw_text(&mut display, "Rotate 270!", 5, 50);
8282

83-
epd4in2.update_frame(&mut spi, &display.buffer())?;
83+
epd4in2.update_frame(&mut spi, &display.buffer(), &mut delay)?;
8484
epd4in2
85-
.display_frame(&mut spi)
85+
.display_frame(&mut spi, &mut delay)
8686
.expect("display frame new graphics");
8787
delay.delay_ms(5000u16);
8888

@@ -121,22 +121,24 @@ fn main() -> Result<(), std::io::Error> {
121121
// a moving `Hello World!`
122122
let limit = 10;
123123
epd4in2.set_lut(&mut spi, Some(RefreshLUT::QUICK)).unwrap();
124-
epd4in2.clear_frame(&mut spi).unwrap();
124+
epd4in2.clear_frame(&mut spi, &mut delay).unwrap();
125125
for i in 0..limit {
126126
//println!("Moving Hello World. Loop {} from {}", (i + 1), limit);
127127

128128
draw_text(&mut display, " Hello World! ", 5 + i * 12, 50);
129129

130-
epd4in2.update_frame(&mut spi, &display.buffer()).unwrap();
131130
epd4in2
132-
.display_frame(&mut spi)
131+
.update_frame(&mut spi, &display.buffer(), &mut delay)
132+
.unwrap();
133+
epd4in2
134+
.display_frame(&mut spi, &mut delay)
133135
.expect("display frame new graphics");
134136

135137
delay.delay_ms(1_000u16);
136138
}
137139

138140
println!("Finished tests - going to sleep");
139-
epd4in2.sleep(&mut spi)
141+
epd4in2.sleep(&mut spi, &mut delay)
140142
}
141143

142144
fn draw_text(display: &mut Display4in2, text: &str, x: i32, y: i32) {

examples/epd4in2_variable_size.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ fn main() -> Result<(), std::io::Error> {
8888
.update_partial_frame(&mut spi, &display.buffer(), x, y, width, height)
8989
.unwrap();
9090
epd4in2
91-
.display_frame(&mut spi)
91+
.display_frame(&mut spi, &mut delay)
9292
.expect("display frame new graphics");
9393
delay.delay_ms(5000u16);
9494

@@ -137,14 +137,14 @@ fn main() -> Result<(), std::io::Error> {
137137
.update_partial_frame(&mut spi, &display.buffer(), x, y, width, height)
138138
.unwrap();
139139
epd4in2
140-
.display_frame(&mut spi)
140+
.display_frame(&mut spi, &mut delay)
141141
.expect("display frame new graphics");
142142

143143
delay.delay_ms(1_000u16);
144144
}
145145

146146
println!("Finished tests - going to sleep");
147-
epd4in2.sleep(&mut spi)
147+
epd4in2.sleep(&mut spi, &mut delay)
148148
}
149149

150150
fn draw_text(display: &mut VarDisplay, text: &str, x: i32, y: i32) {

src/epd1in54/mod.rs

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -72,28 +72,25 @@ pub use crate::epd1in54::graphics::Display1in54;
7272

7373
/// EPD1in54 driver
7474
///
75-
pub struct EPD1in54<SPI, CS, BUSY, DC, RST> {
75+
pub struct EPD1in54<SPI, CS, BUSY, DC, RST, DELAY> {
7676
/// SPI
77-
interface: DisplayInterface<SPI, CS, BUSY, DC, RST>,
77+
interface: DisplayInterface<SPI, CS, BUSY, DC, RST, DELAY>,
7878
/// Color
7979
background_color: Color,
8080
/// Refresh LUT
8181
refresh: RefreshLUT,
8282
}
8383

84-
impl<SPI, CS, BUSY, DC, RST> EPD1in54<SPI, CS, BUSY, DC, RST>
84+
impl<SPI, CS, BUSY, DC, RST, DELAY> EPD1in54<SPI, CS, BUSY, DC, RST, DELAY>
8585
where
8686
SPI: Write<u8>,
8787
CS: OutputPin,
8888
BUSY: InputPin,
8989
DC: OutputPin,
9090
RST: OutputPin,
91+
DELAY: DelayMs<u8>,
9192
{
92-
fn init<DELAY: DelayMs<u8>>(
93-
&mut self,
94-
spi: &mut SPI,
95-
delay: &mut DELAY,
96-
) -> Result<(), SPI::Error> {
93+
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
9794
self.interface.reset(delay, 10);
9895

9996
// 3 Databytes:
@@ -142,14 +139,15 @@ where
142139
}
143140
}
144141

145-
impl<SPI, CS, BUSY, DC, RST, E> WaveshareDisplay<SPI, CS, BUSY, DC, RST>
146-
for EPD1in54<SPI, CS, BUSY, DC, RST>
142+
impl<SPI, CS, BUSY, DC, RST, DELAY, E> WaveshareDisplay<SPI, CS, BUSY, DC, RST, DELAY>
143+
for EPD1in54<SPI, CS, BUSY, DC, RST, DELAY>
147144
where
148145
SPI: Write<u8, Error = E>,
149146
CS: OutputPin,
150147
BUSY: InputPin,
151148
DC: OutputPin,
152149
RST: OutputPin,
150+
DELAY: DelayMs<u8>,
153151
{
154152
type DisplayColor = Color;
155153
fn width(&self) -> u32 {
@@ -160,7 +158,7 @@ where
160158
HEIGHT
161159
}
162160

163-
fn new<DELAY: DelayMs<u8>>(
161+
fn new(
164162
spi: &mut SPI,
165163
cs: CS,
166164
busy: BUSY,
@@ -181,15 +179,11 @@ where
181179
Ok(epd)
182180
}
183181

184-
fn wake_up<DELAY: DelayMs<u8>>(
185-
&mut self,
186-
spi: &mut SPI,
187-
delay: &mut DELAY,
188-
) -> Result<(), SPI::Error> {
182+
fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
189183
self.init(spi, delay)
190184
}
191185

192-
fn sleep(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
186+
fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
193187
self.wait_until_idle();
194188
// 0x00 for Normal mode (Power on Reset), 0x01 for Deep Sleep Mode
195189
//TODO: is 0x00 needed here or would 0x01 be even more efficient?
@@ -198,7 +192,12 @@ where
198192
Ok(())
199193
}
200194

201-
fn update_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> {
195+
fn update_frame(
196+
&mut self,
197+
spi: &mut SPI,
198+
buffer: &[u8],
199+
_delay: &mut DELAY,
200+
) -> Result<(), SPI::Error> {
202201
self.wait_until_idle();
203202
self.use_full_frame(spi)?;
204203
self.interface
@@ -225,7 +224,7 @@ where
225224
Ok(())
226225
}
227226

228-
fn display_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
227+
fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
229228
self.wait_until_idle();
230229
// enable clock signal, enable cp, display pattern -> 0xC4 (tested with the arduino version)
231230
//TODO: test control_1 or control_2 with default value 0xFF (from the datasheet)
@@ -239,13 +238,18 @@ where
239238
Ok(())
240239
}
241240

242-
fn update_and_display_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> {
243-
self.update_frame(spi, buffer)?;
244-
self.display_frame(spi)?;
241+
fn update_and_display_frame(
242+
&mut self,
243+
spi: &mut SPI,
244+
buffer: &[u8],
245+
delay: &mut DELAY,
246+
) -> Result<(), SPI::Error> {
247+
self.update_frame(spi, buffer, delay)?;
248+
self.display_frame(spi, delay)?;
245249
Ok(())
246250
}
247251

248-
fn clear_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
252+
fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
249253
self.wait_until_idle();
250254
self.use_full_frame(spi)?;
251255

@@ -285,16 +289,17 @@ where
285289
}
286290
}
287291

288-
impl<SPI, CS, BUSY, DC, RST> EPD1in54<SPI, CS, BUSY, DC, RST>
292+
impl<SPI, CS, BUSY, DC, RST, DELAY> EPD1in54<SPI, CS, BUSY, DC, RST, DELAY>
289293
where
290294
SPI: Write<u8>,
291295
CS: OutputPin,
292296
BUSY: InputPin,
293297
DC: OutputPin,
294298
RST: OutputPin,
299+
DELAY: DelayMs<u8>,
295300
{
296301
fn wait_until_idle(&mut self) {
297-
self.interface.wait_until_idle(IS_BUSY_LOW);
302+
let _ = self.interface.wait_until_idle(IS_BUSY_LOW, None);
298303
}
299304

300305
pub(crate) fn use_full_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {

0 commit comments

Comments
 (0)