Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions examples/epd1in54_no_graphics.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#![deny(warnings)]

use embedded_hal::prelude::*;
use epd_waveshare::{epd1in54::Epd1in54, prelude::*};
use epd_waveshare::{
buffer_len,
epd1in54::{Epd1in54, HEIGHT, WIDTH},
prelude::*,
};
use linux_embedded_hal::{
spidev::{self, SpidevOptions},
sysfs_gpio::Direction,
Expand All @@ -12,6 +16,8 @@ use linux_embedded_hal::{
// needs to be run with sudo because of some sysfs_gpio permission problems and follow-up timing problems
// see https://github.com/rust-embedded/rust-sysfs-gpio/issues/5 and follow-up issues

const BUFFER_LEN: usize = buffer_len(WIDTH as usize, HEIGHT as usize);

fn main() -> Result<(), std::io::Error> {
// Configure SPI
// SPI settings are from eink-waveshare-rs documenation
Expand Down Expand Up @@ -61,7 +67,11 @@ 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, &mut delay)?;
epd.update_frame(
&mut spi,
&[Color::White.get_byte_value(); BUFFER_LEN],
&mut delay,
)?;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think by removing the clear frame command this got even easier to understand 👍

epd.display_frame(&mut spi, &mut delay)?;

// Speeddemo
Expand All @@ -75,7 +85,11 @@ fn main() -> Result<(), std::io::Error> {
}

// Clear the full screen
epd.clear_frame(&mut spi, &mut delay)?;
epd.update_frame(
&mut spi,
&[Color::White.get_byte_value(); BUFFER_LEN],
&mut delay,
)?;
epd.display_frame(&mut spi, &mut delay)?;

// Draw some squares
Expand Down
1 change: 0 additions & 1 deletion examples/epd2in13_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ fn main() -> Result<(), std::io::Error> {
epd2in13
.set_refresh(&mut spi, &mut delay, RefreshLut::Quick)
.unwrap();
epd2in13.clear_frame(&mut spi, &mut delay).unwrap();

// a moving `Hello World!`
let limit = 10;
Expand Down
1 change: 0 additions & 1 deletion examples/epd4in2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ 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, &mut delay).unwrap();
for i in 0..limit {
//println!("Moving Hello World. Loop {} from {}", (i + 1), limit);

Expand Down
24 changes: 0 additions & 24 deletions src/epd1in54/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ pub use crate::epd1in54::graphics::Display1in54;
pub struct Epd1in54<SPI, CS, BUSY, DC, RST, DELAY> {
/// SPI
interface: DisplayInterface<SPI, CS, BUSY, DC, RST, DELAY>,
/// Color
background_color: Color,
/// Refresh LUT
refresh: RefreshLut,
}
Expand Down Expand Up @@ -170,7 +168,6 @@ where

let mut epd = Epd1in54 {
interface,
background_color: DEFAULT_BACKGROUND_COLOR,
refresh: RefreshLut::Full,
};

Expand Down Expand Up @@ -249,27 +246,6 @@ where
Ok(())
}

fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we aren't able to test all the devices it might be better to just add the color parameter since it might be useful as a helper function.

self.wait_until_idle();
self.use_full_frame(spi)?;

// clear the ram with the background color
let color = self.background_color.get_byte_value();

self.interface.cmd(spi, Command::WriteRam)?;
self.interface
.data_x_times(spi, color, WIDTH / 8 * HEIGHT)?;
Ok(())
}

fn set_background_color(&mut self, background_color: Color) {
self.background_color = background_color;
}

fn background_color(&self) -> &Color {
&self.background_color
}

fn set_lut(
&mut self,
spi: &mut SPI,
Expand Down
27 changes: 0 additions & 27 deletions src/epd1in54_v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ pub use crate::epd1in54::graphics::Display1in54;
pub struct Epd1in54<SPI, CS, BUSY, DC, RST, DELAY> {
/// SPI
interface: DisplayInterface<SPI, CS, BUSY, DC, RST, DELAY>,
/// Color
background_color: Color,

/// Refresh LUT
refresh: RefreshLut,
Expand Down Expand Up @@ -121,7 +119,6 @@ where

let mut epd = Epd1in54 {
interface,
background_color: DEFAULT_BACKGROUND_COLOR,
refresh: RefreshLut::Full,
};

Expand Down Expand Up @@ -203,30 +200,6 @@ where
Ok(())
}

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

// clear the ram with the background color
let color = self.background_color.get_byte_value();

self.interface.cmd(spi, Command::WriteRam)?;
self.interface
.data_x_times(spi, color, WIDTH / 8 * HEIGHT)?;
self.interface.cmd(spi, Command::WriteRam2)?;
self.interface
.data_x_times(spi, color, WIDTH / 8 * HEIGHT)?;
Ok(())
}

fn set_background_color(&mut self, background_color: Color) {
self.background_color = background_color;
}

fn background_color(&self) -> &Color {
&self.background_color
}

fn set_lut(
&mut self,
spi: &mut SPI,
Expand Down
40 changes: 5 additions & 35 deletions src/epd1in54b/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ pub use self::graphics::Display1in54b;
/// Epd1in54b driver
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, DELAY> InternalWiAdditions<SPI, CS, BUSY, DC, RST, DELAY>
Expand Down Expand Up @@ -149,9 +148,8 @@ where
delay: &mut DELAY,
) -> Result<Self, SPI::Error> {
let interface = DisplayInterface::new(cs, busy, dc, rst);
let color = DEFAULT_BACKGROUND_COLOR;

let mut epd = Epd1in54b { interface, color };
let mut epd = Epd1in54b { interface };

epd.init(spi, delay)?;

Expand Down Expand Up @@ -182,14 +180,6 @@ where
self.init(spi, delay)
}

fn set_background_color(&mut self, color: Color) {
self.color = color;
}

fn background_color(&self) -> &Color {
&self.color
}

fn width(&self) -> u32 {
WIDTH
}
Expand Down Expand Up @@ -217,12 +207,12 @@ where

//NOTE: Example code has a delay here

// Clear the read layer
let color = self.color.get_byte_value();
let nbits = WIDTH * (HEIGHT / 8);
// Clear the red layer
let color = 0xff;
let nbytes = WIDTH * (HEIGHT / 8);

self.interface.cmd(spi, Command::DataStartTransmission2)?;
self.interface.data_x_times(spi, color, nbits)?;
self.interface.data_x_times(spi, color, nbytes)?;

//NOTE: Example code has a delay here
Ok(())
Expand Down Expand Up @@ -258,26 +248,6 @@ where
Ok(())
}

fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
self.wait_until_idle();
self.send_resolution(spi)?;

let color = DEFAULT_BACKGROUND_COLOR.get_byte_value();

// Clear the black
self.interface.cmd(spi, Command::DataStartTransmission1)?;

// Uses 2 bits per pixel
self.interface
.data_x_times(spi, color, 2 * (WIDTH * HEIGHT / 8))?;

// Clear the red
self.interface.cmd(spi, Command::DataStartTransmission2)?;
self.interface
.data_x_times(spi, color, WIDTH * HEIGHT / 8)?;
Ok(())
}

fn set_lut(
&mut self,
spi: &mut SPI,
Expand Down
29 changes: 2 additions & 27 deletions src/epd1in54c/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ pub use self::graphics::Display1in54c;
/// Epd1in54c driver
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, DELAY> InternalWiAdditions<SPI, CS, BUSY, DC, RST, DELAY>
Expand Down Expand Up @@ -132,9 +131,8 @@ where
delay: &mut DELAY,
) -> Result<Self, SPI::Error> {
let interface = DisplayInterface::new(cs, busy, dc, rst);
let color = DEFAULT_BACKGROUND_COLOR;

let mut epd = Epd1in54c { interface, color };
let mut epd = Epd1in54c { interface };

epd.init(spi, delay)?;

Expand All @@ -155,14 +153,6 @@ where
self.init(spi, delay)
}

fn set_background_color(&mut self, color: Color) {
self.color = color;
}

fn background_color(&self) -> &Color {
&self.color
}

fn width(&self) -> u32 {
WIDTH
}
Expand All @@ -180,7 +170,7 @@ where
self.update_achromatic_frame(spi, buffer)?;

// Clear the chromatic layer
let color = self.color.get_byte_value();
let color = 0xff;

self.command(spi, Command::DataStartTransmission2)?;
self.interface.data_x_times(spi, color, NUM_DISPLAY_BITS)?;
Expand Down Expand Up @@ -220,21 +210,6 @@ where
Ok(())
}

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();

// Clear the black
self.command(spi, Command::DataStartTransmission1)?;
self.interface.data_x_times(spi, color, NUM_DISPLAY_BITS)?;

// Clear the chromatic
self.command(spi, Command::DataStartTransmission2)?;
self.interface.data_x_times(spi, color, NUM_DISPLAY_BITS)?;

Ok(())
}

fn set_lut(
&mut self,
_spi: &mut SPI,
Expand Down
39 changes: 0 additions & 39 deletions src/epd2in13_v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ pub struct Epd2in13<SPI, CS, BUSY, DC, RST, DELAY> {

sleep_mode: DeepSleepMode,

/// Background Color
background_color: Color,
refresh: RefreshLut,
}

Expand Down Expand Up @@ -172,7 +170,6 @@ where
let mut epd = Epd2in13 {
interface: DisplayInterface::new(cs, busy, dc, rst),
sleep_mode: DeepSleepMode::Mode1,
background_color: DEFAULT_BACKGROUND_COLOR,
refresh: RefreshLut::Full,
};

Expand Down Expand Up @@ -299,42 +296,6 @@ where
Ok(())
}

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)?;
self.set_ram_address_counters(spi, 0, 0)?;

self.command(spi, Command::WriteRam)?;
self.interface.data_x_times(
spi,
color,
buffer_len(WIDTH as usize, HEIGHT as usize) as u32,
)?;

// Always keep the base buffer equals to current if not doing partial refresh.
if self.refresh == RefreshLut::Full {
self.set_ram_area(spi, 0, 0, WIDTH - 1, HEIGHT - 1)?;
self.set_ram_address_counters(spi, 0, 0)?;

self.command(spi, Command::WriteRamRed)?;
self.interface.data_x_times(
spi,
color,
buffer_len(WIDTH as usize, HEIGHT as usize) as u32,
)?;
}
Ok(())
}

fn set_background_color(&mut self, background_color: Color) {
self.background_color = background_color;
}

fn background_color(&self) -> &Color {
&self.background_color
}

fn width(&self) -> u32 {
WIDTH
}
Expand Down
Loading