From 22e3ee22b2f54ac8fa41ffc57861b2a7c8595687 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 30 Oct 2018 14:56:38 +0100 Subject: [PATCH 01/15] Include `set_lut` in WaveshareDisplay Trait --- Cargo.toml | 2 - examples/embedded_linux_epd1in54/src/main.rs | 2 +- examples/embedded_linux_epd2in9/src/main.rs | 4 +- src/epd1in54/mod.rs | 38 +++++++------- src/epd2in9/mod.rs | 43 ++++++++-------- src/epd4in2/constants.rs | 15 ++---- src/epd4in2/mod.rs | 53 ++++++++++---------- src/graphics.rs | 4 +- src/interface.rs | 7 --- src/lib.rs | 2 +- src/traits.rs | 36 +++++++++---- 11 files changed, 105 insertions(+), 101 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0e7779a..a384076 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,8 +24,6 @@ graphics = ["embedded-graphics"] epd1in54 = [] epd2in9 = [] epd4in2 = [] -# Activates the fast LUT for EPD4in2 -epd4in2_fast_update = [] [dependencies.embedded-graphics] optional = true diff --git a/examples/embedded_linux_epd1in54/src/main.rs b/examples/embedded_linux_epd1in54/src/main.rs index f3325d2..7d9e5b1 100644 --- a/examples/embedded_linux_epd1in54/src/main.rs +++ b/examples/embedded_linux_epd1in54/src/main.rs @@ -133,7 +133,7 @@ fn run() -> Result<(), std::io::Error> { // a quickly moving `Hello World!` display.set_rotation(DisplayRotation::Rotate0); - epd.set_lut_quick(&mut spi).expect("SET LUT QUICK error"); + epd.set_lut(&mut spi, Some(RefreshLUT::QUICK)).expect("SET LUT QUICK error"); let limit = 20; for i in 0..limit { println!("Moving Hello World. Loop {} from {}", (i+1), limit); diff --git a/examples/embedded_linux_epd2in9/src/main.rs b/examples/embedded_linux_epd2in9/src/main.rs index 97d1d84..5288fd4 100644 --- a/examples/embedded_linux_epd2in9/src/main.rs +++ b/examples/embedded_linux_epd2in9/src/main.rs @@ -92,7 +92,7 @@ fn run() -> Result<(), std::io::Error> { let mut buffer = Buffer2in9::default(); let mut display = Display::new(epd.width(), epd.height(), &mut buffer.buffer); epd.update_frame(&mut spi, display.buffer()).unwrap(); - epd.display_frame(&mut spi); + epd.display_frame(&mut spi).expect("display frame x03"); display.set_rotation(DisplayRotation::Rotate0); display.draw( @@ -137,7 +137,7 @@ fn run() -> Result<(), std::io::Error> { // a quickly moving `Hello World!` display.set_rotation(DisplayRotation::Rotate0); - epd.set_lut_quick(&mut spi).expect("SET LUT QUICK error"); + epd.set_lut(&mut spi, Some(RefreshLUT::QUICK)).expect("SET LUT QUICK error"); let limit = 20; for i in 0..limit { println!("Moving Hello World. Loop {} from {}", (i+1), limit); diff --git a/src/epd1in54/mod.rs b/src/epd1in54/mod.rs index 019ca79..6ea0ab1 100644 --- a/src/epd1in54/mod.rs +++ b/src/epd1in54/mod.rs @@ -50,7 +50,7 @@ use type_a::{ use color::Color; -use traits::{WaveshareDisplay}; +use traits::{WaveshareDisplay, RefreshLUT}; use interface::DisplayInterface; @@ -62,10 +62,10 @@ pub use epd1in54::graphics::Buffer1in54BlackWhite as Buffer1in54; pub struct EPD1in54 { /// SPI interface: DisplayInterface, - /// EPD (width, height) - //epd: EPD, /// Color background_color: Color, + /// Refresh LUT + refresh: RefreshLUT, } impl EPD1in54 @@ -110,7 +110,7 @@ where // -> address: x increment, y increment, address counter is updated in x direction self.interface.cmd_with_data(spi, Command::DATA_ENTRY_MODE_SETTING, &[0x03])?; - self.set_lut(spi) + self.set_lut(spi, None) } } @@ -140,6 +140,7 @@ where let mut epd = EPD1in54 { interface, background_color: DEFAULT_BACKGROUND_COLOR, + refresh: RefreshLUT::FULL }; epd.init(spi, delay)?; @@ -217,6 +218,20 @@ where fn background_color(&self) -> &Color { &self.background_color } + + fn set_lut(&mut self, spi: &mut SPI, refresh_rate: Option) -> Result<(), SPI::Error> { + if let Some(refresh_lut) = refresh_rate { + self.refresh = refresh_lut; + } + match self.refresh { + RefreshLUT::FULL => { + self.set_lut_helper(spi, &LUT_FULL_UPDATE) + }, + RefreshLUT::QUICK => { + self.set_lut_helper(spi, &LUT_PARTIAL_UPDATE) + } + } + } } impl EPD1in54 @@ -284,21 +299,6 @@ where Ok(()) } - /// Uses the slower full update - pub fn set_lut(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { - self.set_lut_helper(spi, &LUT_FULL_UPDATE) - } - - /// Uses the quick partial refresh - pub fn set_lut_quick(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { - self.set_lut_helper(spi, &LUT_PARTIAL_UPDATE) - } - - //TODO: assert length for LUT is exactly 30 - //fn set_lut_manual(&mut self, buffer: &[u8]) -> Result<(), E> { - // self.set_lut_helper(buffer) - //} - fn set_lut_helper(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> { assert!(buffer.len() == 30); self.interface.cmd_with_data(spi, Command::WRITE_LUT_REGISTER, buffer) diff --git a/src/epd2in9/mod.rs b/src/epd2in9/mod.rs index dcdf1a7..0383bd4 100644 --- a/src/epd2in9/mod.rs +++ b/src/epd2in9/mod.rs @@ -63,10 +63,10 @@ pub use epd2in9::graphics::Buffer2in9; pub struct EPD2in9 { /// SPI interface: DisplayInterface, - /// EPD (width, height) - //epd: EPD, /// Color background_color: Color, + /// Refresh LUT + refresh: RefreshLUT, } impl EPD2in9 @@ -107,7 +107,7 @@ where // -> address: x increment, y increment, address counter is updated in x direction self.interface.cmd_with_data(spi, Command::DATA_ENTRY_MODE_SETTING, &[0x03])?; - self.set_lut(spi) + self.set_lut(spi, None) } } @@ -137,6 +137,7 @@ where let mut epd = EPD2in9 { interface, background_color: DEFAULT_BACKGROUND_COLOR, + refresh: RefreshLUT::FULL, }; epd.init(spi, delay)?; @@ -206,7 +207,6 @@ where ) } - /// Sets the backgroundcolor for various commands like [WaveshareInterface::clear_frame()](clear_frame()) fn set_background_color(&mut self, background_color: Color) { self.background_color = background_color; } @@ -214,6 +214,20 @@ where fn background_color(&self) -> &Color { &self.background_color } + + fn set_lut(&mut self, spi: &mut SPI, refresh_rate: Option) -> Result<(), SPI::Error> { + if let Some(refresh_lut) = refresh_rate { + self.refresh = refresh_lut; + } + match self.refresh { + RefreshLUT::FULL => { + self.set_lut_helper(spi, &LUT_FULL_UPDATE) + }, + RefreshLUT::QUICK => { + self.set_lut_helper(spi, &LUT_PARTIAL_UPDATE) + } + } + } } impl EPD2in9 @@ -228,7 +242,7 @@ where self.interface.wait_until_idle(false); } - pub(crate) fn use_full_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { + fn use_full_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { // choose full frame/ram self.set_ram_area(spi, 0, 0, WIDTH - 1, HEIGHT - 1)?; @@ -236,7 +250,7 @@ where self.set_ram_counter(spi, 0, 0) } - pub(crate) fn set_ram_area( + fn set_ram_area( &mut self, spi: &mut SPI, start_x: u32, @@ -261,7 +275,7 @@ where ) } - pub(crate) fn set_ram_counter(&mut self, spi: &mut SPI, x: u32, y: u32) -> Result<(), SPI::Error> { + fn set_ram_counter(&mut self, spi: &mut SPI, x: u32, y: u32) -> Result<(), SPI::Error> { // x is positioned in bytes, so the last 3 bits which show the position inside a byte in the ram // aren't relevant self.interface.cmd_with_data(spi, Command::SET_RAM_X_ADDRESS_COUNTER, &[(x >> 3) as u8])?; @@ -273,21 +287,6 @@ where Ok(()) } - /// Uses the slower full update - pub fn set_lut(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { - self.set_lut_helper(spi, &LUT_FULL_UPDATE) - } - - /// Uses the quick partial refresh - pub fn set_lut_quick(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { - self.set_lut_helper(spi, &LUT_PARTIAL_UPDATE) - } - - //TODO: assert length for LUT is exactly 30 - //fn set_lut_manual(&mut self, buffer: &[u8]) -> Result<(), E> { - // self.set_lut_helper(buffer) - //} - fn set_lut_helper(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> { assert!(buffer.len() == 30); self.interface.cmd_with_data(spi, Command::WRITE_LUT_REGISTER, buffer) diff --git a/src/epd4in2/constants.rs b/src/epd4in2/constants.rs index 16423e3..e794d5f 100644 --- a/src/epd4in2/constants.rs +++ b/src/epd4in2/constants.rs @@ -15,8 +15,7 @@ pub(crate) const LUT_VCOM0: [u8; 44] = [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ]; -#[allow(dead_code)] -#[cfg(feature = "epd4in2_fast_update")] + pub(crate) const LUT_VCOM0_QUICK: [u8; 44] = [ 0x00, 0x0E, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -38,8 +37,7 @@ pub(crate) const LUT_WW: [u8; 42] =[ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ]; -#[allow(dead_code)] -#[cfg(feature = "epd4in2_fast_update")] + pub(crate) const LUT_WW_QUICK: [u8; 42] =[ 0xA0, 0x0E, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -61,8 +59,7 @@ pub(crate) const LUT_BW: [u8; 42] =[ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ]; -#[allow(dead_code)] -#[cfg(feature = "epd4in2_fast_update")] + pub(crate) const LUT_BW_QUICK: [u8; 42] =[ 0xA0, 0x0E, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -84,8 +81,7 @@ pub(crate) const LUT_BB: [u8; 42] =[ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ]; -#[allow(dead_code)] -#[cfg(feature = "epd4in2_fast_update")] + pub(crate) const LUT_BB_QUICK: [u8; 42] =[ 0x50, 0x0E, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -107,8 +103,7 @@ pub(crate) const LUT_WB: [u8; 42] =[ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ]; -#[allow(dead_code)] -#[cfg(feature = "epd4in2_fast_update")] + pub(crate) const LUT_WB_QUICK: [u8; 42] =[ 0x50, 0x0E, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, diff --git a/src/epd4in2/mod.rs b/src/epd4in2/mod.rs index f45869d..db4e244 100644 --- a/src/epd4in2/mod.rs +++ b/src/epd4in2/mod.rs @@ -51,11 +51,11 @@ use hal::{ digital::*, }; -use traits::{WaveshareDisplay, InternalWiAdditions}; +use traits::{WaveshareDisplay, InternalWiAdditions, RefreshLUT}; use interface::DisplayInterface; //The Lookup Tables for the Display -pub(crate) mod constants; //TODO: Limit to crate::drawing +mod constants; //TODO: Limit to crate::drawing pub use self::constants::*; use color::Color; @@ -74,6 +74,8 @@ pub struct EPD4in2 { interface: DisplayInterface, /// Background Color color: Color, + /// Refresh LUT + refresh: RefreshLUT, } @@ -113,7 +115,7 @@ where // 3A 100HZ 29 150Hz 39 200HZ 31 171HZ DEFAULT: 3c 50Hz self.cmd_with_data(spi, Command::PLL_CONTROL, &[0x3A])?; - self.set_lut(spi)?; + self.set_lut(spi, None)?; Ok(()) } @@ -151,6 +153,7 @@ where let mut epd = EPD4in2 { interface, color, + refresh: RefreshLUT::FULL }; epd.init(spi, delay)?; @@ -270,7 +273,6 @@ where ) } - /// Sets the backgroundcolor for various commands like [WaveshareInterface::clear_frame()](clear_frame()) fn set_background_color(&mut self, color: Color) { self.color = color; } @@ -286,6 +288,27 @@ where fn height(&self) -> u32 { HEIGHT } + + fn set_lut(&mut self, spi: &mut SPI, refresh_rate: Option) -> Result<(), SPI::Error> { + if let Some(refresh_lut) = refresh_rate { + self.refresh = refresh_lut; + } + match self.refresh { + RefreshLUT::FULL => { + self.set_lut_helper(spi, &LUT_VCOM0, &LUT_WW, &LUT_BW, &LUT_WB, &LUT_BB) + }, + RefreshLUT::QUICK => { + self.set_lut_helper( + spi, + &LUT_VCOM0_QUICK, + &LUT_WW_QUICK, + &LUT_BW_QUICK, + &LUT_WB_QUICK, + &LUT_BB_QUICK, + ) + } + } + } } impl EPD4in2 @@ -323,28 +346,6 @@ where self.send_data(spi, &[h as u8]) } - /// Fill the look-up table for the EPD for a full refresh (slower) - pub fn set_lut(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { - self.set_lut_helper(spi, &LUT_VCOM0, &LUT_WW, &LUT_BW, &LUT_WB, &LUT_BB) - } - - /// Fill the look-up table for a quick refresh (partial refresh) - /// - /// WARNING: Might lead to ghosting-effects - #[allow(dead_code)] - #[deprecated(note = "Might lead to ghosting-effects/problems with your display. Use set_lut instead!")] - #[cfg(feature = "epd4in2_fast_update")] - pub fn set_lut_quick(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { - self.set_lut_helper( - spi, - &LUT_VCOM0_QUICK, - &LUT_WW_QUICK, - &LUT_BW_QUICK, - &LUT_WB_QUICK, - &LUT_BB_QUICK, - ) - } - fn set_lut_helper( &mut self, spi: &mut SPI, diff --git a/src/graphics.rs b/src/graphics.rs index 5f42e6a..5a50d1a 100644 --- a/src/graphics.rs +++ b/src/graphics.rs @@ -139,7 +139,7 @@ mod tests { #[test] fn buffer_clear() { - use epd4in2::constants::{WIDTH, HEIGHT}; + use epd4in2::{WIDTH, HEIGHT}; let mut buffer = [Color::Black.get_byte_value(); WIDTH as usize / 8 * HEIGHT as usize]; let mut display = Display::new(WIDTH, HEIGHT, &mut buffer); @@ -158,7 +158,7 @@ mod tests { #[test] fn rotation_overflow() { - use epd4in2::constants::{WIDTH, HEIGHT}; + use epd4in2::{WIDTH, HEIGHT}; let width = WIDTH as u32; let height = HEIGHT as u32; test_rotation_overflow(width, height, DisplayRotation::Rotate0); diff --git a/src/interface.rs b/src/interface.rs index dd8a5da..ed3bfc4 100644 --- a/src/interface.rs +++ b/src/interface.rs @@ -42,8 +42,6 @@ where /// Basic function for sending [Commands](Command). /// /// Enables direct interaction with the device with the help of [data()](DisplayInterface::data()) - /// - /// //TODO: make public? pub(crate) fn cmd(&mut self, spi: &mut SPI, command: T) -> Result<(), SPI::Error> { // low for commands self.dc.set_low(); @@ -55,8 +53,6 @@ where /// Basic function for sending an array of u8-values of data over spi /// /// Enables direct interaction with the device with the help of [command()](EPD4in2::command()) - /// - /// //TODO: make public? pub(crate) fn data(&mut self, spi: &mut SPI, data: &[u8]) -> Result<(), SPI::Error> { // high for data self.dc.set_high(); @@ -67,7 +63,6 @@ where /// Basic function for sending [Commands](Command) and the data belonging to it. /// - /// //TODO: make public? /// TODO: directly use ::write? cs wouldn't needed to be changed twice than pub(crate) fn cmd_with_data(&mut self, spi: &mut SPI, command: T, data: &[u8]) -> Result<(), SPI::Error> { self.cmd(spi, command)?; @@ -78,8 +73,6 @@ where /// Basic function for sending the same byte of data (one u8) multiple times over spi /// /// Enables direct interaction with the device with the help of [command()](ConnectionInterface::command()) - /// - /// //TODO: make public? pub(crate) fn data_x_times( &mut self, spi: &mut SPI, diff --git a/src/lib.rs b/src/lib.rs index 1d5ea1f..36a4a04 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -67,7 +67,7 @@ pub mod epd2in9; pub(crate) mod type_a; pub mod prelude { - pub use traits::{WaveshareDisplay}; + pub use traits::{WaveshareDisplay, RefreshLUT}; pub use color::Color; pub use SPI_MODE; } diff --git a/src/traits.rs b/src/traits.rs index fb395e9..86dc1c2 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -12,12 +12,19 @@ pub(crate) trait Command { fn address(self) -> u8; } -// Trait for using various Waveforms from different LUTs -// E.g. for partial updates -trait LUTSupport { - fn set_lut(&mut self) -> Result<(), ERR>; - fn set_lut_quick(&mut self) -> Result<(), ERR>; - fn set_lut_manual(&mut self, data: &[u8]) -> Result<(), ERR>; +/// Seperates the different LUT for the Display Refresh process +pub enum RefreshLUT { + /// The "normal" full Lookuptable for the Refresh-Sequence + FULL, + /// The quick LUT where not the full refresh sequence is followed. + /// This might lead to some + QUICK +} + +impl Default for RefreshLUT { + fn default() -> Self { + RefreshLUT::FULL + } } pub(crate) trait InternalWiAdditions @@ -71,8 +78,7 @@ where fn sleep(&mut self, spi: &mut SPI) -> Result<(), SPI::Error>; /// Wakes the device up from sleep - fn wake_up>(&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()](WaveshareInterface::clear_frame()) fn set_background_color(&mut self, color: Color); @@ -91,7 +97,9 @@ where /// Transmits partial data to the SRAM of the EPD /// - /// BUFFER needs to be of size: w / 8 * h ! + /// (x,y) is the top left corner + /// + /// BUFFER needs to be of size: width / 8 * height ! fn update_partial_frame( &mut self, spi: &mut SPI, @@ -108,4 +116,14 @@ where /// Clears the frame buffer on the EPD with the declared background color /// The background color can be changed with [`set_background_color`] fn clear_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error>; + + /// Trait for using various Waveforms from different LUTs + /// E.g. for partial refreshes + /// + /// A full refresh is needed after a certain amount of quick refreshes! + /// + /// WARNING: Quick Refresh might lead to ghosting-effects/problems with your display. Especially for the 4.2in Display! + /// + /// If None is used the old value will be loaded on the LUTs once more + fn set_lut(&mut self, spi: &mut SPI, refresh_rate: Option) -> Result<(), SPI::Error>; } From e76a2c45f8b8827e3ff4800e60ec2b519f9a20bd Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 30 Oct 2018 15:04:47 +0100 Subject: [PATCH 02/15] Use data_x_times instead of big buffers --- src/epd4in2/mod.rs | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/src/epd4in2/mod.rs b/src/epd4in2/mod.rs index db4e244..0c0c44d 100644 --- a/src/epd4in2/mod.rs +++ b/src/epd4in2/mod.rs @@ -190,8 +190,8 @@ where //VBDF 17|D7 VBDW 97 VBDB 57 VBDF F7 VBDW 77 VBDB 37 VBDR B7 self.interface.cmd_with_data(spi, Command::VCOM_AND_DATA_INTERVAL_SETTING, &[0x97])?; - //TODO: compare with using a loop instead of the full buffer - self.interface.cmd_with_data(spi, Command::DATA_START_TRANSMISSION_1, &[color_value; WIDTH as usize / 8 * HEIGHT as usize])?; + self.interface.cmd(spi, Command::DATA_START_TRANSMISSION_1)?; + self.interface.data_x_times(spi, color_value, WIDTH / 8 * HEIGHT)?; self.interface.cmd_with_data(spi, Command::DATA_START_TRANSMISSION_2, buffer) } @@ -230,7 +230,7 @@ where //TODO: handle dtm somehow let is_dtm1 = false; if is_dtm1 { - self.command(spi, Command::DATA_START_TRANSMISSION_1)? + self.command(spi, Command::DATA_START_TRANSMISSION_1)? //TODO: check if data_start transmission 1 also needs "old"/background data here } else { self.command(spi, Command::DATA_START_TRANSMISSION_2)? } @@ -252,25 +252,16 @@ where fn clear_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { self.send_resolution(spi)?; - //let size = WIDTH as usize / 8 * HEIGHT as usize; let color_value = self.color.get_byte_value(); - //TODO: this is using a big buffer atm, is it better to just loop over sending a single byte? - self.interface.cmd_with_data( - spi, - Command::DATA_START_TRANSMISSION_1, - &[color_value; WIDTH as usize / 8 * HEIGHT as usize] - )?; + self.interface.cmd(spi, Command::DATA_START_TRANSMISSION_1)?; + self.interface.data_x_times(spi, color_value, WIDTH / 8 * HEIGHT)?; //TODO: Removal of delay. TEST! //self.delay_ms(2); - //TODO: this is using a big buffer atm, is it better to just loop over sending a single byte? - self.interface.cmd_with_data( - spi, - Command::DATA_START_TRANSMISSION_2, - &[color_value; WIDTH as usize / 8 * HEIGHT as usize] - ) + self.interface.cmd(spi, Command::DATA_START_TRANSMISSION_2)?; + self.interface.data_x_times(spi, color_value, WIDTH / 8 * HEIGHT) } fn set_background_color(&mut self, color: Color) { From 4931c7aeb30304cf277757ee9a2b6dc3d56ab3a6 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 30 Oct 2018 15:25:48 +0100 Subject: [PATCH 03/15] - Renaming to epd-waveshare - added changelog --- CHANGELOG.md | 29 ++++++++++++++++++++ Cargo.toml | 14 +++++----- README.md | 2 +- examples/embedded_linux_epd1in54/Cargo.toml | 2 +- examples/embedded_linux_epd1in54/src/main.rs | 4 +-- examples/embedded_linux_epd2in9/Cargo.toml | 2 +- examples/embedded_linux_epd2in9/src/main.rs | 4 +-- examples/embedded_linux_epd4in2/Cargo.toml | 2 +- examples/embedded_linux_epd4in2/src/main.rs | 4 +-- 9 files changed, 46 insertions(+), 17 deletions(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..e9ab6ad --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,29 @@ +# Change Log + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](http://keepachangelog.com/) +and this project adheres to [Semantic Versioning](http://semver.org/). + +## [Unreleased] + + + +## v0.2.0 - 2018-10-30 + +Initial release with Changelog + +### Added +- Uses embedded-graphics now +- Tested and fixed 1.54 inch, 2.9 inch and 4.2 inch display + +### Removed +- Old included Graphics Library + +### Changed +- Lots of internal changes +- Renamed to `epd-waveshare` + + +[Unreleased]: https://github.com/Caemor/eink-waveshare-rs/compare/v0.2.0...HEAD +[v0.2.1]: https://github.com/Caemor/eink-waveshare-rs/compare/v0.2.0...v0.2.1 diff --git a/Cargo.toml b/Cargo.toml index a384076..abab777 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,19 +2,19 @@ authors = ["Christoph Groß "] categories = ["embedded", "hardware-support", "no-std"] description = "An embedded-hal based driver for ePaper displays from Waveshare" -documentation = "https://docs.rs/eink-waveshare-rs" -homepage = "https://github.com/Caemor/eink-waveshare-rs" -keywords = ["ePaper", "Display"] +documentation = "https://docs.rs/epd_waveshare" +homepage = "https://github.com/Caemor/epd_waveshare" +keywords = ["ePaper", "Display", "epd"] license = "ISC" -name = "eink_waveshare_rs" +name = "epd_waveshare" readme = "README.md" -repository = "https://github.com/Caemor/eink-waveshare-rs.git" -version = "0.1.2" +repository = "https://github.com/Caemor/epd_waveshare.git" +version = "0.2.0" [badges] # Travis CI: `repository` in format "/" is required. # `branch` is optional; default is `master` -travis-ci = { repository = "Caemor/eink-waveshare-rs" } +travis-ci = { repository = "Caemor/epd_waveshare" } [features] diff --git a/README.md b/README.md index 5762069..14ad145 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# eink-waveshare-rs [![Build Status](https://travis-ci.com/Caemor/eink-waveshare-rs.svg?branch=master)](https://travis-ci.com/Caemor/eink-waveshare-rs) +[![Build Status](https://travis-ci.com/Caemor/eink-waveshare-rs.svg?branch=master)](https://travis-ci.com/Caemor/eink-waveshare-rs) This library contains a driver for E-Paper Modules from Waveshare. diff --git a/examples/embedded_linux_epd1in54/Cargo.toml b/examples/embedded_linux_epd1in54/Cargo.toml index caa16fa..2d0eeeb 100644 --- a/examples/embedded_linux_epd1in54/Cargo.toml +++ b/examples/embedded_linux_epd1in54/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Christoph Groß "] [dependencies] -eink_waveshare_rs = { path = "../../", default-features = false, features = ["epd1in54", "graphics"]} +epd_waveshare = { path = "../../", default-features = false, features = ["epd1in54", "graphics"]} linux-embedded-hal = "0.2.1" diff --git a/examples/embedded_linux_epd1in54/src/main.rs b/examples/embedded_linux_epd1in54/src/main.rs index 7d9e5b1..d369c87 100644 --- a/examples/embedded_linux_epd1in54/src/main.rs +++ b/examples/embedded_linux_epd1in54/src/main.rs @@ -6,8 +6,8 @@ use lin_hal::sysfs_gpio::Direction; use lin_hal::Delay; // the eink library -extern crate eink_waveshare_rs; -use eink_waveshare_rs::{ +extern crate epd_waveshare; +use epd_waveshare::{ epd1in54::{ EPD1in54, Buffer1in54, diff --git a/examples/embedded_linux_epd2in9/Cargo.toml b/examples/embedded_linux_epd2in9/Cargo.toml index 6286d56..262c965 100644 --- a/examples/embedded_linux_epd2in9/Cargo.toml +++ b/examples/embedded_linux_epd2in9/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Christoph Groß "] [dependencies] -eink_waveshare_rs = { path = "../../", default-features = false, features = ["epd2in9", "graphics"]} +epd_waveshare = { path = "../../", default-features = false, features = ["epd2in9", "graphics"]} linux-embedded-hal = "0.2.1" diff --git a/examples/embedded_linux_epd2in9/src/main.rs b/examples/embedded_linux_epd2in9/src/main.rs index 5288fd4..eca408e 100644 --- a/examples/embedded_linux_epd2in9/src/main.rs +++ b/examples/embedded_linux_epd2in9/src/main.rs @@ -6,8 +6,8 @@ use lin_hal::sysfs_gpio::Direction; use lin_hal::Delay; // the eink library -extern crate eink_waveshare_rs; -use eink_waveshare_rs::{ +extern crate epd_waveshare; +use epd_waveshare::{ epd2in9::{ EPD2in9, Buffer2in9, diff --git a/examples/embedded_linux_epd4in2/Cargo.toml b/examples/embedded_linux_epd4in2/Cargo.toml index e37a444..066bfcd 100644 --- a/examples/embedded_linux_epd4in2/Cargo.toml +++ b/examples/embedded_linux_epd4in2/Cargo.toml @@ -7,7 +7,7 @@ authors = ["Christoph Groß "] ## The Only difference between this one and the one without default features sizewise seems to be a different .d-file Size (dependencies-file) #eink_waveshare_rs = { path = "../../"} -eink_waveshare_rs = { path = "../../", default-features = false, features = ["epd4in2", "graphics"]} +epd_waveshare = { path = "../../", default-features = false, features = ["epd4in2", "graphics"]} linux-embedded-hal = "0.2.1" diff --git a/examples/embedded_linux_epd4in2/src/main.rs b/examples/embedded_linux_epd4in2/src/main.rs index 967f518..48df7d3 100644 --- a/examples/embedded_linux_epd4in2/src/main.rs +++ b/examples/embedded_linux_epd4in2/src/main.rs @@ -6,8 +6,8 @@ use lin_hal::sysfs_gpio::Direction; use lin_hal::Delay; // the eink library -extern crate eink_waveshare_rs; -use eink_waveshare_rs::{ +extern crate epd_waveshare; +use epd_waveshare::{ epd4in2::{ EPD4in2, Buffer4in2, From 375adf4bff8d15a45dd19ee82474b8ebaac44804 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 30 Oct 2018 15:28:34 +0100 Subject: [PATCH 04/15] Use `data_x_times` instead of big u8-slice --- src/epd2in9/mod.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/epd2in9/mod.rs b/src/epd2in9/mod.rs index 0383bd4..6dedc53 100644 --- a/src/epd2in9/mod.rs +++ b/src/epd2in9/mod.rs @@ -200,11 +200,8 @@ where let color = self.background_color.get_byte_value(); //TODO: this is using a big buffer atm, is it better to just loop over sending a single byte? - self.interface.cmd_with_data( - spi, - Command::WRITE_RAM, - &[color; WIDTH as usize / 8 * HEIGHT as usize] - ) + self.interface.cmd(spi, Command::WRITE_RAM)?; + self.interface.data_x_times(spi, color, WIDTH / 8 * HEIGHT) } fn set_background_color(&mut self, background_color: Color) { From e518265273c8252cc9c04faebdc5c871bb2ead91 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 5 Nov 2018 15:31:52 +0100 Subject: [PATCH 05/15] Run cargo fmt (reverted for constants and some graphic calculations) --- src/color.rs | 14 ++-- src/epd1in54/graphics.rs | 35 ++++----- src/epd1in54/mod.rs | 141 +++++++++++++++++++++--------------- src/epd2in9/graphics.rs | 17 ++--- src/epd2in9/mod.rs | 119 ++++++++++++++++++++----------- src/epd4in2/constants.rs | 2 - src/epd4in2/graphics.rs | 59 +++++++++------- src/epd4in2/mod.rs | 149 +++++++++++++++++++++------------------ src/graphics.rs | 32 ++++----- src/interface.rs | 26 +++---- src/lib.rs | 3 +- src/traits.rs | 51 +++++++++----- src/type_a/constants.rs | 2 +- src/type_a/mod.rs | 2 +- 14 files changed, 365 insertions(+), 287 deletions(-) diff --git a/src/color.rs b/src/color.rs index 8c2ab0e..e9223de 100644 --- a/src/color.rs +++ b/src/color.rs @@ -1,6 +1,5 @@ //! B/W Color for EPDs - /// Only for the Black/White-Displays #[derive(Clone, Copy, PartialEq, Debug)] pub enum Color { @@ -34,12 +33,15 @@ impl Color { match val { 0 => Color::Black, 1 => Color::White, - e => panic!("DisplayColor only parses 0 and 1 (Black and White) and not `{}`", e), + e => panic!( + "DisplayColor only parses 0 and 1 (Black and White) and not `{}`", + e + ), } } - /// Returns the inverse of the given color. - /// + /// Returns the inverse of the given color. + /// /// Black returns White and White returns Black pub fn inverse(self) -> Color { match self { @@ -60,8 +62,6 @@ impl From for Color { } } - - #[cfg(test)] mod tests { use super::*; @@ -79,7 +79,7 @@ mod tests { extern crate std; let result = std::panic::catch_unwind(|| Color::from(val)); assert!(result.is_err()); - } + } } #[test] diff --git a/src/epd1in54/graphics.rs b/src/epd1in54/graphics.rs index 1a9d620..b787574 100644 --- a/src/epd1in54/graphics.rs +++ b/src/epd1in54/graphics.rs @@ -1,9 +1,9 @@ -use epd1in54::{DEFAULT_BACKGROUND_COLOR, WIDTH, HEIGHT}; +use epd1in54::{DEFAULT_BACKGROUND_COLOR, HEIGHT, WIDTH}; /// Full size buffer for use with the 1in54 EPD -/// +/// /// Can also be manuall constructed: -/// `buffer: [DEFAULT_BACKGROUND_COLOR.get_byte_value(); WIDTH / 8 * HEIGHT]` +/// `buffer: [DEFAULT_BACKGROUND_COLOR.get_byte_value(); WIDTH / 8 * HEIGHT]` pub struct Buffer1in54BlackWhite { pub buffer: [u8; WIDTH as usize * HEIGHT as usize / 8], } @@ -11,23 +11,20 @@ pub struct Buffer1in54BlackWhite { impl Default for Buffer1in54BlackWhite { fn default() -> Self { Buffer1in54BlackWhite { - buffer: [ - DEFAULT_BACKGROUND_COLOR.get_byte_value(); - WIDTH as usize * HEIGHT as usize / 8 - ] + buffer: [DEFAULT_BACKGROUND_COLOR.get_byte_value(); + WIDTH as usize * HEIGHT as usize / 8], } - } + } } - #[cfg(test)] mod tests { use super::*; - use graphics::{DisplayRotation, Display}; - use embedded_graphics::coord::Coord; - use embedded_graphics::primitives::Line; use color::Color; + use embedded_graphics::coord::Coord; use embedded_graphics::prelude::*; + use embedded_graphics::primitives::Line; + use graphics::{Display, DisplayRotation}; // test buffer length #[test] @@ -36,7 +33,7 @@ mod tests { let display = Display::new(WIDTH, HEIGHT, &mut display1in54.buffer); assert_eq!(display.buffer().len(), 5000); } - + // test default background color on all bytes #[test] fn graphics_default() { @@ -56,7 +53,7 @@ mod tests { .with_stroke(Some(Color::Black)) .into_iter(), ); - + let buffer = display.buffer(); assert_eq!(buffer[0], Color::Black.get_byte_value()); @@ -76,7 +73,7 @@ mod tests { .with_stroke(Some(Color::Black)) .into_iter(), ); - + let buffer = display.buffer(); assert_eq!(buffer[0], Color::Black.get_byte_value()); @@ -96,7 +93,7 @@ mod tests { .with_stroke(Some(Color::Black)) .into_iter(), ); - + let buffer = display.buffer(); extern crate std; @@ -107,7 +104,6 @@ mod tests { for &byte in buffer.iter().skip(1) { assert_eq!(byte, DEFAULT_BACKGROUND_COLOR.get_byte_value()); } - } #[test] @@ -120,7 +116,7 @@ mod tests { .with_stroke(Some(Color::Black)) .into_iter(), ); - + let buffer = display.buffer(); extern crate std; @@ -131,6 +127,5 @@ mod tests { for &byte in buffer.iter().skip(1) { assert_eq!(byte, DEFAULT_BACKGROUND_COLOR.get_byte_value()); } - } -} \ No newline at end of file +} diff --git a/src/epd1in54/mod.rs b/src/epd1in54/mod.rs index 6ea0ab1..9f8aaa1 100644 --- a/src/epd1in54/mod.rs +++ b/src/epd1in54/mod.rs @@ -1,21 +1,21 @@ //! A simple Driver for the Waveshare 1.54" E-Ink Display via SPI -//! +//! //! # Example for the 1.54 in E-Ink Display -//! +//! //! ```ignore //! use eink_waveshare_rs::{ //! epd1in54::{EPD1in54, Buffer1in54}, //! graphics::{Display, DisplayRotation}, //! prelude::*, -//! }; -//! +//! }; +//! //! // Setup EPD //! let mut epd = EPD1in54::new(&mut spi, cs_pin, busy_in, dc, rst, &mut delay)?; //! //! // Use display graphics //! let mut buffer = Buffer1in54::default(); //! let mut display = Display::new(epd.width(), epd.height(), &mut buffer.buffer); -//! +//! //! // Write some hello world in the screenbuffer //! display.draw( //! Font6x8::render_str("Hello World!") @@ -28,7 +28,7 @@ //! // Display updated frame //! epd.update_frame(&mut spi, &display.buffer()).unwrap(); //! epd.display_frame(&mut spi).expect("display frame new graphics"); -//! +//! //! // Set the EPD to sleep //! epd.sleep(&mut spi).expect("sleep"); //! ``` @@ -44,13 +44,13 @@ use hal::{ }; use type_a::{ - command::Command, - constants::{LUT_FULL_UPDATE, LUT_PARTIAL_UPDATE} + command::Command, + constants::{LUT_FULL_UPDATE, LUT_PARTIAL_UPDATE}, }; use color::Color; -use traits::{WaveshareDisplay, RefreshLUT}; +use traits::{RefreshLUT, WaveshareDisplay}; use interface::DisplayInterface; @@ -76,7 +76,11 @@ where DC: OutputPin, RST: OutputPin, { - fn init>(&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); // 3 Databytes: @@ -85,9 +89,9 @@ where // 0.. B[2:0] // Default Values: A = Height of Screen (0x127), B = 0x00 (GD, SM and TB=0?) self.interface.cmd_with_data( - spi, - Command::DRIVER_OUTPUT_CONTROL, - &[HEIGHT as u8, (HEIGHT >> 8) as u8, 0x00] + spi, + Command::DRIVER_OUTPUT_CONTROL, + &[HEIGHT as u8, (HEIGHT >> 8) as u8, 0x00], )?; // 3 Databytes: (and default values from datasheet and arduino) @@ -95,24 +99,31 @@ where // 1 .. B[6:0] = 0xCE | 0xD6 // 1 .. C[6:0] = 0x8D | 0x9D //TODO: test - self.interface.cmd_with_data(spi, Command::BOOSTER_SOFT_START_CONTROL, &[0xD7, 0xD6, 0x9D])?; + self.interface.cmd_with_data( + spi, + Command::BOOSTER_SOFT_START_CONTROL, + &[0xD7, 0xD6, 0x9D], + )?; // One Databyte with value 0xA8 for 7V VCOM - self.interface.cmd_with_data(spi, Command::WRITE_VCOM_REGISTER, &[0xA8])?; + self.interface + .cmd_with_data(spi, Command::WRITE_VCOM_REGISTER, &[0xA8])?; // One Databyte with default value 0x1A for 4 dummy lines per gate - self.interface.cmd_with_data(spi, Command::SET_DUMMY_LINE_PERIOD, &[0x1A])?; + self.interface + .cmd_with_data(spi, Command::SET_DUMMY_LINE_PERIOD, &[0x1A])?; // One Databyte with default value 0x08 for 2us per line - self.interface.cmd_with_data(spi, Command::SET_GATE_LINE_WIDTH, &[0x08])?; + self.interface + .cmd_with_data(spi, Command::SET_GATE_LINE_WIDTH, &[0x08])?; // One Databyte with default value 0x03 // -> address: x increment, y increment, address counter is updated in x direction - self.interface.cmd_with_data(spi, Command::DATA_ENTRY_MODE_SETTING, &[0x03])?; + self.interface + .cmd_with_data(spi, Command::DATA_ENTRY_MODE_SETTING, &[0x03])?; self.set_lut(spi, None) } - } impl WaveshareDisplay @@ -133,14 +144,19 @@ where } fn new>( - spi: &mut SPI, cs: CS, busy: BUSY, dc: DC, rst: RST, delay: &mut DELAY, + spi: &mut SPI, + cs: CS, + busy: BUSY, + dc: DC, + rst: RST, + delay: &mut DELAY, ) -> Result { let interface = DisplayInterface::new(cs, busy, dc, rst); - + let mut epd = EPD1in54 { interface, background_color: DEFAULT_BACKGROUND_COLOR, - refresh: RefreshLUT::FULL + refresh: RefreshLUT::FULL, }; epd.init(spi, delay)?; @@ -148,16 +164,19 @@ where Ok(epd) } - fn wake_up>(&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> { // 0x00 for Normal mode (Power on Reset), 0x01 for Deep Sleep Mode //TODO: is 0x00 needed here or would 0x01 be even more efficient? - self.interface.cmd_with_data(spi, Command::DEEP_SLEEP_MODE, &[0x00])?; + self.interface + .cmd_with_data(spi, Command::DEEP_SLEEP_MODE, &[0x00])?; self.wait_until_idle(); Ok(()) @@ -165,7 +184,8 @@ where fn update_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> { self.use_full_frame(spi)?; - self.interface.cmd_with_data(spi, Command::WRITE_RAM, buffer) + self.interface + .cmd_with_data(spi, Command::WRITE_RAM, buffer) } //TODO: update description: last 3 bits will be ignored for width and x_pos @@ -181,13 +201,15 @@ where self.set_ram_area(spi, x, y, x + width, y + height)?; self.set_ram_counter(spi, x, y)?; - self.interface.cmd_with_data(spi, Command::WRITE_RAM, buffer) + self.interface + .cmd_with_data(spi, Command::WRITE_RAM, buffer) } fn display_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { // 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) - self.interface.cmd_with_data(spi, Command::DISPLAY_UPDATE_CONTROL_2, &[0xC4])?; + self.interface + .cmd_with_data(spi, Command::DISPLAY_UPDATE_CONTROL_2, &[0xC4])?; self.interface.cmd(spi, Command::MASTER_ACTIVATION)?; // MASTER Activation should not be interupted to avoid currption of panel images @@ -202,34 +224,29 @@ where let color = self.background_color.get_byte_value(); //TODO: this is using a big buffer atm, is it better to just loop over sending a single byte? - self.interface.cmd( - spi, - Command::WRITE_RAM - )?; + self.interface.cmd(spi, Command::WRITE_RAM)?; self.interface.data_x_times(spi, color, WIDTH / 8 * HEIGHT) } - 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, refresh_rate: Option) -> Result<(), SPI::Error> { + fn set_lut( + &mut self, + spi: &mut SPI, + refresh_rate: Option, + ) -> Result<(), SPI::Error> { if let Some(refresh_lut) = refresh_rate { self.refresh = refresh_lut; } match self.refresh { - RefreshLUT::FULL => { - self.set_lut_helper(spi, &LUT_FULL_UPDATE) - }, - RefreshLUT::QUICK => { - self.set_lut_helper(spi, &LUT_PARTIAL_UPDATE) - } + RefreshLUT::FULL => self.set_lut_helper(spi, &LUT_FULL_UPDATE), + RefreshLUT::QUICK => self.set_lut_helper(spi, &LUT_PARTIAL_UPDATE), } } } @@ -240,7 +257,7 @@ where CS: OutputPin, BUSY: InputPin, DC: OutputPin, - RST: OutputPin + RST: OutputPin, { fn wait_until_idle(&mut self) { self.interface.wait_until_idle(false); @@ -255,7 +272,7 @@ where } pub(crate) fn set_ram_area( - &mut self, + &mut self, spi: &mut SPI, start_x: u32, start_y: u32, @@ -270,30 +287,39 @@ where self.interface.cmd_with_data( spi, Command::SET_RAM_X_ADDRESS_START_END_POSITION, - &[(start_x >> 3) as u8, (end_x >> 3) as u8] + &[(start_x >> 3) as u8, (end_x >> 3) as u8], )?; // 2 Databytes: A[7:0] & 0..A[8] for each - start and end self.interface.cmd_with_data( - spi, + spi, Command::SET_RAM_Y_ADDRESS_START_END_POSITION, - &[start_y as u8, (start_y >> 8) as u8, end_y as u8, (end_y >> 8) as u8] + &[ + start_y as u8, + (start_y >> 8) as u8, + end_y as u8, + (end_y >> 8) as u8, + ], ) } - pub(crate) fn set_ram_counter(&mut self, spi: &mut SPI, x: u32, y: u32) -> Result<(), SPI::Error> { + pub(crate) fn set_ram_counter( + &mut self, + spi: &mut SPI, + x: u32, + y: u32, + ) -> Result<(), SPI::Error> { // x is positioned in bytes, so the last 3 bits which show the position inside a byte in the ram // aren't relevant - self.interface.cmd_with_data(spi, Command::SET_RAM_X_ADDRESS_COUNTER, &[(x >> 3) as u8])?; + self.interface + .cmd_with_data(spi, Command::SET_RAM_X_ADDRESS_COUNTER, &[(x >> 3) as u8])?; // 2 Databytes: A[7:0] & 0..A[8] self.interface.cmd_with_data( - spi, - Command::SET_RAM_Y_ADDRESS_COUNTER, - &[ - y as u8, - (y >> 8) as u8 - ])?; + spi, + Command::SET_RAM_Y_ADDRESS_COUNTER, + &[y as u8, (y >> 8) as u8], + )?; self.wait_until_idle(); Ok(()) @@ -301,7 +327,8 @@ where fn set_lut_helper(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> { assert!(buffer.len() == 30); - self.interface.cmd_with_data(spi, Command::WRITE_LUT_REGISTER, buffer) + self.interface + .cmd_with_data(spi, Command::WRITE_LUT_REGISTER, buffer) } } @@ -315,4 +342,4 @@ mod tests { assert_eq!(HEIGHT, 200); assert_eq!(DEFAULT_BACKGROUND_COLOR, Color::White); } -} \ No newline at end of file +} diff --git a/src/epd2in9/graphics.rs b/src/epd2in9/graphics.rs index 2e6c31d..044338a 100644 --- a/src/epd2in9/graphics.rs +++ b/src/epd2in9/graphics.rs @@ -1,9 +1,9 @@ -use epd2in9::{DEFAULT_BACKGROUND_COLOR, WIDTH, HEIGHT}; +use epd2in9::{DEFAULT_BACKGROUND_COLOR, HEIGHT, WIDTH}; /// Full size buffer for use with the 2in9 EPD -/// +/// /// Can also be manuall constructed: -/// `buffer: [DEFAULT_BACKGROUND_COLOR.get_byte_value(); WIDTH / 8 * HEIGHT]` +/// `buffer: [DEFAULT_BACKGROUND_COLOR.get_byte_value(); WIDTH / 8 * HEIGHT]` pub struct Buffer2in9 { pub buffer: [u8; WIDTH as usize * HEIGHT as usize / 8], } @@ -11,15 +11,12 @@ pub struct Buffer2in9 { impl Default for Buffer2in9 { fn default() -> Self { Buffer2in9 { - buffer: [ - DEFAULT_BACKGROUND_COLOR.get_byte_value(); - WIDTH as usize * HEIGHT as usize / 8 - ] + buffer: [DEFAULT_BACKGROUND_COLOR.get_byte_value(); + WIDTH as usize * HEIGHT as usize / 8], } } } - #[cfg(test)] mod tests { use super::*; @@ -32,7 +29,7 @@ mod tests { let display = Display::new(WIDTH, HEIGHT, &mut buffer.buffer); assert_eq!(display.buffer().len(), 4736); } - + // test default background color on all bytes #[test] fn graphics_default() { @@ -42,4 +39,4 @@ mod tests { assert_eq!(byte, DEFAULT_BACKGROUND_COLOR.get_byte_value()); } } -} \ No newline at end of file +} diff --git a/src/epd2in9/mod.rs b/src/epd2in9/mod.rs index 6dedc53..920ca5d 100644 --- a/src/epd2in9/mod.rs +++ b/src/epd2in9/mod.rs @@ -3,21 +3,21 @@ //! Untested! //! //! # Example for the 2.9 in E-Ink Display -//! +//! //! ```ignore //! use eink_waveshare_rs::{ //! epd2in9::{EPD2in9, Buffer2in9}, //! graphics::{Display, DisplayRotation}, //! prelude::*, -//! }; -//! +//! }; +//! //! // Setup EPD //! let mut epd = EPD2in9::new(&mut spi, cs_pin, busy_in, dc, rst, &mut delay)?; //! //! // Use display graphics //! let mut buffer = Buffer2in9::default(); //! let mut display = Display::new(epd.width(), epd.height(), &mut buffer.buffer); -//! +//! //! // Write some hello world in the screenbuffer //! display.draw( //! Font6x8::render_str("Hello World!") @@ -30,7 +30,7 @@ //! // Display updated frame //! epd.update_frame(&mut spi, &display.buffer()).unwrap(); //! epd.display_frame(&mut spi).expect("display frame new graphics"); -//! +//! //! // Set the EPD to sleep //! epd.sleep(&mut spi).expect("sleep"); //! ``` @@ -45,8 +45,8 @@ use hal::{ }; use type_a::{ - command::Command, - constants::{LUT_FULL_UPDATE, LUT_PARTIAL_UPDATE} + command::Command, + constants::{LUT_FULL_UPDATE, LUT_PARTIAL_UPDATE}, }; use color::Color; @@ -77,7 +77,11 @@ where DC: OutputPin, RST: OutputPin, { - fn init>(&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); // 3 Databytes: @@ -85,34 +89,42 @@ where // 0.. A[8] // 0.. B[2:0] // Default Values: A = Height of Screen (0x127), B = 0x00 (GD, SM and TB=0?) - self.interface.cmd_with_data(spi, Command::DRIVER_OUTPUT_CONTROL, &[0x27, 0x01, 0x00])?; + self.interface + .cmd_with_data(spi, Command::DRIVER_OUTPUT_CONTROL, &[0x27, 0x01, 0x00])?; // 3 Databytes: (and default values from datasheet and arduino) // 1 .. A[6:0] = 0xCF | 0xD7 // 1 .. B[6:0] = 0xCE | 0xD6 // 1 .. C[6:0] = 0x8D | 0x9D //TODO: test - self.interface.cmd_with_data(spi, Command::BOOSTER_SOFT_START_CONTROL, &[0xD7, 0xD6, 0x9D])?; + self.interface.cmd_with_data( + spi, + Command::BOOSTER_SOFT_START_CONTROL, + &[0xD7, 0xD6, 0x9D], + )?; // One Databyte with value 0xA8 for 7V VCOM - self.interface.cmd_with_data(spi, Command::WRITE_VCOM_REGISTER, &[0xA8])?; + self.interface + .cmd_with_data(spi, Command::WRITE_VCOM_REGISTER, &[0xA8])?; // One Databyte with default value 0x1A for 4 dummy lines per gate - self.interface.cmd_with_data(spi, Command::SET_DUMMY_LINE_PERIOD, &[0x1A])?; + self.interface + .cmd_with_data(spi, Command::SET_DUMMY_LINE_PERIOD, &[0x1A])?; // One Databyte with default value 0x08 for 2us per line - self.interface.cmd_with_data(spi, Command::SET_GATE_LINE_WIDTH, &[0x08])?; + self.interface + .cmd_with_data(spi, Command::SET_GATE_LINE_WIDTH, &[0x08])?; // One Databyte with default value 0x03 // -> address: x increment, y increment, address counter is updated in x direction - self.interface.cmd_with_data(spi, Command::DATA_ENTRY_MODE_SETTING, &[0x03])?; + self.interface + .cmd_with_data(spi, Command::DATA_ENTRY_MODE_SETTING, &[0x03])?; self.set_lut(spi, None) } } -impl - WaveshareDisplay +impl WaveshareDisplay for EPD2in9 where SPI: Write, @@ -130,7 +142,12 @@ where } fn new>( - spi: &mut SPI, cs: CS, busy: BUSY, dc: DC, rst: RST, delay: &mut DELAY, + spi: &mut SPI, + cs: CS, + busy: BUSY, + dc: DC, + rst: RST, + delay: &mut DELAY, ) -> Result { let interface = DisplayInterface::new(cs, busy, dc, rst); @@ -145,30 +162,34 @@ where Ok(epd) } - - fn sleep(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { // 0x00 for Normal mode (Power on Reset), 0x01 for Deep Sleep Mode //TODO: is 0x00 needed here? (see also epd1in54) - self.interface.cmd_with_data(spi, Command::DEEP_SLEEP_MODE, &[0x00])?; + self.interface + .cmd_with_data(spi, Command::DEEP_SLEEP_MODE, &[0x00])?; self.wait_until_idle(); Ok(()) } - fn wake_up>(&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 update_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> { self.use_full_frame(spi)?; - self.interface.cmd_with_data(spi, Command::WRITE_RAM, buffer) + self.interface + .cmd_with_data(spi, Command::WRITE_RAM, buffer) } //TODO: update description: last 3 bits will be ignored for width and x_pos fn update_partial_frame( - &mut self, + &mut self, spi: &mut SPI, buffer: &[u8], x: u32, @@ -179,13 +200,15 @@ where self.set_ram_area(spi, x, y, x + width, y + height)?; self.set_ram_counter(spi, x, y)?; - self.interface.cmd_with_data(spi, Command::WRITE_RAM, buffer) + self.interface + .cmd_with_data(spi, Command::WRITE_RAM, buffer) } fn display_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { // 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) - self.interface.cmd_with_data(spi, Command::DISPLAY_UPDATE_CONTROL_2, &[0xC4])?; + self.interface + .cmd_with_data(spi, Command::DISPLAY_UPDATE_CONTROL_2, &[0xC4])?; self.interface.cmd(spi, Command::MASTER_ACTIVATION)?; // MASTER Activation should not be interupted to avoid currption of panel images @@ -212,17 +235,17 @@ where &self.background_color } - fn set_lut(&mut self, spi: &mut SPI, refresh_rate: Option) -> Result<(), SPI::Error> { + fn set_lut( + &mut self, + spi: &mut SPI, + refresh_rate: Option, + ) -> Result<(), SPI::Error> { if let Some(refresh_lut) = refresh_rate { self.refresh = refresh_lut; } match self.refresh { - RefreshLUT::FULL => { - self.set_lut_helper(spi, &LUT_FULL_UPDATE) - }, - RefreshLUT::QUICK => { - self.set_lut_helper(spi, &LUT_PARTIAL_UPDATE) - } + RefreshLUT::FULL => self.set_lut_helper(spi, &LUT_FULL_UPDATE), + RefreshLUT::QUICK => self.set_lut_helper(spi, &LUT_PARTIAL_UPDATE), } } } @@ -248,7 +271,7 @@ where } fn set_ram_area( - &mut self, + &mut self, spi: &mut SPI, start_x: u32, start_y: u32, @@ -262,23 +285,35 @@ where // aren't relevant self.interface.cmd_with_data( spi, - Command::SET_RAM_X_ADDRESS_START_END_POSITION, - &[(start_x >> 3) as u8, (end_x >> 3) as u8] + Command::SET_RAM_X_ADDRESS_START_END_POSITION, + &[(start_x >> 3) as u8, (end_x >> 3) as u8], )?; // 2 Databytes: A[7:0] & 0..A[8] for each - start and end - self.interface.cmd_with_data(spi, Command::SET_RAM_Y_ADDRESS_START_END_POSITION, - &[start_y as u8, (start_y >> 8) as u8, end_y as u8, (end_y >> 8) as u8] + self.interface.cmd_with_data( + spi, + Command::SET_RAM_Y_ADDRESS_START_END_POSITION, + &[ + start_y as u8, + (start_y >> 8) as u8, + end_y as u8, + (end_y >> 8) as u8, + ], ) } fn set_ram_counter(&mut self, spi: &mut SPI, x: u32, y: u32) -> Result<(), SPI::Error> { // x is positioned in bytes, so the last 3 bits which show the position inside a byte in the ram // aren't relevant - self.interface.cmd_with_data(spi, Command::SET_RAM_X_ADDRESS_COUNTER, &[(x >> 3) as u8])?; + self.interface + .cmd_with_data(spi, Command::SET_RAM_X_ADDRESS_COUNTER, &[(x >> 3) as u8])?; // 2 Databytes: A[7:0] & 0..A[8] - self.interface.cmd_with_data(spi, Command::SET_RAM_Y_ADDRESS_COUNTER, &[y as u8, (y >> 8) as u8])?; + self.interface.cmd_with_data( + spi, + Command::SET_RAM_Y_ADDRESS_COUNTER, + &[y as u8, (y >> 8) as u8], + )?; self.wait_until_idle(); Ok(()) @@ -286,11 +321,11 @@ where fn set_lut_helper(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> { assert!(buffer.len() == 30); - self.interface.cmd_with_data(spi, Command::WRITE_LUT_REGISTER, buffer) + self.interface + .cmd_with_data(spi, Command::WRITE_LUT_REGISTER, buffer) } } - #[cfg(test)] mod tests { use super::*; @@ -301,4 +336,4 @@ mod tests { assert_eq!(HEIGHT, 296); assert_eq!(DEFAULT_BACKGROUND_COLOR, Color::White); } -} \ No newline at end of file +} diff --git a/src/epd4in2/constants.rs b/src/epd4in2/constants.rs index e794d5f..f64548c 100644 --- a/src/epd4in2/constants.rs +++ b/src/epd4in2/constants.rs @@ -4,7 +4,6 @@ pub const WIDTH: u32 = 400; pub const HEIGHT: u32 = 300; pub const DEFAULT_BACKGROUND_COLOR: Color = Color::White; - pub(crate) const LUT_VCOM0: [u8; 44] = [ 0x00, 0x17, 0x00, 0x00, 0x00, 0x02, 0x00, 0x17, 0x17, 0x00, 0x00, 0x02, @@ -15,7 +14,6 @@ pub(crate) const LUT_VCOM0: [u8; 44] = [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ]; - pub(crate) const LUT_VCOM0_QUICK: [u8; 44] = [ 0x00, 0x0E, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, diff --git a/src/epd4in2/graphics.rs b/src/epd4in2/graphics.rs index 601459a..da22261 100644 --- a/src/epd4in2/graphics.rs +++ b/src/epd4in2/graphics.rs @@ -1,9 +1,9 @@ -use epd4in2::constants::{DEFAULT_BACKGROUND_COLOR, WIDTH, HEIGHT}; +use epd4in2::constants::{DEFAULT_BACKGROUND_COLOR, HEIGHT, WIDTH}; /// Full size buffer for use with the 4in2 EPD -/// +/// /// Can also be manuall constructed: -/// `buffer: [DEFAULT_BACKGROUND_COLOR.get_byte_value(); WIDTH / 8 * HEIGHT]` +/// `buffer: [DEFAULT_BACKGROUND_COLOR.get_byte_value(); WIDTH / 8 * HEIGHT]` pub struct Buffer4in2 { pub buffer: [u8; WIDTH as usize * HEIGHT as usize / 8], } @@ -11,24 +11,21 @@ pub struct Buffer4in2 { impl Default for Buffer4in2 { fn default() -> Self { Buffer4in2 { - buffer: [ - DEFAULT_BACKGROUND_COLOR.get_byte_value(); - WIDTH as usize * HEIGHT as usize / 8 - ] + buffer: [DEFAULT_BACKGROUND_COLOR.get_byte_value(); + WIDTH as usize * HEIGHT as usize / 8], } } } - #[cfg(test)] mod tests { use super::*; - use epd4in2; - use graphics::{DisplayRotation, Display}; - use embedded_graphics::coord::Coord; - use embedded_graphics::primitives::Line; use color::Color; + use embedded_graphics::coord::Coord; use embedded_graphics::prelude::*; + use embedded_graphics::primitives::Line; + use epd4in2; + use graphics::{Display, DisplayRotation}; // test buffer length #[test] @@ -37,7 +34,7 @@ mod tests { let display = Display::new(WIDTH, HEIGHT, &mut display4in2.buffer); assert_eq!(display.buffer().len(), 15000); } - + // test default background color on all bytes #[test] fn graphics_default() { @@ -45,7 +42,10 @@ mod tests { let display = Display::new(WIDTH, HEIGHT, &mut display4in2.buffer); use epd4in2; for &byte in display.buffer() { - assert_eq!(byte, epd4in2::constants::DEFAULT_BACKGROUND_COLOR.get_byte_value()); + assert_eq!( + byte, + epd4in2::constants::DEFAULT_BACKGROUND_COLOR.get_byte_value() + ); } } @@ -58,13 +58,16 @@ mod tests { .with_stroke(Some(Color::Black)) .into_iter(), ); - + let buffer = display.buffer(); assert_eq!(buffer[0], Color::Black.get_byte_value()); for &byte in buffer.iter().skip(1) { - assert_eq!(byte, epd4in2::constants::DEFAULT_BACKGROUND_COLOR.get_byte_value()); + assert_eq!( + byte, + epd4in2::constants::DEFAULT_BACKGROUND_COLOR.get_byte_value() + ); } } @@ -78,13 +81,16 @@ mod tests { .with_stroke(Some(Color::Black)) .into_iter(), ); - + let buffer = display.buffer(); assert_eq!(buffer[0], Color::Black.get_byte_value()); for &byte in buffer.iter().skip(1) { - assert_eq!(byte, epd4in2::constants::DEFAULT_BACKGROUND_COLOR.get_byte_value()); + assert_eq!( + byte, + epd4in2::constants::DEFAULT_BACKGROUND_COLOR.get_byte_value() + ); } } @@ -98,7 +104,7 @@ mod tests { .with_stroke(Some(Color::Black)) .into_iter(), ); - + let buffer = display.buffer(); extern crate std; @@ -107,9 +113,11 @@ mod tests { assert_eq!(buffer[0], Color::Black.get_byte_value()); for &byte in buffer.iter().skip(1) { - assert_eq!(byte, epd4in2::constants::DEFAULT_BACKGROUND_COLOR.get_byte_value()); + assert_eq!( + byte, + epd4in2::constants::DEFAULT_BACKGROUND_COLOR.get_byte_value() + ); } - } #[test] @@ -122,7 +130,7 @@ mod tests { .with_stroke(Some(Color::Black)) .into_iter(), ); - + let buffer = display.buffer(); extern crate std; @@ -131,9 +139,10 @@ mod tests { assert_eq!(buffer[0], Color::Black.get_byte_value()); for &byte in buffer.iter().skip(1) { - assert_eq!(byte, epd4in2::constants::DEFAULT_BACKGROUND_COLOR.get_byte_value()); + assert_eq!( + byte, + epd4in2::constants::DEFAULT_BACKGROUND_COLOR.get_byte_value() + ); } - } } - diff --git a/src/epd4in2/mod.rs b/src/epd4in2/mod.rs index 0c0c44d..149fa07 100644 --- a/src/epd4in2/mod.rs +++ b/src/epd4in2/mod.rs @@ -51,8 +51,8 @@ use hal::{ digital::*, }; -use traits::{WaveshareDisplay, InternalWiAdditions, RefreshLUT}; use interface::DisplayInterface; +use traits::{InternalWiAdditions, RefreshLUT, WaveshareDisplay}; //The Lookup Tables for the Display mod constants; //TODO: Limit to crate::drawing @@ -66,7 +66,6 @@ use self::command::Command; mod graphics; pub use self::graphics::Buffer4in2; - /// EPD4in2 driver /// pub struct EPD4in2 { @@ -78,11 +77,7 @@ pub struct EPD4in2 { refresh: RefreshLUT, } - - - -impl - InternalWiAdditions +impl InternalWiAdditions for EPD4in2 where SPI: Write, @@ -91,15 +86,24 @@ where DC: OutputPin, RST: OutputPin, { - fn init>(&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); // set the power settings - self.interface.cmd_with_data(spi, Command::POWER_SETTING, &[0x03, 0x00, 0x2b, 0x2b, 0xff])?; + self.interface.cmd_with_data( + spi, + Command::POWER_SETTING, + &[0x03, 0x00, 0x2b, 0x2b, 0xff], + )?; // start the booster - self.interface.cmd_with_data(spi, Command::BOOSTER_SOFT_START, &[0x17, 0x17, 0x17])?; + self.interface + .cmd_with_data(spi, Command::BOOSTER_SOFT_START, &[0x17, 0x17, 0x17])?; // power on self.command(spi, Command::POWER_ON)?; @@ -114,15 +118,14 @@ where // TODO: Test these other frequencies // 3A 100HZ 29 150Hz 39 200HZ 31 171HZ DEFAULT: 3c 50Hz self.cmd_with_data(spi, Command::PLL_CONTROL, &[0x3A])?; - + self.set_lut(spi, None)?; Ok(()) } } -impl - WaveshareDisplay +impl WaveshareDisplay for EPD4in2 where SPI: Write, @@ -146,14 +149,21 @@ where /// /// epd4in2.sleep(); /// ``` - fn new>(spi: &mut SPI, cs: CS, busy: BUSY, dc: DC, rst: RST, delay: &mut DELAY) -> Result { + fn new>( + spi: &mut SPI, + cs: CS, + busy: BUSY, + dc: DC, + rst: RST, + delay: &mut DELAY, + ) -> Result { let interface = DisplayInterface::new(cs, busy, dc, rst); let color = DEFAULT_BACKGROUND_COLOR; let mut epd = EPD4in2 { interface, color, - refresh: RefreshLUT::FULL + refresh: RefreshLUT::FULL, }; epd.init(spi, delay)?; @@ -161,12 +171,17 @@ where Ok(epd) } - fn wake_up>(&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.interface.cmd_with_data(spi, Command::VCOM_AND_DATA_INTERVAL_SETTING, &[0x17])?; //border floating + self.interface + .cmd_with_data(spi, Command::VCOM_AND_DATA_INTERVAL_SETTING, &[0x17])?; //border floating self.command(spi, Command::VCM_DC_SETTING)?; // VCOM to 0V self.command(spi, Command::PANEL_SETTING)?; @@ -177,7 +192,8 @@ where self.command(spi, Command::POWER_OFF)?; self.wait_until_idle(); - self.interface.cmd_with_data(spi, Command::DEEP_SLEEP, &[0xA5]) + self.interface + .cmd_with_data(spi, Command::DEEP_SLEEP, &[0xA5]) } fn update_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> { @@ -185,20 +201,25 @@ where self.send_resolution(spi)?; - self.interface.cmd_with_data(spi, Command::VCM_DC_SETTING, &[0x12])?; + self.interface + .cmd_with_data(spi, Command::VCM_DC_SETTING, &[0x12])?; //VBDF 17|D7 VBDW 97 VBDB 57 VBDF F7 VBDW 77 VBDB 37 VBDR B7 - self.interface.cmd_with_data(spi, Command::VCOM_AND_DATA_INTERVAL_SETTING, &[0x97])?; + self.interface + .cmd_with_data(spi, Command::VCOM_AND_DATA_INTERVAL_SETTING, &[0x97])?; - self.interface.cmd(spi, Command::DATA_START_TRANSMISSION_1)?; - self.interface.data_x_times(spi, color_value, WIDTH / 8 * HEIGHT)?; + self.interface + .cmd(spi, Command::DATA_START_TRANSMISSION_1)?; + self.interface + .data_x_times(spi, color_value, WIDTH / 8 * HEIGHT)?; - self.interface.cmd_with_data(spi, Command::DATA_START_TRANSMISSION_2, buffer) + self.interface + .cmd_with_data(spi, Command::DATA_START_TRANSMISSION_2, buffer) } fn update_partial_frame( - &mut self, - spi: &mut SPI, + &mut self, + spi: &mut SPI, buffer: &[u8], x: u32, y: u32, @@ -240,8 +261,6 @@ where self.command(spi, Command::PARTIAL_OUT) } - - fn display_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { self.command(spi, Command::DISPLAY_REFRESH)?; @@ -254,14 +273,18 @@ where let color_value = self.color.get_byte_value(); - self.interface.cmd(spi, Command::DATA_START_TRANSMISSION_1)?; - self.interface.data_x_times(spi, color_value, WIDTH / 8 * HEIGHT)?; + self.interface + .cmd(spi, Command::DATA_START_TRANSMISSION_1)?; + self.interface + .data_x_times(spi, color_value, WIDTH / 8 * HEIGHT)?; //TODO: Removal of delay. TEST! //self.delay_ms(2); - self.interface.cmd(spi, Command::DATA_START_TRANSMISSION_2)?; - self.interface.data_x_times(spi, color_value, WIDTH / 8 * HEIGHT) + self.interface + .cmd(spi, Command::DATA_START_TRANSMISSION_2)?; + self.interface + .data_x_times(spi, color_value, WIDTH / 8 * HEIGHT) } fn set_background_color(&mut self, color: Color) { @@ -280,24 +303,26 @@ where HEIGHT } - fn set_lut(&mut self, spi: &mut SPI, refresh_rate: Option) -> Result<(), SPI::Error> { + fn set_lut( + &mut self, + spi: &mut SPI, + refresh_rate: Option, + ) -> Result<(), SPI::Error> { if let Some(refresh_lut) = refresh_rate { self.refresh = refresh_lut; } match self.refresh { RefreshLUT::FULL => { self.set_lut_helper(spi, &LUT_VCOM0, &LUT_WW, &LUT_BW, &LUT_WB, &LUT_BB) - }, - RefreshLUT::QUICK => { - self.set_lut_helper( - spi, - &LUT_VCOM0_QUICK, - &LUT_WW_QUICK, - &LUT_BW_QUICK, - &LUT_WB_QUICK, - &LUT_BB_QUICK, - ) } + RefreshLUT::QUICK => self.set_lut_helper( + spi, + &LUT_VCOM0_QUICK, + &LUT_WW_QUICK, + &LUT_BW_QUICK, + &LUT_WB_QUICK, + &LUT_BB_QUICK, + ), } } } @@ -318,7 +343,12 @@ where self.interface.data(spi, data) } - fn cmd_with_data(&mut self, spi: &mut SPI, command: Command, data: &[u8]) -> Result<(), SPI::Error> { + fn cmd_with_data( + &mut self, + spi: &mut SPI, + command: Command, + data: &[u8], + ) -> Result<(), SPI::Error> { self.interface.cmd_with_data(spi, command, data) } @@ -347,43 +377,22 @@ where lut_bb: &[u8], ) -> Result<(), SPI::Error> { // LUT VCOM - self.cmd_with_data( - spi, - Command::LUT_FOR_VCOM, - lut_vcom - )?; + self.cmd_with_data(spi, Command::LUT_FOR_VCOM, lut_vcom)?; // LUT WHITE to WHITE - self.cmd_with_data( - spi, - Command::LUT_WHITE_TO_WHITE, - lut_ww - )?; + self.cmd_with_data(spi, Command::LUT_WHITE_TO_WHITE, lut_ww)?; // LUT BLACK to WHITE - self.cmd_with_data( - spi, - Command::LUT_BLACK_TO_WHITE, - lut_bw - )?; + self.cmd_with_data(spi, Command::LUT_BLACK_TO_WHITE, lut_bw)?; // LUT WHITE to BLACK - self.cmd_with_data( - spi, - Command::LUT_WHITE_TO_BLACK, - lut_wb, - )?; + self.cmd_with_data(spi, Command::LUT_WHITE_TO_BLACK, lut_wb)?; // LUT BLACK to BLACK - self.cmd_with_data( - spi, - Command::LUT_BLACK_TO_BLACK, - lut_bb, - ) + self.cmd_with_data(spi, Command::LUT_BLACK_TO_BLACK, lut_bb) } } - #[cfg(test)] mod tests { use super::*; @@ -394,4 +403,4 @@ mod tests { assert_eq!(HEIGHT, 300); assert_eq!(DEFAULT_BACKGROUND_COLOR, Color::White); } -} \ No newline at end of file +} diff --git a/src/graphics.rs b/src/graphics.rs index 5a50d1a..1a5bb0f 100644 --- a/src/graphics.rs +++ b/src/graphics.rs @@ -60,14 +60,12 @@ impl<'a> Display<'a> { } } - impl<'a> Drawing for Display<'a> { fn draw(&mut self, item_pixels: T) where - T: Iterator> + T: Iterator>, { - for Pixel(UnsignedCoord(x,y), color) in item_pixels { - + for Pixel(UnsignedCoord(x, y), color) in item_pixels { if outside_display(x, y, self.width, self.height, self.rotation) { continue; } @@ -89,14 +87,13 @@ impl<'a> Drawing for Display<'a> { } } - fn outside_display(x: u32, y: u32, width: u32, height: u32, rotation: DisplayRotation) -> bool { match rotation { DisplayRotation::Rotate0 | DisplayRotation::Rotate180 => { if x >= width || y >= height { return true; } - }, + } DisplayRotation::Rotate90 | DisplayRotation::Rotate270 => { if y >= width || x >= height { return true; @@ -127,19 +124,17 @@ fn rotation(x: u32, y: u32, width: u32, height: u32, rotation: DisplayRotation) } } - - #[cfg(test)] mod tests { - use super::{DisplayRotation, outside_display, rotation, Display}; + use super::{outside_display, rotation, Display, DisplayRotation}; use color::Color; use embedded_graphics::coord::Coord; - use embedded_graphics::primitives::Line; use embedded_graphics::prelude::*; + use embedded_graphics::primitives::Line; #[test] fn buffer_clear() { - use epd4in2::{WIDTH, HEIGHT}; + use epd4in2::{HEIGHT, WIDTH}; let mut buffer = [Color::Black.get_byte_value(); WIDTH as usize / 8 * HEIGHT as usize]; let mut display = Display::new(WIDTH, HEIGHT, &mut buffer); @@ -155,22 +150,21 @@ mod tests { } } - #[test] fn rotation_overflow() { - use epd4in2::{WIDTH, HEIGHT}; + use epd4in2::{HEIGHT, WIDTH}; let width = WIDTH as u32; let height = HEIGHT as u32; test_rotation_overflow(width, height, DisplayRotation::Rotate0); test_rotation_overflow(width, height, DisplayRotation::Rotate90); test_rotation_overflow(width, height, DisplayRotation::Rotate180); test_rotation_overflow(width, height, DisplayRotation::Rotate270); - } fn test_rotation_overflow(width: u32, height: u32, rotation2: DisplayRotation) { let max_value = width / 8 * height; - for x in 0..(width + height) { //limit x because it runs too long + for x in 0..(width + height) { + //limit x because it runs too long for y in 0..(u32::max_value()) { if outside_display(x, y, width, height, rotation2) { break; @@ -182,11 +176,9 @@ mod tests { } } - - #[test] fn graphics_rotation_0() { - use epd2in9::{DEFAULT_BACKGROUND_COLOR}; + use epd2in9::DEFAULT_BACKGROUND_COLOR; let width = 128; let height = 296; @@ -210,7 +202,7 @@ mod tests { #[test] fn graphics_rotation_90() { - use epd2in9::{DEFAULT_BACKGROUND_COLOR}; + use epd2in9::DEFAULT_BACKGROUND_COLOR; let width = 128; let height = 296; @@ -236,4 +228,4 @@ mod tests { assert_eq!(byte, DEFAULT_BACKGROUND_COLOR.get_byte_value()); } } -} \ No newline at end of file +} diff --git a/src/interface.rs b/src/interface.rs index ed3bfc4..179dd77 100644 --- a/src/interface.rs +++ b/src/interface.rs @@ -1,8 +1,8 @@ +use core::marker::PhantomData; use hal::{ blocking::{delay::*, spi::Write}, digital::*, }; -use core::marker::PhantomData; use traits::Command; /// The Connection Interface of all (?) Waveshare EPD-Devices @@ -20,8 +20,7 @@ pub(crate) struct DisplayInterface { rst: RST, } -impl - DisplayInterface +impl DisplayInterface where SPI: Write, CS: OutputPin, @@ -62,14 +61,18 @@ where } /// Basic function for sending [Commands](Command) and the data belonging to it. - /// + /// /// TODO: directly use ::write? cs wouldn't needed to be changed twice than - pub(crate) fn cmd_with_data(&mut self, spi: &mut SPI, command: T, data: &[u8]) -> Result<(), SPI::Error> { - self.cmd(spi, command)?; - self.data(spi, data) + pub(crate) fn cmd_with_data( + &mut self, + spi: &mut SPI, + command: T, + data: &[u8], + ) -> Result<(), SPI::Error> { + self.cmd(spi, command)?; + self.data(spi, data) } - /// Basic function for sending the same byte of data (one u8) multiple times over spi /// /// Enables direct interaction with the device with the help of [command()](ConnectionInterface::command()) @@ -89,8 +92,7 @@ where } // spi write helper/abstraction function - fn write(&mut self, spi: &mut SPI, data: &[u8]) -> Result<(), SPI::Error> - { + fn write(&mut self, spi: &mut SPI, data: &[u8]) -> Result<(), SPI::Error> { // activate spi with cs low self.cs.set_low(); @@ -104,7 +106,7 @@ where } else { spi.write(data)?; } - + // deativate spi with cs high self.cs.set_high(); @@ -125,7 +127,7 @@ 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) { - // TODO: removal of delay. TEST! + // TODO: removal of delay. TEST! //self.delay_ms(1); //low: busy, high: idle while (is_busy_low && self.busy.is_low()) || (!is_busy_low && self.busy.is_high()) { diff --git a/src/lib.rs b/src/lib.rs index 36a4a04..0a120af 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -67,12 +67,11 @@ pub mod epd2in9; pub(crate) mod type_a; pub mod prelude { - pub use traits::{WaveshareDisplay, RefreshLUT}; pub use color::Color; + pub use traits::{RefreshLUT, WaveshareDisplay}; pub use SPI_MODE; } - extern crate embedded_hal as hal; use hal::spi::{Mode, Phase, Polarity}; diff --git a/src/traits.rs b/src/traits.rs index 86dc1c2..7ea2857 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -1,10 +1,9 @@ +use color::Color; use core::marker::Sized; use hal::{ blocking::{delay::*, spi::Write}, digital::*, }; -use color::Color; - /// All commands need to have this trait which gives the address of the command /// which needs to be send via SPI with activated CommandsPin (Data/Command Pin in CommandMode) @@ -17,8 +16,8 @@ pub enum RefreshLUT { /// The "normal" full Lookuptable for the Refresh-Sequence FULL, /// The quick LUT where not the full refresh sequence is followed. - /// This might lead to some - QUICK + /// This might lead to some + QUICK, } impl Default for RefreshLUT { @@ -37,20 +36,23 @@ where { /// This initialises the EPD and powers it up /// - /// This function is already called from + /// This function is already called from /// - [new()](WaveshareInterface::new()) /// - [`wake_up`] - /// + /// /// /// This function calls [reset()](WaveshareInterface::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>(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error>; + fn init>( + &mut self, + spi: &mut SPI, + delay: &mut DELAY, + ) -> Result<(), SPI::Error>; } - /// All the functions to interact with the EPDs -/// +/// /// This trait includes all public functions to use the EPDS pub trait WaveshareDisplay where @@ -64,10 +66,15 @@ where /// /// This already initialises the device. That means [init()](WaveshareInterface::init()) isn't needed directly afterwards fn new>( - spi: &mut SPI, cs: CS, busy: BUSY, dc: DC, rst: RST, delay: &mut DELAY, + spi: &mut SPI, + cs: CS, + busy: BUSY, + dc: DC, + rst: RST, + delay: &mut DELAY, ) -> Result where - Self: Sized; + Self: Sized; /// Let the device enter deep-sleep mode to save power. /// @@ -78,7 +85,11 @@ where fn sleep(&mut self, spi: &mut SPI) -> Result<(), SPI::Error>; /// Wakes the device up from sleep - fn wake_up>(&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()](WaveshareInterface::clear_frame()) fn set_background_color(&mut self, color: Color); @@ -98,7 +109,7 @@ where /// Transmits partial data to the SRAM of the EPD /// /// (x,y) is the top left corner - /// + /// /// BUFFER needs to be of size: width / 8 * height ! fn update_partial_frame( &mut self, @@ -119,11 +130,15 @@ where /// Trait for using various Waveforms from different LUTs /// E.g. for partial refreshes - /// - /// A full refresh is needed after a certain amount of quick refreshes! - /// + /// + /// A full refresh is needed after a certain amount of quick refreshes! + /// /// WARNING: Quick Refresh might lead to ghosting-effects/problems with your display. Especially for the 4.2in Display! - /// + /// /// If None is used the old value will be loaded on the LUTs once more - fn set_lut(&mut self, spi: &mut SPI, refresh_rate: Option) -> Result<(), SPI::Error>; + fn set_lut( + &mut self, + spi: &mut SPI, + refresh_rate: Option, + ) -> Result<(), SPI::Error>; } diff --git a/src/type_a/constants.rs b/src/type_a/constants.rs index 63de296..c4bb9c1 100644 --- a/src/type_a/constants.rs +++ b/src/type_a/constants.rs @@ -11,4 +11,4 @@ pub(crate) const LUT_PARTIAL_UPDATE: [u8; 30] =[ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x14, 0x44, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -]; \ No newline at end of file +]; diff --git a/src/type_a/mod.rs b/src/type_a/mod.rs index 11b59c7..84c4f1c 100644 --- a/src/type_a/mod.rs +++ b/src/type_a/mod.rs @@ -1,2 +1,2 @@ pub(crate) mod command; -pub(crate) mod constants; \ No newline at end of file +pub(crate) mod constants; From b505440c09a6b3725767d0c8281a97580fa705a3 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 6 Nov 2018 09:00:33 +0100 Subject: [PATCH 06/15] improved readme --- README.md | 30 +++++++++++++++++++-- examples/embedded_linux_epd4in2/src/main.rs | 5 ---- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 14ad145..895ccae 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,34 @@ This library contains a driver for E-Paper Modules from Waveshare. It uses the [embedded graphics](https://crates.io/crates/embedded-graphics) library for the optional graphics support. +## Examples + +There are multiple examples in the examples folder. For more infos about the examples see the seperate Readme [there](/examples/Readme.md). + +```Rust +// Setup the epd +let mut epd = EPD4in2::new(&mut spi, cs, busy, dc, rst, &mut delay)?; + +// Setup the graphics +let mut buffer = Buffer4in2::default(); +let mut display = Display::new(epd.width(), epd.height(), &mut buffer.buffer); + +// Draw some text +display.draw( + Font12x16::render_str("Hello Rust!") + .with_stroke(Some(Color::Black)) + .with_fill(Some(Color::White)) + .translate(Coord::new(5, 50)) + .into_iter(), +); + +// Transfer the frame data to the epd +epd.update_frame(&mut spi, &display.buffer())?; + +// Display the frame on the epd +epd.display_frame(&mut spi)?; +``` + ## (Supported) Devices | Device (with Link) | Colors | Flexible Display | Partial Refresh | Supported | Tested | @@ -64,9 +92,7 @@ They are also called A and B, but you shouldn't get confused and mix it with the - [ ] improve the partial drawing/check the timings/timing improvements/.... -## Examples -There are multiple examples in the examples folder. For more infos see the seperate Readme [there](/examples/Readme.md): diff --git a/examples/embedded_linux_epd4in2/src/main.rs b/examples/embedded_linux_epd4in2/src/main.rs index 48df7d3..514232f 100644 --- a/examples/embedded_linux_epd4in2/src/main.rs +++ b/examples/embedded_linux_epd4in2/src/main.rs @@ -76,11 +76,6 @@ fn run() -> Result<(), std::io::Error> { let mut delay = Delay {}; - - - - //TODO: wait for Digital::InputPin - //fixed currently with the HackInputPin, see further above let mut epd4in2 = EPD4in2::new(&mut spi, cs, busy, dc, rst, &mut delay).expect("eink initalize error"); println!("Test all the rotations"); From 2796d875f548cf35782944db626878f4600960b8 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 6 Nov 2018 09:03:19 +0100 Subject: [PATCH 07/15] Add rustfmt::skip to constants and graphics::rotation --- src/epd4in2/constants.rs | 18 ++++++++++-------- src/graphics.rs | 18 ++++++++++-------- src/type_a/constants.rs | 2 ++ 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/epd4in2/constants.rs b/src/epd4in2/constants.rs index f64548c..0821cb2 100644 --- a/src/epd4in2/constants.rs +++ b/src/epd4in2/constants.rs @@ -4,6 +4,7 @@ pub const WIDTH: u32 = 400; pub const HEIGHT: u32 = 300; pub const DEFAULT_BACKGROUND_COLOR: Color = Color::White; +#[rustfmt::skip] pub(crate) const LUT_VCOM0: [u8; 44] = [ 0x00, 0x17, 0x00, 0x00, 0x00, 0x02, 0x00, 0x17, 0x17, 0x00, 0x00, 0x02, @@ -14,6 +15,7 @@ pub(crate) const LUT_VCOM0: [u8; 44] = [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ]; +#[rustfmt::skip] pub(crate) const LUT_VCOM0_QUICK: [u8; 44] = [ 0x00, 0x0E, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -24,7 +26,7 @@ pub(crate) const LUT_VCOM0_QUICK: [u8; 44] = [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ]; - +#[rustfmt::skip] pub(crate) const LUT_WW: [u8; 42] =[ 0x40, 0x17, 0x00, 0x00, 0x00, 0x02, 0x90, 0x17, 0x17, 0x00, 0x00, 0x02, @@ -35,7 +37,7 @@ pub(crate) const LUT_WW: [u8; 42] =[ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ]; - +#[rustfmt::skip] pub(crate) const LUT_WW_QUICK: [u8; 42] =[ 0xA0, 0x0E, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -46,7 +48,7 @@ pub(crate) const LUT_WW_QUICK: [u8; 42] =[ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ]; - +#[rustfmt::skip] pub(crate) const LUT_BW: [u8; 42] =[ 0x40, 0x17, 0x00, 0x00, 0x00, 0x02, 0x90, 0x17, 0x17, 0x00, 0x00, 0x02, @@ -57,7 +59,7 @@ pub(crate) const LUT_BW: [u8; 42] =[ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ]; - +#[rustfmt::skip] pub(crate) const LUT_BW_QUICK: [u8; 42] =[ 0xA0, 0x0E, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -68,7 +70,7 @@ pub(crate) const LUT_BW_QUICK: [u8; 42] =[ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ]; - +#[rustfmt::skip] pub(crate) const LUT_BB: [u8; 42] =[ 0x80, 0x17, 0x00, 0x00, 0x00, 0x02, 0x90, 0x17, 0x17, 0x00, 0x00, 0x02, @@ -79,7 +81,7 @@ pub(crate) const LUT_BB: [u8; 42] =[ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ]; - +#[rustfmt::skip] pub(crate) const LUT_BB_QUICK: [u8; 42] =[ 0x50, 0x0E, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -90,7 +92,7 @@ pub(crate) const LUT_BB_QUICK: [u8; 42] =[ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ]; - +#[rustfmt::skip] pub(crate) const LUT_WB: [u8; 42] =[ 0x80, 0x17, 0x00, 0x00, 0x00, 0x02, 0x90, 0x17, 0x17, 0x00, 0x00, 0x02, @@ -101,7 +103,7 @@ pub(crate) const LUT_WB: [u8; 42] =[ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ]; - +#[rustfmt::skip] pub(crate) const LUT_WB_QUICK: [u8; 42] =[ 0x50, 0x0E, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, diff --git a/src/graphics.rs b/src/graphics.rs index 1a5bb0f..df28f0f 100644 --- a/src/graphics.rs +++ b/src/graphics.rs @@ -3,7 +3,7 @@ use color::Color; use embedded_graphics::prelude::*; -/// Displayrotation +/// Displayrotation #[derive(Clone, Copy)] pub enum DisplayRotation { /// No rotation @@ -82,7 +82,7 @@ impl<'a> Drawing for Display<'a> { Color::White => { self.buffer[index] |= bit; } - } + } } } } @@ -97,12 +97,14 @@ fn outside_display(x: u32, y: u32, width: u32, height: u32, rotation: DisplayRot DisplayRotation::Rotate90 | DisplayRotation::Rotate270 => { if y >= width || x >= height { return true; - } + } } } false } +#[rustfmt::skip] +//returns index position in the u8-slice and the bit-position inside that u8 fn rotation(x: u32, y: u32, width: u32, height: u32, rotation: DisplayRotation) -> (u32, u8) { match rotation { DisplayRotation::Rotate0 => ( @@ -147,7 +149,7 @@ mod tests { for &byte in display.buffer.iter() { assert_eq!(byte, Color::White.get_byte_value()); - } + } } #[test] @@ -181,7 +183,7 @@ mod tests { use epd2in9::DEFAULT_BACKGROUND_COLOR; let width = 128; let height = 296; - + let mut buffer = [DEFAULT_BACKGROUND_COLOR.get_byte_value(); 128 / 8 * 296]; let mut display = Display::new(width, height, &mut buffer); @@ -190,7 +192,7 @@ mod tests { .with_stroke(Some(Color::Black)) .into_iter(), ); - + let buffer = display.buffer(); assert_eq!(buffer[0], Color::Black.get_byte_value()); @@ -205,7 +207,7 @@ mod tests { use epd2in9::DEFAULT_BACKGROUND_COLOR; let width = 128; let height = 296; - + let mut buffer = [DEFAULT_BACKGROUND_COLOR.get_byte_value(); 128 / 8 * 296]; let mut display = Display::new(width, height, &mut buffer); @@ -216,7 +218,7 @@ mod tests { .with_stroke(Some(Color::Black)) .into_iter(), ); - + let buffer = display.buffer(); extern crate std; diff --git a/src/type_a/constants.rs b/src/type_a/constants.rs index c4bb9c1..f1afc9e 100644 --- a/src/type_a/constants.rs +++ b/src/type_a/constants.rs @@ -1,4 +1,5 @@ // Original Waveforms from Waveshare +#[rustfmt::skip] pub(crate) const LUT_FULL_UPDATE: [u8; 30] =[ 0x02, 0x02, 0x01, 0x11, 0x12, 0x12, 0x22, 0x22, 0x66, 0x69, 0x69, 0x59, 0x58, 0x99, 0x99, 0x88, @@ -6,6 +7,7 @@ pub(crate) const LUT_FULL_UPDATE: [u8; 30] =[ 0x35, 0x51, 0x51, 0x19, 0x01, 0x00 ]; +#[rustfmt::skip] pub(crate) const LUT_PARTIAL_UPDATE: [u8; 30] =[ 0x10, 0x18, 0x18, 0x08, 0x18, 0x18, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, From bd79ffdbc65be6de3bbe930e58d2c4f85d890aa2 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 6 Nov 2018 09:07:37 +0100 Subject: [PATCH 08/15] added cargo fmt to travis --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c1cc455..91f34dc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -95,11 +95,13 @@ install: - rustup override set nightly - rustup target add thumbv7m-none-eabi - rustup component add clippy-preview + - rustup component add rustfmt-preview #TODO: remove -A clippy::new_ret_no_self when new version of clippy gets released! script: - - cargo check + - cargo fmt --all -- --check - cargo clippy --all-targets --all-features -- -D warnings -A clippy::new_ret_no_self + - cargo check - cargo test --all-features --release - cargo doc --all-features --release - cd examples/embedded_linux_epd4in2 && cargo check && cd ../../ From 973b1d8982dfc69c9300926657e86775cdf4dd4a Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 6 Nov 2018 09:10:24 +0100 Subject: [PATCH 09/15] run cargo fmt over 4in2 example --- examples/embedded_linux_epd4in2/src/main.rs | 82 ++++++++++----------- 1 file changed, 39 insertions(+), 43 deletions(-) diff --git a/examples/embedded_linux_epd4in2/src/main.rs b/examples/embedded_linux_epd4in2/src/main.rs index 514232f..f6fe437 100644 --- a/examples/embedded_linux_epd4in2/src/main.rs +++ b/examples/embedded_linux_epd4in2/src/main.rs @@ -1,17 +1,14 @@ // the library for the embedded linux device extern crate linux_embedded_hal as lin_hal; use lin_hal::spidev::{self, SpidevOptions}; -use lin_hal::{Pin, Spidev}; use lin_hal::sysfs_gpio::Direction; use lin_hal::Delay; +use lin_hal::{Pin, Spidev}; // the eink library extern crate epd_waveshare; use epd_waveshare::{ - epd4in2::{ - EPD4in2, - Buffer4in2, - }, + epd4in2::{Buffer4in2, EPD4in2}, graphics::{Display, DisplayRotation}, prelude::*, }; @@ -19,7 +16,7 @@ use epd_waveshare::{ // Graphics extern crate embedded_graphics; use embedded_graphics::coord::Coord; -use embedded_graphics::fonts::{Font6x8, Font12x16}; +use embedded_graphics::fonts::{Font12x16, Font6x8}; use embedded_graphics::prelude::*; use embedded_graphics::primitives::{Circle, Line}; use embedded_graphics::Drawing; @@ -37,9 +34,8 @@ fn main() { } fn run() -> Result<(), std::io::Error> { - // Configure SPI - // Settings are taken from + // Settings are taken from let mut spi = Spidev::open("/dev/spidev0.0").expect("spidev directory"); let options = SpidevOptions::new() .bits_per_word(8) @@ -49,13 +45,13 @@ fn run() -> Result<(), std::io::Error> { spi.configure(&options).expect("spi configuration"); // Configure Digital I/O Pin to be used as Chip Select for SPI - let cs = Pin::new(26);//BCM7 CE0 + let cs = Pin::new(26); //BCM7 CE0 cs.export().expect("cs export"); while !cs.is_exported() {} cs.set_direction(Direction::Out).expect("CS Direction"); cs.set_value(1).expect("CS Value set to 1"); - let busy = Pin::new(5);//pin 29 + let busy = Pin::new(5); //pin 29 busy.export().expect("busy export"); while !busy.is_exported() {} busy.set_direction(Direction::In).expect("busy Direction"); @@ -71,58 +67,58 @@ fn run() -> Result<(), std::io::Error> { rst.export().expect("rst export"); while !rst.is_exported() {} rst.set_direction(Direction::Out).expect("rst Direction"); - rst.set_value(1).expect("rst Value set to 1"); + rst.set_value(1).expect("rst Value set to 1"); let mut delay = Delay {}; - - let mut epd4in2 = EPD4in2::new(&mut spi, cs, busy, dc, rst, &mut delay).expect("eink initalize error"); + let mut epd4in2 = + EPD4in2::new(&mut spi, cs, busy, dc, rst, &mut delay).expect("eink initalize error"); println!("Test all the rotations"); let mut buffer = Buffer4in2::default(); let mut display = Display::new(epd4in2.width(), epd4in2.height(), &mut buffer.buffer); display.set_rotation(DisplayRotation::Rotate0); display.draw( - Font6x8::render_str("Rotate 0!") - .with_stroke(Some(Color::Black)) - .with_fill(Some(Color::White)) - .translate(Coord::new(5, 50)) - .into_iter(), + Font6x8::render_str("Rotate 0!") + .with_stroke(Some(Color::Black)) + .with_fill(Some(Color::White)) + .translate(Coord::new(5, 50)) + .into_iter(), ); display.set_rotation(DisplayRotation::Rotate90); display.draw( - Font6x8::render_str("Rotate 90!") - .with_stroke(Some(Color::Black)) - .with_fill(Some(Color::White)) - .translate(Coord::new(5, 50)) - .into_iter(), + Font6x8::render_str("Rotate 90!") + .with_stroke(Some(Color::Black)) + .with_fill(Some(Color::White)) + .translate(Coord::new(5, 50)) + .into_iter(), ); display.set_rotation(DisplayRotation::Rotate180); display.draw( - Font6x8::render_str("Rotate 180!") - .with_stroke(Some(Color::Black)) - .with_fill(Some(Color::White)) - .translate(Coord::new(5, 50)) - .into_iter(), + Font6x8::render_str("Rotate 180!") + .with_stroke(Some(Color::Black)) + .with_fill(Some(Color::White)) + .translate(Coord::new(5, 50)) + .into_iter(), ); display.set_rotation(DisplayRotation::Rotate270); display.draw( - Font6x8::render_str("Rotate 270!") - .with_stroke(Some(Color::Black)) - .with_fill(Some(Color::White)) - .translate(Coord::new(5, 50)) - .into_iter(), + Font6x8::render_str("Rotate 270!") + .with_stroke(Some(Color::Black)) + .with_fill(Some(Color::White)) + .translate(Coord::new(5, 50)) + .into_iter(), ); - epd4in2.update_frame(&mut spi, &display.buffer()).unwrap(); - epd4in2.display_frame(&mut spi).expect("display frame new graphics"); + epd4in2 + .display_frame(&mut spi) + .expect("display frame new graphics"); delay.delay_ms(5000u16); - println!("Now test new graphics with default rotation and some special stuff:"); display.clear_buffer(Color::White); @@ -168,12 +164,11 @@ fn run() -> Result<(), std::io::Error> { .translate(Coord::new(50, 200)) .into_iter(), ); - // a moving `Hello World!` let limit = 10; for i in 0..limit { - println!("Moving Hello World. Loop {} from {}", (i+1), limit); + println!("Moving Hello World. Loop {} from {}", (i + 1), limit); display.draw( Font6x8::render_str(" Hello World! ") @@ -182,17 +177,18 @@ fn run() -> Result<(), std::io::Error> { stroke_color: Some(Color::Black), stroke_width: 0u8, // Has no effect on fonts }) - .translate(Coord::new(5 + i*12, 50)) + .translate(Coord::new(5 + i * 12, 50)) .into_iter(), - ); + ); epd4in2.update_frame(&mut spi, &display.buffer()).unwrap(); - epd4in2.display_frame(&mut spi).expect("display frame new graphics"); + epd4in2 + .display_frame(&mut spi) + .expect("display frame new graphics"); delay.delay_ms(1_000u16); } - println!("Finished tests - going to sleep"); epd4in2.sleep(&mut spi) -} +} From 559b0efdae4fd095e644085950df5f229e8c276f Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 6 Nov 2018 09:12:39 +0100 Subject: [PATCH 10/15] run cargo fmt over all examples --- examples/embedded_linux_epd1in54/src/main.rs | 75 ++++++++++---------- examples/embedded_linux_epd2in9/src/main.rs | 75 ++++++++++---------- 2 files changed, 76 insertions(+), 74 deletions(-) diff --git a/examples/embedded_linux_epd1in54/src/main.rs b/examples/embedded_linux_epd1in54/src/main.rs index d369c87..94031d7 100644 --- a/examples/embedded_linux_epd1in54/src/main.rs +++ b/examples/embedded_linux_epd1in54/src/main.rs @@ -1,17 +1,14 @@ // the library for the embedded linux device extern crate linux_embedded_hal as lin_hal; use lin_hal::spidev::{self, SpidevOptions}; -use lin_hal::{Pin, Spidev}; use lin_hal::sysfs_gpio::Direction; use lin_hal::Delay; +use lin_hal::{Pin, Spidev}; // the eink library extern crate epd_waveshare; use epd_waveshare::{ - epd1in54::{ - EPD1in54, - Buffer1in54, - }, + epd1in54::{Buffer1in54, EPD1in54}, graphics::{Display, DisplayRotation}, prelude::*, }; @@ -19,7 +16,7 @@ use epd_waveshare::{ // Graphics extern crate embedded_graphics; use embedded_graphics::coord::Coord; -use embedded_graphics::fonts::{Font6x8}; +use embedded_graphics::fonts::Font6x8; use embedded_graphics::prelude::*; //use embedded_graphics::primitives::{Circle, Line}; use embedded_graphics::Drawing; @@ -48,14 +45,16 @@ fn run() -> Result<(), std::io::Error> { spi.configure(&options).expect("spi configuration"); // Configure Digital I/O Pin to be used as Chip Select for SPI - let cs_pin = Pin::new(26);//BCM7 CE0 + let cs_pin = Pin::new(26); //BCM7 CE0 cs_pin.export().expect("cs_pin export"); while !cs_pin.is_exported() {} - cs_pin.set_direction(Direction::Out).expect("cs_pin Direction"); + cs_pin + .set_direction(Direction::Out) + .expect("cs_pin Direction"); cs_pin.set_value(1).expect("cs_pin Value set to 1"); // Configure Busy Input Pin - let busy = Pin::new(5);//pin 29 + let busy = Pin::new(5); //pin 29 busy.export().expect("busy export"); while !busy.is_exported() {} busy.set_direction(Direction::In).expect("busy Direction"); @@ -73,12 +72,11 @@ fn run() -> Result<(), std::io::Error> { rst.export().expect("rst export"); while !rst.is_exported() {} rst.set_direction(Direction::Out).expect("rst Direction"); - rst.set_value(1).expect("rst Value set to 1"); + rst.set_value(1).expect("rst Value set to 1"); // Configure Delay let mut delay = Delay {}; - // Setup of the needed pins is finished here // Now the "real" usage of the eink-waveshare-rs crate begins let mut epd = EPD1in54::new(&mut spi, cs_pin, busy, dc, rst, &mut delay)?; @@ -92,51 +90,53 @@ fn run() -> Result<(), std::io::Error> { let mut display = Display::new(epd.width(), epd.height(), &mut buffer.buffer); display.set_rotation(DisplayRotation::Rotate0); display.draw( - Font6x8::render_str("Rotate 0!") - .with_stroke(Some(Color::Black)) - .with_fill(Some(Color::White)) - .translate(Coord::new(5, 50)) - .into_iter(), + Font6x8::render_str("Rotate 0!") + .with_stroke(Some(Color::Black)) + .with_fill(Some(Color::White)) + .translate(Coord::new(5, 50)) + .into_iter(), ); display.set_rotation(DisplayRotation::Rotate90); display.draw( - Font6x8::render_str("Rotate 90!") - .with_stroke(Some(Color::Black)) - .with_fill(Some(Color::White)) - .translate(Coord::new(5, 50)) - .into_iter(), + Font6x8::render_str("Rotate 90!") + .with_stroke(Some(Color::Black)) + .with_fill(Some(Color::White)) + .translate(Coord::new(5, 50)) + .into_iter(), ); display.set_rotation(DisplayRotation::Rotate180); display.draw( - Font6x8::render_str("Rotate 180!") - .with_stroke(Some(Color::Black)) - .with_fill(Some(Color::White)) - .translate(Coord::new(5, 50)) - .into_iter(), + Font6x8::render_str("Rotate 180!") + .with_stroke(Some(Color::Black)) + .with_fill(Some(Color::White)) + .translate(Coord::new(5, 50)) + .into_iter(), ); display.set_rotation(DisplayRotation::Rotate270); display.draw( - Font6x8::render_str("Rotate 270!") - .with_stroke(Some(Color::Black)) - .with_fill(Some(Color::White)) - .translate(Coord::new(5, 50)) - .into_iter(), + Font6x8::render_str("Rotate 270!") + .with_stroke(Some(Color::Black)) + .with_fill(Some(Color::White)) + .translate(Coord::new(5, 50)) + .into_iter(), ); // Display updated frame epd.update_frame(&mut spi, &display.buffer()).unwrap(); - epd.display_frame(&mut spi).expect("display frame new graphics"); + epd.display_frame(&mut spi) + .expect("display frame new graphics"); delay.delay_ms(5000u16); // a quickly moving `Hello World!` display.set_rotation(DisplayRotation::Rotate0); - epd.set_lut(&mut spi, Some(RefreshLUT::QUICK)).expect("SET LUT QUICK error"); + epd.set_lut(&mut spi, Some(RefreshLUT::QUICK)) + .expect("SET LUT QUICK error"); let limit = 20; for i in 0..limit { - println!("Moving Hello World. Loop {} from {}", (i+1), limit); + println!("Moving Hello World. Loop {} from {}", (i + 1), limit); display.draw( Font6x8::render_str(" Hello World! ") @@ -145,12 +145,13 @@ fn run() -> Result<(), std::io::Error> { stroke_color: Some(Color::Black), stroke_width: 0u8, // Has no effect on fonts }) - .translate(Coord::new(5 + i*6, 50)) + .translate(Coord::new(5 + i * 6, 50)) .into_iter(), - ); + ); epd.update_frame(&mut spi, &display.buffer()).unwrap(); - epd.display_frame(&mut spi).expect("display frame new graphics"); + epd.display_frame(&mut spi) + .expect("display frame new graphics"); } // Set the EPD to sleep diff --git a/examples/embedded_linux_epd2in9/src/main.rs b/examples/embedded_linux_epd2in9/src/main.rs index eca408e..ffeeaae 100644 --- a/examples/embedded_linux_epd2in9/src/main.rs +++ b/examples/embedded_linux_epd2in9/src/main.rs @@ -1,17 +1,14 @@ // the library for the embedded linux device extern crate linux_embedded_hal as lin_hal; use lin_hal::spidev::{self, SpidevOptions}; -use lin_hal::{Pin, Spidev}; use lin_hal::sysfs_gpio::Direction; use lin_hal::Delay; +use lin_hal::{Pin, Spidev}; // the eink library extern crate epd_waveshare; use epd_waveshare::{ - epd2in9::{ - EPD2in9, - Buffer2in9, - }, + epd2in9::{Buffer2in9, EPD2in9}, graphics::{Display, DisplayRotation}, prelude::*, }; @@ -19,7 +16,7 @@ use epd_waveshare::{ // Graphics extern crate embedded_graphics; use embedded_graphics::coord::Coord; -use embedded_graphics::fonts::{Font6x8}; +use embedded_graphics::fonts::Font6x8; use embedded_graphics::prelude::*; //use embedded_graphics::primitives::{Circle, Line}; use embedded_graphics::Drawing; @@ -49,14 +46,16 @@ fn run() -> Result<(), std::io::Error> { spi.configure(&options).expect("spi configuration"); // Configure Digital I/O Pin to be used as Chip Select for SPI - let cs_pin = Pin::new(26);//BCM7 CE0 + let cs_pin = Pin::new(26); //BCM7 CE0 cs_pin.export().expect("cs_pin export"); while !cs_pin.is_exported() {} - cs_pin.set_direction(Direction::Out).expect("cs_pin Direction"); + cs_pin + .set_direction(Direction::Out) + .expect("cs_pin Direction"); cs_pin.set_value(1).expect("cs_pin Value set to 1"); // Configure Busy Input Pin - let busy = Pin::new(5);//pin 29 + let busy = Pin::new(5); //pin 29 busy.export().expect("busy export"); while !busy.is_exported() {} busy.set_direction(Direction::In).expect("busy Direction"); @@ -74,12 +73,11 @@ fn run() -> Result<(), std::io::Error> { rst.export().expect("rst export"); while !rst.is_exported() {} rst.set_direction(Direction::Out).expect("rst Direction"); - rst.set_value(1).expect("rst Value set to 1"); + rst.set_value(1).expect("rst Value set to 1"); // Configure Delay let mut delay = Delay {}; - // Setup of the needed pins is finished here // Now the "real" usage of the eink-waveshare-rs crate begins let mut epd = EPD2in9::new(&mut spi, cs_pin, busy, dc, rst, &mut delay)?; @@ -96,51 +94,53 @@ fn run() -> Result<(), std::io::Error> { display.set_rotation(DisplayRotation::Rotate0); display.draw( - Font6x8::render_str("Rotate 0!") - .with_stroke(Some(Color::Black)) - .with_fill(Some(Color::White)) - .translate(Coord::new(5, 50)) - .into_iter(), + Font6x8::render_str("Rotate 0!") + .with_stroke(Some(Color::Black)) + .with_fill(Some(Color::White)) + .translate(Coord::new(5, 50)) + .into_iter(), ); display.set_rotation(DisplayRotation::Rotate90); display.draw( - Font6x8::render_str("Rotate 90!") - .with_stroke(Some(Color::Black)) - .with_fill(Some(Color::White)) - .translate(Coord::new(5, 50)) - .into_iter(), + Font6x8::render_str("Rotate 90!") + .with_stroke(Some(Color::Black)) + .with_fill(Some(Color::White)) + .translate(Coord::new(5, 50)) + .into_iter(), ); display.set_rotation(DisplayRotation::Rotate180); display.draw( - Font6x8::render_str("Rotate 180!") - .with_stroke(Some(Color::Black)) - .with_fill(Some(Color::White)) - .translate(Coord::new(5, 50)) - .into_iter(), + Font6x8::render_str("Rotate 180!") + .with_stroke(Some(Color::Black)) + .with_fill(Some(Color::White)) + .translate(Coord::new(5, 50)) + .into_iter(), ); display.set_rotation(DisplayRotation::Rotate270); display.draw( - Font6x8::render_str("Rotate 270!") - .with_stroke(Some(Color::Black)) - .with_fill(Some(Color::White)) - .translate(Coord::new(5, 50)) - .into_iter(), + Font6x8::render_str("Rotate 270!") + .with_stroke(Some(Color::Black)) + .with_fill(Some(Color::White)) + .translate(Coord::new(5, 50)) + .into_iter(), ); // Display updated frame epd.update_frame(&mut spi, &display.buffer()).unwrap(); - epd.display_frame(&mut spi).expect("display frame new graphics"); + epd.display_frame(&mut spi) + .expect("display frame new graphics"); delay.delay_ms(5000u16); // a quickly moving `Hello World!` display.set_rotation(DisplayRotation::Rotate0); - epd.set_lut(&mut spi, Some(RefreshLUT::QUICK)).expect("SET LUT QUICK error"); + epd.set_lut(&mut spi, Some(RefreshLUT::QUICK)) + .expect("SET LUT QUICK error"); let limit = 20; for i in 0..limit { - println!("Moving Hello World. Loop {} from {}", (i+1), limit); + println!("Moving Hello World. Loop {} from {}", (i + 1), limit); display.draw( Font6x8::render_str(" Hello World! ") @@ -149,12 +149,13 @@ fn run() -> Result<(), std::io::Error> { stroke_color: Some(Color::Black), stroke_width: 0u8, // Has no effect on fonts }) - .translate(Coord::new(5 + i*6, 50)) + .translate(Coord::new(5 + i * 6, 50)) .into_iter(), - ); + ); epd.update_frame(&mut spi, &display.buffer()).unwrap(); - epd.display_frame(&mut spi).expect("display frame new graphics"); + epd.display_frame(&mut spi) + .expect("display frame new graphics"); } // Set the EPD to sleep From 08d14689f2267183a02fd0608b265b6c2b65c10f Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 6 Nov 2018 09:12:59 +0100 Subject: [PATCH 11/15] add 2in9 example to travis and also check for cargo fmt there --- .travis.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 91f34dc..177ad49 100644 --- a/.travis.yml +++ b/.travis.yml @@ -104,8 +104,9 @@ script: - cargo check - cargo test --all-features --release - cargo doc --all-features --release - - cd examples/embedded_linux_epd4in2 && cargo check && cd ../../ - - cd examples/embedded_linux_epd1in54 && cargo check && cd ../../ + - cd examples/embedded_linux_epd4in2 && cargo fmt --all -- --check && cargo check && cd ../../ + - cd examples/embedded_linux_epd1in54 && cargo fmt --all -- --check && cargo check && cd ../../ + - cd examples/embedded_linux_epd2in9 && cargo fmt --all -- --check && cargo check && cd ../../ # - cd examples/stm32f3discovery && cargo check --target thumbv7m-none-eabi && cd ../../ #- cd ../f3_stm32f30x && cargo build From ebb33661c308a34b105e5ba414f17dadfd242790 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 6 Nov 2018 13:16:57 +0100 Subject: [PATCH 12/15] cleanup of a few tested/resolved todos --- src/epd1in54/mod.rs | 1 - src/epd2in9/mod.rs | 3 +-- src/epd4in2/mod.rs | 5 +---- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/epd1in54/mod.rs b/src/epd1in54/mod.rs index 9f8aaa1..59c5f71 100644 --- a/src/epd1in54/mod.rs +++ b/src/epd1in54/mod.rs @@ -223,7 +223,6 @@ where // clear the ram with the background color let color = self.background_color.get_byte_value(); - //TODO: this is using a big buffer atm, is it better to just loop over sending a single byte? self.interface.cmd(spi, Command::WRITE_RAM)?; self.interface.data_x_times(spi, color, WIDTH / 8 * HEIGHT) } diff --git a/src/epd2in9/mod.rs b/src/epd2in9/mod.rs index 920ca5d..dbccf23 100644 --- a/src/epd2in9/mod.rs +++ b/src/epd2in9/mod.rs @@ -221,8 +221,7 @@ where // clear the ram with the background color let color = self.background_color.get_byte_value(); - - //TODO: this is using a big buffer atm, is it better to just loop over sending a single byte? + self.interface.cmd(spi, Command::WRITE_RAM)?; self.interface.data_x_times(spi, color, WIDTH / 8 * HEIGHT) } diff --git a/src/epd4in2/mod.rs b/src/epd4in2/mod.rs index 149fa07..7775690 100644 --- a/src/epd4in2/mod.rs +++ b/src/epd4in2/mod.rs @@ -55,7 +55,7 @@ use interface::DisplayInterface; use traits::{InternalWiAdditions, RefreshLUT, WaveshareDisplay}; //The Lookup Tables for the Display -mod constants; //TODO: Limit to crate::drawing +mod constants; pub use self::constants::*; use color::Color; @@ -278,9 +278,6 @@ where self.interface .data_x_times(spi, color_value, WIDTH / 8 * HEIGHT)?; - //TODO: Removal of delay. TEST! - //self.delay_ms(2); - self.interface .cmd(spi, Command::DATA_START_TRANSMISSION_2)?; self.interface From eeb89dfa1d2cec758631f16070fce2a5ad0bb7a2 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 6 Nov 2018 13:17:32 +0100 Subject: [PATCH 13/15] add beta and stable builds to travis --- .travis.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 177ad49..47c96d5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,9 @@ dist: trusty language: rust -rust: +rust: + - stable + - beta - nightly sudo: required @@ -12,6 +14,8 @@ sudo: required matrix: + allow_failures: + # - nightly # TODO These are all the build jobs. Adjust as necessary. Comment out what you # don't need include: From b9395b5eff4283c10a12c6a1dc8c75af9bae57c3 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 6 Nov 2018 15:50:47 +0100 Subject: [PATCH 14/15] Prepare release - fix cargo fmt error - rename forgotten stuff --- Cargo.toml | 10 +++++----- README.md | 2 +- examples/embedded_linux_epd4in2/Cargo.toml | 2 +- src/epd1in54/mod.rs | 2 +- src/epd2in9/mod.rs | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index abab777..f043dd5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,12 +1,12 @@ [package] -authors = ["Christoph Groß "] +authors = ["Christoph Groß "] categories = ["embedded", "hardware-support", "no-std"] description = "An embedded-hal based driver for ePaper displays from Waveshare" -documentation = "https://docs.rs/epd_waveshare" -homepage = "https://github.com/Caemor/epd_waveshare" +documentation = "https://docs.rs/epd-waveshare" +homepage = "https://github.com/caemor/epd-waveshare" keywords = ["ePaper", "Display", "epd"] license = "ISC" -name = "epd_waveshare" +name = "epd-waveshare" readme = "README.md" repository = "https://github.com/Caemor/epd_waveshare.git" version = "0.2.0" @@ -14,7 +14,7 @@ version = "0.2.0" [badges] # Travis CI: `repository` in format "/" is required. # `branch` is optional; default is `master` -travis-ci = { repository = "Caemor/epd_waveshare" } +travis-ci = { repository = "caemor/epd-waveshare" } [features] diff --git a/README.md b/README.md index 895ccae..92663e9 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Build Status](https://travis-ci.com/Caemor/eink-waveshare-rs.svg?branch=master)](https://travis-ci.com/Caemor/eink-waveshare-rs) +[![Build Status](https://travis-ci.com/caemor/epd-waveshare.svg?branch=master)](https://travis-ci.com/caemor/epd-waveshare) This library contains a driver for E-Paper Modules from Waveshare. diff --git a/examples/embedded_linux_epd4in2/Cargo.toml b/examples/embedded_linux_epd4in2/Cargo.toml index 066bfcd..519fd29 100644 --- a/examples/embedded_linux_epd4in2/Cargo.toml +++ b/examples/embedded_linux_epd4in2/Cargo.toml @@ -6,7 +6,7 @@ authors = ["Christoph Groß "] [dependencies] ## The Only difference between this one and the one without default features sizewise seems to be a different .d-file Size (dependencies-file) -#eink_waveshare_rs = { path = "../../"} +#epd_waveshare = { path = "../../"} epd_waveshare = { path = "../../", default-features = false, features = ["epd4in2", "graphics"]} linux-embedded-hal = "0.2.1" diff --git a/src/epd1in54/mod.rs b/src/epd1in54/mod.rs index 59c5f71..a7c00ff 100644 --- a/src/epd1in54/mod.rs +++ b/src/epd1in54/mod.rs @@ -3,7 +3,7 @@ //! # Example for the 1.54 in E-Ink Display //! //! ```ignore -//! use eink_waveshare_rs::{ +//! use epd_waveshare::{ //! epd1in54::{EPD1in54, Buffer1in54}, //! graphics::{Display, DisplayRotation}, //! prelude::*, diff --git a/src/epd2in9/mod.rs b/src/epd2in9/mod.rs index dbccf23..d28114a 100644 --- a/src/epd2in9/mod.rs +++ b/src/epd2in9/mod.rs @@ -5,7 +5,7 @@ //! # Example for the 2.9 in E-Ink Display //! //! ```ignore -//! use eink_waveshare_rs::{ +//! use epd_waveshare::{ //! epd2in9::{EPD2in9, Buffer2in9}, //! graphics::{Display, DisplayRotation}, //! prelude::*, @@ -221,7 +221,7 @@ where // clear the ram with the background color let color = self.background_color.get_byte_value(); - + self.interface.cmd(spi, Command::WRITE_RAM)?; self.interface.data_x_times(spi, color, WIDTH / 8 * HEIGHT) } From 68cd8006dc1c796d46d4f9206a9aabd8f5c45dd4 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 6 Nov 2018 17:40:34 +0100 Subject: [PATCH 15/15] Fix wrongly named dep in examples --- examples/embedded_linux_epd1in54/Cargo.toml | 2 +- examples/embedded_linux_epd2in9/Cargo.toml | 2 +- examples/embedded_linux_epd4in2/Cargo.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/embedded_linux_epd1in54/Cargo.toml b/examples/embedded_linux_epd1in54/Cargo.toml index 2d0eeeb..351ebe6 100644 --- a/examples/embedded_linux_epd1in54/Cargo.toml +++ b/examples/embedded_linux_epd1in54/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Christoph Groß "] [dependencies] -epd_waveshare = { path = "../../", default-features = false, features = ["epd1in54", "graphics"]} +epd-waveshare = { path = "../../", default-features = false, features = ["epd1in54", "graphics"]} linux-embedded-hal = "0.2.1" diff --git a/examples/embedded_linux_epd2in9/Cargo.toml b/examples/embedded_linux_epd2in9/Cargo.toml index 262c965..1dfb5e4 100644 --- a/examples/embedded_linux_epd2in9/Cargo.toml +++ b/examples/embedded_linux_epd2in9/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Christoph Groß "] [dependencies] -epd_waveshare = { path = "../../", default-features = false, features = ["epd2in9", "graphics"]} +epd-waveshare = { path = "../../", default-features = false, features = ["epd2in9", "graphics"]} linux-embedded-hal = "0.2.1" diff --git a/examples/embedded_linux_epd4in2/Cargo.toml b/examples/embedded_linux_epd4in2/Cargo.toml index 519fd29..02bb866 100644 --- a/examples/embedded_linux_epd4in2/Cargo.toml +++ b/examples/embedded_linux_epd4in2/Cargo.toml @@ -7,7 +7,7 @@ authors = ["Christoph Groß "] ## The Only difference between this one and the one without default features sizewise seems to be a different .d-file Size (dependencies-file) #epd_waveshare = { path = "../../"} -epd_waveshare = { path = "../../", default-features = false, features = ["epd4in2", "graphics"]} +epd-waveshare = { path = "../../", default-features = false, features = ["epd4in2", "graphics"]} linux-embedded-hal = "0.2.1"