Browse Source

Merge branch 'fix-70'

main
Andreas 5 years ago
parent
commit
ae25129ada
  1. 64
      src/epd2in9_v2/mod.rs

64
src/epd2in9_v2/mod.rs

@ -33,11 +33,11 @@
//! .draw(&mut display); //! .draw(&mut display);
//! //!
//! // Display updated frame //! // Display updated frame
//!epd.update_frame(&mut spi, &display.buffer())?; //!epd.update_frame(&mut spi, &display.buffer(), &mut delay)?;
//!epd.display_frame(&mut spi)?; //!epd.display_frame(&mut spi, &mut delay)?;
//! //!
//!// Set the EPD to sleep //!// Set the EPD to sleep
//!epd.sleep(&mut spi)?; //!epd.sleep(&mut spi, &mut delay)?;
//!# Ok(()) //!# Ok(())
//!# } //!# }
//!``` //!```
@ -83,28 +83,25 @@ pub use crate::epd2in9_v2::graphics::Display2in9;
/// Epd2in9 driver /// Epd2in9 driver
/// ///
pub struct Epd2in9<SPI, CS, BUSY, DC, RST> { pub struct Epd2in9<SPI, CS, BUSY, DC, RST, DELAY> {
/// SPI /// SPI
interface: DisplayInterface<SPI, CS, BUSY, DC, RST>, interface: DisplayInterface<SPI, CS, BUSY, DC, RST, DELAY>,
/// Color /// Color
background_color: Color, background_color: Color,
/// Refresh LUT /// Refresh LUT
refresh: RefreshLut, refresh: RefreshLut,
} }
impl<SPI, CS, BUSY, DC, RST> Epd2in9<SPI, CS, BUSY, DC, RST> impl<SPI, CS, BUSY, DC, RST, DELAY> Epd2in9<SPI, CS, BUSY, DC, RST, DELAY>
where where
SPI: Write<u8>, SPI: Write<u8>,
CS: OutputPin, CS: OutputPin,
BUSY: InputPin, BUSY: InputPin,
DC: OutputPin, DC: OutputPin,
RST: OutputPin, RST: OutputPin,
DELAY: DelayMs<u8>,
{ {
fn init<DELAY: DelayMs<u8>>( fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
&mut self,
spi: &mut SPI,
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
self.interface.reset(delay, 2); self.interface.reset(delay, 2);
self.wait_until_idle(); self.wait_until_idle();
@ -136,14 +133,15 @@ where
} }
} }
impl<SPI, CS, BUSY, DC, RST> WaveshareDisplay<SPI, CS, BUSY, DC, RST> impl<SPI, CS, BUSY, DC, RST, DELAY> WaveshareDisplay<SPI, CS, BUSY, DC, RST, DELAY>
for Epd2in9<SPI, CS, BUSY, DC, RST> for Epd2in9<SPI, CS, BUSY, DC, RST, DELAY>
where where
SPI: Write<u8>, SPI: Write<u8>,
CS: OutputPin, CS: OutputPin,
BUSY: InputPin, BUSY: InputPin,
DC: OutputPin, DC: OutputPin,
RST: OutputPin, RST: OutputPin,
DELAY: DelayMs<u8>,
{ {
type DisplayColor = Color; type DisplayColor = Color;
fn width(&self) -> u32 { fn width(&self) -> u32 {
@ -154,7 +152,7 @@ where
HEIGHT HEIGHT
} }
fn new<DELAY: DelayMs<u8>>( fn new(
spi: &mut SPI, spi: &mut SPI,
cs: CS, cs: CS,
busy: BUSY, busy: BUSY,
@ -175,7 +173,7 @@ where
Ok(epd) Ok(epd)
} }
fn sleep(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
self.wait_until_idle(); self.wait_until_idle();
// 0x00 for Normal mode (Power on Reset), 0x01 for Deep Sleep Mode // 0x00 for Normal mode (Power on Reset), 0x01 for Deep Sleep Mode
self.interface self.interface
@ -183,16 +181,17 @@ where
Ok(()) Ok(())
} }
fn wake_up<DELAY: DelayMs<u8>>( fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
&mut self,
spi: &mut SPI,
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
self.init(spi, delay)?; self.init(spi, delay)?;
Ok(()) Ok(())
} }
fn update_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> { fn update_frame(
&mut self,
spi: &mut SPI,
buffer: &[u8],
_delay: &mut DELAY,
) -> Result<(), SPI::Error> {
self.wait_until_idle(); self.wait_until_idle();
self.interface.cmd_with_data(spi, Command::WriteRam, buffer) self.interface.cmd_with_data(spi, Command::WriteRam, buffer)
} }
@ -215,7 +214,7 @@ where
Ok(()) Ok(())
} }
fn display_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
self.wait_until_idle(); self.wait_until_idle();
// Enable clock signal, Enable Analog, Load temperature value, DISPLAY with DISPLAY Mode 1, Disable Analog, Disable OSC // Enable clock signal, Enable Analog, Load temperature value, DISPLAY with DISPLAY Mode 1, Disable Analog, Disable OSC
self.interface self.interface
@ -225,13 +224,18 @@ where
Ok(()) Ok(())
} }
fn update_and_display_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> { fn update_and_display_frame(
self.update_frame(spi, buffer)?; &mut self,
self.display_frame(spi)?; spi: &mut SPI,
buffer: &[u8],
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
self.update_frame(spi, buffer, delay)?;
self.display_frame(spi, delay)?;
Ok(()) Ok(())
} }
fn clear_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> { fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
self.wait_until_idle(); self.wait_until_idle();
// clear the ram with the background color // clear the ram with the background color
@ -265,13 +269,14 @@ where
} }
} }
impl<SPI, CS, BUSY, DC, RST> Epd2in9<SPI, CS, BUSY, DC, RST> impl<SPI, CS, BUSY, DC, RST, DELAY> Epd2in9<SPI, CS, BUSY, DC, RST, DELAY>
where where
SPI: Write<u8>, SPI: Write<u8>,
CS: OutputPin, CS: OutputPin,
BUSY: InputPin, BUSY: InputPin,
DC: OutputPin, DC: OutputPin,
RST: OutputPin, RST: OutputPin,
DELAY: DelayMs<u8>,
{ {
fn wait_until_idle(&mut self) { fn wait_until_idle(&mut self) {
self.interface.wait_until_idle(IS_BUSY_LOW); self.interface.wait_until_idle(IS_BUSY_LOW);
@ -343,14 +348,15 @@ where
} }
} }
impl<SPI, CS, BUSY, DC, RST> QuickRefresh<SPI, CS, BUSY, DC, RST> impl<SPI, CS, BUSY, DC, RST, DELAY> QuickRefresh<SPI, CS, BUSY, DC, RST>
for Epd2in9<SPI, CS, BUSY, DC, RST> for Epd2in9<SPI, CS, BUSY, DC, RST, DELAY>
where where
SPI: Write<u8>, SPI: Write<u8>,
CS: OutputPin, CS: OutputPin,
BUSY: InputPin, BUSY: InputPin,
DC: OutputPin, DC: OutputPin,
RST: OutputPin, RST: OutputPin,
DELAY: DelayMs<u8>,
{ {
/// To be followed immediately by `update_new_frame`. /// To be followed immediately by `update_new_frame`.
fn update_old_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> { fn update_old_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> {

Loading…
Cancel
Save