Browse Source

removed duplicate spi_mode and improved naming of spi_error type

embedded-hal-1.0
Christoph Groß 7 years ago
parent
commit
38f446304b
  1. 47
      src/epd4in2/mod.rs

47
src/epd4in2/mod.rs

@ -63,13 +63,7 @@ use drawing::color::Color;
pub mod command; pub mod command;
pub use self::command::Command; pub use self::command::Command;
//TODO: test spi mode use epds::EPD;
/// SPI mode -
/// For more infos see [Requirements: SPI](index.html#spi)
pub const SPI_MODE: Mode = Mode {
phase: Phase::CaptureOnFirstTransition,
polarity: Polarity::IdleLow,
};
/// EPD4in2 driver /// EPD4in2 driver
/// ///
@ -87,10 +81,10 @@ pub struct EPD4in2<SPI, CS, BUSY, DC, RST, D>
impl<SPI, CS, BUSY, DataCommand, RST, Delay, Error> WaveshareInterface<SPI, CS, BUSY, DataCommand, RST, Delay, Error> impl<SPI, CS, BUSY, DataCommand, RST, Delay, SPI_Error> WaveshareInterface<SPI, CS, BUSY, DataCommand, RST, Delay, SPI_Error>
for EPD4in2<SPI, CS, BUSY, DataCommand, RST, Delay> for EPD4in2<SPI, CS, BUSY, DataCommand, RST, Delay>
where where
SPI: Write<u8>, SPI: Write<u8, Error = SPI_Error>,
CS: OutputPin, CS: OutputPin,
BUSY: InputPin, BUSY: InputPin,
DataCommand: OutputPin, DataCommand: OutputPin,
@ -120,7 +114,7 @@ where
/// ///
/// epd4in2.sleep(); /// epd4in2.sleep();
/// ``` /// ```
fn new(interface: ConnectionInterface<SPI, CS, BUSY, DataCommand, RST, Delay>) -> Result<Self, Error> { fn new(interface: ConnectionInterface<SPI, CS, BUSY, DataCommand, RST, Delay>, epd: EPD) -> Result<Self, SPI_Error> {
let width = WIDTH as u16; let width = WIDTH as u16;
let height = HEIGHT as u16; let height = HEIGHT as u16;
@ -138,7 +132,7 @@ where
Ok(epd) Ok(epd)
} }
fn init(&mut self) -> Result<(), Error> { fn init(&mut self) -> Result<(), SPI_Error> {
// reset the device // reset the device
self.reset(); self.reset();
@ -185,7 +179,7 @@ where
Ok(()) 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_command(Command::VCOM_AND_DATA_INTERVAL_SETTING)?;
self.send_data(0x17)?; //border floating self.send_data(0x17)?; //border floating
self.send_command(Command::VCM_DC_SETTING)?; // VCOM to 0V self.send_command(Command::VCM_DC_SETTING)?; // VCOM to 0V
@ -214,7 +208,7 @@ where
self.interface.delay_ms(delay) 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(); let color_value = self.color.get_byte_value();
self.send_resolution()?; self.send_resolution()?;
@ -250,7 +244,8 @@ where
y: u16, y: u16,
width: u16, width: u16,
height: u16, height: u16,
) -> Result<(), E> { ) -> Result<(), SPI_Error> {
if buffer.len() as u16 != width / 8 * height { if buffer.len() as u16 != width / 8 * height {
//TODO: panic!! or sth like that //TODO: panic!! or sth like that
//return Err("Wrong buffersize"); //return Err("Wrong buffersize");
@ -286,13 +281,13 @@ where
self.send_command(Command::PARTIAL_OUT) 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.update_frame(buffer)?;
self.display_frame() 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.send_command(Command::DISPLAY_REFRESH)?;
self.wait_until_idle(); self.wait_until_idle();
@ -302,7 +297,7 @@ where
// TODO: add this abstraction function // 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<(), E>;
fn clear_frame(&mut self) -> Result<(), E> { fn clear_frame(&mut self) -> Result<(), SPI_Error> {
self.send_resolution()?; self.send_resolution()?;
let size = self.width / 8 * self.height; let size = self.width / 8 * self.height;
@ -330,24 +325,24 @@ where
} }
} }
impl<SPI, CS, BUSY, DC, RST, D, E> EPD4in2<SPI, CS, BUSY, DC, RST, D> impl<SPI, CS, BUSY, DC, RST, D, SPI_Error> EPD4in2<SPI, CS, BUSY, DC, RST, D>
where where
SPI: Write<u8, Error = E>, SPI: Write<u8, Error = SPI_Error>,
CS: OutputPin, CS: OutputPin,
BUSY: InputPin, BUSY: InputPin,
DC: OutputPin, DC: OutputPin,
RST: OutputPin, RST: OutputPin,
D: DelayUs<u16> + DelayMs<u16>, D: DelayUs<u16> + DelayMs<u16>,
{ {
fn send_command(&mut self, command: Command) -> Result<(), E> { fn send_command(&mut self, command: Command) -> Result<(), SPI_Error> {
self.interface.send_command(command) 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) 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) self.interface.send_multiple_data(data)
} }
@ -355,7 +350,7 @@ where
self.interface.wait_until_idle(true) 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 w = self.get_width();
let h = self.get_height(); let h = self.get_height();
@ -368,7 +363,7 @@ where
/// Fill the look-up table for the EPD /// Fill the look-up table for the EPD
//TODO: make public? //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) 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()) /// Is automatically done by [EPD4in2::display_frame_quick()](EPD4in2::display_frame_quick())
/// //TODO: make public? /// //TODO: make public?
#[cfg(feature = "epd4in2_fast_update")] #[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( self.set_lut_helper(
&LUT_VCOM0_QUICK, &LUT_VCOM0_QUICK,
&LUT_WW_QUICK, &LUT_WW_QUICK,
@ -394,7 +389,7 @@ where
lut_bw: &[u8], lut_bw: &[u8],
lut_wb: &[u8], lut_wb: &[u8],
lut_bb: &[u8], lut_bb: &[u8],
) -> Result<(), E> { ) -> Result<(), SPI_Error> {
// LUT VCOM // LUT VCOM
self.send_command(Command::LUT_FOR_VCOM)?; self.send_command(Command::LUT_FOR_VCOM)?;
self.send_multiple_data(lut_vcom)?; self.send_multiple_data(lut_vcom)?;

Loading…
Cancel
Save