diff --git a/src/color.rs b/src/color.rs index c8bd818..b9388c7 100644 --- a/src/color.rs +++ b/src/color.rs @@ -2,7 +2,7 @@ #[cfg(feature = "graphics")] use embedded_graphics::pixelcolor::BinaryColor; -#[cfg(feature = "graphics")] +#[cfg(feature = "graphics")] use embedded_graphics::pixelcolor::PixelColor; #[cfg(feature = "graphics")] @@ -83,7 +83,7 @@ impl OctColor { 0x05 => Ok(OctColor::Yellow), 0x06 => Ok(OctColor::Orange), 0x07 => Ok(OctColor::HiZ), - _ => Err(()) + _ => Err(()), } } ///Split the nibbles of a single byte and convert both to an OctColor if possible diff --git a/src/epd5in65f/command.rs b/src/epd5in65f/command.rs index 54c4ac2..5035bb8 100644 --- a/src/epd5in65f/command.rs +++ b/src/epd5in65f/command.rs @@ -66,7 +66,7 @@ pub(crate) enum Command { /// Image Process Command IMAGE_PROCESS_COMMAND = 0x13, - + /// This command builds the VCOM Look-Up Table (LUTC). LUT_FOR_VCOM = 0x20, /// This command builds the Black Look-Up Table (LUTB). diff --git a/src/epd5in65f/graphics.rs b/src/epd5in65f/graphics.rs index 9ec124c..2a52b15 100644 --- a/src/epd5in65f/graphics.rs +++ b/src/epd5in65f/graphics.rs @@ -1,7 +1,7 @@ +use crate::color::OctColor; use crate::epd5in65f::{DEFAULT_BACKGROUND_COLOR, HEIGHT, WIDTH}; -use crate::graphics::{OctDisplay, DisplayRotation}; +use crate::graphics::{DisplayRotation, OctDisplay}; use embedded_graphics::prelude::*; -use crate::color::OctColor; /// Full size buffer for use with the 5in65f EPD /// @@ -56,14 +56,14 @@ impl OctDisplay for Display5in65f { mod tests { use super::*; use crate::epd5in65f; - use crate::graphics::{OctDisplay, DisplayRotation}; + use crate::graphics::{DisplayRotation, OctDisplay}; use embedded_graphics::{primitives::Line, style::PrimitiveStyle}; // test buffer length #[test] fn graphics_size() { let display = Display5in65f::default(); - assert_eq!(display.buffer().len(), 448*600 / 2); + assert_eq!(display.buffer().len(), 448 * 600 / 2); } // test default background color on all bytes @@ -71,10 +71,13 @@ mod tests { fn graphics_default() { let display = Display5in65f::default(); for &byte in display.buffer() { - assert_eq!(byte, OctColor::colors_byte( - epd5in65f::DEFAULT_BACKGROUND_COLOR, - epd5in65f::DEFAULT_BACKGROUND_COLOR, - )); + assert_eq!( + byte, + OctColor::colors_byte( + epd5in65f::DEFAULT_BACKGROUND_COLOR, + epd5in65f::DEFAULT_BACKGROUND_COLOR, + ) + ); } } @@ -87,15 +90,21 @@ mod tests { .draw(&mut display); let buffer = display.buffer(); - + for &byte in buffer.iter().take(1) { - assert_eq!(OctColor::split_byte(byte), Ok((OctColor::Black, OctColor::Black))); + assert_eq!( + OctColor::split_byte(byte), + Ok((OctColor::Black, OctColor::Black)) + ); } for &byte in buffer.iter().skip(1) { assert_eq!( OctColor::split_byte(byte), - Ok((epd5in65f::DEFAULT_BACKGROUND_COLOR, epd5in65f::DEFAULT_BACKGROUND_COLOR)) + Ok(( + epd5in65f::DEFAULT_BACKGROUND_COLOR, + epd5in65f::DEFAULT_BACKGROUND_COLOR + )) ); } } @@ -105,20 +114,29 @@ mod tests { let mut display = Display5in65f::default(); display.set_rotation(DisplayRotation::Rotate90); - let _ = Line::new(Point::new(0, WIDTH as i32 - 2), Point::new(0, WIDTH as i32- 1)) - .into_styled(PrimitiveStyle::with_stroke(OctColor::Black, 1)) - .draw(&mut display); + let _ = Line::new( + Point::new(0, WIDTH as i32 - 2), + Point::new(0, WIDTH as i32 - 1), + ) + .into_styled(PrimitiveStyle::with_stroke(OctColor::Black, 1)) + .draw(&mut display); let buffer = display.buffer(); for &byte in buffer.iter().take(1) { - assert_eq!(OctColor::split_byte(byte), Ok((OctColor::Black, OctColor::Black))); + assert_eq!( + OctColor::split_byte(byte), + Ok((OctColor::Black, OctColor::Black)) + ); } for &byte in buffer.iter().skip(1) { assert_eq!( OctColor::split_byte(byte), - Ok((epd5in65f::DEFAULT_BACKGROUND_COLOR, epd5in65f::DEFAULT_BACKGROUND_COLOR)) + Ok(( + epd5in65f::DEFAULT_BACKGROUND_COLOR, + epd5in65f::DEFAULT_BACKGROUND_COLOR + )) ); } } @@ -128,21 +146,29 @@ mod tests { let mut display = Display5in65f::default(); display.set_rotation(DisplayRotation::Rotate180); - let _ = Line::new(Point::new(WIDTH as i32 - 2, HEIGHT as i32 - 1), - Point::new(WIDTH as i32 - 1, HEIGHT as i32 - 1)) - .into_styled(PrimitiveStyle::with_stroke(OctColor::Black, 1)) - .draw(&mut display); + let _ = Line::new( + Point::new(WIDTH as i32 - 2, HEIGHT as i32 - 1), + Point::new(WIDTH as i32 - 1, HEIGHT as i32 - 1), + ) + .into_styled(PrimitiveStyle::with_stroke(OctColor::Black, 1)) + .draw(&mut display); let buffer = display.buffer(); - + for &byte in buffer.iter().take(1) { - assert_eq!(OctColor::split_byte(byte), Ok((OctColor::Black, OctColor::Black))); + assert_eq!( + OctColor::split_byte(byte), + Ok((OctColor::Black, OctColor::Black)) + ); } for &byte in buffer.iter().skip(1) { assert_eq!( OctColor::split_byte(byte), - Ok((epd5in65f::DEFAULT_BACKGROUND_COLOR, epd5in65f::DEFAULT_BACKGROUND_COLOR)) + Ok(( + epd5in65f::DEFAULT_BACKGROUND_COLOR, + epd5in65f::DEFAULT_BACKGROUND_COLOR + )) ); } } @@ -152,21 +178,29 @@ mod tests { let mut display = Display5in65f::default(); display.set_rotation(DisplayRotation::Rotate270); - let _ = Line::new(Point::new(HEIGHT as i32 -1, 0), - Point::new(HEIGHT as i32 -1, 1)) - .into_styled(PrimitiveStyle::with_stroke(OctColor::Black, 1)) - .draw(&mut display); + let _ = Line::new( + Point::new(HEIGHT as i32 - 1, 0), + Point::new(HEIGHT as i32 - 1, 1), + ) + .into_styled(PrimitiveStyle::with_stroke(OctColor::Black, 1)) + .draw(&mut display); let buffer = display.buffer(); for &byte in buffer.iter().take(1) { - assert_eq!(OctColor::split_byte(byte), Ok((OctColor::Black, OctColor::Black))); + assert_eq!( + OctColor::split_byte(byte), + Ok((OctColor::Black, OctColor::Black)) + ); } for &byte in buffer.iter().skip(1) { assert_eq!( OctColor::split_byte(byte), - Ok((epd5in65f::DEFAULT_BACKGROUND_COLOR, epd5in65f::DEFAULT_BACKGROUND_COLOR)) + Ok(( + epd5in65f::DEFAULT_BACKGROUND_COLOR, + epd5in65f::DEFAULT_BACKGROUND_COLOR + )) ); } } diff --git a/src/epd5in65f/mod.rs b/src/epd5in65f/mod.rs index fb80fb7..d10dddc 100644 --- a/src/epd5in65f/mod.rs +++ b/src/epd5in65f/mod.rs @@ -6,7 +6,6 @@ //! - [Waveshare C driver](https://github.com/waveshare/e-Paper/blob/master/RaspberryPi%26JetsonNano/c/lib/e-Paper/EPD_5in65f.c) //! - [Waveshare Python driver](https://github.com/waveshare/e-Paper/blob/master/RaspberryPi%26JetsonNano/python/lib/waveshare_epd/epd5in65f.py) - use embedded_hal::{ blocking::{delay::*, spi::Write}, digital::v2::{InputPin, OutputPin}, @@ -69,9 +68,9 @@ where self.send_resolution(spi)?; self.cmd_with_data(spi, Command::FLASH_MODE, &[0xAA])?; - + delay.delay_ms(100); - + self.cmd_with_data(spi, Command::VCOM_AND_DATA_INTERVAL_SETTING, &[0x37])?; Ok(()) } @@ -159,7 +158,7 @@ where self.wait_busy_high(); self.send_resolution(spi)?; self.command(spi, Command::DATA_START_TRANSMISSION_1)?; - self.interface.data_x_times(spi, bg, WIDTH * HEIGHT / 2)?; + self.interface.data_x_times(spi, bg, WIDTH * HEIGHT / 2)?; self.display_frame(spi)?; Ok(()) } diff --git a/src/graphics.rs b/src/graphics.rs index 524e550..f9aac40 100644 --- a/src/graphics.rs +++ b/src/graphics.rs @@ -1,7 +1,7 @@ //! Graphics Support for EPDs use crate::buffer_len; -use crate::color::{OctColor, Color}; +use crate::color::{Color, OctColor}; use embedded_graphics::{pixelcolor::BinaryColor, prelude::*}; /// Displayrotation @@ -129,7 +129,8 @@ pub trait OctDisplay: DrawTarget { } // Give us index inside the buffer and the bit-position in that u8 which needs to be changed - let (index, upper) = find_oct_position(point.x as u32, point.y as u32, width, height, rotation); + let (index, upper) = + find_oct_position(point.x as u32, point.y as u32, width, height, rotation); let index = index as usize; // "Draw" the Pixel on that bit @@ -251,19 +252,19 @@ fn find_rotation(x: u32, y: u32, width: u32, height: u32, rotation: DisplayRotat DisplayRotation::Rotate0 => { nx = x; ny = y; - }, + } DisplayRotation::Rotate90 => { nx = width - 1 - y; ny = x; - } , + } DisplayRotation::Rotate180 => { nx = width - 1 - x; ny = height - 1 - y; - }, + } DisplayRotation::Rotate270 => { nx = y; ny = height - 1 - x; - }, + } } (nx, ny) } diff --git a/src/lib.rs b/src/lib.rs index 94f275e..175dc01 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -78,21 +78,21 @@ pub mod epd2in13_v2; pub mod epd2in9; pub mod epd2in9bc; pub mod epd4in2; +pub mod epd5in65f; pub mod epd7in5; pub mod epd7in5_v2; -pub mod epd5in65f; pub(crate) mod type_a; /// Includes everything important besides the chosen Display pub mod prelude { - pub use crate::color::{Color, TriColor, OctColor}; + pub use crate::color::{Color, OctColor, TriColor}; pub use crate::traits::{RefreshLUT, WaveshareDisplay, WaveshareThreeColorDisplay}; pub use crate::SPI_MODE; #[cfg(feature = "graphics")] - pub use crate::graphics::{OctDisplay, Display, DisplayRotation}; + pub use crate::graphics::{Display, DisplayRotation, OctDisplay}; } /// Computes the needed buffer length. Takes care of rounding up in case width