From 38f446304b4e52da8fb305ce16fb5d51794a5068 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20Gro=C3=9F?= Date: Mon, 6 Aug 2018 09:45:43 +0200 Subject: [PATCH] removed duplicate spi_mode and improved naming of spi_error type --- src/epd4in2/mod.rs | 47 +++++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/src/epd4in2/mod.rs b/src/epd4in2/mod.rs index a24ff31..7b2d49c 100644 --- a/src/epd4in2/mod.rs +++ b/src/epd4in2/mod.rs @@ -63,13 +63,7 @@ use drawing::color::Color; pub mod command; pub use self::command::Command; -//TODO: test spi mode -/// SPI mode - -/// For more infos see [Requirements: SPI](index.html#spi) -pub const SPI_MODE: Mode = Mode { - phase: Phase::CaptureOnFirstTransition, - polarity: Polarity::IdleLow, -}; +use epds::EPD; /// EPD4in2 driver /// @@ -87,10 +81,10 @@ pub struct EPD4in2 -impl WaveshareInterface +impl WaveshareInterface for EPD4in2 where - SPI: Write, + SPI: Write, CS: OutputPin, BUSY: InputPin, DataCommand: OutputPin, @@ -120,7 +114,7 @@ where /// /// epd4in2.sleep(); /// ``` - fn new(interface: ConnectionInterface) -> Result { + fn new(interface: ConnectionInterface, epd: EPD) -> Result { let width = WIDTH as u16; let height = HEIGHT as u16; @@ -138,7 +132,7 @@ where Ok(epd) } - fn init(&mut self) -> Result<(), Error> { + fn init(&mut self) -> Result<(), SPI_Error> { // reset the device self.reset(); @@ -185,7 +179,7 @@ where Ok(()) } - fn sleep(&mut self) -> Result<(), E> { + fn sleep(&mut self) -> Result<(), SPI_Error> { self.send_command(Command::VCOM_AND_DATA_INTERVAL_SETTING)?; self.send_data(0x17)?; //border floating self.send_command(Command::VCM_DC_SETTING)?; // VCOM to 0V @@ -214,7 +208,7 @@ where self.interface.delay_ms(delay) } - fn update_frame(&mut self, buffer: &[u8]) -> Result<(), E> { + fn update_frame(&mut self, buffer: &[u8]) -> Result<(), SPI_Error> { let color_value = self.color.get_byte_value(); self.send_resolution()?; @@ -250,7 +244,8 @@ where y: u16, width: u16, height: u16, - ) -> Result<(), E> { + ) -> Result<(), SPI_Error> { + if buffer.len() as u16 != width / 8 * height { //TODO: panic!! or sth like that //return Err("Wrong buffersize"); @@ -286,13 +281,13 @@ where self.send_command(Command::PARTIAL_OUT) } - fn update_and_display_frame(&mut self, buffer: &[u8]) -> Result<(), E>{ + fn update_and_display_frame(&mut self, buffer: &[u8]) -> Result<(), SPI_Error>{ self.update_frame(buffer)?; self.display_frame() } - fn display_frame(&mut self) -> Result<(), E> { + fn display_frame(&mut self) -> Result<(), SPI_Error> { self.send_command(Command::DISPLAY_REFRESH)?; self.wait_until_idle(); @@ -302,7 +297,7 @@ where // TODO: add this abstraction function // fn update_and_display_frame(&mut self, buffer: &[u8]) -> Result<(), E>; - fn clear_frame(&mut self) -> Result<(), E> { + fn clear_frame(&mut self) -> Result<(), SPI_Error> { self.send_resolution()?; let size = self.width / 8 * self.height; @@ -330,24 +325,24 @@ where } } -impl EPD4in2 +impl EPD4in2 where - SPI: Write, + SPI: Write, CS: OutputPin, BUSY: InputPin, DC: OutputPin, RST: OutputPin, D: DelayUs + DelayMs, { - fn send_command(&mut self, command: Command) -> Result<(), E> { + fn send_command(&mut self, command: Command) -> Result<(), SPI_Error> { self.interface.send_command(command) } - fn send_data(&mut self, val: u8) -> Result<(), E> { + fn send_data(&mut self, val: u8) -> Result<(), SPI_Error> { self.interface.send_data(val) } - fn send_multiple_data(&mut self, data: &[u8]) -> Result<(), E> { + fn send_multiple_data(&mut self, data: &[u8]) -> Result<(), SPI_Error> { self.interface.send_multiple_data(data) } @@ -355,7 +350,7 @@ where self.interface.wait_until_idle(true) } - fn send_resolution(&mut self) -> Result<(), E> { + fn send_resolution(&mut self) -> Result<(), SPI_Error> { let w = self.get_width(); let h = self.get_height(); @@ -368,7 +363,7 @@ where /// Fill the look-up table for the EPD //TODO: make public? - fn set_lut(&mut self) -> Result<(), E> { + fn set_lut(&mut self) -> Result<(), SPI_Error> { self.set_lut_helper(&LUT_VCOM0, &LUT_WW, &LUT_BW, &LUT_WB, &LUT_BB) } @@ -377,7 +372,7 @@ where /// Is automatically done by [EPD4in2::display_frame_quick()](EPD4in2::display_frame_quick()) /// //TODO: make public? #[cfg(feature = "epd4in2_fast_update")] - fn set_lut_quick(&mut self) -> Result<(), E> { + fn set_lut_quick(&mut self) -> Result<(), SPI_Error> { self.set_lut_helper( &LUT_VCOM0_QUICK, &LUT_WW_QUICK, @@ -394,7 +389,7 @@ where lut_bw: &[u8], lut_wb: &[u8], lut_bb: &[u8], - ) -> Result<(), E> { + ) -> Result<(), SPI_Error> { // LUT VCOM self.send_command(Command::LUT_FOR_VCOM)?; self.send_multiple_data(lut_vcom)?;