diff --git a/.travis.yml b/.travis.yml index e613f1c..c1cc455 100644 --- a/.travis.yml +++ b/.travis.yml @@ -94,16 +94,17 @@ install: - cargo install cargo-travis || true - rustup override set nightly - rustup target add thumbv7m-none-eabi + - rustup component add clippy-preview + #TODO: remove -A clippy::new_ret_no_self when new version of clippy gets released! script: - cargo check - - cargo build --release - - cargo test + - cargo clippy --all-targets --all-features -- -D warnings -A clippy::new_ret_no_self - 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/stm32f3discovery && cargo check --target thumbv7m-none-eabi && cd ../../ + # - cd examples/stm32f3discovery && cargo check --target thumbv7m-none-eabi && cd ../../ #- cd ../f3_stm32f30x && cargo build after_success: diff --git a/examples/embedded_linux_epd1in54/Cargo.toml b/examples/embedded_linux_epd1in54/Cargo.toml index d51c42e..caa16fa 100644 --- a/examples/embedded_linux_epd1in54/Cargo.toml +++ b/examples/embedded_linux_epd1in54/Cargo.toml @@ -5,11 +5,9 @@ authors = ["Christoph Groß "] [dependencies] -#eink_waveshare_rs = { git = "https://github.com/Caemor/eink-waveshare-rs"} -#eink_waveshare_rs = { path = "../../"} eink_waveshare_rs = { path = "../../", default-features = false, features = ["epd1in54", "graphics"]} -linux-embedded-hal = "0.2.0" +linux-embedded-hal = "0.2.1" embedded-graphics = "0.4.3" diff --git a/examples/embedded_linux_epd1in54/src/main.rs b/examples/embedded_linux_epd1in54/src/main.rs index aef8786..f3325d2 100644 --- a/examples/embedded_linux_epd1in54/src/main.rs +++ b/examples/embedded_linux_epd1in54/src/main.rs @@ -1,10 +1,12 @@ // 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; // the eink library extern crate eink_waveshare_rs; - - use eink_waveshare_rs::{ epd1in54::{ EPD1in54, @@ -14,11 +16,7 @@ use eink_waveshare_rs::{ prelude::*, }; -use lin_hal::spidev::{self, SpidevOptions}; -use lin_hal::{Pin, Spidev}; -use lin_hal::sysfs_gpio::Direction; -use lin_hal::Delay; - +// Graphics extern crate embedded_graphics; use embedded_graphics::coord::Coord; use embedded_graphics::fonts::{Font6x8}; @@ -26,6 +24,7 @@ use embedded_graphics::prelude::*; //use embedded_graphics::primitives::{Circle, Line}; use embedded_graphics::Drawing; +// HAL (Traits) extern crate embedded_hal; use embedded_hal::prelude::*; @@ -33,43 +32,7 @@ use embedded_hal::prelude::*; // needs to be run with sudo because of some sysfs_gpio permission problems and follow-up timing problems // see https://github.com/rust-embedded/rust-sysfs-gpio/issues/5 and follow-up issues - -// DigitalIn Hack as long as it's not in the linux_embedded_hal -// from https://github.com/rudihorn/max31865/blob/extra_examples/examples/rpi.rs -// (slightly changed now as OutputPin doesn't provide is_high and is_low anymore) -use embedded_hal::digital::{InputPin}; - -//TODO: Remove when linux_embedded_hal implements InputPin -struct HackInputPin<'a> { - pin: &'a Pin -} - -//TODO: Remove when linux_embedded_hal implements InputPin -impl<'a> HackInputPin<'a> { - fn new(p : &'a Pin) -> HackInputPin { - HackInputPin { - pin: p - } - } -} - -//TODO: Remove when linux_embedded_hal implements InputPin -// for now it defaults to is_low if an error appears -// could be handled better! -impl<'a> InputPin for HackInputPin<'a> { - fn is_low(&self) -> bool { - self.pin.get_value().unwrap_or(0) == 0 - } - - fn is_high(&self) -> bool { - !self.is_low() - } -} - -//TODO: Test this implemenation -//BE CAREFUL: this wasn't tested yet fn main() { - run().unwrap(); } @@ -97,7 +60,6 @@ fn run() -> Result<(), std::io::Error> { while !busy.is_exported() {} busy.set_direction(Direction::In).expect("busy Direction"); //busy.set_value(1).expect("busy Value set to 1"); - let busy_in = HackInputPin::new(&busy); // Configure Data/Command OutputPin let dc = Pin::new(6); //pin 31 //bcm6 @@ -119,7 +81,7 @@ fn run() -> Result<(), std::io::Error> { // 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_in, dc, rst, &mut delay)?; + let mut epd = EPD1in54::new(&mut spi, cs_pin, busy, dc, rst, &mut delay)?; // Clear the full screen epd.clear_frame(&mut spi).expect("clear frame 1"); diff --git a/examples/embedded_linux_epd2in9/Cargo.toml b/examples/embedded_linux_epd2in9/Cargo.toml index b5eba5c..6286d56 100644 --- a/examples/embedded_linux_epd2in9/Cargo.toml +++ b/examples/embedded_linux_epd2in9/Cargo.toml @@ -7,7 +7,7 @@ authors = ["Christoph Groß "] eink_waveshare_rs = { path = "../../", default-features = false, features = ["epd2in9", "graphics"]} -linux-embedded-hal = "0.2.0" +linux-embedded-hal = "0.2.1" embedded-graphics = "0.4.3" diff --git a/examples/embedded_linux_epd2in9/src/main.rs b/examples/embedded_linux_epd2in9/src/main.rs index 65a3c45..97d1d84 100644 --- a/examples/embedded_linux_epd2in9/src/main.rs +++ b/examples/embedded_linux_epd2in9/src/main.rs @@ -1,10 +1,12 @@ // 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; // the eink library extern crate eink_waveshare_rs; - - use eink_waveshare_rs::{ epd2in9::{ EPD2in9, @@ -14,11 +16,7 @@ use eink_waveshare_rs::{ prelude::*, }; -use lin_hal::spidev::{self, SpidevOptions}; -use lin_hal::{Pin, Spidev}; -use lin_hal::sysfs_gpio::Direction; -use lin_hal::Delay; - +// Graphics extern crate embedded_graphics; use embedded_graphics::coord::Coord; use embedded_graphics::fonts::{Font6x8}; @@ -26,6 +24,7 @@ use embedded_graphics::prelude::*; //use embedded_graphics::primitives::{Circle, Line}; use embedded_graphics::Drawing; +// HAL (Traits) extern crate embedded_hal; use embedded_hal::prelude::*; @@ -33,43 +32,8 @@ use embedded_hal::prelude::*; // needs to be run with sudo because of some sysfs_gpio permission problems and follow-up timing problems // see https://github.com/rust-embedded/rust-sysfs-gpio/issues/5 and follow-up issues - -// DigitalIn Hack as long as it's not in the linux_embedded_hal -// from https://github.com/rudihorn/max31865/blob/extra_examples/examples/rpi.rs -// (slightly changed now as OutputPin doesn't provide is_high and is_low anymore) -use embedded_hal::digital::{InputPin}; - -//TODO: Remove when linux_embedded_hal implements InputPin -struct HackInputPin<'a> { - pin: &'a Pin -} - -//TODO: Remove when linux_embedded_hal implements InputPin -impl<'a> HackInputPin<'a> { - fn new(p : &'a Pin) -> HackInputPin { - HackInputPin { - pin: p - } - } -} - -//TODO: Remove when linux_embedded_hal implements InputPin -// for now it defaults to is_low if an error appears -// could be handled better! -impl<'a> InputPin for HackInputPin<'a> { - fn is_low(&self) -> bool { - self.pin.get_value().unwrap_or(0) == 0 - } - - fn is_high(&self) -> bool { - !self.is_low() - } -} - -//TODO: Test this implemenation -//BE CAREFUL: this wasn't tested yet +//TODO: Test this implemenation with a new display fn main() { - run().unwrap(); } @@ -97,7 +61,6 @@ fn run() -> Result<(), std::io::Error> { while !busy.is_exported() {} busy.set_direction(Direction::In).expect("busy Direction"); //busy.set_value(1).expect("busy Value set to 1"); - let busy_in = HackInputPin::new(&busy); // Configure Data/Command OutputPin let dc = Pin::new(6); //pin 31 //bcm6 @@ -119,7 +82,7 @@ fn run() -> Result<(), std::io::Error> { // 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_in, dc, rst, &mut delay)?; + let mut epd = EPD2in9::new(&mut spi, cs_pin, busy, dc, rst, &mut delay)?; // Clear the full screen epd.clear_frame(&mut spi).expect("clear frame 1"); diff --git a/examples/embedded_linux_epd4in2/Cargo.toml b/examples/embedded_linux_epd4in2/Cargo.toml index 1731f4a..e37a444 100644 --- a/examples/embedded_linux_epd4in2/Cargo.toml +++ b/examples/embedded_linux_epd4in2/Cargo.toml @@ -9,12 +9,8 @@ authors = ["Christoph Groß "] #eink_waveshare_rs = { path = "../../"} eink_waveshare_rs = { path = "../../", default-features = false, features = ["epd4in2", "graphics"]} -linux-embedded-hal = "0.2.0" +linux-embedded-hal = "0.2.1" embedded-graphics = "0.4.3" -# embedded-graphics = {git = "https://github.com/caemor/embedded-graphics", branch = "master"} -# embedded-graphics = {git = "https://github.com/jamwaffles/embedded-graphics", branch = "master"} - - embedded-hal = { version = "0.2.1", features = ["unproven"] } diff --git a/examples/embedded_linux_epd4in2/src/main.rs b/examples/embedded_linux_epd4in2/src/main.rs index 8306cf4..967f518 100644 --- a/examples/embedded_linux_epd4in2/src/main.rs +++ b/examples/embedded_linux_epd4in2/src/main.rs @@ -1,10 +1,12 @@ // 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; // the eink library extern crate eink_waveshare_rs; - - use eink_waveshare_rs::{ epd4in2::{ EPD4in2, @@ -14,6 +16,7 @@ use eink_waveshare_rs::{ prelude::*, }; +// Graphics extern crate embedded_graphics; use embedded_graphics::coord::Coord; use embedded_graphics::fonts::{Font6x8, Font12x16}; @@ -21,54 +24,18 @@ use embedded_graphics::prelude::*; use embedded_graphics::primitives::{Circle, Line}; use embedded_graphics::Drawing; -use lin_hal::spidev::{self, SpidevOptions}; -use lin_hal::{Pin, Spidev}; -use lin_hal::sysfs_gpio::Direction; -use lin_hal::Delay; +// HAL (Traits) +extern crate embedded_hal; +use embedded_hal::prelude::*; // activate spi, gpio in raspi-config // needs to be run with sudo because of some sysfs_gpio permission problems and follow-up timing problems // see https://github.com/rust-embedded/rust-sysfs-gpio/issues/5 and follow-up issues - -// DigitalIn Hack as long as it's not in the linux_embedded_hal -// from https://github.com/rudihorn/max31865/blob/extra_examples/examples/rpi.rs -// (slightly changed now as OutputPin doesn't provide is_high and is_low anymore) -extern crate embedded_hal; -use embedded_hal::{ - digital::{InputPin}, -}; -use embedded_hal::prelude::*; - -struct HackInputPin<'a> { - pin: &'a Pin -} - -impl<'a> HackInputPin<'a> { - fn new(p : &'a Pin) -> HackInputPin { - HackInputPin { - pin: p - } - } -} - -impl<'a> InputPin for HackInputPin<'a> { - fn is_low(&self) -> bool { - self.pin.get_value().unwrap_or(0) == 0 - } - - fn is_high(&self) -> bool { - self.pin.get_value().unwrap_or(0) == 1 - } -} - - - fn main() { run().map_err(|e| println!("{}", e.to_string())).unwrap(); } - fn run() -> Result<(), std::io::Error> { // Configure SPI @@ -93,7 +60,6 @@ fn run() -> Result<(), std::io::Error> { while !busy.is_exported() {} busy.set_direction(Direction::In).expect("busy Direction"); //busy.set_value(1).expect("busy Value set to 1"); - let busy_in = HackInputPin::new(&busy); let dc = Pin::new(6); //pin 31 //bcm6 dc.export().expect("dc export"); @@ -115,7 +81,7 @@ fn run() -> Result<(), std::io::Error> { //TODO: wait for Digital::InputPin //fixed currently with the HackInputPin, see further above - let mut epd4in2 = EPD4in2::new(&mut spi, cs, busy_in, 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(); diff --git a/src/color.rs b/src/color.rs index 611965e..8c2ab0e 100644 --- a/src/color.rs +++ b/src/color.rs @@ -14,7 +14,7 @@ pub enum Color { impl Color { /// Get the color encoding of the color for one bit - pub fn get_bit_value(&self) -> u8 { + pub fn get_bit_value(self) -> u8 { match self { Color::White => 1u8, Color::Black => 0u8, @@ -22,7 +22,7 @@ impl Color { } /// Gets a full byte of black or white pixels - pub fn get_byte_value(&self) -> u8 { + pub fn get_byte_value(self) -> u8 { match self { Color::White => 0xff, Color::Black => 0x00, @@ -41,7 +41,7 @@ impl Color { /// Returns the inverse of the given color. /// /// Black returns White and White returns Black - pub fn inverse(&self) -> Color { + pub fn inverse(self) -> Color { match self { Color::White => Color::Black, Color::Black => Color::White, diff --git a/src/epd4in2/constants.rs b/src/epd4in2/constants.rs index 9e019cc..16423e3 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; + 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, ]; +#[allow(dead_code)] #[cfg(feature = "epd4in2_fast_update")] pub(crate) const LUT_VCOM0_QUICK: [u8; 44] = [ 0x00, 0x0E, 0x00, 0x00, 0x00, 0x01, @@ -36,6 +38,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, @@ -58,6 +61,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, @@ -80,6 +84,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, @@ -102,6 +107,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, diff --git a/src/epd4in2/mod.rs b/src/epd4in2/mod.rs index bbea54f..f45869d 100644 --- a/src/epd4in2/mod.rs +++ b/src/epd4in2/mod.rs @@ -323,18 +323,18 @@ where self.send_data(spi, &[h as u8]) } - /// Fill the look-up table for the EPD - //TODO: make public? - fn set_lut(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { + /// 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 display (partial refresh) + /// Fill the look-up table for a quick refresh (partial refresh) /// - /// Is automatically done by [EPD4in2::display_frame_quick()](EPD4in2::display_frame_quick()) - /// //TODO: make public? + /// 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")] - fn set_lut_quick(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { + pub fn set_lut_quick(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { self.set_lut_helper( spi, &LUT_VCOM0_QUICK,