Browse Source

API change to partially fix #70

main
Edwin Svensson 5 years ago
parent
commit
9a1575b2ec
No known key found for this signature in database
GPG Key ID: 79178CFF478E7C64
  1. 14
      examples/epd1in54_no_graphics.rs
  2. 14
      examples/epd2in13_v2.rs
  3. 14
      examples/epd4in2.rs
  4. 6
      examples/epd4in2_variable_size.rs
  5. 55
      src/epd1in54/mod.rs
  6. 62
      src/epd1in54b/mod.rs
  7. 62
      src/epd1in54c/mod.rs
  8. 59
      src/epd2in13_v2/mod.rs
  9. 60
      src/epd2in7b/mod.rs
  10. 55
      src/epd2in9/mod.rs
  11. 62
      src/epd2in9bc/mod.rs
  12. 60
      src/epd4in2/mod.rs
  13. 61
      src/epd5in65f/mod.rs
  14. 55
      src/epd7in5/mod.rs
  15. 79
      src/epd7in5_v2/mod.rs
  16. 39
      src/interface.rs
  17. 48
      src/traits.rs

14
examples/epd1in54_no_graphics.rs

@ -61,8 +61,8 @@ fn main() -> Result<(), std::io::Error> {
let mut epd = EPD1in54::new(&mut spi, cs_pin, busy, dc, rst, &mut delay)?;
// Clear the full screen
epd.clear_frame(&mut spi)?;
epd.display_frame(&mut spi)?;
epd.clear_frame(&mut spi, &mut delay)?;
epd.display_frame(&mut spi, &mut delay)?;
// Speeddemo
epd.set_lut(&mut spi, Some(RefreshLUT::QUICK))?;
@ -71,12 +71,12 @@ fn main() -> Result<(), std::io::Error> {
for i in 0..number_of_runs {
let offset = i * 8 % 150;
epd.update_partial_frame(&mut spi, &small_buffer, 25 + offset, 25 + offset, 16, 16)?;
epd.display_frame(&mut spi)?;
epd.display_frame(&mut spi, &mut delay)?;
}
// Clear the full screen
epd.clear_frame(&mut spi)?;
epd.display_frame(&mut spi)?;
epd.clear_frame(&mut spi, &mut delay)?;
epd.display_frame(&mut spi, &mut delay)?;
// Draw some squares
let small_buffer = [Color::Black.get_byte_value(); 3200]; //160x160
@ -89,11 +89,11 @@ fn main() -> Result<(), std::io::Error> {
epd.update_partial_frame(&mut spi, &small_buffer, 96, 96, 8, 8)?;
// Display updated frame
epd.display_frame(&mut spi)?;
epd.display_frame(&mut spi, &mut delay)?;
delay.delay_ms(5000u16);
// Set the EPD to sleep
epd.sleep(&mut spi)?;
epd.sleep(&mut spi, &mut delay)?;
Ok(())
}

14
examples/epd2in13_v2.rs

@ -80,9 +80,9 @@ fn main() -> Result<(), std::io::Error> {
display.set_rotation(DisplayRotation::Rotate270);
draw_text(&mut display, "Rotate 270!", 5, 50);
epd2in13.update_frame(&mut spi, &display.buffer())?;
epd2in13.update_frame(&mut spi, &display.buffer(), &mut delay)?;
epd2in13
.display_frame(&mut spi)
.display_frame(&mut spi, &mut delay)
.expect("display frame new graphics");
delay.delay_ms(5000u16);
@ -123,7 +123,7 @@ fn main() -> Result<(), std::io::Error> {
epd2in13
.set_refresh(&mut spi, &mut delay, RefreshLUT::QUICK)
.unwrap();
epd2in13.clear_frame(&mut spi).unwrap();
epd2in13.clear_frame(&mut spi, &mut delay).unwrap();
// a moving `Hello World!`
let limit = 10;
@ -131,7 +131,7 @@ fn main() -> Result<(), std::io::Error> {
draw_text(&mut display, " Hello World! ", 5 + i * 12, 50);
epd2in13
.update_and_display_frame(&mut spi, &display.buffer())
.update_and_display_frame(&mut spi, &display.buffer(), &mut delay)
.expect("display frame new graphics");
delay.delay_ms(1_000u16);
}
@ -140,7 +140,7 @@ fn main() -> Result<(), std::io::Error> {
// the screen can refresh for this kind of change (small single character)
display.clear_buffer(Color::White);
epd2in13
.update_and_display_frame(&mut spi, &display.buffer())
.update_and_display_frame(&mut spi, &display.buffer(), &mut delay)
.unwrap();
let spinner = ["|", "/", "-", "\\"];
@ -148,12 +148,12 @@ fn main() -> Result<(), std::io::Error> {
display.clear_buffer(Color::White);
draw_text(&mut display, spinner[i % spinner.len()], 10, 100);
epd2in13
.update_and_display_frame(&mut spi, &display.buffer())
.update_and_display_frame(&mut spi, &display.buffer(), &mut delay)
.unwrap();
}
println!("Finished tests - going to sleep");
epd2in13.sleep(&mut spi)
epd2in13.sleep(&mut spi, &mut delay)
}
fn draw_text(display: &mut Display2in13, text: &str, x: i32, y: i32) {

14
examples/epd4in2.rs

@ -80,9 +80,9 @@ fn main() -> Result<(), std::io::Error> {
display.set_rotation(DisplayRotation::Rotate270);
draw_text(&mut display, "Rotate 270!", 5, 50);
epd4in2.update_frame(&mut spi, &display.buffer())?;
epd4in2.update_frame(&mut spi, &display.buffer(), &mut delay)?;
epd4in2
.display_frame(&mut spi)
.display_frame(&mut spi, &mut delay)
.expect("display frame new graphics");
delay.delay_ms(5000u16);
@ -121,22 +121,24 @@ fn main() -> Result<(), std::io::Error> {
// a moving `Hello World!`
let limit = 10;
epd4in2.set_lut(&mut spi, Some(RefreshLUT::QUICK)).unwrap();
epd4in2.clear_frame(&mut spi).unwrap();
epd4in2.clear_frame(&mut spi, &mut delay).unwrap();
for i in 0..limit {
//println!("Moving Hello World. Loop {} from {}", (i + 1), limit);
draw_text(&mut display, " Hello World! ", 5 + i * 12, 50);
epd4in2.update_frame(&mut spi, &display.buffer()).unwrap();
epd4in2
.display_frame(&mut spi)
.update_frame(&mut spi, &display.buffer(), &mut delay)
.unwrap();
epd4in2
.display_frame(&mut spi, &mut delay)
.expect("display frame new graphics");
delay.delay_ms(1_000u16);
}
println!("Finished tests - going to sleep");
epd4in2.sleep(&mut spi)
epd4in2.sleep(&mut spi, &mut delay)
}
fn draw_text(display: &mut Display4in2, text: &str, x: i32, y: i32) {

6
examples/epd4in2_variable_size.rs

@ -88,7 +88,7 @@ fn main() -> Result<(), std::io::Error> {
.update_partial_frame(&mut spi, &display.buffer(), x, y, width, height)
.unwrap();
epd4in2
.display_frame(&mut spi)
.display_frame(&mut spi, &mut delay)
.expect("display frame new graphics");
delay.delay_ms(5000u16);
@ -137,14 +137,14 @@ fn main() -> Result<(), std::io::Error> {
.update_partial_frame(&mut spi, &display.buffer(), x, y, width, height)
.unwrap();
epd4in2
.display_frame(&mut spi)
.display_frame(&mut spi, &mut delay)
.expect("display frame new graphics");
delay.delay_ms(1_000u16);
}
println!("Finished tests - going to sleep");
epd4in2.sleep(&mut spi)
epd4in2.sleep(&mut spi, &mut delay)
}
fn draw_text(display: &mut VarDisplay, text: &str, x: i32, y: i32) {

55
src/epd1in54/mod.rs

@ -72,28 +72,25 @@ pub use crate::epd1in54::graphics::Display1in54;
/// EPD1in54 driver
///
pub struct EPD1in54<SPI, CS, BUSY, DC, RST> {
pub struct EPD1in54<SPI, CS, BUSY, DC, RST, DELAY> {
/// SPI
interface: DisplayInterface<SPI, CS, BUSY, DC, RST>,
interface: DisplayInterface<SPI, CS, BUSY, DC, RST, DELAY>,
/// Color
background_color: Color,
/// Refresh LUT
refresh: RefreshLUT,
}
impl<SPI, CS, BUSY, DC, RST> EPD1in54<SPI, CS, BUSY, DC, RST>
impl<SPI, CS, BUSY, DC, RST, DELAY> EPD1in54<SPI, CS, BUSY, DC, RST, DELAY>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
DELAY: DelayMs<u8>,
{
fn init<DELAY: DelayMs<u8>>(
&mut self,
spi: &mut SPI,
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
self.interface.reset(delay, 10);
// 3 Databytes:
@ -142,14 +139,15 @@ where
}
}
impl<SPI, CS, BUSY, DC, RST, E> WaveshareDisplay<SPI, CS, BUSY, DC, RST>
for EPD1in54<SPI, CS, BUSY, DC, RST>
impl<SPI, CS, BUSY, DC, RST, DELAY, E> WaveshareDisplay<SPI, CS, BUSY, DC, RST, DELAY>
for EPD1in54<SPI, CS, BUSY, DC, RST, DELAY>
where
SPI: Write<u8, Error = E>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
DELAY: DelayMs<u8>,
{
type DisplayColor = Color;
fn width(&self) -> u32 {
@ -160,7 +158,7 @@ where
HEIGHT
}
fn new<DELAY: DelayMs<u8>>(
fn new(
spi: &mut SPI,
cs: CS,
busy: BUSY,
@ -181,15 +179,11 @@ where
Ok(epd)
}
fn wake_up<DELAY: DelayMs<u8>>(
&mut self,
spi: &mut SPI,
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
self.init(spi, delay)
}
fn sleep(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> 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?
@ -198,7 +192,12 @@ where
Ok(())
}
fn update_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> {
fn update_frame(
&mut self,
spi: &mut SPI,
buffer: &[u8],
_delay: &mut DELAY,
) -> Result<(), SPI::Error> {
self.wait_until_idle();
self.use_full_frame(spi)?;
self.interface
@ -225,7 +224,7 @@ where
Ok(())
}
fn display_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> 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)
@ -239,13 +238,18 @@ where
Ok(())
}
fn update_and_display_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> {
self.update_frame(spi, buffer)?;
self.display_frame(spi)?;
fn update_and_display_frame(
&mut self,
spi: &mut SPI,
buffer: &[u8],
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
self.update_frame(spi, buffer, delay)?;
self.display_frame(spi, delay)?;
Ok(())
}
fn clear_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
self.wait_until_idle();
self.use_full_frame(spi)?;
@ -285,16 +289,17 @@ where
}
}
impl<SPI, CS, BUSY, DC, RST> EPD1in54<SPI, CS, BUSY, DC, RST>
impl<SPI, CS, BUSY, DC, RST, DELAY> EPD1in54<SPI, CS, BUSY, DC, RST, DELAY>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
DELAY: DelayMs<u8>,
{
fn wait_until_idle(&mut self) {
self.interface.wait_until_idle(IS_BUSY_LOW);
let _ = self.interface.wait_until_idle(IS_BUSY_LOW, None);
}
pub(crate) fn use_full_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {

62
src/epd1in54b/mod.rs

@ -33,25 +33,22 @@ mod graphics;
pub use self::graphics::Display1in54b;
/// EPD1in54b driver
pub struct EPD1in54b<SPI, CS, BUSY, DC, RST> {
interface: DisplayInterface<SPI, CS, BUSY, DC, RST>,
pub struct EPD1in54b<SPI, CS, BUSY, DC, RST, DELAY> {
interface: DisplayInterface<SPI, CS, BUSY, DC, RST, DELAY>,
color: Color,
}
impl<SPI, CS, BUSY, DC, RST> InternalWiAdditions<SPI, CS, BUSY, DC, RST>
for EPD1in54b<SPI, CS, BUSY, DC, RST>
impl<SPI, CS, BUSY, DC, RST, DELAY> InternalWiAdditions<SPI, CS, BUSY, DC, RST, DELAY>
for EPD1in54b<SPI, CS, BUSY, DC, RST, DELAY>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
DELAY: DelayMs<u8>,
{
fn init<DELAY: DelayMs<u8>>(
&mut self,
spi: &mut SPI,
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
self.interface.reset(delay, 10);
// set the power settings
@ -88,14 +85,15 @@ where
}
}
impl<SPI, CS, BUSY, DC, RST> WaveshareThreeColorDisplay<SPI, CS, BUSY, DC, RST>
for EPD1in54b<SPI, CS, BUSY, DC, RST>
impl<SPI, CS, BUSY, DC, RST, DELAY> WaveshareThreeColorDisplay<SPI, CS, BUSY, DC, RST, DELAY>
for EPD1in54b<SPI, CS, BUSY, DC, RST, DELAY>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
DELAY: DelayMs<u8>,
{
fn update_color_frame(
&mut self,
@ -133,17 +131,18 @@ where
}
}
impl<SPI, CS, BUSY, DC, RST> WaveshareDisplay<SPI, CS, BUSY, DC, RST>
for EPD1in54b<SPI, CS, BUSY, DC, RST>
impl<SPI, CS, BUSY, DC, RST, DELAY> WaveshareDisplay<SPI, CS, BUSY, DC, RST, DELAY>
for EPD1in54b<SPI, CS, BUSY, DC, RST, DELAY>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
DELAY: DelayMs<u8>,
{
type DisplayColor = Color;
fn new<DELAY: DelayMs<u8>>(
fn new(
spi: &mut SPI,
cs: CS,
busy: BUSY,
@ -161,7 +160,7 @@ where
Ok(epd)
}
fn sleep(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
self.wait_until_idle();
self.interface
.cmd_with_data(spi, Command::VCOM_AND_DATA_INTERVAL_SETTING, &[0x17])?; //border floating
@ -181,11 +180,7 @@ where
Ok(())
}
fn wake_up<DELAY: DelayMs<u8>>(
&mut self,
spi: &mut SPI,
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
self.init(spi, delay)
}
@ -205,7 +200,12 @@ where
HEIGHT
}
fn update_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> {
fn update_frame(
&mut self,
spi: &mut SPI,
buffer: &[u8],
_delay: &mut DELAY,
) -> Result<(), SPI::Error> {
self.wait_until_idle();
self.send_resolution(spi)?;
@ -245,19 +245,24 @@ where
unimplemented!()
}
fn display_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
self.wait_until_idle();
self.command(spi, Command::DISPLAY_REFRESH)?;
Ok(())
}
fn update_and_display_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> {
self.update_frame(spi, buffer)?;
self.display_frame(spi)?;
fn update_and_display_frame(
&mut self,
spi: &mut SPI,
buffer: &[u8],
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
self.update_frame(spi, buffer, delay)?;
self.display_frame(spi, delay)?;
Ok(())
}
fn clear_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
self.wait_until_idle();
self.send_resolution(spi)?;
@ -307,13 +312,14 @@ where
}
}
impl<SPI, CS, BUSY, DC, RST> EPD1in54b<SPI, CS, BUSY, DC, RST>
impl<SPI, CS, BUSY, DC, RST, DELAY> EPD1in54b<SPI, CS, BUSY, DC, RST, DELAY>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
DELAY: DelayMs<u8>,
{
fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), SPI::Error> {
self.interface.cmd(spi, command)
@ -333,7 +339,7 @@ where
}
fn wait_until_idle(&mut self) {
self.interface.wait_until_idle(IS_BUSY_LOW)
let _ = self.interface.wait_until_idle(IS_BUSY_LOW, None);
}
fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {

62
src/epd1in54c/mod.rs

@ -31,25 +31,22 @@ mod graphics;
pub use self::graphics::Display1in54c;
/// EPD1in54c driver
pub struct EPD1in54c<SPI, CS, BUSY, DC, RST> {
interface: DisplayInterface<SPI, CS, BUSY, DC, RST>,
pub struct EPD1in54c<SPI, CS, BUSY, DC, RST, DELAY> {
interface: DisplayInterface<SPI, CS, BUSY, DC, RST, DELAY>,
color: Color,
}
impl<SPI, CS, BUSY, DC, RST> InternalWiAdditions<SPI, CS, BUSY, DC, RST>
for EPD1in54c<SPI, CS, BUSY, DC, RST>
impl<SPI, CS, BUSY, DC, RST, DELAY> InternalWiAdditions<SPI, CS, BUSY, DC, RST, DELAY>
for EPD1in54c<SPI, CS, BUSY, DC, RST, DELAY>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
DELAY: DelayMs<u8>,
{
fn init<DELAY: DelayMs<u8>>(
&mut self,
spi: &mut SPI,
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
// Based on Reference Program Code from:
// https://www.waveshare.com/w/upload/a/ac/1.54inch_e-Paper_Module_C_Specification.pdf
// and:
@ -76,14 +73,15 @@ where
}
}
impl<SPI, CS, BUSY, DC, RST> WaveshareThreeColorDisplay<SPI, CS, BUSY, DC, RST>
for EPD1in54c<SPI, CS, BUSY, DC, RST>
impl<SPI, CS, BUSY, DC, RST, DELAY> WaveshareThreeColorDisplay<SPI, CS, BUSY, DC, RST, DELAY>
for EPD1in54c<SPI, CS, BUSY, DC, RST, DELAY>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
DELAY: DelayMs<u8>,
{
fn update_color_frame(
&mut self,
@ -114,17 +112,18 @@ where
}
}
impl<SPI, CS, BUSY, DC, RST> WaveshareDisplay<SPI, CS, BUSY, DC, RST>
for EPD1in54c<SPI, CS, BUSY, DC, RST>
impl<SPI, CS, BUSY, DC, RST, DELAY> WaveshareDisplay<SPI, CS, BUSY, DC, RST, DELAY>
for EPD1in54c<SPI, CS, BUSY, DC, RST, DELAY>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
DELAY: DelayMs<u8>,
{
type DisplayColor = Color;
fn new<DELAY: DelayMs<u8>>(
fn new(
spi: &mut SPI,
cs: CS,
busy: BUSY,
@ -142,7 +141,7 @@ where
Ok(epd)
}
fn sleep(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
self.wait_until_idle();
self.command(spi, Command::POWER_OFF)?;
@ -152,11 +151,7 @@ where
Ok(())
}
fn wake_up<DELAY: DelayMs<u8>>(
&mut self,
spi: &mut SPI,
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
self.init(spi, delay)
}
@ -176,7 +171,12 @@ where
HEIGHT
}
fn update_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> {
fn update_frame(
&mut self,
spi: &mut SPI,
buffer: &[u8],
_delay: &mut DELAY,
) -> Result<(), SPI::Error> {
self.update_achromatic_frame(spi, buffer)?;
// Clear the chromatic layer
@ -201,21 +201,26 @@ where
unimplemented!()
}
fn display_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
self.command(spi, Command::DISPLAY_REFRESH)?;
self.wait_until_idle();
Ok(())
}
fn update_and_display_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> {
self.update_frame(spi, buffer)?;
self.display_frame(spi)?;
fn update_and_display_frame(
&mut self,
spi: &mut SPI,
buffer: &[u8],
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
self.update_frame(spi, buffer, delay)?;
self.display_frame(spi, delay)?;
Ok(())
}
fn clear_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
self.wait_until_idle();
let color = DEFAULT_BACKGROUND_COLOR.get_byte_value();
@ -243,13 +248,14 @@ where
}
}
impl<SPI, CS, BUSY, DC, RST> EPD1in54c<SPI, CS, BUSY, DC, RST>
impl<SPI, CS, BUSY, DC, RST, DELAY> EPD1in54c<SPI, CS, BUSY, DC, RST, DELAY>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
DELAY: DelayMs<u8>,
{
fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), SPI::Error> {
self.interface.cmd(spi, command)
@ -269,7 +275,7 @@ where
}
fn wait_until_idle(&mut self) {
self.interface.wait_until_idle(IS_BUSY_LOW)
let _ = self.interface.wait_until_idle(IS_BUSY_LOW, None);
}
fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {

59
src/epd2in13_v2/mod.rs

@ -45,9 +45,9 @@ const IS_BUSY_LOW: bool = false;
/// EPD2in13 (V2) driver
///
pub struct EPD2in13<SPI, CS, BUSY, DC, RST> {
pub struct EPD2in13<SPI, CS, BUSY, DC, RST, DELAY> {
/// Connection Interface
interface: DisplayInterface<SPI, CS, BUSY, DC, RST>,
interface: DisplayInterface<SPI, CS, BUSY, DC, RST, DELAY>,
sleep_mode: DeepSleepMode,
@ -56,20 +56,17 @@ pub struct EPD2in13<SPI, CS, BUSY, DC, RST> {
refresh: RefreshLUT,
}
impl<SPI, CS, BUSY, DC, RST> InternalWiAdditions<SPI, CS, BUSY, DC, RST>
for EPD2in13<SPI, CS, BUSY, DC, RST>
impl<SPI, CS, BUSY, DC, RST, DELAY> InternalWiAdditions<SPI, CS, BUSY, DC, RST, DELAY>
for EPD2in13<SPI, CS, BUSY, DC, RST, DELAY>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
DELAY: DelayMs<u8>,
{
fn init<DELAY: DelayMs<u8>>(
&mut self,
spi: &mut SPI,
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
// HW reset
self.interface.reset(delay, 10);
@ -157,17 +154,18 @@ where
}
}
impl<SPI, CS, BUSY, DC, RST> WaveshareDisplay<SPI, CS, BUSY, DC, RST>
for EPD2in13<SPI, CS, BUSY, DC, RST>
impl<SPI, CS, BUSY, DC, RST, DELAY> WaveshareDisplay<SPI, CS, BUSY, DC, RST, DELAY>
for EPD2in13<SPI, CS, BUSY, DC, RST, DELAY>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
DELAY: DelayMs<u8>,
{
type DisplayColor = Color;
fn new<DELAY: DelayMs<u8>>(
fn new(
spi: &mut SPI,
cs: CS,
busy: BUSY,
@ -186,15 +184,11 @@ where
Ok(epd)
}
fn wake_up<DELAY: DelayMs<u8>>(
&mut self,
spi: &mut SPI,
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
self.init(spi, delay)
}
fn sleep(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
self.wait_until_idle();
// All sample code enables and disables analog/clocks...
@ -212,7 +206,12 @@ where
Ok(())
}
fn update_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> {
fn update_frame(
&mut self,
spi: &mut SPI,
buffer: &[u8],
_delay: &mut DELAY,
) -> Result<(), SPI::Error> {
assert!(buffer.len() == buffer_len(WIDTH as usize, HEIGHT as usize));
self.set_ram_area(spi, 0, 0, WIDTH - 1, HEIGHT - 1)?;
self.set_ram_address_counters(spi, 0, 0)?;
@ -269,7 +268,7 @@ where
/// Never use directly this function when using partial refresh, or also
/// keep the base buffer in syncd using `set_partial_base_buffer` function.
fn display_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
if self.refresh == RefreshLUT::FULL {
self.set_display_update_control_2(
spi,
@ -289,9 +288,14 @@ where
Ok(())
}
fn update_and_display_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> {
self.update_frame(spi, buffer)?;
self.display_frame(spi)?;
fn update_and_display_frame(
&mut self,
spi: &mut SPI,
buffer: &[u8],
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
self.update_frame(spi, buffer, delay)?;
self.display_frame(spi, delay)?;
if self.refresh == RefreshLUT::QUICK {
self.set_partial_base_buffer(spi, buffer)?;
@ -299,7 +303,7 @@ where
Ok(())
}
fn clear_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
let color = self.background_color.get_byte_value();
self.set_ram_area(spi, 0, 0, WIDTH - 1, HEIGHT - 1)?;
@ -361,13 +365,14 @@ where
}
}
impl<SPI, CS, BUSY, DC, RST> EPD2in13<SPI, CS, BUSY, DC, RST>
impl<SPI, CS, BUSY, DC, RST, DELAY> EPD2in13<SPI, CS, BUSY, DC, RST, DELAY>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
DELAY: DelayMs<u8>,
{
/// When using partial refresh, the controller uses the provided buffer for
/// comparison with new buffer.
@ -391,7 +396,7 @@ where
/// Sets the refresh mode. When changing mode, the screen will be
/// re-initialized accordingly.
pub fn set_refresh<DELAY: DelayMs<u8>>(
pub fn set_refresh(
&mut self,
spi: &mut SPI,
delay: &mut DELAY,
@ -559,7 +564,7 @@ where
}
fn wait_until_idle(&mut self) {
self.interface.wait_until_idle(IS_BUSY_LOW)
let _ = self.interface.wait_until_idle(IS_BUSY_LOW, None);
}
}

60
src/epd2in7b/mod.rs

@ -35,27 +35,24 @@ mod graphics;
pub use self::graphics::Display2in7b;
/// EPD2in7b driver
pub struct EPD2in7b<SPI, CS, BUSY, DC, RST> {
pub struct EPD2in7b<SPI, CS, BUSY, DC, RST, DELAY> {
/// Connection Interface
interface: DisplayInterface<SPI, CS, BUSY, DC, RST>,
interface: DisplayInterface<SPI, CS, BUSY, DC, RST, DELAY>,
/// Background Color
color: Color,
}
impl<SPI, CS, BUSY, DC, RST> InternalWiAdditions<SPI, CS, BUSY, DC, RST>
for EPD2in7b<SPI, CS, BUSY, DC, RST>
impl<SPI, CS, BUSY, DC, RST, DELAY> InternalWiAdditions<SPI, CS, BUSY, DC, RST, DELAY>
for EPD2in7b<SPI, CS, BUSY, DC, RST, DELAY>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
DELAY: DelayMs<u8>,
{
fn init<DELAY: DelayMs<u8>>(
&mut self,
spi: &mut SPI,
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
// reset the device
self.interface.reset(delay, 2);
@ -111,17 +108,18 @@ where
}
}
impl<SPI, CS, BUSY, DC, RST> WaveshareDisplay<SPI, CS, BUSY, DC, RST>
for EPD2in7b<SPI, CS, BUSY, DC, RST>
impl<SPI, CS, BUSY, DC, RST, DELAY> WaveshareDisplay<SPI, CS, BUSY, DC, RST, DELAY>
for EPD2in7b<SPI, CS, BUSY, DC, RST, DELAY>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
DELAY: DelayMs<u8>,
{
type DisplayColor = Color;
fn new<DELAY: DelayMs<u8>>(
fn new(
spi: &mut SPI,
cs: CS,
busy: BUSY,
@ -139,15 +137,11 @@ where
Ok(epd)
}
fn wake_up<DELAY: DelayMs<u8>>(
&mut self,
spi: &mut SPI,
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
self.init(spi, delay)
}
fn sleep(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
self.wait_until_idle();
self.interface
.cmd_with_data(spi, Command::VCOM_AND_DATA_INTERVAL_SETTING, &[0xf7])?;
@ -159,7 +153,12 @@ where
Ok(())
}
fn update_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> {
fn update_frame(
&mut self,
spi: &mut SPI,
buffer: &[u8],
_delay: &mut DELAY,
) -> Result<(), SPI::Error> {
self.interface
.cmd(spi, Command::DATA_START_TRANSMISSION_1)?;
self.send_buffer_helper(spi, buffer)?;
@ -201,19 +200,24 @@ where
self.interface.cmd(spi, Command::DATA_STOP)
}
fn display_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
self.command(spi, Command::DISPLAY_REFRESH)?;
self.wait_until_idle();
Ok(())
}
fn update_and_display_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> {
self.update_frame(spi, buffer)?;
fn update_and_display_frame(
&mut self,
spi: &mut SPI,
buffer: &[u8],
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
self.update_frame(spi, buffer, delay)?;
self.command(spi, Command::DISPLAY_REFRESH)?;
Ok(())
}
fn clear_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
self.wait_until_idle();
let color_value = self.color.get_byte_value();
@ -267,14 +271,15 @@ where
}
}
impl<SPI, CS, BUSY, DC, RST> WaveshareThreeColorDisplay<SPI, CS, BUSY, DC, RST>
for EPD2in7b<SPI, CS, BUSY, DC, RST>
impl<SPI, CS, BUSY, DC, RST, DELAY> WaveshareThreeColorDisplay<SPI, CS, BUSY, DC, RST, DELAY>
for EPD2in7b<SPI, CS, BUSY, DC, RST, DELAY>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
DELAY: DelayMs<u8>,
{
fn update_color_frame(
&mut self,
@ -322,13 +327,14 @@ where
}
}
impl<SPI, CS, BUSY, DC, RST> EPD2in7b<SPI, CS, BUSY, DC, RST>
impl<SPI, CS, BUSY, DC, RST, DELAY> EPD2in7b<SPI, CS, BUSY, DC, RST, DELAY>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
DELAY: DelayMs<u8>,
{
fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), SPI::Error> {
self.interface.cmd(spi, command)
@ -357,7 +363,7 @@ where
}
fn wait_until_idle(&mut self) {
self.interface.wait_until_idle(IS_BUSY_LOW)
let _ = self.interface.wait_until_idle(IS_BUSY_LOW, None);
}
/// Refresh display for partial frame

55
src/epd2in9/mod.rs

@ -72,28 +72,25 @@ pub use crate::epd2in9::graphics::Display2in9;
/// EPD2in9 driver
///
pub struct EPD2in9<SPI, CS, BUSY, DC, RST> {
pub struct EPD2in9<SPI, CS, BUSY, DC, RST, DELAY> {
/// SPI
interface: DisplayInterface<SPI, CS, BUSY, DC, RST>,
interface: DisplayInterface<SPI, CS, BUSY, DC, RST, DELAY>,
/// Color
background_color: Color,
/// Refresh LUT
refresh: RefreshLUT,
}
impl<SPI, CS, BUSY, DC, RST> EPD2in9<SPI, CS, BUSY, DC, RST>
impl<SPI, CS, BUSY, DC, RST, DELAY> EPD2in9<SPI, CS, BUSY, DC, RST, DELAY>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
DELAY: DelayMs<u8>,
{
fn init<DELAY: DelayMs<u8>>(
&mut self,
spi: &mut SPI,
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
self.interface.reset(delay, 10);
self.wait_until_idle();
@ -138,14 +135,15 @@ where
}
}
impl<SPI, CS, BUSY, DC, RST> WaveshareDisplay<SPI, CS, BUSY, DC, RST>
for EPD2in9<SPI, CS, BUSY, DC, RST>
impl<SPI, CS, BUSY, DC, RST, DELAY> WaveshareDisplay<SPI, CS, BUSY, DC, RST, DELAY>
for EPD2in9<SPI, CS, BUSY, DC, RST, DELAY>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
DELAY: DelayMs<u8>,
{
type DisplayColor = Color;
fn width(&self) -> u32 {
@ -156,7 +154,7 @@ where
HEIGHT
}
fn new<DELAY: DelayMs<u8>>(
fn new(
spi: &mut SPI,
cs: CS,
busy: BUSY,
@ -177,7 +175,7 @@ where
Ok(epd)
}
fn sleep(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
self.wait_until_idle();
// 0x00 for Normal mode (Power on Reset), 0x01 for Deep Sleep Mode
//TODO: is 0x00 needed here? (see also epd1in54)
@ -186,17 +184,18 @@ where
Ok(())
}
fn wake_up<DELAY: DelayMs<u8>>(
&mut self,
spi: &mut SPI,
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
self.wait_until_idle();
self.init(spi, delay)?;
Ok(())
}
fn update_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> {
fn update_frame(
&mut self,
spi: &mut SPI,
buffer: &[u8],
_delay: &mut DELAY,
) -> Result<(), SPI::Error> {
self.wait_until_idle();
self.use_full_frame(spi)?;
@ -224,7 +223,7 @@ where
Ok(())
}
fn display_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> 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)
@ -238,13 +237,18 @@ where
Ok(())
}
fn update_and_display_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> {
self.update_frame(spi, buffer)?;
self.display_frame(spi)?;
fn update_and_display_frame(
&mut self,
spi: &mut SPI,
buffer: &[u8],
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
self.update_frame(spi, buffer, delay)?;
self.display_frame(spi, delay)?;
Ok(())
}
fn clear_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
self.wait_until_idle();
self.use_full_frame(spi)?;
@ -284,16 +288,17 @@ where
}
}
impl<SPI, CS, BUSY, DC, RST> EPD2in9<SPI, CS, BUSY, DC, RST>
impl<SPI, CS, BUSY, DC, RST, DELAY> EPD2in9<SPI, CS, BUSY, DC, RST, DELAY>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
DELAY: DelayMs<u8>,
{
fn wait_until_idle(&mut self) {
self.interface.wait_until_idle(IS_BUSY_LOW);
let _ = self.interface.wait_until_idle(IS_BUSY_LOW, None);
}
fn use_full_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {

62
src/epd2in9bc/mod.rs

@ -90,25 +90,22 @@ mod graphics;
pub use self::graphics::Display2in9bc;
/// EPD2in9bc driver
pub struct EPD2in9bc<SPI, CS, BUSY, DC, RST> {
interface: DisplayInterface<SPI, CS, BUSY, DC, RST>,
pub struct EPD2in9bc<SPI, CS, BUSY, DC, RST, DELAY> {
interface: DisplayInterface<SPI, CS, BUSY, DC, RST, DELAY>,
color: Color,
}
impl<SPI, CS, BUSY, DC, RST> InternalWiAdditions<SPI, CS, BUSY, DC, RST>
for EPD2in9bc<SPI, CS, BUSY, DC, RST>
impl<SPI, CS, BUSY, DC, RST, DELAY> InternalWiAdditions<SPI, CS, BUSY, DC, RST, DELAY>
for EPD2in9bc<SPI, CS, BUSY, DC, RST, DELAY>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
DELAY: DelayMs<u8>,
{
fn init<DELAY: DelayMs<u8>>(
&mut self,
spi: &mut SPI,
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
// Values taken from datasheet and sample code
self.interface.reset(delay, 10);
@ -142,14 +139,15 @@ where
}
}
impl<SPI, CS, BUSY, DC, RST> WaveshareThreeColorDisplay<SPI, CS, BUSY, DC, RST>
for EPD2in9bc<SPI, CS, BUSY, DC, RST>
impl<SPI, CS, BUSY, DC, RST, DELAY> WaveshareThreeColorDisplay<SPI, CS, BUSY, DC, RST, DELAY>
for EPD2in9bc<SPI, CS, BUSY, DC, RST, DELAY>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
DELAY: DelayMs<u8>,
{
fn update_color_frame(
&mut self,
@ -188,17 +186,18 @@ where
}
}
impl<SPI, CS, BUSY, DC, RST> WaveshareDisplay<SPI, CS, BUSY, DC, RST>
for EPD2in9bc<SPI, CS, BUSY, DC, RST>
impl<SPI, CS, BUSY, DC, RST, DELAY> WaveshareDisplay<SPI, CS, BUSY, DC, RST, DELAY>
for EPD2in9bc<SPI, CS, BUSY, DC, RST, DELAY>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
DELAY: DelayMs<u8>,
{
type DisplayColor = Color;
fn new<DELAY: DelayMs<u8>>(
fn new(
spi: &mut SPI,
cs: CS,
busy: BUSY,
@ -216,7 +215,7 @@ where
Ok(epd)
}
fn sleep(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
// Section 8.2 from datasheet
self.interface.cmd_with_data(
spi,
@ -233,11 +232,7 @@ where
Ok(())
}
fn wake_up<DELAY: DelayMs<u8>>(
&mut self,
spi: &mut SPI,
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
self.init(spi, delay)
}
@ -257,7 +252,12 @@ where
HEIGHT
}
fn update_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> {
fn update_frame(
&mut self,
spi: &mut SPI,
buffer: &[u8],
_delay: &mut DELAY,
) -> Result<(), SPI::Error> {
self.interface
.cmd(spi, Command::DATA_START_TRANSMISSION_1)?;
@ -287,20 +287,25 @@ where
Ok(())
}
fn display_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
self.command(spi, Command::DISPLAY_REFRESH)?;
self.wait_until_idle();
Ok(())
}
fn update_and_display_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> {
self.update_frame(spi, buffer)?;
self.display_frame(spi)?;
fn update_and_display_frame(
&mut self,
spi: &mut SPI,
buffer: &[u8],
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
self.update_frame(spi, buffer, delay)?;
self.display_frame(spi, delay)?;
Ok(())
}
fn clear_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
self.send_resolution(spi)?;
let color = DEFAULT_BACKGROUND_COLOR.get_byte_value();
@ -333,13 +338,14 @@ where
}
}
impl<SPI, CS, BUSY, DC, RST> EPD2in9bc<SPI, CS, BUSY, DC, RST>
impl<SPI, CS, BUSY, DC, RST, DELAY> EPD2in9bc<SPI, CS, BUSY, DC, RST, DELAY>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
DELAY: DelayMs<u8>,
{
fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), SPI::Error> {
self.interface.cmd(spi, command)
@ -359,7 +365,7 @@ where
}
fn wait_until_idle(&mut self) {
self.interface.wait_until_idle(IS_BUSY_LOW)
let _ = self.interface.wait_until_idle(IS_BUSY_LOW, None);
}
fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {

60
src/epd4in2/mod.rs

@ -81,29 +81,26 @@ pub use self::graphics::Display4in2;
/// EPD4in2 driver
///
pub struct EPD4in2<SPI, CS, BUSY, DC, RST> {
pub struct EPD4in2<SPI, CS, BUSY, DC, RST, DELAY> {
/// Connection Interface
interface: DisplayInterface<SPI, CS, BUSY, DC, RST>,
interface: DisplayInterface<SPI, CS, BUSY, DC, RST, DELAY>,
/// Background Color
color: Color,
/// Refresh LUT
refresh: RefreshLUT,
}
impl<SPI, CS, BUSY, DC, RST> InternalWiAdditions<SPI, CS, BUSY, DC, RST>
for EPD4in2<SPI, CS, BUSY, DC, RST>
impl<SPI, CS, BUSY, DC, RST, DELAY> InternalWiAdditions<SPI, CS, BUSY, DC, RST, DELAY>
for EPD4in2<SPI, CS, BUSY, DC, RST, DELAY>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
DELAY: DelayMs<u8>,
{
fn init<DELAY: DelayMs<u8>>(
&mut self,
spi: &mut SPI,
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
// reset the device
self.interface.reset(delay, 10);
@ -148,17 +145,18 @@ where
}
}
impl<SPI, CS, BUSY, DC, RST> WaveshareDisplay<SPI, CS, BUSY, DC, RST>
for EPD4in2<SPI, CS, BUSY, DC, RST>
impl<SPI, CS, BUSY, DC, RST, DELAY> WaveshareDisplay<SPI, CS, BUSY, DC, RST, DELAY>
for EPD4in2<SPI, CS, BUSY, DC, RST, DELAY>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
DELAY: DelayMs<u8>,
{
type DisplayColor = Color;
fn new<DELAY: DelayMs<u8>>(
fn new(
spi: &mut SPI,
cs: CS,
busy: BUSY,
@ -180,15 +178,11 @@ where
Ok(epd)
}
fn wake_up<DELAY: DelayMs<u8>>(
&mut self,
spi: &mut SPI,
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
self.init(spi, delay)
}
fn sleep(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
self.wait_until_idle();
self.interface
.cmd_with_data(spi, Command::VCOM_AND_DATA_INTERVAL_SETTING, &[0x17])?; //border floating
@ -207,7 +201,12 @@ where
Ok(())
}
fn update_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> {
fn update_frame(
&mut self,
spi: &mut SPI,
buffer: &[u8],
_delay: &mut DELAY,
) -> Result<(), SPI::Error> {
self.wait_until_idle();
let color_value = self.color.get_byte_value();
@ -267,19 +266,24 @@ where
Ok(())
}
fn display_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
self.wait_until_idle();
self.command(spi, Command::DISPLAY_REFRESH)?;
Ok(())
}
fn update_and_display_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> {
self.update_frame(spi, buffer)?;
fn update_and_display_frame(
&mut self,
spi: &mut SPI,
buffer: &[u8],
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
self.update_frame(spi, buffer, delay)?;
self.command(spi, Command::DISPLAY_REFRESH)?;
Ok(())
}
fn clear_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
self.wait_until_idle();
self.send_resolution(spi)?;
@ -341,13 +345,14 @@ where
}
}
impl<SPI, CS, BUSY, DC, RST> EPD4in2<SPI, CS, BUSY, DC, RST>
impl<SPI, CS, BUSY, DC, RST, DELAY> EPD4in2<SPI, CS, BUSY, DC, RST, DELAY>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
DELAY: DelayMs<u8>,
{
fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), SPI::Error> {
self.interface.cmd(spi, command)
@ -367,7 +372,7 @@ where
}
fn wait_until_idle(&mut self) {
self.interface.wait_until_idle(IS_BUSY_LOW)
let _ = self.interface.wait_until_idle(IS_BUSY_LOW, None);
}
fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
@ -437,14 +442,15 @@ where
}
}
impl<SPI, CS, BUSY, DC, RST> QuickRefresh<SPI, CS, BUSY, DC, RST>
for EPD4in2<SPI, CS, BUSY, DC, RST>
impl<SPI, CS, BUSY, DC, RST, DELAY> QuickRefresh<SPI, CS, BUSY, DC, RST, DELAY>
for EPD4in2<SPI, CS, BUSY, DC, RST, DELAY>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
DELAY: DelayMs<u8>,
{
/// To be followed immediately after by `update_old_frame`.
fn update_old_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> {

61
src/epd5in65f/mod.rs

@ -33,27 +33,24 @@ const IS_BUSY_LOW: bool = true;
/// EPD5in65f driver
///
pub struct EPD5in65f<SPI, CS, BUSY, DC, RST> {
pub struct EPD5in65f<SPI, CS, BUSY, DC, RST, DELAY> {
/// Connection Interface
interface: DisplayInterface<SPI, CS, BUSY, DC, RST>,
interface: DisplayInterface<SPI, CS, BUSY, DC, RST, DELAY>,
/// Background Color
color: OctColor,
}
impl<SPI, CS, BUSY, DC, RST> InternalWiAdditions<SPI, CS, BUSY, DC, RST>
for EPD5in65f<SPI, CS, BUSY, DC, RST>
impl<SPI, CS, BUSY, DC, RST, DELAY> InternalWiAdditions<SPI, CS, BUSY, DC, RST, DELAY>
for EPD5in65f<SPI, CS, BUSY, DC, RST, DELAY>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
DELAY: DelayMs<u8>,
{
fn init<DELAY: DelayMs<u8>>(
&mut self,
spi: &mut SPI,
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
// Reset the device
self.interface.reset(delay, 2);
@ -76,17 +73,18 @@ where
}
}
impl<SPI, CS, BUSY, DC, RST> WaveshareDisplay<SPI, CS, BUSY, DC, RST>
for EPD5in65f<SPI, CS, BUSY, DC, RST>
impl<SPI, CS, BUSY, DC, RST, DELAY> WaveshareDisplay<SPI, CS, BUSY, DC, RST, DELAY>
for EPD5in65f<SPI, CS, BUSY, DC, RST, DELAY>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
DELAY: DelayMs<u8>,
{
type DisplayColor = OctColor;
fn new<DELAY: DelayMs<u8>>(
fn new(
spi: &mut SPI,
cs: CS,
busy: BUSY,
@ -104,20 +102,21 @@ where
Ok(epd)
}
fn wake_up<DELAY: DelayMs<u8>>(
&mut self,
spi: &mut SPI,
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
self.init(spi, delay)
}
fn sleep(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
self.cmd_with_data(spi, Command::DEEP_SLEEP, &[0xA5])?;
Ok(())
}
fn update_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> {
fn update_frame(
&mut self,
spi: &mut SPI,
buffer: &[u8],
_delay: &mut DELAY,
) -> Result<(), SPI::Error> {
self.wait_busy_high();
self.send_resolution(spi)?;
self.cmd_with_data(spi, Command::DATA_START_TRANSMISSION_1, buffer)?;
@ -136,7 +135,7 @@ where
unimplemented!();
}
fn display_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
self.wait_busy_high();
self.command(spi, Command::POWER_ON)?;
self.wait_busy_high();
@ -147,19 +146,24 @@ where
Ok(())
}
fn update_and_display_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> {
self.update_frame(spi, buffer)?;
self.display_frame(spi)?;
fn update_and_display_frame(
&mut self,
spi: &mut SPI,
buffer: &[u8],
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
self.update_frame(spi, buffer, delay)?;
self.display_frame(spi, delay)?;
Ok(())
}
fn clear_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
fn clear_frame(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
let bg = OctColor::colors_byte(self.color, self.color);
self.wait_busy_high();
self.send_resolution(spi)?;
self.command(spi, Command::DATA_START_TRANSMISSION_1)?;
self.interface.data_x_times(spi, bg, WIDTH * HEIGHT / 2)?;
self.display_frame(spi)?;
self.display_frame(spi, delay)?;
Ok(())
}
@ -192,13 +196,14 @@ where
}
}
impl<SPI, CS, BUSY, DC, RST> EPD5in65f<SPI, CS, BUSY, DC, RST>
impl<SPI, CS, BUSY, DC, RST, DELAY> EPD5in65f<SPI, CS, BUSY, DC, RST, DELAY>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
DELAY: DelayMs<u8>,
{
fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), SPI::Error> {
self.interface.cmd(spi, command)
@ -218,10 +223,10 @@ where
}
fn wait_busy_high(&mut self) {
self.interface.wait_until_idle(true)
let _ = self.interface.wait_until_idle(true, None);
}
fn wait_busy_low(&mut self) {
self.interface.wait_until_idle(false)
let _ = self.interface.wait_until_idle(false, None);
}
fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
let w = self.width();

55
src/epd7in5/mod.rs

@ -33,27 +33,24 @@ const IS_BUSY_LOW: bool = true;
/// EPD7in5 driver
///
pub struct EPD7in5<SPI, CS, BUSY, DC, RST> {
pub struct EPD7in5<SPI, CS, BUSY, DC, RST, DELAY> {
/// Connection Interface
interface: DisplayInterface<SPI, CS, BUSY, DC, RST>,
interface: DisplayInterface<SPI, CS, BUSY, DC, RST, DELAY>,
/// Background Color
color: Color,
}
impl<SPI, CS, BUSY, DC, RST> InternalWiAdditions<SPI, CS, BUSY, DC, RST>
for EPD7in5<SPI, CS, BUSY, DC, RST>
impl<SPI, CS, BUSY, DC, RST, DELAY> InternalWiAdditions<SPI, CS, BUSY, DC, RST, DELAY>
for EPD7in5<SPI, CS, BUSY, DC, RST, DELAY>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
DELAY: DelayMs<u8>,
{
fn init<DELAY: DelayMs<u8>>(
&mut self,
spi: &mut SPI,
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
// Reset the device
self.interface.reset(delay, 10);
@ -99,17 +96,18 @@ where
}
}
impl<SPI, CS, BUSY, DC, RST> WaveshareDisplay<SPI, CS, BUSY, DC, RST>
for EPD7in5<SPI, CS, BUSY, DC, RST>
impl<SPI, CS, BUSY, DC, RST, DELAY> WaveshareDisplay<SPI, CS, BUSY, DC, RST, DELAY>
for EPD7in5<SPI, CS, BUSY, DC, RST, DELAY>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
DELAY: DelayMs<u8>,
{
type DisplayColor = Color;
fn new<DELAY: DelayMs<u8>>(
fn new(
spi: &mut SPI,
cs: CS,
busy: BUSY,
@ -127,15 +125,11 @@ where
Ok(epd)
}
fn wake_up<DELAY: DelayMs<u8>>(
&mut self,
spi: &mut SPI,
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
self.init(spi, delay)
}
fn sleep(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
self.wait_until_idle();
self.command(spi, Command::POWER_OFF)?;
self.wait_until_idle();
@ -143,7 +137,12 @@ where
Ok(())
}
fn update_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> {
fn update_frame(
&mut self,
spi: &mut SPI,
buffer: &[u8],
_delay: &mut DELAY,
) -> Result<(), SPI::Error> {
self.wait_until_idle();
self.command(spi, Command::DATA_START_TRANSMISSION_1)?;
for byte in buffer {
@ -172,19 +171,24 @@ where
unimplemented!();
}
fn display_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
self.wait_until_idle();
self.command(spi, Command::DISPLAY_REFRESH)?;
Ok(())
}
fn update_and_display_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> {
self.update_frame(spi, buffer)?;
fn update_and_display_frame(
&mut self,
spi: &mut SPI,
buffer: &[u8],
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
self.update_frame(spi, buffer, delay)?;
self.command(spi, Command::DISPLAY_REFRESH)?;
Ok(())
}
fn clear_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
self.wait_until_idle();
self.send_resolution(spi)?;
@ -224,13 +228,14 @@ where
}
}
impl<SPI, CS, BUSY, DC, RST> EPD7in5<SPI, CS, BUSY, DC, RST>
impl<SPI, CS, BUSY, DC, RST, DELAY> EPD7in5<SPI, CS, BUSY, DC, RST, DELAY>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
DELAY: DelayMs<u8>,
{
fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), SPI::Error> {
self.interface.cmd(spi, command)
@ -250,7 +255,7 @@ where
}
fn wait_until_idle(&mut self) {
self.interface.wait_until_idle(IS_BUSY_LOW)
let _ = self.interface.wait_until_idle(IS_BUSY_LOW, None);
}
fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {

79
src/epd7in5_v2/mod.rs

@ -37,27 +37,24 @@ const IS_BUSY_LOW: bool = true;
/// EPD7in5 (V2) driver
///
pub struct EPD7in5<SPI, CS, BUSY, DC, RST> {
pub struct EPD7in5<SPI, CS, BUSY, DC, RST, DELAY> {
/// Connection Interface
interface: DisplayInterface<SPI, CS, BUSY, DC, RST>,
interface: DisplayInterface<SPI, CS, BUSY, DC, RST, DELAY>,
/// Background Color
color: Color,
}
impl<SPI, CS, BUSY, DC, RST> InternalWiAdditions<SPI, CS, BUSY, DC, RST>
for EPD7in5<SPI, CS, BUSY, DC, RST>
impl<SPI, CS, BUSY, DC, RST, DELAY> InternalWiAdditions<SPI, CS, BUSY, DC, RST, DELAY>
for EPD7in5<SPI, CS, BUSY, DC, RST, DELAY>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
DELAY: DelayMs<u8>,
{
fn init<DELAY: DelayMs<u8>>(
&mut self,
spi: &mut SPI,
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
// Reset the device
self.interface.reset(delay, 2);
@ -69,29 +66,30 @@ where
self.cmd_with_data(spi, Command::BOOSTER_SOFT_START, &[0x17, 0x17, 0x27, 0x17])?;
self.cmd_with_data(spi, Command::POWER_SETTING, &[0x07, 0x17, 0x3F, 0x3F])?;
self.command(spi, Command::POWER_ON)?;
self.wait_until_idle();
self.wait_until_idle(spi, delay)?;
self.cmd_with_data(spi, Command::PANEL_SETTING, &[0x1F])?;
self.cmd_with_data(spi, Command::PLL_CONTROL, &[0x06])?;
self.cmd_with_data(spi, Command::TCON_RESOLUTION, &[0x03, 0x20, 0x01, 0xE0])?;
self.cmd_with_data(spi, Command::DUAL_SPI, &[0x00])?;
self.cmd_with_data(spi, Command::TCON_SETTING, &[0x22])?;
self.cmd_with_data(spi, Command::VCOM_AND_DATA_INTERVAL_SETTING, &[0x10, 0x07])?;
self.wait_until_idle();
self.wait_until_idle(spi, delay)?;
Ok(())
}
}
impl<SPI, CS, BUSY, DC, RST> WaveshareDisplay<SPI, CS, BUSY, DC, RST>
for EPD7in5<SPI, CS, BUSY, DC, RST>
impl<SPI, CS, BUSY, DC, RST, DELAY> WaveshareDisplay<SPI, CS, BUSY, DC, RST, DELAY>
for EPD7in5<SPI, CS, BUSY, DC, RST, DELAY>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
DELAY: DelayMs<u8>,
{
type DisplayColor = Color;
fn new<DELAY: DelayMs<u8>>(
fn new(
spi: &mut SPI,
cs: CS,
busy: BUSY,
@ -109,24 +107,25 @@ where
Ok(epd)
}
fn wake_up<DELAY: DelayMs<u8>>(
&mut self,
spi: &mut SPI,
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
self.init(spi, delay)
}
fn sleep(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
self.wait_until_idle();
fn sleep(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
self.wait_until_idle(spi, delay)?;
self.command(spi, Command::POWER_OFF)?;
self.wait_until_idle();
self.wait_until_idle(spi, delay)?;
self.cmd_with_data(spi, Command::DEEP_SLEEP, &[0xA5])?;
Ok(())
}
fn update_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> {
self.wait_until_idle();
fn update_frame(
&mut self,
spi: &mut SPI,
buffer: &[u8],
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
self.wait_until_idle(spi, delay)?;
self.cmd_with_data(spi, Command::DATA_START_TRANSMISSION_2, buffer)?;
Ok(())
}
@ -143,20 +142,25 @@ where
unimplemented!();
}
fn display_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
self.wait_until_idle();
fn display_frame(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
self.wait_until_idle(spi, delay)?;
self.command(spi, Command::DISPLAY_REFRESH)?;
Ok(())
}
fn update_and_display_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> {
self.update_frame(spi, buffer)?;
fn update_and_display_frame(
&mut self,
spi: &mut SPI,
buffer: &[u8],
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
self.update_frame(spi, buffer, delay)?;
self.command(spi, Command::DISPLAY_REFRESH)?;
Ok(())
}
fn clear_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
self.wait_until_idle();
fn clear_frame(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
self.wait_until_idle(spi, delay)?;
self.send_resolution(spi)?;
self.command(spi, Command::DATA_START_TRANSMISSION_1)?;
@ -198,13 +202,14 @@ where
}
}
impl<SPI, CS, BUSY, DC, RST> EPD7in5<SPI, CS, BUSY, DC, RST>
impl<SPI, CS, BUSY, DC, RST, DELAY> EPD7in5<SPI, CS, BUSY, DC, RST, DELAY>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
DELAY: DelayMs<u8>,
{
fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), SPI::Error> {
self.interface.cmd(spi, command)
@ -223,8 +228,16 @@ where
self.interface.cmd_with_data(spi, command, data)
}
fn wait_until_idle(&mut self) {
self.interface.wait_until_idle(IS_BUSY_LOW)
fn wait_until_idle(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
self.interface.wait_until_idle(
IS_BUSY_LOW,
Some((spi, delay, |i, s, d| {
i.cmd(s, Command::GET_STATUS)?;
d.delay_ms(20);
Ok(())
})),
)?;
Ok(())
}
fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {

39
src/interface.rs

@ -7,9 +7,11 @@ use embedded_hal::{
/// The Connection Interface of all (?) Waveshare EPD-Devices
///
pub(crate) struct DisplayInterface<SPI, CS, BUSY, DC, RST> {
pub(crate) struct DisplayInterface<SPI, CS, BUSY, DC, RST, DELAY> {
/// SPI
_spi: PhantomData<SPI>,
/// DELAY
_delay: PhantomData<DELAY>,
/// CS for SPI
cs: CS,
/// Low for busy, Wait until display is ready!
@ -20,17 +22,19 @@ pub(crate) struct DisplayInterface<SPI, CS, BUSY, DC, RST> {
rst: RST,
}
impl<SPI, CS, BUSY, DC, RST> DisplayInterface<SPI, CS, BUSY, DC, RST>
impl<SPI, CS, BUSY, DC, RST, DELAY> DisplayInterface<SPI, CS, BUSY, DC, RST, DELAY>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
DELAY: DelayMs<u8>,
{
pub fn new(cs: CS, busy: BUSY, dc: DC, rst: RST) -> Self {
DisplayInterface {
_spi: PhantomData::default(),
_delay: PhantomData::default(),
cs,
busy,
dc,
@ -126,15 +130,32 @@ where
///
/// Most likely there was a mistake with the 2in9 busy connection
/// //TODO: use the #cfg feature to make this compile the right way for the certain types
pub(crate) fn wait_until_idle(&mut self, is_busy_low: bool) {
//tested: worked without the delay for all tested devices
//self.delay_ms(1);
pub(crate) fn wait_until_idle(
&mut self,
is_busy_low: bool,
mut task: Option<(
&mut SPI,
&mut DELAY,
fn(&mut Self, &mut SPI, &mut DELAY) -> Result<(), SPI::Error>,
)>,
) -> Result<(), SPI::Error> {
// //tested: worked without the delay for all tested devices
// //self.delay_ms(1);
// Some displays need special treatment (Only 7.5"V2 known so far)
// In those cases, a "task" is provided and run here. If note, this
// just busy waits for the display.
while self.is_busy(is_busy_low) {
//tested: REMOVAL of DELAY: it's only waiting for the signal anyway and should continue work asap
//old: shorten the time? it was 100 in the beginning
//self.delay_ms(5);
match task {
// TODO: Ignore this error?
Some((ref mut spi, ref mut delay, tcb)) => tcb(self, spi, delay)?,
None => {}
}
// //tested: REMOVAL of DELAY: it's only waiting for the signal anyway and should continue work asap
// //old: shorten the time? it was 100 in the beginning
// //self.delay_ms(5);
}
Ok(())
}
/// Checks if device is still busy
@ -162,7 +183,7 @@ where
/// The timing of keeping the reset pin low seems to be important and different per device.
/// Most displays seem to require keeping it low for 10ms, but the 7in5_v2 only seems to reset
/// properly with 2ms
pub(crate) fn reset<DELAY: DelayMs<u8>>(&mut self, delay: &mut DELAY, duration: u8) {
pub(crate) fn reset(&mut self, delay: &mut DELAY, duration: u8) {
let _ = self.rst.set_high();
delay.delay_ms(10);

48
src/traits.rs

@ -26,13 +26,14 @@ impl Default for RefreshLUT {
}
}
pub(crate) trait InternalWiAdditions<SPI, CS, BUSY, DC, RST>
pub(crate) trait InternalWiAdditions<SPI, CS, BUSY, DC, RST, DELAY>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
DELAY: DelayMs<u8>,
{
/// This initialises the EPD and powers it up
///
@ -44,22 +45,19 @@ where
/// This function calls [reset](WaveshareDisplay::reset),
/// so you don't need to call reset your self when trying to wake your device up
/// after setting it to sleep.
fn init<DELAY: DelayMs<u8>>(
&mut self,
spi: &mut SPI,
delay: &mut DELAY,
) -> Result<(), SPI::Error>;
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error>;
}
/// Functions to interact with three color panels
pub trait WaveshareThreeColorDisplay<SPI, CS, BUSY, DC, RST>:
WaveshareDisplay<SPI, CS, BUSY, DC, RST>
pub trait WaveshareThreeColorDisplay<SPI, CS, BUSY, DC, RST, DELAY>:
WaveshareDisplay<SPI, CS, BUSY, DC, RST, DELAY>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
DELAY: DelayMs<u8>,
{
/// Transmit data to the SRAM of the EPD
///
@ -127,20 +125,21 @@ where
///# Ok(())
///# }
///```
pub trait WaveshareDisplay<SPI, CS, BUSY, DC, RST>
pub trait WaveshareDisplay<SPI, CS, BUSY, DC, RST, DELAY>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
DELAY: DelayMs<u8>,
{
/// The Color Type used by the Display
type DisplayColor;
/// Creates a new driver from a SPI peripheral, CS Pin, Busy InputPin, DC
///
/// This already initialises the device.
fn new<DELAY: DelayMs<u8>>(
fn new(
spi: &mut SPI,
cs: CS,
busy: BUSY,
@ -154,16 +153,12 @@ where
/// Let the device enter deep-sleep mode to save power.
///
/// The deep sleep mode returns to standby with a hardware reset.
fn sleep(&mut self, spi: &mut SPI) -> Result<(), SPI::Error>;
fn sleep(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error>;
/// Wakes the device up from sleep
///
/// Also reintialises the device if necessary.
fn wake_up<DELAY: DelayMs<u8>>(
&mut self,
spi: &mut SPI,
delay: &mut DELAY,
) -> Result<(), SPI::Error>;
fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error>;
/// Sets the backgroundcolor for various commands like [clear_frame](WaveshareDisplay::clear_frame)
fn set_background_color(&mut self, color: Self::DisplayColor);
@ -178,7 +173,12 @@ where
fn height(&self) -> u32;
/// Transmit a full frame to the SRAM of the EPD
fn update_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error>;
fn update_frame(
&mut self,
spi: &mut SPI,
buffer: &[u8],
delay: &mut DELAY,
) -> Result<(), SPI::Error>;
/// Transmits partial data to the SRAM of the EPD
///
@ -198,15 +198,20 @@ where
/// Displays the frame data from SRAM
///
/// This function waits until the device isn`t busy anymore
fn display_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error>;
fn display_frame(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error>;
/// Provide a combined update&display and save some time (skipping a busy check in between)
fn update_and_display_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error>;
fn update_and_display_frame(
&mut self,
spi: &mut SPI,
buffer: &[u8],
delay: &mut DELAY,
) -> Result<(), SPI::Error>;
/// Clears the frame buffer on the EPD with the declared background color
///
/// The background color can be changed with [`WaveshareDisplay::set_background_color`]
fn clear_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error>;
fn clear_frame(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error>;
/// Trait for using various Waveforms from different LUTs
/// E.g. for partial refreshes
@ -275,13 +280,14 @@ where
///# Ok(())
///# }
///```
pub trait QuickRefresh<SPI, CS, BUSY, DC, RST>
pub trait QuickRefresh<SPI, CS, BUSY, DC, RST, DELAY>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
DELAY: DelayMs<u8>,
{
/// Updates the old frame.
fn update_old_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error>;

Loading…
Cancel
Save