From c4ba7ffb21d8fb276342454c1ae9eb36ea434b09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20Gro=C3=9F?= Date: Fri, 3 Aug 2018 14:23:09 +0200 Subject: [PATCH] Added a new Display Trait, but that is still in work and renamed a few other traitnames to make them more clear --- src/epd4in2/mod.rs | 23 +++++++++++++---------- src/interface/mod.rs | 38 ++++++++++++++++++++------------------ 2 files changed, 33 insertions(+), 28 deletions(-) diff --git a/src/epd4in2/mod.rs b/src/epd4in2/mod.rs index 0f5ee76..a24ff31 100644 --- a/src/epd4in2/mod.rs +++ b/src/epd4in2/mod.rs @@ -73,7 +73,8 @@ pub const SPI_MODE: Mode = Mode { /// EPD4in2 driver /// -pub struct EPD4in2 { +pub struct EPD4in2 + { /// Connection Interface interface: ConnectionInterface, /// Width @@ -84,15 +85,17 @@ pub struct EPD4in2 { color: Color, } -impl WaveshareInterface - for EPD4in2 -where - SPI: Write, + + +impl WaveshareInterface + for EPD4in2 +where + SPI: Write, CS: OutputPin, BUSY: InputPin, - DC: OutputPin, + DataCommand: OutputPin, RST: OutputPin, - D: DelayUs + DelayMs, + Delay: DelayUs + DelayMs, { fn get_width(&self) -> u16 { self.width @@ -117,11 +120,11 @@ where /// /// epd4in2.sleep(); /// ``` - fn new(spi: SPI, cs: CS, busy: BUSY, dc: DC, rst: RST, delay: D) -> Result { + fn new(interface: ConnectionInterface) -> Result { let width = WIDTH as u16; let height = HEIGHT as u16; - let interface = ConnectionInterface::new(spi, cs, busy, dc, rst, delay); + let color = Color::White; let mut epd = EPD4in2 { interface, @@ -135,7 +138,7 @@ where Ok(epd) } - fn init(&mut self) -> Result<(), E> { + fn init(&mut self) -> Result<(), Error> { // reset the device self.reset(); diff --git a/src/interface/mod.rs b/src/interface/mod.rs index 0bf783a..308ced9 100644 --- a/src/interface/mod.rs +++ b/src/interface/mod.rs @@ -12,6 +12,7 @@ use drawing::color::Color; /// Interface for the physical connection between display and the controlling device pub mod connection_interface; +use self::connection_interface::ConnectionInterface; /// All commands need to have this trait which gives the address of the command @@ -21,6 +22,12 @@ pub(crate) trait Command { } +pub trait Displays { + fn width(self) -> u8; + fn height(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 { @@ -30,14 +37,14 @@ trait LUTSupport { } -pub trait WaveshareInterface +pub trait WaveshareInterface where - SPI: Write, + SPI: Write, CS: OutputPin, BUSY: InputPin, - DC: OutputPin, + DataCommand: OutputPin, RST: OutputPin, - D: DelayUs + DelayMs, + Delay: DelayUs + DelayMs, { /// Get the width of the display fn get_width(&self) -> u16; @@ -49,13 +56,8 @@ pub trait WaveshareInterface /// /// 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: D - ) -> Result + interface: ConnectionInterface, + ) -> Result where Self: Sized; /// This initialises the EPD and powers it up @@ -65,13 +67,13 @@ pub trait WaveshareInterface /// 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<(), E>; + fn init(&mut self) -> Result<(), Error>; // void DisplayFrame(const unsigned char* frame_buffer); /// Transmit a full frame to the SRAM of the DPD /// - fn update_frame(&mut self, buffer: &[u8]) -> Result<(), E>; + fn update_frame(&mut self, buffer: &[u8]) -> Result<(), Error>; //TODO: is dtm always used? /// Transmit partial data to the SRAM of the EPD, @@ -81,18 +83,18 @@ pub trait WaveshareInterface /// Normally it should be dtm2, so use false /// /// BUFFER needs to be of size: w / 8 * l ! - fn update_partial_frame(&mut self, buffer: &[u8], x: u16, y: u16, width: u16, height: u16) -> Result<(), E>; + fn update_partial_frame(&mut self, buffer: &[u8], x: u16, y: u16, width: u16, height: u16) -> Result<(), Error>; /// Displays the frame data from SRAM - fn display_frame(&mut self) -> Result<(), E>; + fn display_frame(&mut self) -> Result<(), Error>; // TODO: add this abstraction function - fn update_and_display_frame(&mut self, buffer: &[u8]) -> Result<(), E>; + fn update_and_display_frame(&mut self, buffer: &[u8]) -> Result<(), Error>; /// Clears the frame from the buffer /// /// Uses the chosen background color - fn clear_frame(&mut self) -> Result<(), E>; + fn clear_frame(&mut self) -> Result<(), Error>; /// Sets the backgroundcolor for various commands like [clear_frame()](WaveshareInterface::clear_frame()) fn set_background_color(&mut self, color: Color); @@ -104,7 +106,7 @@ pub trait WaveshareInterface /// But you can also use [reset()](WaveshareInterface::reset()) to awaken. /// But as you need to power it up once more anyway you can also just directly use [init()](WaveshareInterface::init()) for resetting /// and initialising which already contains the reset - fn sleep(&mut self) -> Result<(), E>; + fn sleep(&mut self) -> Result<(), Error>; /// Resets the device. ///