use core::marker::Sized; use hal::{ blocking::{delay::*, spi::Write}, digital::*, }; use color::Color; /// Interface for the physical connection between display and the controlling device pub(crate) mod connection_interface; /// All commands need to have this trait which gives the address of the command /// which needs to be send via SPI with activated CommandsPin (Data/Command Pin in CommandMode) pub(crate) trait Command { fn address(self) -> u8; } //TODO: add LUT trait with set_fast_lut and set_manual_lut and set_normal_lut or sth like that? // for partial updates trait LUTSupport { fn set_lut(&mut self) -> Result<(), ERR>; fn set_lut_quick(&mut self) -> Result<(), ERR>; fn set_lut_manual(&mut self, data: &[u8]) -> Result<(), ERR>; } pub(crate) trait InternalWiAdditions where SPI: Write, CS: OutputPin, BUSY: InputPin, DC: OutputPin, RST: OutputPin, Delay: DelayUs + DelayMs, { /// This initialises the EPD and powers it up /// /// This function is already called from /// - [new()](WaveshareInterface::new()) /// - [`wake_up`] /// /// /// This function calls [reset()](WaveshareInterface::reset()), /// so you don't need to call reset your self when trying to wake your device up /// after setting it to sleep. fn init(&mut self) -> Result<(), ERR>; } pub trait WaveshareInterface where SPI: Write, CS: OutputPin, BUSY: InputPin, DC: OutputPin, RST: OutputPin, Delay: DelayUs + DelayMs, { /// Creates a new driver from a SPI peripheral, CS Pin, Busy InputPin, DC /// /// This already initialises the device. That means [init()](WaveshareInterface::init()) isn't needed directly afterwards fn new( spi: SPI, cs: CS, busy: BUSY, dc: DC, rst: RST, delay: Delay, ) -> Result where Self: Sized; /// Let the device enter deep-sleep mode to save power. /// /// The deep sleep mode returns to standby with a hardware reset. /// But you can also use [wake_up()](WaveshareInterface::wake_up()) to awaken. /// But as you need to power it up once more anyway you can also just directly use [new()](WaveshareInterface::new()) for resetting /// and initialising which already contains the reset fn sleep(&mut self) -> Result<(), ERR>; fn wake_up(&mut self) -> Result<(), ERR>; /// Sets the backgroundcolor for various commands like [clear_frame()](WaveshareInterface::clear_frame()) fn set_background_color(&mut self, color: Color); /// Get current background color fn background_color(&self) -> &Color; /// Get the width of the display fn width(&self) -> u16; /// Get the height of the display fn height(&self) -> u16; /// Abstraction of setting the delay for simpler calls /// /// maximum delay ~65 seconds (u16:max in ms) fn delay_ms(&mut self, delay: u16); /// Transmit a full frame to the SRAM of the EPD fn update_frame(&mut self, buffer: &[u8]) -> Result<(), ERR>; /// Transmits partial data to the SRAM of the EPD /// /// BUFFER needs to be of size: w / 8 * h ! fn update_partial_frame( &mut self, buffer: &[u8], x: u16, y: u16, width: u16, height: u16, ) -> Result<(), ERR>; /// Displays the frame data from SRAM fn display_frame(&mut self) -> Result<(), ERR>; /// Clears the frame buffer on the EPD with the declared background color /// The background color can be changed with [`set_background_color`] fn clear_frame(&mut self) -> Result<(), ERR>; }