diff --git a/examples/epd1in54_no_graphics.rs b/examples/epd1in54_no_graphics.rs index 5baa47e..1a293ae 100644 --- a/examples/epd1in54_no_graphics.rs +++ b/examples/epd1in54_no_graphics.rs @@ -1,21 +1,30 @@ #![deny(warnings)] +use core::convert::Infallible; use embedded_hal::delay::blocking::DelayUs; use epd_waveshare::{epd1in54::Epd1in54, prelude::*}; +use linux_embedded_hal::SPIError; use linux_embedded_hal::{ spidev::{self, SpidevOptions}, sysfs_gpio::Direction, Delay, Spidev, SysfsPin as Pin, }; -use core::convert::Infallible; -use linux_embedded_hal::SPIError; - // 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 -fn main() -> Result<(), epd_waveshare::Error> { +fn main() -> Result< + (), + epd_waveshare::Error< + SPIError, + linux_embedded_hal::sysfs_gpio::Error, + linux_embedded_hal::sysfs_gpio::Error, + linux_embedded_hal::sysfs_gpio::Error, + linux_embedded_hal::sysfs_gpio::Error, + Infallible, + >, +> { // Configure SPI // SPI settings are from eink-waveshare-rs documenation let mut spi = Spidev::open("/dev/spidev0.0")?; diff --git a/examples/epd2in13_v2.rs b/examples/epd2in13_v2.rs index 718601b..8663785 100644 --- a/examples/epd2in13_v2.rs +++ b/examples/epd2in13_v2.rs @@ -1,5 +1,6 @@ #![deny(warnings)] +use core::convert::Infallible; use embedded_graphics::{ mono_font::MonoTextStyleBuilder, prelude::*, @@ -13,20 +14,28 @@ use epd_waveshare::{ graphics::DisplayRotation, prelude::*, }; +use linux_embedded_hal::SPIError; use linux_embedded_hal::{ spidev::{self, SpidevOptions}, sysfs_gpio::Direction, Delay, Spidev, SysfsPin as Pin, }; -use core::convert::Infallible; -use linux_embedded_hal::SPIError; - // 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 -fn main() -> Result<(), epd_waveshare::Error> { +fn main() -> Result< + (), + epd_waveshare::Error< + SPIError, + linux_embedded_hal::sysfs_gpio::Error, + linux_embedded_hal::sysfs_gpio::Error, + linux_embedded_hal::sysfs_gpio::Error, + linux_embedded_hal::sysfs_gpio::Error, + Infallible, + >, +> { // Configure SPI // Settings are taken from let mut spi = Spidev::open("/dev/spidev0.0").expect("spidev directory"); diff --git a/examples/epd2in13bc.rs b/examples/epd2in13bc.rs index a0411e5..77f0e46 100644 --- a/examples/epd2in13bc.rs +++ b/examples/epd2in13bc.rs @@ -1,5 +1,6 @@ #![deny(warnings)] +use core::convert::Infallible; use embedded_graphics::{ mono_font::MonoTextStyleBuilder, prelude::*, @@ -13,14 +14,12 @@ use epd_waveshare::{ graphics::{DisplayRotation, TriDisplay}, prelude::*, }; +use linux_embedded_hal::SPIError; use linux_embedded_hal::{ spidev::{self, SpidevOptions}, sysfs_gpio::Direction, Delay, Spidev, SysfsPin as Pin, }; -use core::convert::Infallible; -use linux_embedded_hal::SPIError; - // activate spi, gpio in raspi-config // needs to be run with sudo because of some sysfs_gpio permission problems and follow-up timing problems @@ -37,7 +36,17 @@ use linux_embedded_hal::SPIError; // // after finishing, put the display to sleep -fn main() -> Result<(), epd_waveshare::Error> { +fn main() -> Result< + (), + epd_waveshare::Error< + SPIError, + linux_embedded_hal::sysfs_gpio::Error, + linux_embedded_hal::sysfs_gpio::Error, + linux_embedded_hal::sysfs_gpio::Error, + linux_embedded_hal::sysfs_gpio::Error, + Infallible, + >, +> { let busy = Pin::new(24); // GPIO 24, board J-18 busy.export().expect("busy export"); while !busy.is_exported() {} diff --git a/examples/epd4in2.rs b/examples/epd4in2.rs index 1c10139..e2b562e 100644 --- a/examples/epd4in2.rs +++ b/examples/epd4in2.rs @@ -1,5 +1,6 @@ #![deny(warnings)] +use core::convert::Infallible; use embedded_graphics::{ mono_font::MonoTextStyleBuilder, prelude::*, @@ -13,19 +14,28 @@ use epd_waveshare::{ graphics::DisplayRotation, prelude::*, }; +use linux_embedded_hal::SPIError; use linux_embedded_hal::{ spidev::{self, SpidevOptions}, sysfs_gpio::Direction, Delay, Spidev, SysfsPin as Pin, }; -use core::convert::Infallible; -use linux_embedded_hal::SPIError; // 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 -fn main() -> Result<(), epd_waveshare::Error> { +fn main() -> Result< + (), + epd_waveshare::Error< + SPIError, + linux_embedded_hal::sysfs_gpio::Error, + linux_embedded_hal::sysfs_gpio::Error, + linux_embedded_hal::sysfs_gpio::Error, + linux_embedded_hal::sysfs_gpio::Error, + Infallible, + >, +> { // Configure SPI // Settings are taken from let mut spi = Spidev::open("/dev/spidev0.0").expect("spidev directory"); diff --git a/examples/epd4in2_variable_size.rs b/examples/epd4in2_variable_size.rs index 365097e..a2f2ebc 100644 --- a/examples/epd4in2_variable_size.rs +++ b/examples/epd4in2_variable_size.rs @@ -1,6 +1,7 @@ #![deny(warnings)] #![deny(warnings)] +use core::convert::Infallible; use embedded_graphics::{ mono_font::MonoTextStyleBuilder, prelude::*, @@ -14,21 +15,28 @@ use epd_waveshare::{ graphics::{Display, DisplayRotation, VarDisplay}, prelude::*, }; +use linux_embedded_hal::SPIError; use linux_embedded_hal::{ spidev::{self, SpidevOptions}, sysfs_gpio::Direction, Delay, Spidev, SysfsPin as Pin, }; -use core::convert::Infallible; -use linux_embedded_hal::SPIError; - - // 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 -fn main() -> Result<(), epd_waveshare::Error> { +fn main() -> Result< + (), + epd_waveshare::Error< + SPIError, + linux_embedded_hal::sysfs_gpio::Error, + linux_embedded_hal::sysfs_gpio::Error, + linux_embedded_hal::sysfs_gpio::Error, + linux_embedded_hal::sysfs_gpio::Error, + Infallible, + >, +> { // Configure SPI // Settings are taken from let mut spi = Spidev::open("/dev/spidev0.0").expect("spidev directory"); diff --git a/src/epd1in54/mod.rs b/src/epd1in54/mod.rs index 83feba8..f503032 100644 --- a/src/epd1in54/mod.rs +++ b/src/epd1in54/mod.rs @@ -53,13 +53,13 @@ pub const DEFAULT_BACKGROUND_COLOR: Color = Color::White; //const DPI: u16 = 184; const IS_BUSY_LOW: bool = false; +use crate::color::Color; use crate::eh_prelude::*; use crate::type_a::{ command::Command, constants::{LUT_FULL_UPDATE, LUT_PARTIAL_UPDATE}, }; use crate::Error; -use crate::color::Color; use crate::traits::{RefreshLut, WaveshareDisplay}; @@ -80,8 +80,6 @@ pub struct Epd1in54 { refresh: RefreshLut, } - - impl Epd1in54 where SPI: Write, @@ -91,7 +89,12 @@ where RST: OutputPin, DELAY: DelayUs, { - fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error>{ + fn init( + &mut self, + spi: &mut SPI, + delay: &mut DELAY, + ) -> Result<(), Error> + { self.interface.reset(delay, 10)?; // 3 Databytes: @@ -163,7 +166,8 @@ where dc: DC, rst: RST, delay: &mut DELAY, - ) -> Result>{ + ) -> Result> + { let interface = DisplayInterface::new(cs, busy, dc, rst); let mut epd = Epd1in54 { @@ -177,11 +181,21 @@ where Ok(epd) } - fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error>{ + fn wake_up( + &mut self, + spi: &mut SPI, + delay: &mut DELAY, + ) -> Result<(), Error> + { self.init(spi, delay) } - fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error>{ + fn sleep( + &mut self, + spi: &mut SPI, + _delay: &mut DELAY, + ) -> Result<(), Error> + { self.wait_until_idle(); // 0x00 for Normal mode (Power on Reset), 0x01 for Deep Sleep Mode //TODO: is 0x00 needed here or would 0x01 be even more efficient? @@ -195,7 +209,8 @@ where spi: &mut SPI, buffer: &[u8], _delay: &mut DELAY, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.wait_until_idle(); self.use_full_frame(spi)?; self.interface @@ -212,7 +227,8 @@ where y: u32, width: u32, height: u32, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.wait_until_idle(); self.set_ram_area(spi, x, y, x + width, y + height)?; self.set_ram_counter(spi, x, y)?; @@ -222,7 +238,12 @@ where Ok(()) } - fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error>{ + fn display_frame( + &mut self, + spi: &mut SPI, + _delay: &mut DELAY, + ) -> Result<(), Error> + { self.wait_until_idle(); // enable clock signal, enable cp, display pattern -> 0xC4 (tested with the arduino version) //TODO: test control_1 or control_2 with default value 0xFF (from the datasheet) @@ -241,13 +262,19 @@ where spi: &mut SPI, buffer: &[u8], delay: &mut DELAY, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.update_frame(spi, buffer, delay)?; self.display_frame(spi, delay)?; Ok(()) } - fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error>{ + fn clear_frame( + &mut self, + spi: &mut SPI, + _delay: &mut DELAY, + ) -> Result<(), Error> + { self.wait_until_idle(); self.use_full_frame(spi)?; @@ -272,7 +299,8 @@ where &mut self, spi: &mut SPI, refresh_rate: Option, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { if let Some(refresh_lut) = refresh_rate { self.refresh = refresh_lut; } @@ -300,7 +328,11 @@ where let _ = self.interface.wait_until_idle(IS_BUSY_LOW); } - pub(crate) fn use_full_frame(&mut self, spi: &mut SPI) -> Result<(), Error>{ + pub(crate) fn use_full_frame( + &mut self, + spi: &mut SPI, + ) -> Result<(), Error> + { // choose full frame/ram self.set_ram_area(spi, 0, 0, WIDTH - 1, HEIGHT - 1)?; @@ -315,7 +347,8 @@ where start_y: u32, end_x: u32, end_y: u32, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.wait_until_idle(); assert!(start_x < end_x); assert!(start_y < end_y); @@ -347,7 +380,8 @@ where spi: &mut SPI, x: u32, y: u32, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.wait_until_idle(); // x is positioned in bytes, so the last 3 bits which show the position inside a byte in the ram // aren't relevant @@ -363,7 +397,12 @@ where Ok(()) } - fn set_lut_helper(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), Error>{ + fn set_lut_helper( + &mut self, + spi: &mut SPI, + buffer: &[u8], + ) -> Result<(), Error> + { self.wait_until_idle(); assert!(buffer.len() == 30); diff --git a/src/epd1in54b/mod.rs b/src/epd1in54b/mod.rs index 34451df..333a30b 100644 --- a/src/epd1in54b/mod.rs +++ b/src/epd1in54b/mod.rs @@ -1,10 +1,10 @@ //! A simple Driver for the Waveshare 1.54" (B) E-Ink Display via SPI -use crate::{eh_prelude::*, Error}; use crate::interface::DisplayInterface; use crate::traits::{ InternalWiAdditions, RefreshLut, WaveshareDisplay, WaveshareThreeColorDisplay, }; +use crate::{eh_prelude::*, Error}; //The Lookup Tables for the Display mod constants; @@ -44,7 +44,12 @@ where RST: OutputPin, DELAY: DelayUs, { - fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error>{ + fn init( + &mut self, + spi: &mut SPI, + delay: &mut DELAY, + ) -> Result<(), Error> + { self.interface.reset(delay, 10)?; // set the power settings @@ -96,12 +101,18 @@ where spi: &mut SPI, black: &[u8], chromatic: &[u8], - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.update_achromatic_frame(spi, black)?; self.update_chromatic_frame(spi, chromatic) } - fn update_achromatic_frame(&mut self, spi: &mut SPI, black: &[u8]) -> Result<(), Error>{ + fn update_achromatic_frame( + &mut self, + spi: &mut SPI, + black: &[u8], + ) -> Result<(), Error> + { self.wait_until_idle(); self.send_resolution(spi)?; @@ -118,7 +129,8 @@ where &mut self, spi: &mut SPI, chromatic: &[u8], - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.interface.cmd(spi, Command::DataStartTransmission2)?; self.interface.data(spi, chromatic)?; Ok(()) @@ -143,7 +155,8 @@ where dc: DC, rst: RST, delay: &mut DELAY, - ) -> Result>{ + ) -> Result> + { let interface = DisplayInterface::new(cs, busy, dc, rst); let color = DEFAULT_BACKGROUND_COLOR; @@ -154,7 +167,12 @@ where Ok(epd) } - fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error>{ + fn sleep( + &mut self, + spi: &mut SPI, + _delay: &mut DELAY, + ) -> Result<(), Error> + { self.wait_until_idle(); self.interface .cmd_with_data(spi, Command::VcomAndDataIntervalSetting, &[0x17])?; //border floating @@ -174,7 +192,12 @@ where Ok(()) } - fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error>{ + fn wake_up( + &mut self, + spi: &mut SPI, + delay: &mut DELAY, + ) -> Result<(), Error> + { self.init(spi, delay) } @@ -199,7 +222,8 @@ where spi: &mut SPI, buffer: &[u8], _delay: &mut DELAY, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.wait_until_idle(); self.send_resolution(spi)?; @@ -233,11 +257,17 @@ where y: u32, width: u32, height: u32, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { unimplemented!() } - fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error>{ + fn display_frame( + &mut self, + spi: &mut SPI, + _delay: &mut DELAY, + ) -> Result<(), Error> + { self.wait_until_idle(); self.command(spi, Command::DisplayRefresh)?; Ok(()) @@ -248,13 +278,19 @@ where spi: &mut SPI, buffer: &[u8], delay: &mut DELAY, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.update_frame(spi, buffer, delay)?; self.display_frame(spi, delay)?; Ok(()) } - fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error>{ + fn clear_frame( + &mut self, + spi: &mut SPI, + _delay: &mut DELAY, + ) -> Result<(), Error> + { self.wait_until_idle(); self.send_resolution(spi)?; @@ -278,7 +314,8 @@ where &mut self, spi: &mut SPI, _refresh_rate: Option, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.interface .cmd_with_data(spi, Command::LutForVcom, LUT_VCOM0)?; self.interface @@ -311,11 +348,21 @@ where RST: OutputPin, DELAY: DelayUs, { - fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), Error>{ + fn command( + &mut self, + spi: &mut SPI, + command: Command, + ) -> Result<(), Error> + { self.interface.cmd(spi, command) } - fn send_data(&mut self, spi: &mut SPI, data: &[u8]) -> Result<(), Error>{ + fn send_data( + &mut self, + spi: &mut SPI, + data: &[u8], + ) -> Result<(), Error> + { self.interface.data(spi, data) } @@ -324,7 +371,8 @@ where spi: &mut SPI, command: Command, data: &[u8], - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.interface.cmd_with_data(spi, command, data) } @@ -332,7 +380,11 @@ where let _ = self.interface.wait_until_idle(IS_BUSY_LOW); } - fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), Error>{ + fn send_resolution( + &mut self, + spi: &mut SPI, + ) -> Result<(), Error> + { let w = self.width(); let h = self.height(); diff --git a/src/epd1in54c/mod.rs b/src/epd1in54c/mod.rs index 8477f65..b6fea57 100644 --- a/src/epd1in54c/mod.rs +++ b/src/epd1in54c/mod.rs @@ -1,10 +1,10 @@ //! A simple Driver for the Waveshare 1.54" (C) E-Ink Display via SPI -use crate::{eh_prelude::*, Error}; use crate::interface::DisplayInterface; use crate::traits::{ InternalWiAdditions, RefreshLut, WaveshareDisplay, WaveshareThreeColorDisplay, }; +use crate::{eh_prelude::*, Error}; /// Width of epd1in54 in pixels pub const WIDTH: u32 = 152; @@ -42,7 +42,12 @@ where RST: OutputPin, DELAY: DelayUs, { - fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error>{ + fn init( + &mut self, + spi: &mut SPI, + delay: &mut DELAY, + ) -> Result<(), Error> + { // Based on Reference Program Code from: // https://www.waveshare.com/w/upload/a/ac/1.54inch_e-Paper_Module_C_Specification.pdf // and: @@ -84,12 +89,18 @@ where spi: &mut SPI, black: &[u8], chromatic: &[u8], - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.update_achromatic_frame(spi, black)?; self.update_chromatic_frame(spi, chromatic) } - fn update_achromatic_frame(&mut self, spi: &mut SPI, black: &[u8]) -> Result<(), Error>{ + fn update_achromatic_frame( + &mut self, + spi: &mut SPI, + black: &[u8], + ) -> Result<(), Error> + { self.wait_until_idle(); self.cmd_with_data(spi, Command::DataStartTransmission1, black)?; @@ -100,7 +111,8 @@ where &mut self, spi: &mut SPI, chromatic: &[u8], - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.wait_until_idle(); self.cmd_with_data(spi, Command::DataStartTransmission2, chromatic)?; @@ -126,7 +138,8 @@ where dc: DC, rst: RST, delay: &mut DELAY, - ) -> Result>{ + ) -> Result> + { let interface = DisplayInterface::new(cs, busy, dc, rst); let color = DEFAULT_BACKGROUND_COLOR; @@ -137,7 +150,12 @@ where Ok(epd) } - fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error>{ + fn sleep( + &mut self, + spi: &mut SPI, + _delay: &mut DELAY, + ) -> Result<(), Error> + { self.wait_until_idle(); self.command(spi, Command::PowerOff)?; @@ -147,7 +165,12 @@ where Ok(()) } - fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error>{ + fn wake_up( + &mut self, + spi: &mut SPI, + delay: &mut DELAY, + ) -> Result<(), Error> + { self.init(spi, delay) } @@ -172,7 +195,8 @@ where spi: &mut SPI, buffer: &[u8], _delay: &mut DELAY, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.update_achromatic_frame(spi, buffer)?; // Clear the chromatic layer @@ -193,11 +217,17 @@ where y: u32, width: u32, height: u32, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { unimplemented!() } - fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error>{ + fn display_frame( + &mut self, + spi: &mut SPI, + _delay: &mut DELAY, + ) -> Result<(), Error> + { self.command(spi, Command::DisplayRefresh)?; self.wait_until_idle(); @@ -209,14 +239,20 @@ where spi: &mut SPI, buffer: &[u8], delay: &mut DELAY, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.update_frame(spi, buffer, delay)?; self.display_frame(spi, delay)?; Ok(()) } - fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error>{ + fn clear_frame( + &mut self, + spi: &mut SPI, + _delay: &mut DELAY, + ) -> Result<(), Error> + { self.wait_until_idle(); let color = DEFAULT_BACKGROUND_COLOR.get_byte_value(); @@ -235,7 +271,8 @@ where &mut self, _spi: &mut SPI, _refresh_rate: Option, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { Ok(()) } @@ -253,11 +290,21 @@ where RST: OutputPin, DELAY: DelayUs, { - fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), Error>{ + fn command( + &mut self, + spi: &mut SPI, + command: Command, + ) -> Result<(), Error> + { self.interface.cmd(spi, command) } - fn send_data(&mut self, spi: &mut SPI, data: &[u8]) -> Result<(), Error>{ + fn send_data( + &mut self, + spi: &mut SPI, + data: &[u8], + ) -> Result<(), Error> + { self.interface.data(spi, data) } @@ -266,7 +313,8 @@ where spi: &mut SPI, command: Command, data: &[u8], - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.interface.cmd_with_data(spi, command, data) } @@ -274,7 +322,11 @@ where let _ = self.interface.wait_until_idle(IS_BUSY_LOW); } - fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), Error>{ + fn send_resolution( + &mut self, + spi: &mut SPI, + ) -> Result<(), Error> + { let w = self.width(); let h = self.height(); diff --git a/src/epd2in13_v2/mod.rs b/src/epd2in13_v2/mod.rs index 3c5cedb..130d3dc 100644 --- a/src/epd2in13_v2/mod.rs +++ b/src/epd2in13_v2/mod.rs @@ -8,11 +8,12 @@ //! - [Controller Datasheet SS1780](http://www.e-paper-display.com/download_detail/downloadsId=682.html) //! -use crate::{buffer_len};use crate::Error; +use crate::buffer_len; use crate::color::Color; use crate::eh_prelude::*; use crate::interface::DisplayInterface; use crate::traits::{InternalWiAdditions, RefreshLut, WaveshareDisplay}; +use crate::Error; pub(crate) mod command; use self::command::{ @@ -62,7 +63,12 @@ where RST: OutputPin, DELAY: DelayUs, { - fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error>{ + fn init( + &mut self, + spi: &mut SPI, + delay: &mut DELAY, + ) -> Result<(), Error> + { // HW reset self.interface.reset(delay, 10)?; @@ -164,7 +170,8 @@ where dc: DC, rst: RST, delay: &mut DELAY, - ) -> Result>{ + ) -> Result> + { let mut epd = Epd2in13 { interface: DisplayInterface::new(cs, busy, dc, rst), sleep_mode: DeepSleepMode::Mode1, @@ -176,11 +183,21 @@ where Ok(epd) } - fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error>{ + fn wake_up( + &mut self, + spi: &mut SPI, + delay: &mut DELAY, + ) -> Result<(), Error> + { self.init(spi, delay) } - fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error>{ + fn sleep( + &mut self, + spi: &mut SPI, + _delay: &mut DELAY, + ) -> Result<(), Error> + { self.wait_until_idle(); // All sample code enables and disables analog/clocks... @@ -203,7 +220,8 @@ where spi: &mut SPI, buffer: &[u8], _delay: &mut DELAY, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { assert!(buffer.len() == buffer_len(WIDTH as usize, HEIGHT as usize)); self.set_ram_area(spi, 0, 0, WIDTH - 1, HEIGHT - 1)?; self.set_ram_address_counters(spi, 0, 0)?; @@ -231,7 +249,8 @@ where y: u32, width: u32, height: u32, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { assert!((width * height / 8) as usize == buffer.len()); // This should not be used when doing partial refresh. The RAM_RED must @@ -260,7 +279,12 @@ where /// Never use directly this function when using partial refresh, or also /// keep the base buffer in syncd using `set_partial_base_buffer` function. - fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error>{ + fn display_frame( + &mut self, + spi: &mut SPI, + _delay: &mut DELAY, + ) -> Result<(), Error> + { if self.refresh == RefreshLut::Full { self.set_display_update_control_2( spi, @@ -285,7 +309,8 @@ where spi: &mut SPI, buffer: &[u8], delay: &mut DELAY, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.update_frame(spi, buffer, delay)?; self.display_frame(spi, delay)?; @@ -295,7 +320,12 @@ where Ok(()) } - fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error>{ + fn clear_frame( + &mut self, + spi: &mut SPI, + _delay: &mut DELAY, + ) -> Result<(), Error> + { let color = self.background_color.get_byte_value(); self.set_ram_area(spi, 0, 0, WIDTH - 1, HEIGHT - 1)?; @@ -343,7 +373,8 @@ where &mut self, spi: &mut SPI, refresh_rate: Option, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { let buffer = match refresh_rate { Some(RefreshLut::Full) | None => &LUT_FULL_UPDATE, Some(RefreshLut::Quick) => &LUT_PARTIAL_UPDATE, @@ -372,7 +403,8 @@ where &mut self, spi: &mut SPI, buffer: &[u8], - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { assert!(buffer_len(WIDTH as usize, HEIGHT as usize) == buffer.len()); self.set_ram_area(spi, 0, 0, WIDTH - 1, HEIGHT - 1)?; self.set_ram_address_counters(spi, 0, 0)?; @@ -393,7 +425,8 @@ where spi: &mut SPI, delay: &mut DELAY, refresh: RefreshLut, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { if self.refresh != refresh { self.refresh = refresh; self.init(spi, delay)?; @@ -405,7 +438,8 @@ where &mut self, spi: &mut SPI, start: u16, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { assert!(start <= 295); self.cmd_with_data( spi, @@ -418,7 +452,8 @@ where &mut self, spi: &mut SPI, borderwaveform: BorderWaveForm, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.cmd_with_data( spi, Command::BorderWaveformControl, @@ -426,7 +461,12 @@ where ) } - fn set_vcom_register(&mut self, spi: &mut SPI, vcom: Vcom) -> Result<(), Error>{ + fn set_vcom_register( + &mut self, + spi: &mut SPI, + vcom: Vcom, + ) -> Result<(), Error> + { self.cmd_with_data(spi, Command::WriteVcomRegister, &[vcom.0]) } @@ -434,7 +474,8 @@ where &mut self, spi: &mut SPI, voltage: GateDrivingVoltage, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.cmd_with_data(spi, Command::GateDrivingVoltageCtrl, &[voltage.0]) } @@ -442,12 +483,18 @@ where &mut self, spi: &mut SPI, number_of_lines: u8, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { assert!(number_of_lines <= 127); self.cmd_with_data(spi, Command::SetDummyLinePeriod, &[number_of_lines]) } - fn set_gate_line_width(&mut self, spi: &mut SPI, width: u8) -> Result<(), Error>{ + fn set_gate_line_width( + &mut self, + spi: &mut SPI, + width: u8, + ) -> Result<(), Error> + { self.cmd_with_data(spi, Command::SetGateLineWidth, &[width & 0x0F]) } @@ -458,7 +505,8 @@ where vsh1: SourceDrivingVoltage, vsh2: SourceDrivingVoltage, vsl: SourceDrivingVoltage, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.cmd_with_data( spi, Command::SourceDrivingVoltageCtrl, @@ -472,16 +520,27 @@ where &mut self, spi: &mut SPI, value: DisplayUpdateControl2, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.cmd_with_data(spi, Command::DisplayUpdateControl2, &[value.0]) } /// Triggers the deep sleep mode - fn set_sleep_mode(&mut self, spi: &mut SPI, mode: DeepSleepMode) -> Result<(), Error>{ + fn set_sleep_mode( + &mut self, + spi: &mut SPI, + mode: DeepSleepMode, + ) -> Result<(), Error> + { self.cmd_with_data(spi, Command::DeepSleepMode, &[mode as u8]) } - fn set_driver_output(&mut self, spi: &mut SPI, output: DriverOutput) -> Result<(), Error>{ + fn set_driver_output( + &mut self, + spi: &mut SPI, + output: DriverOutput, + ) -> Result<(), Error> + { self.cmd_with_data(spi, Command::DriverOutputControl, &output.to_bytes()) } @@ -492,7 +551,8 @@ where spi: &mut SPI, counter_incr_mode: DataEntryModeIncr, counter_direction: DataEntryModeDir, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { let mode = counter_incr_mode as u8 | counter_direction as u8; self.cmd_with_data(spi, Command::DataEntryModeSetting, &[mode]) } @@ -505,7 +565,8 @@ where start_y: u32, end_x: u32, end_y: u32, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.cmd_with_data( spi, Command::SetRamXAddressStartEndPosition, @@ -530,7 +591,8 @@ where spi: &mut SPI, x: u32, y: u32, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.wait_until_idle(); self.cmd_with_data(spi, Command::SetRamXAddressCounter, &[(x >> 3) as u8])?; @@ -542,7 +604,12 @@ where Ok(()) } - fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), Error>{ + fn command( + &mut self, + spi: &mut SPI, + command: Command, + ) -> Result<(), Error> + { self.interface.cmd(spi, command) } @@ -551,7 +618,8 @@ where spi: &mut SPI, command: Command, data: &[u8], - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.interface.cmd_with_data(spi, command, data) } diff --git a/src/epd2in13bc/mod.rs b/src/epd2in13bc/mod.rs index 5a8e0f2..2524bbe 100644 --- a/src/epd2in13bc/mod.rs +++ b/src/epd2in13bc/mod.rs @@ -50,11 +50,11 @@ //!# } //!``` -use crate::{eh_prelude::*, Error}; use crate::interface::DisplayInterface; use crate::traits::{ InternalWiAdditions, RefreshLut, WaveshareDisplay, WaveshareThreeColorDisplay, }; +use crate::{eh_prelude::*, Error}; /// Width of epd2in13bc in pixels pub const WIDTH: u32 = 104; @@ -99,7 +99,12 @@ where RST: OutputPin, DELAY: DelayUs, { - fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error>{ + fn init( + &mut self, + spi: &mut SPI, + delay: &mut DELAY, + ) -> Result<(), Error> + { // Values taken from datasheet and sample code self.interface.reset(delay, 10)?; @@ -148,7 +153,8 @@ where spi: &mut SPI, black: &[u8], chromatic: &[u8], - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.update_achromatic_frame(spi, black)?; self.update_chromatic_frame(spi, chromatic) } @@ -156,7 +162,12 @@ where /// Update only the black/white data of the display. /// /// Finish by calling `update_chromatic_frame`. - fn update_achromatic_frame(&mut self, spi: &mut SPI, black: &[u8]) -> Result<(), Error>{ + fn update_achromatic_frame( + &mut self, + spi: &mut SPI, + black: &[u8], + ) -> Result<(), Error> + { self.interface.cmd(spi, Command::DataStartTransmission1)?; self.interface.data(spi, black)?; Ok(()) @@ -169,7 +180,8 @@ where &mut self, spi: &mut SPI, chromatic: &[u8], - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.interface.cmd(spi, Command::DataStartTransmission2)?; self.interface.data(spi, chromatic)?; @@ -196,7 +208,8 @@ where dc: DC, rst: RST, delay: &mut DELAY, - ) -> Result>{ + ) -> Result> + { let interface = DisplayInterface::new(cs, busy, dc, rst); let color = DEFAULT_BACKGROUND_COLOR; @@ -207,7 +220,12 @@ where Ok(epd) } - fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error>{ + fn sleep( + &mut self, + spi: &mut SPI, + _delay: &mut DELAY, + ) -> Result<(), Error> + { // Section 8.2 from datasheet self.interface.cmd_with_data( spi, @@ -224,7 +242,12 @@ where Ok(()) } - fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error>{ + fn wake_up( + &mut self, + spi: &mut SPI, + delay: &mut DELAY, + ) -> Result<(), Error> + { self.init(spi, delay) } @@ -249,7 +272,8 @@ where spi: &mut SPI, buffer: &[u8], _delay: &mut DELAY, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.interface.cmd(spi, Command::DataStartTransmission1)?; self.interface.data(spi, buffer)?; @@ -273,11 +297,17 @@ where y: u32, width: u32, height: u32, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { Ok(()) } - fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error>{ + fn display_frame( + &mut self, + spi: &mut SPI, + _delay: &mut DELAY, + ) -> Result<(), Error> + { self.command(spi, Command::DisplayRefresh)?; self.wait_until_idle(); @@ -289,13 +319,19 @@ where spi: &mut SPI, buffer: &[u8], delay: &mut DELAY, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.update_frame(spi, buffer, delay)?; self.display_frame(spi, delay)?; Ok(()) } - fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error>{ + fn clear_frame( + &mut self, + spi: &mut SPI, + _delay: &mut DELAY, + ) -> Result<(), Error> + { self.send_resolution(spi)?; let color = DEFAULT_BACKGROUND_COLOR.get_byte_value(); @@ -317,7 +353,8 @@ where &mut self, _spi: &mut SPI, _refresh_rate: Option, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { Ok(()) } @@ -335,11 +372,21 @@ where RST: OutputPin, DELAY: DelayUs, { - fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), Error>{ + fn command( + &mut self, + spi: &mut SPI, + command: Command, + ) -> Result<(), Error> + { self.interface.cmd(spi, command) } - fn send_data(&mut self, spi: &mut SPI, data: &[u8]) -> Result<(), Error>{ + fn send_data( + &mut self, + spi: &mut SPI, + data: &[u8], + ) -> Result<(), Error> + { self.interface.data(spi, data) } @@ -348,7 +395,8 @@ where spi: &mut SPI, command: Command, data: &[u8], - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.interface.cmd_with_data(spi, command, data) } @@ -356,7 +404,11 @@ where let _ = self.interface.wait_until_idle(IS_BUSY_LOW); } - fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), Error>{ + fn send_resolution( + &mut self, + spi: &mut SPI, + ) -> Result<(), Error> + { let w = self.width(); let h = self.height(); @@ -368,7 +420,12 @@ where } /// Set the outer border of the display to the chosen color. - pub fn set_border_color(&mut self, spi: &mut SPI, color: TriColor) -> Result<(), Error>{ + pub fn set_border_color( + &mut self, + spi: &mut SPI, + color: TriColor, + ) -> Result<(), Error> + { let border = match color { TriColor::Black => BLACK_BORDER, TriColor::White => WHITE_BORDER, diff --git a/src/epd2in7b/mod.rs b/src/epd2in7b/mod.rs index f6a2605..9f088a8 100644 --- a/src/epd2in7b/mod.rs +++ b/src/epd2in7b/mod.rs @@ -2,11 +2,11 @@ //! //! [Documentation](https://www.waveshare.com/wiki/2.7inch_e-Paper_HAT_(B)) -use crate::{eh_prelude::*, Error}; use crate::interface::DisplayInterface; use crate::traits::{ InternalWiAdditions, RefreshLut, WaveshareDisplay, WaveshareThreeColorDisplay, }; +use crate::{eh_prelude::*, Error}; // The Lookup Tables for the Display mod constants; @@ -48,7 +48,12 @@ where RST: OutputPin, DELAY: DelayUs, { - fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error>{ + fn init( + &mut self, + spi: &mut SPI, + delay: &mut DELAY, + ) -> Result<(), Error> + { // reset the device self.interface.reset(delay, 2)?; @@ -122,7 +127,8 @@ where dc: DC, rst: RST, delay: &mut DELAY, - ) -> Result>{ + ) -> Result> + { let interface = DisplayInterface::new(cs, busy, dc, rst); let color = DEFAULT_BACKGROUND_COLOR; @@ -133,11 +139,21 @@ where Ok(epd) } - fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error>{ + fn wake_up( + &mut self, + spi: &mut SPI, + delay: &mut DELAY, + ) -> Result<(), Error> + { self.init(spi, delay) } - fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error>{ + fn sleep( + &mut self, + spi: &mut SPI, + _delay: &mut DELAY, + ) -> Result<(), Error> + { self.wait_until_idle(); self.interface .cmd_with_data(spi, Command::VcomAndDataIntervalSetting, &[0xf7])?; @@ -154,7 +170,8 @@ where spi: &mut SPI, buffer: &[u8], _delay: &mut DELAY, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.interface.cmd(spi, Command::DataStartTransmission1)?; self.send_buffer_helper(spi, buffer)?; @@ -175,7 +192,8 @@ where y: u32, width: u32, height: u32, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.interface .cmd(spi, Command::PartialDataStartTransmission1)?; @@ -194,7 +212,12 @@ where self.interface.cmd(spi, Command::DataStop) } - fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error>{ + fn display_frame( + &mut self, + spi: &mut SPI, + _delay: &mut DELAY, + ) -> Result<(), Error> + { self.command(spi, Command::DisplayRefresh)?; self.wait_until_idle(); Ok(()) @@ -205,13 +228,19 @@ where spi: &mut SPI, buffer: &[u8], delay: &mut DELAY, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.update_frame(spi, buffer, delay)?; self.command(spi, Command::DisplayRefresh)?; Ok(()) } - fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error>{ + fn clear_frame( + &mut self, + spi: &mut SPI, + _delay: &mut DELAY, + ) -> Result<(), Error> + { self.wait_until_idle(); let color_value = self.color.get_byte_value(); @@ -248,7 +277,8 @@ where &mut self, spi: &mut SPI, _refresh_rate: Option, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.wait_until_idle(); self.cmd_with_data(spi, Command::LutForVcom, &LUT_VCOM_DC)?; self.cmd_with_data(spi, Command::LutWhiteToWhite, &LUT_WW)?; @@ -278,7 +308,8 @@ where spi: &mut SPI, black: &[u8], chromatic: &[u8], - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.update_achromatic_frame(spi, black)?; self.update_chromatic_frame(spi, chromatic) } @@ -290,7 +321,8 @@ where &mut self, spi: &mut SPI, achromatic: &[u8], - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.interface.cmd(spi, Command::DataStartTransmission1)?; self.send_buffer_helper(spi, achromatic)?; @@ -305,7 +337,8 @@ where &mut self, spi: &mut SPI, chromatic: &[u8], - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.interface.cmd(spi, Command::DataStartTransmission2)?; self.send_buffer_helper(spi, chromatic)?; @@ -326,15 +359,30 @@ where RST: OutputPin, DELAY: DelayUs, { - fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), Error>{ + fn command( + &mut self, + spi: &mut SPI, + command: Command, + ) -> Result<(), Error> + { self.interface.cmd(spi, command) } - fn send_data(&mut self, spi: &mut SPI, data: &[u8]) -> Result<(), Error>{ + fn send_data( + &mut self, + spi: &mut SPI, + data: &[u8], + ) -> Result<(), Error> + { self.interface.data(spi, data) } - fn send_buffer_helper(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), Error>{ + fn send_buffer_helper( + &mut self, + spi: &mut SPI, + buffer: &[u8], + ) -> Result<(), Error> + { // Based on the waveshare implementation, all data for color values is flipped. This helper // method makes that transmission easier for b in buffer.iter() { @@ -348,7 +396,8 @@ where spi: &mut SPI, command: Command, data: &[u8], - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.interface.cmd_with_data(spi, command, data) } @@ -364,7 +413,8 @@ where y: u32, width: u32, height: u32, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.command(spi, Command::PartialDisplayRefresh)?; self.send_data(spi, &[(x >> 8) as u8])?; self.send_data(spi, &[(x & 0xf8) as u8])?; @@ -387,7 +437,8 @@ where y: u32, width: u32, height: u32, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.interface .cmd(spi, Command::PartialDataStartTransmission1)?; self.send_data(spi, &[(x >> 8) as u8])?; @@ -417,7 +468,8 @@ where y: u32, width: u32, height: u32, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.interface .cmd(spi, Command::PartialDataStartTransmission2)?; self.send_data(spi, &[(x >> 8) as u8])?; diff --git a/src/epd2in9/mod.rs b/src/epd2in9/mod.rs index aa3082b..c874f70 100644 --- a/src/epd2in9/mod.rs +++ b/src/epd2in9/mod.rs @@ -49,13 +49,13 @@ pub const HEIGHT: u32 = 296; pub const DEFAULT_BACKGROUND_COLOR: Color = Color::White; const IS_BUSY_LOW: bool = false; -use crate::{eh_prelude::*}; +use crate::color::Color; +use crate::eh_prelude::*; use crate::type_a::{ command::Command, constants::{LUT_FULL_UPDATE, LUT_PARTIAL_UPDATE}, }; use crate::Error; -use crate::color::Color; use crate::traits::*; @@ -86,7 +86,12 @@ where RST: OutputPin, DELAY: DelayUs, { - fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error>{ + fn init( + &mut self, + spi: &mut SPI, + delay: &mut DELAY, + ) -> Result<(), Error> + { self.interface.reset(delay, 10)?; self.wait_until_idle(); @@ -154,7 +159,8 @@ where dc: DC, rst: RST, delay: &mut DELAY, - ) -> Result>{ + ) -> Result> + { let interface = DisplayInterface::new(cs, busy, dc, rst); let mut epd = Epd2in9 { @@ -168,7 +174,12 @@ where Ok(epd) } - fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error>{ + fn sleep( + &mut self, + spi: &mut SPI, + _delay: &mut DELAY, + ) -> Result<(), Error> + { self.wait_until_idle(); // 0x00 for Normal mode (Power on Reset), 0x01 for Deep Sleep Mode //TODO: is 0x00 needed here? (see also epd1in54) @@ -177,7 +188,12 @@ where Ok(()) } - fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error>{ + fn wake_up( + &mut self, + spi: &mut SPI, + delay: &mut DELAY, + ) -> Result<(), Error> + { self.wait_until_idle(); self.init(spi, delay)?; Ok(()) @@ -188,7 +204,8 @@ where spi: &mut SPI, buffer: &[u8], _delay: &mut DELAY, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.wait_until_idle(); self.use_full_frame(spi)?; @@ -206,7 +223,8 @@ where y: u32, width: u32, height: u32, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.wait_until_idle(); self.set_ram_area(spi, x, y, x + width, y + height)?; self.set_ram_counter(spi, x, y)?; @@ -216,7 +234,12 @@ where Ok(()) } - fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error>{ + fn display_frame( + &mut self, + spi: &mut SPI, + _delay: &mut DELAY, + ) -> Result<(), Error> + { self.wait_until_idle(); // enable clock signal, enable cp, display pattern -> 0xC4 (tested with the arduino version) //TODO: test control_1 or control_2 with default value 0xFF (from the datasheet) @@ -235,13 +258,19 @@ where spi: &mut SPI, buffer: &[u8], delay: &mut DELAY, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.update_frame(spi, buffer, delay)?; self.display_frame(spi, delay)?; Ok(()) } - fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error>{ + fn clear_frame( + &mut self, + spi: &mut SPI, + _delay: &mut DELAY, + ) -> Result<(), Error> + { self.wait_until_idle(); self.use_full_frame(spi)?; @@ -266,7 +295,8 @@ where &mut self, spi: &mut SPI, refresh_rate: Option, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { if let Some(refresh_lut) = refresh_rate { self.refresh = refresh_lut; } @@ -294,7 +324,11 @@ where let _ = self.interface.wait_until_idle(IS_BUSY_LOW); } - fn use_full_frame(&mut self, spi: &mut SPI) -> Result<(), Error>{ + fn use_full_frame( + &mut self, + spi: &mut SPI, + ) -> Result<(), Error> + { // choose full frame/ram self.set_ram_area(spi, 0, 0, WIDTH - 1, HEIGHT - 1)?; @@ -309,7 +343,8 @@ where start_y: u32, end_x: u32, end_y: u32, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { assert!(start_x < end_x); assert!(start_y < end_y); @@ -334,7 +369,13 @@ where ) } - fn set_ram_counter(&mut self, spi: &mut SPI, x: u32, y: u32) -> Result<(), Error>{ + fn set_ram_counter( + &mut self, + spi: &mut SPI, + x: u32, + y: u32, + ) -> Result<(), Error> + { self.wait_until_idle(); // x is positioned in bytes, so the last 3 bits which show the position inside a byte in the ram // aren't relevant @@ -351,7 +392,12 @@ where } /// Set your own LUT, this function is also used internally for set_lut - fn set_lut_helper(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), Error>{ + fn set_lut_helper( + &mut self, + spi: &mut SPI, + buffer: &[u8], + ) -> Result<(), Error> + { self.wait_until_idle(); assert!(buffer.len() == 30); self.interface diff --git a/src/epd2in9_v2/mod.rs b/src/epd2in9_v2/mod.rs index fc15f51..dfeed1c 100644 --- a/src/epd2in9_v2/mod.rs +++ b/src/epd2in9_v2/mod.rs @@ -74,10 +74,10 @@ const LUT_PARTIAL_2IN9: [u8; 153] = [ 0x22, 0x0, 0x0, 0x0, ]; -use crate::{eh_prelude::*}; +use crate::color::Color; +use crate::eh_prelude::*; use crate::type_a::command::Command; use crate::Error; -use crate::color::Color; use crate::traits::*; @@ -109,7 +109,12 @@ where RST: OutputPin, DELAY: DelayUs, { - fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error>{ + fn init( + &mut self, + spi: &mut SPI, + delay: &mut DELAY, + ) -> Result<(), Error> + { self.interface.reset(delay, 2)?; self.wait_until_idle(); @@ -167,7 +172,8 @@ where dc: DC, rst: RST, delay: &mut DELAY, - ) -> Result>{ + ) -> Result> + { let interface = DisplayInterface::new(cs, busy, dc, rst); let mut epd = Epd2in9 { @@ -181,7 +187,12 @@ where Ok(epd) } - fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error>{ + fn sleep( + &mut self, + spi: &mut SPI, + _delay: &mut DELAY, + ) -> Result<(), Error> + { self.wait_until_idle(); // 0x00 for Normal mode (Power on Reset), 0x01 for Deep Sleep Mode self.interface @@ -189,7 +200,12 @@ where Ok(()) } - fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error>{ + fn wake_up( + &mut self, + spi: &mut SPI, + delay: &mut DELAY, + ) -> Result<(), Error> + { self.init(spi, delay)?; Ok(()) } @@ -199,7 +215,8 @@ where spi: &mut SPI, buffer: &[u8], _delay: &mut DELAY, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.wait_until_idle(); self.interface.cmd_with_data(spi, Command::WriteRam, buffer) } @@ -212,7 +229,8 @@ where y: u32, width: u32, height: u32, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { //TODO This is copied from epd2in9 but it seems not working. Partial refresh supported by version 2? self.wait_until_idle(); self.set_ram_area(spi, x, y, x + width, y + height)?; @@ -223,7 +241,12 @@ where Ok(()) } - fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error>{ + fn display_frame( + &mut self, + spi: &mut SPI, + _delay: &mut DELAY, + ) -> Result<(), Error> + { self.wait_until_idle(); // Enable clock signal, Enable Analog, Load temperature value, DISPLAY with DISPLAY Mode 1, Disable Analog, Disable OSC self.interface @@ -238,13 +261,19 @@ where spi: &mut SPI, buffer: &[u8], delay: &mut DELAY, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.update_frame(spi, buffer, delay)?; self.display_frame(spi, delay)?; Ok(()) } - fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error>{ + fn clear_frame( + &mut self, + spi: &mut SPI, + _delay: &mut DELAY, + ) -> Result<(), Error> + { self.wait_until_idle(); // clear the ram with the background color @@ -266,7 +295,8 @@ where &mut self, _spi: &mut SPI, refresh_rate: Option, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { if let Some(refresh_lut) = refresh_rate { self.refresh = refresh_lut; } @@ -291,7 +321,11 @@ where self.interface.wait_until_idle(IS_BUSY_LOW); } - fn use_full_frame(&mut self, spi: &mut SPI) -> Result<(), Error>{ + fn use_full_frame( + &mut self, + spi: &mut SPI, + ) -> Result<(), Error> + { // choose full frame/ram self.set_ram_area(spi, 0, 0, WIDTH - 1, HEIGHT - 1)?; @@ -306,7 +340,8 @@ where start_y: u32, end_x: u32, end_y: u32, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { assert!(start_x < end_x); assert!(start_y < end_y); @@ -331,7 +366,13 @@ where ) } - fn set_ram_counter(&mut self, spi: &mut SPI, x: u32, y: u32) -> Result<(), Error>{ + fn set_ram_counter( + &mut self, + spi: &mut SPI, + x: u32, + y: u32, + ) -> Result<(), Error> + { self.wait_until_idle(); // x is positioned in bytes, so the last 3 bits which show the position inside a byte in the ram // aren't relevant @@ -348,7 +389,12 @@ where } /// Set your own LUT, this function is also used internally for set_lut - fn set_lut_helper(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), Error>{ + fn set_lut_helper( + &mut self, + spi: &mut SPI, + buffer: &[u8], + ) -> Result<(), Error> + { self.wait_until_idle(); self.interface .cmd_with_data(spi, Command::WriteLutRegister, buffer)?; @@ -373,7 +419,8 @@ where spi: &mut SPI, buffer: &[u8], _delay: &mut DELAY, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.wait_until_idle(); self.interface .cmd_with_data(spi, Command::WriteRam, buffer)?; @@ -387,7 +434,8 @@ where spi: &mut SPI, buffer: &[u8], delay: &mut DELAY, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.wait_until_idle(); self.interface.reset(delay, 2)?; @@ -413,7 +461,12 @@ where } /// For a quick refresh of the new updated frame. To be used immediately after `update_new_frame` - fn display_new_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error>{ + fn display_new_frame( + &mut self, + spi: &mut SPI, + _delay: &mut DELAY, + ) -> Result<(), Error> + { self.wait_until_idle(); self.interface .cmd_with_data(spi, Command::DisplayUpdateControl2, &[0x0F])?; @@ -428,7 +481,8 @@ where spi: &mut SPI, buffer: &[u8], delay: &mut DELAY, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.update_new_frame(spi, buffer, delay)?; self.display_new_frame(spi, delay)?; Ok(()) @@ -444,7 +498,8 @@ where y: u32, width: u32, height: u32, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { //TODO supported by display? unimplemented!() } @@ -459,7 +514,8 @@ where y: u32, width: u32, height: u32, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { //TODO supported by display? unimplemented!() } @@ -473,7 +529,8 @@ where y: u32, width: u32, height: u32, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { //TODO supported by display? unimplemented!() } diff --git a/src/epd2in9bc/mod.rs b/src/epd2in9bc/mod.rs index 5514a14..e71c430 100644 --- a/src/epd2in9bc/mod.rs +++ b/src/epd2in9bc/mod.rs @@ -54,11 +54,11 @@ //!# } //!``` //! -use crate::{eh_prelude::*, Error}; use crate::interface::DisplayInterface; use crate::traits::{ InternalWiAdditions, RefreshLut, WaveshareDisplay, WaveshareThreeColorDisplay, }; +use crate::{eh_prelude::*, Error}; /// Width of epd2in9bc in pixels pub const WIDTH: u32 = 128; @@ -76,7 +76,6 @@ const BLACK_BORDER: u8 = 0x30; const CHROMATIC_BORDER: u8 = 0xb0; const FLOATING_BORDER: u8 = 0xF0; - use crate::color::{Color, TriColor}; pub(crate) mod command; @@ -103,7 +102,12 @@ where RST: OutputPin, DELAY: DelayUs, { - fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error>{ + fn init( + &mut self, + spi: &mut SPI, + delay: &mut DELAY, + ) -> Result<(), Error> + { // Values taken from datasheet and sample code self.interface.reset(delay, 10)?; @@ -152,7 +156,8 @@ where spi: &mut SPI, black: &[u8], chromatic: &[u8], - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.update_achromatic_frame(spi, black)?; self.update_chromatic_frame(spi, chromatic) } @@ -160,7 +165,12 @@ where /// Update only the black/white data of the display. /// /// Finish by calling `update_chromatic_frame`. - fn update_achromatic_frame(&mut self, spi: &mut SPI, black: &[u8]) -> Result<(), Error>{ + fn update_achromatic_frame( + &mut self, + spi: &mut SPI, + black: &[u8], + ) -> Result<(), Error> + { self.interface.cmd(spi, Command::DataStartTransmission1)?; self.interface.data(spi, black)?; Ok(()) @@ -173,7 +183,8 @@ where &mut self, spi: &mut SPI, chromatic: &[u8], - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.interface.cmd(spi, Command::DataStartTransmission2)?; self.interface.data(spi, chromatic)?; @@ -200,7 +211,8 @@ where dc: DC, rst: RST, delay: &mut DELAY, - ) -> Result>{ + ) -> Result> + { let interface = DisplayInterface::new(cs, busy, dc, rst); let color = DEFAULT_BACKGROUND_COLOR; @@ -211,7 +223,12 @@ where Ok(epd) } - fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error>{ + fn sleep( + &mut self, + spi: &mut SPI, + _delay: &mut DELAY, + ) -> Result<(), Error> + { // Section 8.2 from datasheet self.interface.cmd_with_data( spi, @@ -228,7 +245,12 @@ where Ok(()) } - fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error>{ + fn wake_up( + &mut self, + spi: &mut SPI, + delay: &mut DELAY, + ) -> Result<(), Error> + { self.init(spi, delay) } @@ -253,7 +275,8 @@ where spi: &mut SPI, buffer: &[u8], _delay: &mut DELAY, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.interface.cmd(spi, Command::DataStartTransmission1)?; self.interface.data(spi, buffer)?; @@ -277,11 +300,17 @@ where y: u32, width: u32, height: u32, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { Ok(()) } - fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error>{ + fn display_frame( + &mut self, + spi: &mut SPI, + _delay: &mut DELAY, + ) -> Result<(), Error> + { self.command(spi, Command::DisplayRefresh)?; self.wait_until_idle(); @@ -293,13 +322,19 @@ where spi: &mut SPI, buffer: &[u8], delay: &mut DELAY, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.update_frame(spi, buffer, delay)?; self.display_frame(spi, delay)?; Ok(()) } - fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error>{ + fn clear_frame( + &mut self, + spi: &mut SPI, + _delay: &mut DELAY, + ) -> Result<(), Error> + { self.send_resolution(spi)?; let color = DEFAULT_BACKGROUND_COLOR.get_byte_value(); @@ -321,7 +356,8 @@ where &mut self, _spi: &mut SPI, _refresh_rate: Option, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { Ok(()) } @@ -339,11 +375,21 @@ where RST: OutputPin, DELAY: DelayUs, { - fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), Error>{ + fn command( + &mut self, + spi: &mut SPI, + command: Command, + ) -> Result<(), Error> + { self.interface.cmd(spi, command) } - fn send_data(&mut self, spi: &mut SPI, data: &[u8]) -> Result<(), Error>{ + fn send_data( + &mut self, + spi: &mut SPI, + data: &[u8], + ) -> Result<(), Error> + { self.interface.data(spi, data) } @@ -352,7 +398,8 @@ where spi: &mut SPI, command: Command, data: &[u8], - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.interface.cmd_with_data(spi, command, data) } @@ -360,7 +407,11 @@ where let _ = self.interface.wait_until_idle(IS_BUSY_LOW); } - fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), Error>{ + fn send_resolution( + &mut self, + spi: &mut SPI, + ) -> Result<(), Error> + { let w = self.width(); let h = self.height(); @@ -372,7 +423,12 @@ where } /// Set the outer border of the display to the chosen color. - pub fn set_border_color(&mut self, spi: &mut SPI, color: TriColor) -> Result<(), Error>{ + pub fn set_border_color( + &mut self, + spi: &mut SPI, + color: TriColor, + ) -> Result<(), Error> + { let border = match color { TriColor::Black => BLACK_BORDER, TriColor::White => WHITE_BORDER, diff --git a/src/epd4in2/mod.rs b/src/epd4in2/mod.rs index 5866109..093375e 100644 --- a/src/epd4in2/mod.rs +++ b/src/epd4in2/mod.rs @@ -49,9 +49,9 @@ //! //! BE CAREFUL! The screen can get ghosting/burn-ins through the Partial Fast Update Drawing. -use crate::{eh_prelude::*, Error}; use crate::interface::DisplayInterface; use crate::traits::{InternalWiAdditions, QuickRefresh, RefreshLut, WaveshareDisplay}; +use crate::{eh_prelude::*, Error}; //The Lookup Tables for the Display mod constants; @@ -96,7 +96,12 @@ where RST: OutputPin, DELAY: DelayUs, { - fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error>{ + fn init( + &mut self, + spi: &mut SPI, + delay: &mut DELAY, + ) -> Result<(), Error> + { // reset the device self.interface.reset(delay, 10)?; @@ -159,7 +164,8 @@ where dc: DC, rst: RST, delay: &mut DELAY, - ) -> Result>{ + ) -> Result> + { let interface = DisplayInterface::new(cs, busy, dc, rst); let color = DEFAULT_BACKGROUND_COLOR; @@ -174,11 +180,21 @@ where Ok(epd) } - fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error>{ + fn wake_up( + &mut self, + spi: &mut SPI, + delay: &mut DELAY, + ) -> Result<(), Error> + { self.init(spi, delay) } - fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error>{ + fn sleep( + &mut self, + spi: &mut SPI, + _delay: &mut DELAY, + ) -> Result<(), Error> + { self.wait_until_idle(); self.interface .cmd_with_data(spi, Command::VcomAndDataIntervalSetting, &[0x17])?; //border floating @@ -202,7 +218,8 @@ where spi: &mut SPI, buffer: &[u8], _delay: &mut DELAY, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.wait_until_idle(); let color_value = self.color.get_byte_value(); @@ -223,7 +240,8 @@ where y: u32, width: u32, height: u32, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.wait_until_idle(); if buffer.len() as u32 != width / 8 * height { //TODO: panic!! or sth like that @@ -261,7 +279,12 @@ where Ok(()) } - fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error>{ + fn display_frame( + &mut self, + spi: &mut SPI, + _delay: &mut DELAY, + ) -> Result<(), Error> + { self.wait_until_idle(); self.command(spi, Command::DisplayRefresh)?; Ok(()) @@ -272,13 +295,19 @@ where spi: &mut SPI, buffer: &[u8], delay: &mut DELAY, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.update_frame(spi, buffer, delay)?; self.command(spi, Command::DisplayRefresh)?; Ok(()) } - fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error>{ + fn clear_frame( + &mut self, + spi: &mut SPI, + _delay: &mut DELAY, + ) -> Result<(), Error> + { self.wait_until_idle(); self.send_resolution(spi)?; @@ -314,7 +343,8 @@ where &mut self, spi: &mut SPI, refresh_rate: Option, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { if let Some(refresh_lut) = refresh_rate { self.refresh = refresh_lut; } @@ -347,11 +377,21 @@ where RST: OutputPin, DELAY: DelayUs, { - fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), Error>{ + fn command( + &mut self, + spi: &mut SPI, + command: Command, + ) -> Result<(), Error> + { self.interface.cmd(spi, command) } - fn send_data(&mut self, spi: &mut SPI, data: &[u8]) -> Result<(), Error>{ + fn send_data( + &mut self, + spi: &mut SPI, + data: &[u8], + ) -> Result<(), Error> + { self.interface.data(spi, data) } @@ -360,7 +400,8 @@ where spi: &mut SPI, command: Command, data: &[u8], - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.interface.cmd_with_data(spi, command, data) } @@ -368,7 +409,11 @@ where let _ = self.interface.wait_until_idle(IS_BUSY_LOW); } - fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), Error>{ + fn send_resolution( + &mut self, + spi: &mut SPI, + ) -> Result<(), Error> + { let w = self.width(); let h = self.height(); @@ -387,7 +432,8 @@ where lut_bw: &[u8], lut_wb: &[u8], lut_bb: &[u8], - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.wait_until_idle(); // LUT VCOM self.cmd_with_data(spi, Command::LutForVcom, lut_vcom)?; @@ -415,7 +461,8 @@ where y: u32, width: u32, height: u32, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.send_data(spi, &[(x >> 8) as u8])?; let tmp = x & 0xf8; self.send_data(spi, &[tmp as u8])?; // x should be the multiple of 8, the last 3 bit will always be ignored @@ -451,7 +498,8 @@ where spi: &mut SPI, buffer: &[u8], _delay: &mut DELAY, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.wait_until_idle(); self.interface.cmd(spi, Command::DataStartTransmission1)?; @@ -467,7 +515,8 @@ where spi: &mut SPI, buffer: &[u8], _delay: &mut DELAY, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.wait_until_idle(); // self.send_resolution(spi)?; @@ -480,7 +529,12 @@ where /// This is a wrapper around `display_frame` for using this device as a true /// `QuickRefresh` device. - fn display_new_frame(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error>{ + fn display_new_frame( + &mut self, + spi: &mut SPI, + delay: &mut DELAY, + ) -> Result<(), Error> + { self.display_frame(spi, delay) } @@ -493,7 +547,8 @@ where spi: &mut SPI, buffer: &[u8], delay: &mut DELAY, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.update_new_frame(spi, buffer, delay)?; self.display_frame(spi, delay) } @@ -506,7 +561,8 @@ where y: u32, width: u32, height: u32, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.wait_until_idle(); if buffer.len() as u32 != width / 8 * height { @@ -536,7 +592,8 @@ where y: u32, width: u32, height: u32, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.wait_until_idle(); if buffer.len() as u32 != width / 8 * height { //TODO: panic!! or sth like that @@ -560,7 +617,8 @@ where y: u32, width: u32, height: u32, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.wait_until_idle(); self.send_resolution(spi)?; diff --git a/src/epd5in65f/mod.rs b/src/epd5in65f/mod.rs index 15a66bb..eb50c07 100644 --- a/src/epd5in65f/mod.rs +++ b/src/epd5in65f/mod.rs @@ -6,11 +6,11 @@ //! - [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 crate::Error; use crate::color::OctColor; -use crate::{eh_prelude::*}; +use crate::eh_prelude::*; use crate::interface::DisplayInterface; use crate::traits::{InternalWiAdditions, RefreshLut, WaveshareDisplay}; +use crate::Error; pub(crate) mod command; use self::command::Command; @@ -47,7 +47,12 @@ where RST: OutputPin, DELAY: DelayUs, { - fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error>{ + fn init( + &mut self, + spi: &mut SPI, + delay: &mut DELAY, + ) -> Result<(), Error> + { // Reset the device self.interface.reset(delay, 2)?; @@ -88,7 +93,8 @@ where dc: DC, rst: RST, delay: &mut DELAY, - ) -> Result>{ + ) -> Result> + { let interface = DisplayInterface::new(cs, busy, dc, rst); let color = DEFAULT_BACKGROUND_COLOR; @@ -99,11 +105,21 @@ where Ok(epd) } - fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error>{ + fn wake_up( + &mut self, + spi: &mut SPI, + delay: &mut DELAY, + ) -> Result<(), Error> + { self.init(spi, delay) } - fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error>{ + fn sleep( + &mut self, + spi: &mut SPI, + _delay: &mut DELAY, + ) -> Result<(), Error> + { self.cmd_with_data(spi, Command::DeepSleep, &[0xA5])?; Ok(()) } @@ -113,7 +129,8 @@ where spi: &mut SPI, buffer: &[u8], _delay: &mut DELAY, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.wait_busy_high(); self.update_vcom(spi)?; self.send_resolution(spi)?; @@ -129,11 +146,17 @@ where _y: u32, _width: u32, _height: u32, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { unimplemented!(); } - fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error>{ + fn display_frame( + &mut self, + spi: &mut SPI, + _delay: &mut DELAY, + ) -> Result<(), Error> + { self.wait_busy_high(); self.command(spi, Command::PowerOn)?; self.wait_busy_high(); @@ -149,13 +172,19 @@ where spi: &mut SPI, buffer: &[u8], delay: &mut DELAY, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.update_frame(spi, buffer, delay)?; self.display_frame(spi, delay)?; Ok(()) } - fn clear_frame(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error>{ + fn clear_frame( + &mut self, + spi: &mut SPI, + delay: &mut DELAY, + ) -> Result<(), Error> + { let bg = OctColor::colors_byte(self.color, self.color); self.wait_busy_high(); self.update_vcom(spi)?; @@ -186,7 +215,8 @@ where &mut self, _spi: &mut SPI, _refresh_rate: Option, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { unimplemented!(); } @@ -204,11 +234,21 @@ where RST: OutputPin, DELAY: DelayUs, { - fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), Error>{ + fn command( + &mut self, + spi: &mut SPI, + command: Command, + ) -> Result<(), Error> + { self.interface.cmd(spi, command) } - fn send_data(&mut self, spi: &mut SPI, data: &[u8]) -> Result<(), Error>{ + fn send_data( + &mut self, + spi: &mut SPI, + data: &[u8], + ) -> Result<(), Error> + { self.interface.data(spi, data) } @@ -217,7 +257,8 @@ where spi: &mut SPI, command: Command, data: &[u8], - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.interface.cmd_with_data(spi, command, data) } @@ -227,7 +268,11 @@ where fn wait_busy_low(&mut self) { let _ = self.interface.wait_until_idle(false); } - fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), Error>{ + fn send_resolution( + &mut self, + spi: &mut SPI, + ) -> Result<(), Error> + { let w = self.width(); let h = self.height(); @@ -238,7 +283,11 @@ where self.send_data(spi, &[h as u8]) } - fn update_vcom(&mut self, spi: &mut SPI) -> Result<(), Error>{ + fn update_vcom( + &mut self, + spi: &mut SPI, + ) -> Result<(), Error> + { let bg_color = (self.color.get_nibble() & 0b111) << 5; self.cmd_with_data(spi, Command::VcomAndDataIntervalSetting, &[0x17 | bg_color])?; Ok(()) diff --git a/src/epd7in5/mod.rs b/src/epd7in5/mod.rs index b714033..349d694 100644 --- a/src/epd7in5/mod.rs +++ b/src/epd7in5/mod.rs @@ -5,11 +5,11 @@ //! - [Datasheet](https://www.waveshare.com/wiki/7.5inch_e-Paper_HAT) //! - [Waveshare C driver](https://github.com/waveshare/e-Paper/blob/702def06bcb75983c98b0f9d25d43c552c248eb0/RaspberryPi%26JetsonNano/c/lib/e-Paper/EPD_7in5.c) //! - [Waveshare Python driver](https://github.com/waveshare/e-Paper/blob/702def06bcb75983c98b0f9d25d43c552c248eb0/RaspberryPi%26JetsonNano/python/lib/waveshare_epd/epd7in5.py) -use crate::Error; use crate::color::Color; -use crate::{eh_prelude::*}; +use crate::eh_prelude::*; use crate::interface::DisplayInterface; use crate::traits::{InternalWiAdditions, RefreshLut, WaveshareDisplay}; +use crate::Error; pub(crate) mod command; use self::command::Command; @@ -46,7 +46,12 @@ where RST: OutputPin, DELAY: DelayUs, { - fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error>{ + fn init( + &mut self, + spi: &mut SPI, + delay: &mut DELAY, + ) -> Result<(), Error> + { // Reset the device self.interface.reset(delay, 10)?; @@ -110,7 +115,8 @@ where dc: DC, rst: RST, delay: &mut DELAY, - ) -> Result>{ + ) -> Result> + { let interface = DisplayInterface::new(cs, busy, dc, rst); let color = DEFAULT_BACKGROUND_COLOR; @@ -121,11 +127,21 @@ where Ok(epd) } - fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error>{ + fn wake_up( + &mut self, + spi: &mut SPI, + delay: &mut DELAY, + ) -> Result<(), Error> + { self.init(spi, delay) } - fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error>{ + fn sleep( + &mut self, + spi: &mut SPI, + _delay: &mut DELAY, + ) -> Result<(), Error> + { self.wait_until_idle(); self.command(spi, Command::PowerOff)?; self.wait_until_idle(); @@ -138,7 +154,8 @@ where spi: &mut SPI, buffer: &[u8], _delay: &mut DELAY, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.wait_until_idle(); self.command(spi, Command::DataStartTransmission1)?; for byte in buffer { @@ -163,11 +180,17 @@ where _y: u32, _width: u32, _height: u32, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { unimplemented!(); } - fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error>{ + fn display_frame( + &mut self, + spi: &mut SPI, + _delay: &mut DELAY, + ) -> Result<(), Error> + { self.wait_until_idle(); self.command(spi, Command::DisplayRefresh)?; Ok(()) @@ -178,13 +201,19 @@ where spi: &mut SPI, buffer: &[u8], delay: &mut DELAY, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.update_frame(spi, buffer, delay)?; self.command(spi, Command::DisplayRefresh)?; Ok(()) } - fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error>{ + fn clear_frame( + &mut self, + spi: &mut SPI, + _delay: &mut DELAY, + ) -> Result<(), Error> + { self.wait_until_idle(); self.send_resolution(spi)?; @@ -215,7 +244,8 @@ where &mut self, _spi: &mut SPI, _refresh_rate: Option, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { unimplemented!(); } @@ -233,11 +263,21 @@ where RST: OutputPin, DELAY: DelayUs, { - fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), Error>{ + fn command( + &mut self, + spi: &mut SPI, + command: Command, + ) -> Result<(), Error> + { self.interface.cmd(spi, command) } - fn send_data(&mut self, spi: &mut SPI, data: &[u8]) -> Result<(), Error>{ + fn send_data( + &mut self, + spi: &mut SPI, + data: &[u8], + ) -> Result<(), Error> + { self.interface.data(spi, data) } @@ -246,7 +286,8 @@ where spi: &mut SPI, command: Command, data: &[u8], - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.interface.cmd_with_data(spi, command, data) } @@ -254,7 +295,11 @@ where let _ = self.interface.wait_until_idle(IS_BUSY_LOW); } - fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), Error>{ + fn send_resolution( + &mut self, + spi: &mut SPI, + ) -> Result<(), Error> + { let w = self.width(); let h = self.height(); diff --git a/src/epd7in5_hd/mod.rs b/src/epd7in5_hd/mod.rs index 50e42d1..29eef95 100644 --- a/src/epd7in5_hd/mod.rs +++ b/src/epd7in5_hd/mod.rs @@ -8,11 +8,11 @@ //! //! - [Datasheet](https://www.waveshare.com/w/upload/2/27/7inch_HD_e-Paper_Specification.pdf) //! - [Waveshare Python driver](https://github.com/waveshare/e-Paper/blob/master/RaspberryPi_JetsonNano/python/lib/waveshare_epd/epd7in5_HD.py) -use crate::Error; use crate::color::Color; -use crate::{eh_prelude::*}; +use crate::eh_prelude::*; use crate::interface::DisplayInterface; use crate::traits::{InternalWiAdditions, RefreshLut, WaveshareDisplay}; +use crate::Error; pub(crate) mod command; use self::command::Command; @@ -49,7 +49,12 @@ where RST: OutputPin, DELAY: DelayUs, { - fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error>{ + fn init( + &mut self, + spi: &mut SPI, + delay: &mut DELAY, + ) -> Result<(), Error> + { // Reset the device self.interface.reset(delay, 2)?; @@ -110,7 +115,8 @@ where dc: DC, rst: RST, delay: &mut DELAY, - ) -> Result>{ + ) -> Result> + { let interface = DisplayInterface::new(cs, busy, dc, rst); let color = DEFAULT_BACKGROUND_COLOR; @@ -121,11 +127,21 @@ where Ok(epd) } - fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error>{ + fn wake_up( + &mut self, + spi: &mut SPI, + delay: &mut DELAY, + ) -> Result<(), Error> + { self.init(spi, delay) } - fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error>{ + fn sleep( + &mut self, + spi: &mut SPI, + _delay: &mut DELAY, + ) -> Result<(), Error> + { self.wait_until_idle(); self.cmd_with_data(spi, Command::DeepSleep, &[0x01])?; Ok(()) @@ -136,7 +152,8 @@ where spi: &mut SPI, buffer: &[u8], _delay: &mut DELAY, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.wait_until_idle(); self.cmd_with_data(spi, Command::SetRamYAc, &[0x00, 0x00])?; self.cmd_with_data(spi, Command::WriteRamBw, buffer)?; @@ -152,11 +169,17 @@ where _y: u32, _width: u32, _height: u32, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { unimplemented!(); } - fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error>{ + fn display_frame( + &mut self, + spi: &mut SPI, + _delay: &mut DELAY, + ) -> Result<(), Error> + { self.command(spi, Command::MasterActivation)?; self.wait_until_idle(); Ok(()) @@ -167,13 +190,19 @@ where spi: &mut SPI, buffer: &[u8], delay: &mut DELAY, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.update_frame(spi, buffer, delay)?; self.display_frame(spi, delay)?; Ok(()) } - fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error>{ + fn clear_frame( + &mut self, + spi: &mut SPI, + _delay: &mut DELAY, + ) -> Result<(), Error> + { let pixel_count = WIDTH * HEIGHT / 8; let background_color_byte = self.color.get_byte_value(); @@ -212,7 +241,8 @@ where &mut self, _spi: &mut SPI, _refresh_rate: Option, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { unimplemented!(); } @@ -230,7 +260,12 @@ where RST: OutputPin, DELAY: DelayUs, { - fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), Error>{ + fn command( + &mut self, + spi: &mut SPI, + command: Command, + ) -> Result<(), Error> + { self.interface.cmd(spi, command) } @@ -239,7 +274,8 @@ where spi: &mut SPI, command: Command, data: &[u8], - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.interface.cmd_with_data(spi, command, data) } diff --git a/src/epd7in5_v2/mod.rs b/src/epd7in5_v2/mod.rs index b4ccfda..b5dddc9 100644 --- a/src/epd7in5_v2/mod.rs +++ b/src/epd7in5_v2/mod.rs @@ -9,11 +9,11 @@ //! Important note for V2: //! Revision V2 has been released on 2019.11, the resolution is upgraded to 800×480, from 640×384 of V1. //! The hardware and interface of V2 are compatible with V1, however, the related software should be updated. -use crate::Error; use crate::color::Color; -use crate::{eh_prelude::*}; +use crate::eh_prelude::*; use crate::interface::DisplayInterface; use crate::traits::{InternalWiAdditions, RefreshLut, WaveshareDisplay}; +use crate::Error; pub(crate) mod command; use self::command::Command; @@ -50,7 +50,12 @@ where RST: OutputPin, DELAY: DelayUs, { - fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error>{ + fn init( + &mut self, + spi: &mut SPI, + delay: &mut DELAY, + ) -> Result<(), Error> + { // Reset the device self.interface.reset(delay, 2)?; @@ -92,7 +97,8 @@ where dc: DC, rst: RST, delay: &mut DELAY, - ) -> Result>{ + ) -> Result> + { let interface = DisplayInterface::new(cs, busy, dc, rst); let color = DEFAULT_BACKGROUND_COLOR; @@ -103,11 +109,21 @@ where Ok(epd) } - fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error>{ + fn wake_up( + &mut self, + spi: &mut SPI, + delay: &mut DELAY, + ) -> Result<(), Error> + { self.init(spi, delay) } - fn sleep(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error>{ + fn sleep( + &mut self, + spi: &mut SPI, + delay: &mut DELAY, + ) -> Result<(), Error> + { self.wait_until_idle(spi, delay)?; self.command(spi, Command::PowerOff)?; self.wait_until_idle(spi, delay)?; @@ -120,7 +136,8 @@ where spi: &mut SPI, buffer: &[u8], delay: &mut DELAY, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.wait_until_idle(spi, delay)?; self.cmd_with_data(spi, Command::DataStartTransmission2, buffer)?; Ok(()) @@ -134,11 +151,17 @@ where _y: u32, _width: u32, _height: u32, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { unimplemented!(); } - fn display_frame(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error>{ + fn display_frame( + &mut self, + spi: &mut SPI, + delay: &mut DELAY, + ) -> Result<(), Error> + { self.wait_until_idle(spi, delay)?; self.command(spi, Command::DisplayRefresh)?; Ok(()) @@ -149,13 +172,19 @@ where spi: &mut SPI, buffer: &[u8], delay: &mut DELAY, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.update_frame(spi, buffer, delay)?; self.command(spi, Command::DisplayRefresh)?; Ok(()) } - fn clear_frame(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error>{ + fn clear_frame( + &mut self, + spi: &mut SPI, + delay: &mut DELAY, + ) -> Result<(), Error> + { self.wait_until_idle(spi, delay)?; self.send_resolution(spi)?; @@ -189,7 +218,8 @@ where &mut self, _spi: &mut SPI, _refresh_rate: Option, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { unimplemented!(); } @@ -207,11 +237,21 @@ where RST: OutputPin, DELAY: DelayUs, { - fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), Error>{ + fn command( + &mut self, + spi: &mut SPI, + command: Command, + ) -> Result<(), Error> + { self.interface.cmd(spi, command) } - fn send_data(&mut self, spi: &mut SPI, data: &[u8]) -> Result<(), Error>{ + fn send_data( + &mut self, + spi: &mut SPI, + data: &[u8], + ) -> Result<(), Error> + { self.interface.data(spi, data) } @@ -220,11 +260,17 @@ where spi: &mut SPI, command: Command, data: &[u8], - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.interface.cmd_with_data(spi, command, data) } - fn wait_until_idle(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error>{ + fn wait_until_idle( + &mut self, + spi: &mut SPI, + delay: &mut DELAY, + ) -> Result<(), Error> + { while self.interface.is_busy(IS_BUSY_LOW) { self.interface.cmd(spi, Command::GetStatus)?; delay.delay_ms(20).map_err(|e| Error::Delay(e))?; @@ -232,7 +278,11 @@ where Ok(()) } - fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), Error>{ + fn send_resolution( + &mut self, + spi: &mut SPI, + ) -> Result<(), Error> + { let w = self.width(); let h = self.height(); diff --git a/src/interface.rs b/src/interface.rs index 55a0491..077cede 100644 --- a/src/interface.rs +++ b/src/interface.rs @@ -1,5 +1,5 @@ -use crate::{eh_prelude::*, Error}; use crate::traits::Command; +use crate::{eh_prelude::*, Error}; use core::marker::PhantomData; /// The Connection Interface of all (?) Waveshare EPD-Devices @@ -42,7 +42,12 @@ where /// Basic function for sending [Commands](Command). /// /// Enables direct interaction with the device with the help of [data()](DisplayInterface::data()) - pub(crate) fn cmd(&mut self, spi: &mut SPI, command: T) -> Result<(), Error>{ + pub(crate) fn cmd( + &mut self, + spi: &mut SPI, + command: T, + ) -> Result<(), Error> + { // low for commands let _ = self.dc.set_low(); @@ -53,7 +58,12 @@ 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()) - pub(crate) fn data(&mut self, spi: &mut SPI, data: &[u8]) -> Result<(), Error>{ + pub(crate) fn data( + &mut self, + spi: &mut SPI, + data: &[u8], + ) -> Result<(), Error> + { // high for data let _ = self.dc.set_high(); @@ -73,7 +83,8 @@ where spi: &mut SPI, command: T, data: &[u8], - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { self.cmd(spi, command)?; self.data(spi, data) } @@ -86,7 +97,8 @@ where spi: &mut SPI, val: u8, repetitions: u32, - ) -> Result<(), Error>{ + ) -> Result<(), Error> + { // high for data let _ = self.dc.set_high(); // Transfer data (u8) over spi @@ -97,7 +109,12 @@ where } // spi write helper/abstraction function - fn write(&mut self, spi: &mut SPI, data: &[u8]) -> Result<(), Error>{ + fn write( + &mut self, + spi: &mut SPI, + data: &[u8], + ) -> Result<(), Error> + { // activate spi with cs low let _ = self.cs.set_low(); @@ -166,7 +183,12 @@ where /// The timing of keeping the reset pin low seems to be important and different per device. /// Most displays seem to require keeping it low for 10ms, but the 7in5_v2 only seems to reset /// properly with 2ms - pub(crate) fn reset(&mut self, delay: &mut DELAY, duration: u32) -> Result<(), Error> { + pub(crate) fn reset( + &mut self, + delay: &mut DELAY, + duration: u32, + ) -> Result<(), Error> + { self.rst.set_high().map_err(|e| Error::RST(e))?; delay.delay_ms(10).map_err(|e| Error::Delay(e))?; diff --git a/src/lib.rs b/src/lib.rs index afa888b..96b14ee 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -124,7 +124,7 @@ pub const fn buffer_len(width: usize, height: usize) -> usize { (width + 7) / 8 * height } -use embedded_hal::{spi::{Mode, Phase, Polarity}}; +use embedded_hal::spi::{Mode, Phase, Polarity}; /// SPI mode - /// For more infos see [Requirements: SPI](index.html#spi) @@ -133,7 +133,7 @@ pub const SPI_MODE: Mode = Mode { polarity: Polarity::IdleLow, }; -#[derive(Debug)] +#[derive(Debug)] /// Error pub enum Error { /// SPI Errors @@ -150,10 +150,10 @@ pub enum Error { RST(RSTError), } -impl From for Error { +impl From + for Error +{ fn from(spi: SPIError) -> Self { Self::Spi(spi) } } - - diff --git a/src/traits.rs b/src/traits.rs index 11e09cf..9931bfd 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -42,7 +42,11 @@ where /// This function calls [reset](WaveshareDisplay::reset), /// so you don't need to call reset your self when trying to wake your device up /// after setting it to sleep. - fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error>; + fn init( + &mut self, + spi: &mut SPI, + delay: &mut DELAY, + ) -> Result<(), Error>; } /// Functions to interact with three color panels @@ -69,14 +73,21 @@ where /// Update only the black/white data of the display. /// /// This must be finished by calling `update_chromatic_frame`. - fn update_achromatic_frame(&mut self, spi: &mut SPI, black: &[u8]) -> Result<(), Error>; + fn update_achromatic_frame( + &mut self, + spi: &mut SPI, + black: &[u8], + ) -> Result<(), Error>; /// Update only the chromatic data of the display. /// /// This should be preceded by a call to `update_achromatic_frame`. /// This data takes precedence over the black/white data. - fn update_chromatic_frame(&mut self, spi: &mut SPI, chromatic: &[u8]) - -> Result<(), Error>; + fn update_chromatic_frame( + &mut self, + spi: &mut SPI, + chromatic: &[u8], + ) -> Result<(), Error>; } /// All the functions to interact with the EPDs @@ -151,12 +162,20 @@ where /// Let the device enter deep-sleep mode to save power. /// /// The deep sleep mode returns to standby with a hardware reset. - fn sleep(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error>; + fn sleep( + &mut self, + spi: &mut SPI, + delay: &mut DELAY, + ) -> Result<(), Error>; /// Wakes the device up from sleep /// /// Also reintialises the device if necessary. - fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error>; + fn wake_up( + &mut self, + spi: &mut SPI, + delay: &mut DELAY, + ) -> Result<(), Error>; /// Sets the backgroundcolor for various commands like [clear_frame](WaveshareDisplay::clear_frame) fn set_background_color(&mut self, color: Self::DisplayColor); @@ -196,7 +215,11 @@ where /// Displays the frame data from SRAM /// /// This function waits until the device isn`t busy anymore - fn display_frame(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error>; + fn display_frame( + &mut self, + spi: &mut SPI, + delay: &mut DELAY, + ) -> Result<(), Error>; /// Provide a combined update&display and save some time (skipping a busy check in between) fn update_and_display_frame( @@ -209,7 +232,11 @@ where /// Clears the frame buffer on the EPD with the declared background color /// /// The background color can be changed with [`WaveshareDisplay::set_background_color`] - fn clear_frame(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error>; + fn clear_frame( + &mut self, + spi: &mut SPI, + delay: &mut DELAY, + ) -> Result<(), Error>; /// Trait for using various Waveforms from different LUTs /// E.g. for partial refreshes @@ -304,7 +331,11 @@ where ) -> Result<(), Error>; /// Displays the new frame - fn display_new_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error>; + fn display_new_frame( + &mut self, + spi: &mut SPI, + _delay: &mut DELAY, + ) -> Result<(), Error>; /// Updates and displays the new frame. fn update_and_display_new_frame(