Browse Source

Update to new error type from eh 1.0a6

embedded-hal-1.0
Caemor 4 years ago
parent
commit
53bfeab6cc
  1. 5
      examples/epd1in54_no_graphics.rs
  2. 5
      examples/epd2in13_v2.rs
  3. 5
      examples/epd2in13bc.rs
  4. 4
      examples/epd4in2.rs
  5. 6
      examples/epd4in2_variable_size.rs
  6. 34
      src/epd1in54/mod.rs
  7. 40
      src/epd1in54b/mod.rs
  8. 40
      src/epd1in54c/mod.rs
  9. 58
      src/epd2in13_v2/mod.rs
  10. 42
      src/epd2in13bc/mod.rs
  11. 46
      src/epd2in7b/mod.rs
  12. 34
      src/epd2in9/mod.rs
  13. 50
      src/epd2in9_v2/mod.rs
  14. 43
      src/epd2in9bc/mod.rs
  15. 52
      src/epd4in2/mod.rs
  16. 37
      src/epd5in65f/mod.rs
  17. 36
      src/epd7in5/mod.rs
  18. 30
      src/epd7in5_hd/mod.rs
  19. 38
      src/epd7in5_v2/mod.rs
  20. 29
      src/interface.rs
  21. 27
      src/lib.rs
  22. 42
      src/traits.rs

5
examples/epd1in54_no_graphics.rs

@ -7,12 +7,15 @@ use linux_embedded_hal::{
sysfs_gpio::Direction,
Delay, Spidev, SysfsPin as Pin,
};
use core::convert::Infallible;
use linux_embedded_hal::SPIError;
// activate spi, gpio in raspi-config
// needs to be run with sudo because of some sysfs_gpio permission problems and follow-up timing problems
// see https://github.com/rust-embedded/rust-sysfs-gpio/issues/5 and follow-up issues
fn main() -> Result<(), linux_embedded_hal::SPIError> {
fn main() -> Result<(), epd_waveshare::Error<SPIError, linux_embedded_hal::sysfs_gpio::Error, linux_embedded_hal::sysfs_gpio::Error, linux_embedded_hal::sysfs_gpio::Error, linux_embedded_hal::sysfs_gpio::Error, Infallible>> {
// Configure SPI
// SPI settings are from eink-waveshare-rs documenation
let mut spi = Spidev::open("/dev/spidev0.0")?;

5
examples/epd2in13_v2.rs

@ -18,12 +18,15 @@ use linux_embedded_hal::{
sysfs_gpio::Direction,
Delay, Spidev, SysfsPin as Pin,
};
use core::convert::Infallible;
use linux_embedded_hal::SPIError;
// activate spi, gpio in raspi-config
// needs to be run with sudo because of some sysfs_gpio permission problems and follow-up timing problems
// see https://github.com/rust-embedded/rust-sysfs-gpio/issues/5 and follow-up issues
fn main() -> Result<(), linux_embedded_hal::SPIError> {
fn main() -> Result<(), epd_waveshare::Error<SPIError, linux_embedded_hal::sysfs_gpio::Error, linux_embedded_hal::sysfs_gpio::Error, linux_embedded_hal::sysfs_gpio::Error, linux_embedded_hal::sysfs_gpio::Error, Infallible>> {
// Configure SPI
// Settings are taken from
let mut spi = Spidev::open("/dev/spidev0.0").expect("spidev directory");

5
examples/epd2in13bc.rs

@ -18,6 +18,9 @@ use linux_embedded_hal::{
sysfs_gpio::Direction,
Delay, Spidev, SysfsPin as Pin,
};
use core::convert::Infallible;
use linux_embedded_hal::SPIError;
// activate spi, gpio in raspi-config
// needs to be run with sudo because of some sysfs_gpio permission problems and follow-up timing problems
@ -34,7 +37,7 @@ use linux_embedded_hal::{
//
// after finishing, put the display to sleep
fn main() -> Result<(), linux_embedded_hal::SPIError> {
fn main() -> Result<(), epd_waveshare::Error<SPIError, linux_embedded_hal::sysfs_gpio::Error, linux_embedded_hal::sysfs_gpio::Error, linux_embedded_hal::sysfs_gpio::Error, linux_embedded_hal::sysfs_gpio::Error, Infallible>> {
let busy = Pin::new(24); // GPIO 24, board J-18
busy.export().expect("busy export");
while !busy.is_exported() {}

4
examples/epd4in2.rs

@ -18,12 +18,14 @@ use linux_embedded_hal::{
sysfs_gpio::Direction,
Delay, Spidev, SysfsPin as Pin,
};
use core::convert::Infallible;
use linux_embedded_hal::SPIError;
// activate spi, gpio in raspi-config
// needs to be run with sudo because of some sysfs_gpio permission problems and follow-up timing problems
// see https://github.com/rust-embedded/rust-sysfs-gpio/issues/5 and follow-up issues
fn main() -> Result<(), linux_embedded_hal::SPIError> {
fn main() -> Result<(), epd_waveshare::Error<SPIError, linux_embedded_hal::sysfs_gpio::Error, linux_embedded_hal::sysfs_gpio::Error, linux_embedded_hal::sysfs_gpio::Error, linux_embedded_hal::sysfs_gpio::Error, Infallible>> {
// Configure SPI
// Settings are taken from
let mut spi = Spidev::open("/dev/spidev0.0").expect("spidev directory");

6
examples/epd4in2_variable_size.rs

@ -19,12 +19,16 @@ use linux_embedded_hal::{
sysfs_gpio::Direction,
Delay, Spidev, SysfsPin as Pin,
};
use core::convert::Infallible;
use linux_embedded_hal::SPIError;
// activate spi, gpio in raspi-config
// needs to be run with sudo because of some sysfs_gpio permission problems and follow-up timing problems
// see https://github.com/rust-embedded/rust-sysfs-gpio/issues/5 and follow-up issues
fn main() -> Result<(), linux_embedded_hal::SPIError> {
fn main() -> Result<(), epd_waveshare::Error<SPIError, linux_embedded_hal::sysfs_gpio::Error, linux_embedded_hal::sysfs_gpio::Error, linux_embedded_hal::sysfs_gpio::Error, linux_embedded_hal::sysfs_gpio::Error, Infallible>> {
// Configure SPI
// Settings are taken from
let mut spi = Spidev::open("/dev/spidev0.0").expect("spidev directory");

34
src/epd1in54/mod.rs

@ -58,7 +58,7 @@ use crate::type_a::{
command::Command,
constants::{LUT_FULL_UPDATE, LUT_PARTIAL_UPDATE},
};
use crate::Error;
use crate::color::Color;
use crate::traits::{RefreshLut, WaveshareDisplay};
@ -80,6 +80,8 @@ pub struct Epd1in54<SPI, CS, BUSY, DC, RST, DELAY> {
refresh: RefreshLut,
}
impl<SPI, CS, BUSY, DC, RST, DELAY> Epd1in54<SPI, CS, BUSY, DC, RST, DELAY>
where
SPI: Write<u8>,
@ -89,8 +91,8 @@ where
RST: OutputPin,
DELAY: DelayUs,
{
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
self.interface.reset(delay, 10);
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.interface.reset(delay, 10)?;
// 3 Databytes:
// A[7:0]
@ -161,7 +163,7 @@ where
dc: DC,
rst: RST,
delay: &mut DELAY,
) -> Result<Self, SPI::Error> {
) -> Result<Self, Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
let interface = DisplayInterface::new(cs, busy, dc, rst);
let mut epd = Epd1in54 {
@ -175,11 +177,11 @@ where
Ok(epd)
}
fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.init(spi, delay)
}
fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
// 0x00 for Normal mode (Power on Reset), 0x01 for Deep Sleep Mode
//TODO: is 0x00 needed here or would 0x01 be even more efficient?
@ -193,7 +195,7 @@ where
spi: &mut SPI,
buffer: &[u8],
_delay: &mut DELAY,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
self.use_full_frame(spi)?;
self.interface
@ -210,7 +212,7 @@ where
y: u32,
width: u32,
height: u32,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
self.set_ram_area(spi, x, y, x + width, y + height)?;
self.set_ram_counter(spi, x, y)?;
@ -220,7 +222,7 @@ where
Ok(())
}
fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
// enable clock signal, enable cp, display pattern -> 0xC4 (tested with the arduino version)
//TODO: test control_1 or control_2 with default value 0xFF (from the datasheet)
@ -239,13 +241,13 @@ where
spi: &mut SPI,
buffer: &[u8],
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.update_frame(spi, buffer, delay)?;
self.display_frame(spi, delay)?;
Ok(())
}
fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
self.use_full_frame(spi)?;
@ -270,7 +272,7 @@ where
&mut self,
spi: &mut SPI,
refresh_rate: Option<RefreshLut>,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
if let Some(refresh_lut) = refresh_rate {
self.refresh = refresh_lut;
}
@ -298,7 +300,7 @@ where
let _ = self.interface.wait_until_idle(IS_BUSY_LOW);
}
pub(crate) fn use_full_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
pub(crate) fn use_full_frame(&mut self, spi: &mut SPI) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
// choose full frame/ram
self.set_ram_area(spi, 0, 0, WIDTH - 1, HEIGHT - 1)?;
@ -313,7 +315,7 @@ where
start_y: u32,
end_x: u32,
end_y: u32,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
assert!(start_x < end_x);
assert!(start_y < end_y);
@ -345,7 +347,7 @@ where
spi: &mut SPI,
x: u32,
y: u32,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
// x is positioned in bytes, so the last 3 bits which show the position inside a byte in the ram
// aren't relevant
@ -361,7 +363,7 @@ where
Ok(())
}
fn set_lut_helper(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> {
fn set_lut_helper(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
assert!(buffer.len() == 30);

40
src/epd1in54b/mod.rs

@ -1,6 +1,6 @@
//! A simple Driver for the Waveshare 1.54" (B) E-Ink Display via SPI
use crate::eh_prelude::*;
use crate::{eh_prelude::*, Error};
use crate::interface::DisplayInterface;
use crate::traits::{
InternalWiAdditions, RefreshLut, WaveshareDisplay, WaveshareThreeColorDisplay,
@ -44,8 +44,8 @@ where
RST: OutputPin,
DELAY: DelayUs,
{
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
self.interface.reset(delay, 10);
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.interface.reset(delay, 10)?;
// set the power settings
self.interface
@ -57,7 +57,7 @@ where
// power on
self.command(spi, Command::PowerOn)?;
delay.delay_ms(5);
delay.delay_ms(5).map_err(|e| Error::Delay(e))?;
self.wait_until_idle();
// set the panel settings
@ -96,12 +96,12 @@ where
spi: &mut SPI,
black: &[u8],
chromatic: &[u8],
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.update_achromatic_frame(spi, black)?;
self.update_chromatic_frame(spi, chromatic)
}
fn update_achromatic_frame(&mut self, spi: &mut SPI, black: &[u8]) -> Result<(), SPI::Error> {
fn update_achromatic_frame(&mut self, spi: &mut SPI, black: &[u8]) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
self.send_resolution(spi)?;
@ -118,7 +118,7 @@ where
&mut self,
spi: &mut SPI,
chromatic: &[u8],
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.interface.cmd(spi, Command::DataStartTransmission2)?;
self.interface.data(spi, chromatic)?;
Ok(())
@ -143,7 +143,7 @@ where
dc: DC,
rst: RST,
delay: &mut DELAY,
) -> Result<Self, SPI::Error> {
) -> Result<Self, Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
let interface = DisplayInterface::new(cs, busy, dc, rst);
let color = DEFAULT_BACKGROUND_COLOR;
@ -154,7 +154,7 @@ where
Ok(epd)
}
fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
self.interface
.cmd_with_data(spi, Command::VcomAndDataIntervalSetting, &[0x17])?; //border floating
@ -174,7 +174,7 @@ where
Ok(())
}
fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.init(spi, delay)
}
@ -199,7 +199,7 @@ where
spi: &mut SPI,
buffer: &[u8],
_delay: &mut DELAY,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
self.send_resolution(spi)?;
@ -233,11 +233,11 @@ where
y: u32,
width: u32,
height: u32,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
unimplemented!()
}
fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
self.command(spi, Command::DisplayRefresh)?;
Ok(())
@ -248,13 +248,13 @@ where
spi: &mut SPI,
buffer: &[u8],
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.update_frame(spi, buffer, delay)?;
self.display_frame(spi, delay)?;
Ok(())
}
fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
self.send_resolution(spi)?;
@ -278,7 +278,7 @@ where
&mut self,
spi: &mut SPI,
_refresh_rate: Option<RefreshLut>,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.interface
.cmd_with_data(spi, Command::LutForVcom, LUT_VCOM0)?;
self.interface
@ -311,11 +311,11 @@ where
RST: OutputPin,
DELAY: DelayUs,
{
fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), SPI::Error> {
fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.interface.cmd(spi, command)
}
fn send_data(&mut self, spi: &mut SPI, data: &[u8]) -> Result<(), SPI::Error> {
fn send_data(&mut self, spi: &mut SPI, data: &[u8]) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.interface.data(spi, data)
}
@ -324,7 +324,7 @@ where
spi: &mut SPI,
command: Command,
data: &[u8],
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.interface.cmd_with_data(spi, command, data)
}
@ -332,7 +332,7 @@ where
let _ = self.interface.wait_until_idle(IS_BUSY_LOW);
}
fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
let w = self.width();
let h = self.height();

40
src/epd1in54c/mod.rs

@ -1,6 +1,6 @@
//! A simple Driver for the Waveshare 1.54" (C) E-Ink Display via SPI
use crate::eh_prelude::*;
use crate::{eh_prelude::*, Error};
use crate::interface::DisplayInterface;
use crate::traits::{
InternalWiAdditions, RefreshLut, WaveshareDisplay, WaveshareThreeColorDisplay,
@ -42,19 +42,19 @@ where
RST: OutputPin,
DELAY: DelayUs,
{
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
// Based on Reference Program Code from:
// https://www.waveshare.com/w/upload/a/ac/1.54inch_e-Paper_Module_C_Specification.pdf
// and:
// https://github.com/waveshare/e-Paper/blob/master/STM32/STM32-F103ZET6/User/e-Paper/EPD_1in54c.c
self.interface.reset(delay, 2);
self.interface.reset(delay, 2)?;
// start the booster
self.cmd_with_data(spi, Command::BoosterSoftStart, &[0x17, 0x17, 0x17])?;
// power on
self.command(spi, Command::PowerOn)?;
delay.delay_ms(5);
delay.delay_ms(5).map_err(|e| Error::Delay(e))?;
self.wait_until_idle();
// set the panel settings
@ -84,12 +84,12 @@ where
spi: &mut SPI,
black: &[u8],
chromatic: &[u8],
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.update_achromatic_frame(spi, black)?;
self.update_chromatic_frame(spi, chromatic)
}
fn update_achromatic_frame(&mut self, spi: &mut SPI, black: &[u8]) -> Result<(), SPI::Error> {
fn update_achromatic_frame(&mut self, spi: &mut SPI, black: &[u8]) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
self.cmd_with_data(spi, Command::DataStartTransmission1, black)?;
@ -100,7 +100,7 @@ where
&mut self,
spi: &mut SPI,
chromatic: &[u8],
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
self.cmd_with_data(spi, Command::DataStartTransmission2, chromatic)?;
@ -126,7 +126,7 @@ where
dc: DC,
rst: RST,
delay: &mut DELAY,
) -> Result<Self, SPI::Error> {
) -> Result<Self, Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
let interface = DisplayInterface::new(cs, busy, dc, rst);
let color = DEFAULT_BACKGROUND_COLOR;
@ -137,7 +137,7 @@ where
Ok(epd)
}
fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
self.command(spi, Command::PowerOff)?;
@ -147,7 +147,7 @@ where
Ok(())
}
fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.init(spi, delay)
}
@ -172,7 +172,7 @@ where
spi: &mut SPI,
buffer: &[u8],
_delay: &mut DELAY,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.update_achromatic_frame(spi, buffer)?;
// Clear the chromatic layer
@ -193,11 +193,11 @@ where
y: u32,
width: u32,
height: u32,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
unimplemented!()
}
fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.command(spi, Command::DisplayRefresh)?;
self.wait_until_idle();
@ -209,14 +209,14 @@ where
spi: &mut SPI,
buffer: &[u8],
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.update_frame(spi, buffer, delay)?;
self.display_frame(spi, delay)?;
Ok(())
}
fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
let color = DEFAULT_BACKGROUND_COLOR.get_byte_value();
@ -235,7 +235,7 @@ where
&mut self,
_spi: &mut SPI,
_refresh_rate: Option<RefreshLut>,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
Ok(())
}
@ -253,11 +253,11 @@ where
RST: OutputPin,
DELAY: DelayUs,
{
fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), SPI::Error> {
fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.interface.cmd(spi, command)
}
fn send_data(&mut self, spi: &mut SPI, data: &[u8]) -> Result<(), SPI::Error> {
fn send_data(&mut self, spi: &mut SPI, data: &[u8]) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.interface.data(spi, data)
}
@ -266,7 +266,7 @@ where
spi: &mut SPI,
command: Command,
data: &[u8],
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.interface.cmd_with_data(spi, command, data)
}
@ -274,7 +274,7 @@ where
let _ = self.interface.wait_until_idle(IS_BUSY_LOW);
}
fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
let w = self.width();
let h = self.height();

58
src/epd2in13_v2/mod.rs

@ -8,7 +8,7 @@
//! - [Controller Datasheet SS1780](http://www.e-paper-display.com/download_detail/downloadsId=682.html)
//!
use crate::buffer_len;
use crate::{buffer_len};use crate::Error;
use crate::color::Color;
use crate::eh_prelude::*;
use crate::interface::DisplayInterface;
@ -62,9 +62,9 @@ where
RST: OutputPin,
DELAY: DelayUs,
{
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
// HW reset
self.interface.reset(delay, 10);
self.interface.reset(delay, 10)?;
if self.refresh == RefreshLut::Quick {
self.set_vcom_register(spi, (-9).vcom())?;
@ -164,7 +164,7 @@ where
dc: DC,
rst: RST,
delay: &mut DELAY,
) -> Result<Self, SPI::Error> {
) -> Result<Self, Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
let mut epd = Epd2in13 {
interface: DisplayInterface::new(cs, busy, dc, rst),
sleep_mode: DeepSleepMode::Mode1,
@ -176,11 +176,11 @@ where
Ok(epd)
}
fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.init(spi, delay)
}
fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
// All sample code enables and disables analog/clocks...
@ -203,7 +203,7 @@ where
spi: &mut SPI,
buffer: &[u8],
_delay: &mut DELAY,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
assert!(buffer.len() == buffer_len(WIDTH as usize, HEIGHT as usize));
self.set_ram_area(spi, 0, 0, WIDTH - 1, HEIGHT - 1)?;
self.set_ram_address_counters(spi, 0, 0)?;
@ -231,7 +231,7 @@ where
y: u32,
width: u32,
height: u32,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
assert!((width * height / 8) as usize == buffer.len());
// This should not be used when doing partial refresh. The RAM_RED must
@ -260,7 +260,7 @@ where
/// Never use directly this function when using partial refresh, or also
/// keep the base buffer in syncd using `set_partial_base_buffer` function.
fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
if self.refresh == RefreshLut::Full {
self.set_display_update_control_2(
spi,
@ -285,7 +285,7 @@ where
spi: &mut SPI,
buffer: &[u8],
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.update_frame(spi, buffer, delay)?;
self.display_frame(spi, delay)?;
@ -295,7 +295,7 @@ where
Ok(())
}
fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
let color = self.background_color.get_byte_value();
self.set_ram_area(spi, 0, 0, WIDTH - 1, HEIGHT - 1)?;
@ -343,7 +343,7 @@ where
&mut self,
spi: &mut SPI,
refresh_rate: Option<RefreshLut>,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
let buffer = match refresh_rate {
Some(RefreshLut::Full) | None => &LUT_FULL_UPDATE,
Some(RefreshLut::Quick) => &LUT_PARTIAL_UPDATE,
@ -372,7 +372,7 @@ where
&mut self,
spi: &mut SPI,
buffer: &[u8],
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
assert!(buffer_len(WIDTH as usize, HEIGHT as usize) == buffer.len());
self.set_ram_area(spi, 0, 0, WIDTH - 1, HEIGHT - 1)?;
self.set_ram_address_counters(spi, 0, 0)?;
@ -393,7 +393,7 @@ where
spi: &mut SPI,
delay: &mut DELAY,
refresh: RefreshLut,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
if self.refresh != refresh {
self.refresh = refresh;
self.init(spi, delay)?;
@ -405,7 +405,7 @@ where
&mut self,
spi: &mut SPI,
start: u16,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
assert!(start <= 295);
self.cmd_with_data(
spi,
@ -418,7 +418,7 @@ where
&mut self,
spi: &mut SPI,
borderwaveform: BorderWaveForm,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.cmd_with_data(
spi,
Command::BorderWaveformControl,
@ -426,7 +426,7 @@ where
)
}
fn set_vcom_register(&mut self, spi: &mut SPI, vcom: Vcom) -> Result<(), SPI::Error> {
fn set_vcom_register(&mut self, spi: &mut SPI, vcom: Vcom) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.cmd_with_data(spi, Command::WriteVcomRegister, &[vcom.0])
}
@ -434,7 +434,7 @@ where
&mut self,
spi: &mut SPI,
voltage: GateDrivingVoltage,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.cmd_with_data(spi, Command::GateDrivingVoltageCtrl, &[voltage.0])
}
@ -442,12 +442,12 @@ where
&mut self,
spi: &mut SPI,
number_of_lines: u8,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
assert!(number_of_lines <= 127);
self.cmd_with_data(spi, Command::SetDummyLinePeriod, &[number_of_lines])
}
fn set_gate_line_width(&mut self, spi: &mut SPI, width: u8) -> Result<(), SPI::Error> {
fn set_gate_line_width(&mut self, spi: &mut SPI, width: u8) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.cmd_with_data(spi, Command::SetGateLineWidth, &[width & 0x0F])
}
@ -458,7 +458,7 @@ where
vsh1: SourceDrivingVoltage,
vsh2: SourceDrivingVoltage,
vsl: SourceDrivingVoltage,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.cmd_with_data(
spi,
Command::SourceDrivingVoltageCtrl,
@ -472,16 +472,16 @@ where
&mut self,
spi: &mut SPI,
value: DisplayUpdateControl2,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.cmd_with_data(spi, Command::DisplayUpdateControl2, &[value.0])
}
/// Triggers the deep sleep mode
fn set_sleep_mode(&mut self, spi: &mut SPI, mode: DeepSleepMode) -> Result<(), SPI::Error> {
fn set_sleep_mode(&mut self, spi: &mut SPI, mode: DeepSleepMode) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.cmd_with_data(spi, Command::DeepSleepMode, &[mode as u8])
}
fn set_driver_output(&mut self, spi: &mut SPI, output: DriverOutput) -> Result<(), SPI::Error> {
fn set_driver_output(&mut self, spi: &mut SPI, output: DriverOutput) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.cmd_with_data(spi, Command::DriverOutputControl, &output.to_bytes())
}
@ -492,7 +492,7 @@ where
spi: &mut SPI,
counter_incr_mode: DataEntryModeIncr,
counter_direction: DataEntryModeDir,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
let mode = counter_incr_mode as u8 | counter_direction as u8;
self.cmd_with_data(spi, Command::DataEntryModeSetting, &[mode])
}
@ -505,7 +505,7 @@ where
start_y: u32,
end_x: u32,
end_y: u32,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.cmd_with_data(
spi,
Command::SetRamXAddressStartEndPosition,
@ -530,7 +530,7 @@ where
spi: &mut SPI,
x: u32,
y: u32,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
self.cmd_with_data(spi, Command::SetRamXAddressCounter, &[(x >> 3) as u8])?;
@ -542,7 +542,7 @@ where
Ok(())
}
fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), SPI::Error> {
fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.interface.cmd(spi, command)
}
@ -551,7 +551,7 @@ where
spi: &mut SPI,
command: Command,
data: &[u8],
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.interface.cmd_with_data(spi, command, data)
}

42
src/epd2in13bc/mod.rs

@ -50,7 +50,7 @@
//!# }
//!```
use crate::eh_prelude::*;
use crate::{eh_prelude::*, Error};
use crate::interface::DisplayInterface;
use crate::traits::{
InternalWiAdditions, RefreshLut, WaveshareDisplay, WaveshareThreeColorDisplay,
@ -99,10 +99,10 @@ where
RST: OutputPin,
DELAY: DelayUs,
{
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
// Values taken from datasheet and sample code
self.interface.reset(delay, 10);
self.interface.reset(delay, 10)?;
// start the booster
self.interface
@ -110,7 +110,7 @@ where
// power on
self.command(spi, Command::PowerOn)?;
delay.delay_ms(5);
delay.delay_ms(5).map_err(|e| Error::Delay(e))?;
self.wait_until_idle();
// set the panel settings
@ -148,7 +148,7 @@ where
spi: &mut SPI,
black: &[u8],
chromatic: &[u8],
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.update_achromatic_frame(spi, black)?;
self.update_chromatic_frame(spi, chromatic)
}
@ -156,7 +156,7 @@ where
/// Update only the black/white data of the display.
///
/// Finish by calling `update_chromatic_frame`.
fn update_achromatic_frame(&mut self, spi: &mut SPI, black: &[u8]) -> Result<(), SPI::Error> {
fn update_achromatic_frame(&mut self, spi: &mut SPI, black: &[u8]) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.interface.cmd(spi, Command::DataStartTransmission1)?;
self.interface.data(spi, black)?;
Ok(())
@ -169,7 +169,7 @@ where
&mut self,
spi: &mut SPI,
chromatic: &[u8],
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.interface.cmd(spi, Command::DataStartTransmission2)?;
self.interface.data(spi, chromatic)?;
@ -196,7 +196,7 @@ where
dc: DC,
rst: RST,
delay: &mut DELAY,
) -> Result<Self, SPI::Error> {
) -> Result<Self, Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
let interface = DisplayInterface::new(cs, busy, dc, rst);
let color = DEFAULT_BACKGROUND_COLOR;
@ -207,7 +207,7 @@ where
Ok(epd)
}
fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
// Section 8.2 from datasheet
self.interface.cmd_with_data(
spi,
@ -224,7 +224,7 @@ where
Ok(())
}
fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.init(spi, delay)
}
@ -249,7 +249,7 @@ where
spi: &mut SPI,
buffer: &[u8],
_delay: &mut DELAY,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.interface.cmd(spi, Command::DataStartTransmission1)?;
self.interface.data(spi, buffer)?;
@ -273,11 +273,11 @@ where
y: u32,
width: u32,
height: u32,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
Ok(())
}
fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.command(spi, Command::DisplayRefresh)?;
self.wait_until_idle();
@ -289,13 +289,13 @@ where
spi: &mut SPI,
buffer: &[u8],
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.update_frame(spi, buffer, delay)?;
self.display_frame(spi, delay)?;
Ok(())
}
fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.send_resolution(spi)?;
let color = DEFAULT_BACKGROUND_COLOR.get_byte_value();
@ -317,7 +317,7 @@ where
&mut self,
_spi: &mut SPI,
_refresh_rate: Option<RefreshLut>,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
Ok(())
}
@ -335,11 +335,11 @@ where
RST: OutputPin,
DELAY: DelayUs,
{
fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), SPI::Error> {
fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.interface.cmd(spi, command)
}
fn send_data(&mut self, spi: &mut SPI, data: &[u8]) -> Result<(), SPI::Error> {
fn send_data(&mut self, spi: &mut SPI, data: &[u8]) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.interface.data(spi, data)
}
@ -348,7 +348,7 @@ where
spi: &mut SPI,
command: Command,
data: &[u8],
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.interface.cmd_with_data(spi, command, data)
}
@ -356,7 +356,7 @@ where
let _ = self.interface.wait_until_idle(IS_BUSY_LOW);
}
fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
let w = self.width();
let h = self.height();
@ -368,7 +368,7 @@ where
}
/// Set the outer border of the display to the chosen color.
pub fn set_border_color(&mut self, spi: &mut SPI, color: TriColor) -> Result<(), SPI::Error> {
pub fn set_border_color(&mut self, spi: &mut SPI, color: TriColor) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
let border = match color {
TriColor::Black => BLACK_BORDER,
TriColor::White => WHITE_BORDER,

46
src/epd2in7b/mod.rs

@ -2,7 +2,7 @@
//!
//! [Documentation](https://www.waveshare.com/wiki/2.7inch_e-Paper_HAT_(B))
use crate::eh_prelude::*;
use crate::{eh_prelude::*, Error};
use crate::interface::DisplayInterface;
use crate::traits::{
InternalWiAdditions, RefreshLut, WaveshareDisplay, WaveshareThreeColorDisplay,
@ -48,13 +48,13 @@ where
RST: OutputPin,
DELAY: DelayUs,
{
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
// reset the device
self.interface.reset(delay, 2);
self.interface.reset(delay, 2)?;
// power on
self.command(spi, Command::PowerOn)?;
delay.delay_ms(5);
delay.delay_ms(5).map_err(|e| Error::Delay(e))?;
self.wait_until_idle();
// set panel settings, 0xbf is bw, 0xaf is multi-color
@ -122,7 +122,7 @@ where
dc: DC,
rst: RST,
delay: &mut DELAY,
) -> Result<Self, SPI::Error> {
) -> Result<Self, Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
let interface = DisplayInterface::new(cs, busy, dc, rst);
let color = DEFAULT_BACKGROUND_COLOR;
@ -133,11 +133,11 @@ where
Ok(epd)
}
fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.init(spi, delay)
}
fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
self.interface
.cmd_with_data(spi, Command::VcomAndDataIntervalSetting, &[0xf7])?;
@ -154,7 +154,7 @@ where
spi: &mut SPI,
buffer: &[u8],
_delay: &mut DELAY,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.interface.cmd(spi, Command::DataStartTransmission1)?;
self.send_buffer_helper(spi, buffer)?;
@ -175,7 +175,7 @@ where
y: u32,
width: u32,
height: u32,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.interface
.cmd(spi, Command::PartialDataStartTransmission1)?;
@ -194,7 +194,7 @@ where
self.interface.cmd(spi, Command::DataStop)
}
fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.command(spi, Command::DisplayRefresh)?;
self.wait_until_idle();
Ok(())
@ -205,13 +205,13 @@ where
spi: &mut SPI,
buffer: &[u8],
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.update_frame(spi, buffer, delay)?;
self.command(spi, Command::DisplayRefresh)?;
Ok(())
}
fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
let color_value = self.color.get_byte_value();
@ -248,7 +248,7 @@ where
&mut self,
spi: &mut SPI,
_refresh_rate: Option<RefreshLut>,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
self.cmd_with_data(spi, Command::LutForVcom, &LUT_VCOM_DC)?;
self.cmd_with_data(spi, Command::LutWhiteToWhite, &LUT_WW)?;
@ -278,7 +278,7 @@ where
spi: &mut SPI,
black: &[u8],
chromatic: &[u8],
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.update_achromatic_frame(spi, black)?;
self.update_chromatic_frame(spi, chromatic)
}
@ -290,7 +290,7 @@ where
&mut self,
spi: &mut SPI,
achromatic: &[u8],
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.interface.cmd(spi, Command::DataStartTransmission1)?;
self.send_buffer_helper(spi, achromatic)?;
@ -305,7 +305,7 @@ where
&mut self,
spi: &mut SPI,
chromatic: &[u8],
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.interface.cmd(spi, Command::DataStartTransmission2)?;
self.send_buffer_helper(spi, chromatic)?;
@ -326,15 +326,15 @@ where
RST: OutputPin,
DELAY: DelayUs,
{
fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), SPI::Error> {
fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.interface.cmd(spi, command)
}
fn send_data(&mut self, spi: &mut SPI, data: &[u8]) -> Result<(), SPI::Error> {
fn send_data(&mut self, spi: &mut SPI, data: &[u8]) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.interface.data(spi, data)
}
fn send_buffer_helper(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> {
fn send_buffer_helper(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
// Based on the waveshare implementation, all data for color values is flipped. This helper
// method makes that transmission easier
for b in buffer.iter() {
@ -348,7 +348,7 @@ where
spi: &mut SPI,
command: Command,
data: &[u8],
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.interface.cmd_with_data(spi, command, data)
}
@ -364,7 +364,7 @@ where
y: u32,
width: u32,
height: u32,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.command(spi, Command::PartialDisplayRefresh)?;
self.send_data(spi, &[(x >> 8) as u8])?;
self.send_data(spi, &[(x & 0xf8) as u8])?;
@ -387,7 +387,7 @@ where
y: u32,
width: u32,
height: u32,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.interface
.cmd(spi, Command::PartialDataStartTransmission1)?;
self.send_data(spi, &[(x >> 8) as u8])?;
@ -417,7 +417,7 @@ where
y: u32,
width: u32,
height: u32,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.interface
.cmd(spi, Command::PartialDataStartTransmission2)?;
self.send_data(spi, &[(x >> 8) as u8])?;

34
src/epd2in9/mod.rs

@ -49,12 +49,12 @@ pub const HEIGHT: u32 = 296;
pub const DEFAULT_BACKGROUND_COLOR: Color = Color::White;
const IS_BUSY_LOW: bool = false;
use crate::eh_prelude::*;
use crate::{eh_prelude::*};
use crate::type_a::{
command::Command,
constants::{LUT_FULL_UPDATE, LUT_PARTIAL_UPDATE},
};
use crate::Error;
use crate::color::Color;
use crate::traits::*;
@ -86,8 +86,8 @@ where
RST: OutputPin,
DELAY: DelayUs,
{
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
self.interface.reset(delay, 10);
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.interface.reset(delay, 10)?;
self.wait_until_idle();
@ -154,7 +154,7 @@ where
dc: DC,
rst: RST,
delay: &mut DELAY,
) -> Result<Self, SPI::Error> {
) -> Result<Self, Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
let interface = DisplayInterface::new(cs, busy, dc, rst);
let mut epd = Epd2in9 {
@ -168,7 +168,7 @@ where
Ok(epd)
}
fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
// 0x00 for Normal mode (Power on Reset), 0x01 for Deep Sleep Mode
//TODO: is 0x00 needed here? (see also epd1in54)
@ -177,7 +177,7 @@ where
Ok(())
}
fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
self.init(spi, delay)?;
Ok(())
@ -188,7 +188,7 @@ where
spi: &mut SPI,
buffer: &[u8],
_delay: &mut DELAY,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
self.use_full_frame(spi)?;
@ -206,7 +206,7 @@ where
y: u32,
width: u32,
height: u32,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
self.set_ram_area(spi, x, y, x + width, y + height)?;
self.set_ram_counter(spi, x, y)?;
@ -216,7 +216,7 @@ where
Ok(())
}
fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
// enable clock signal, enable cp, display pattern -> 0xC4 (tested with the arduino version)
//TODO: test control_1 or control_2 with default value 0xFF (from the datasheet)
@ -235,13 +235,13 @@ where
spi: &mut SPI,
buffer: &[u8],
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.update_frame(spi, buffer, delay)?;
self.display_frame(spi, delay)?;
Ok(())
}
fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
self.use_full_frame(spi)?;
@ -266,7 +266,7 @@ where
&mut self,
spi: &mut SPI,
refresh_rate: Option<RefreshLut>,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
if let Some(refresh_lut) = refresh_rate {
self.refresh = refresh_lut;
}
@ -294,7 +294,7 @@ where
let _ = self.interface.wait_until_idle(IS_BUSY_LOW);
}
fn use_full_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
fn use_full_frame(&mut self, spi: &mut SPI) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
// choose full frame/ram
self.set_ram_area(spi, 0, 0, WIDTH - 1, HEIGHT - 1)?;
@ -309,7 +309,7 @@ where
start_y: u32,
end_x: u32,
end_y: u32,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
assert!(start_x < end_x);
assert!(start_y < end_y);
@ -334,7 +334,7 @@ where
)
}
fn set_ram_counter(&mut self, spi: &mut SPI, x: u32, y: u32) -> Result<(), SPI::Error> {
fn set_ram_counter(&mut self, spi: &mut SPI, x: u32, y: u32) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
// x is positioned in bytes, so the last 3 bits which show the position inside a byte in the ram
// aren't relevant
@ -351,7 +351,7 @@ where
}
/// Set your own LUT, this function is also used internally for set_lut
fn set_lut_helper(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> {
fn set_lut_helper(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
assert!(buffer.len() == 30);
self.interface

50
src/epd2in9_v2/mod.rs

@ -74,9 +74,9 @@ const LUT_PARTIAL_2IN9: [u8; 153] = [
0x22, 0x0, 0x0, 0x0,
];
use crate::eh_prelude::*;
use crate::{eh_prelude::*};
use crate::type_a::command::Command;
use crate::Error;
use crate::color::Color;
use crate::traits::*;
@ -109,8 +109,8 @@ where
RST: OutputPin,
DELAY: DelayUs,
{
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
self.interface.reset(delay, 2);
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.interface.reset(delay, 2)?;
self.wait_until_idle();
self.interface.cmd(spi, Command::SwReset)?;
@ -167,7 +167,7 @@ where
dc: DC,
rst: RST,
delay: &mut DELAY,
) -> Result<Self, SPI::Error> {
) -> Result<Self, Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
let interface = DisplayInterface::new(cs, busy, dc, rst);
let mut epd = Epd2in9 {
@ -181,7 +181,7 @@ where
Ok(epd)
}
fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
// 0x00 for Normal mode (Power on Reset), 0x01 for Deep Sleep Mode
self.interface
@ -189,7 +189,7 @@ where
Ok(())
}
fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.init(spi, delay)?;
Ok(())
}
@ -199,7 +199,7 @@ where
spi: &mut SPI,
buffer: &[u8],
_delay: &mut DELAY,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
self.interface.cmd_with_data(spi, Command::WriteRam, buffer)
}
@ -212,7 +212,7 @@ where
y: u32,
width: u32,
height: u32,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
//TODO This is copied from epd2in9 but it seems not working. Partial refresh supported by version 2?
self.wait_until_idle();
self.set_ram_area(spi, x, y, x + width, y + height)?;
@ -223,7 +223,7 @@ where
Ok(())
}
fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
// Enable clock signal, Enable Analog, Load temperature value, DISPLAY with DISPLAY Mode 1, Disable Analog, Disable OSC
self.interface
@ -238,13 +238,13 @@ where
spi: &mut SPI,
buffer: &[u8],
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.update_frame(spi, buffer, delay)?;
self.display_frame(spi, delay)?;
Ok(())
}
fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
// clear the ram with the background color
@ -266,7 +266,7 @@ where
&mut self,
_spi: &mut SPI,
refresh_rate: Option<RefreshLut>,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
if let Some(refresh_lut) = refresh_rate {
self.refresh = refresh_lut;
}
@ -291,7 +291,7 @@ where
self.interface.wait_until_idle(IS_BUSY_LOW);
}
fn use_full_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
fn use_full_frame(&mut self, spi: &mut SPI) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
// choose full frame/ram
self.set_ram_area(spi, 0, 0, WIDTH - 1, HEIGHT - 1)?;
@ -306,7 +306,7 @@ where
start_y: u32,
end_x: u32,
end_y: u32,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
assert!(start_x < end_x);
assert!(start_y < end_y);
@ -331,7 +331,7 @@ where
)
}
fn set_ram_counter(&mut self, spi: &mut SPI, x: u32, y: u32) -> Result<(), SPI::Error> {
fn set_ram_counter(&mut self, spi: &mut SPI, x: u32, y: u32) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
// x is positioned in bytes, so the last 3 bits which show the position inside a byte in the ram
// aren't relevant
@ -348,7 +348,7 @@ where
}
/// Set your own LUT, this function is also used internally for set_lut
fn set_lut_helper(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> {
fn set_lut_helper(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
self.interface
.cmd_with_data(spi, Command::WriteLutRegister, buffer)?;
@ -373,7 +373,7 @@ where
spi: &mut SPI,
buffer: &[u8],
_delay: &mut DELAY,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
self.interface
.cmd_with_data(spi, Command::WriteRam, buffer)?;
@ -387,9 +387,9 @@ where
spi: &mut SPI,
buffer: &[u8],
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
self.interface.reset(delay, 2);
self.interface.reset(delay, 2)?;
self.set_lut_helper(spi, &LUT_PARTIAL_2IN9)?;
self.interface.cmd_with_data(
@ -413,7 +413,7 @@ where
}
/// For a quick refresh of the new updated frame. To be used immediately after `update_new_frame`
fn display_new_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
fn display_new_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
self.interface
.cmd_with_data(spi, Command::DisplayUpdateControl2, &[0x0F])?;
@ -428,7 +428,7 @@ where
spi: &mut SPI,
buffer: &[u8],
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.update_new_frame(spi, buffer, delay)?;
self.display_new_frame(spi, delay)?;
Ok(())
@ -444,7 +444,7 @@ where
y: u32,
width: u32,
height: u32,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
//TODO supported by display?
unimplemented!()
}
@ -459,7 +459,7 @@ where
y: u32,
width: u32,
height: u32,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
//TODO supported by display?
unimplemented!()
}
@ -473,7 +473,7 @@ where
y: u32,
width: u32,
height: u32,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
//TODO supported by display?
unimplemented!()
}

43
src/epd2in9bc/mod.rs

@ -54,7 +54,7 @@
//!# }
//!```
//!
use crate::eh_prelude::*;
use crate::{eh_prelude::*, Error};
use crate::interface::DisplayInterface;
use crate::traits::{
InternalWiAdditions, RefreshLut, WaveshareDisplay, WaveshareThreeColorDisplay,
@ -76,6 +76,7 @@ const BLACK_BORDER: u8 = 0x30;
const CHROMATIC_BORDER: u8 = 0xb0;
const FLOATING_BORDER: u8 = 0xF0;
use crate::color::{Color, TriColor};
pub(crate) mod command;
@ -102,10 +103,10 @@ where
RST: OutputPin,
DELAY: DelayUs,
{
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
// Values taken from datasheet and sample code
self.interface.reset(delay, 10);
self.interface.reset(delay, 10)?;
// start the booster
self.interface
@ -113,7 +114,7 @@ where
// power on
self.command(spi, Command::PowerOn)?;
delay.delay_ms(5);
delay.delay_ms(5).map_err(|e| Error::Delay(e))?;
self.wait_until_idle();
// set the panel settings
@ -151,7 +152,7 @@ where
spi: &mut SPI,
black: &[u8],
chromatic: &[u8],
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.update_achromatic_frame(spi, black)?;
self.update_chromatic_frame(spi, chromatic)
}
@ -159,7 +160,7 @@ where
/// Update only the black/white data of the display.
///
/// Finish by calling `update_chromatic_frame`.
fn update_achromatic_frame(&mut self, spi: &mut SPI, black: &[u8]) -> Result<(), SPI::Error> {
fn update_achromatic_frame(&mut self, spi: &mut SPI, black: &[u8]) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.interface.cmd(spi, Command::DataStartTransmission1)?;
self.interface.data(spi, black)?;
Ok(())
@ -172,7 +173,7 @@ where
&mut self,
spi: &mut SPI,
chromatic: &[u8],
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.interface.cmd(spi, Command::DataStartTransmission2)?;
self.interface.data(spi, chromatic)?;
@ -199,7 +200,7 @@ where
dc: DC,
rst: RST,
delay: &mut DELAY,
) -> Result<Self, SPI::Error> {
) -> Result<Self, Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
let interface = DisplayInterface::new(cs, busy, dc, rst);
let color = DEFAULT_BACKGROUND_COLOR;
@ -210,7 +211,7 @@ where
Ok(epd)
}
fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
// Section 8.2 from datasheet
self.interface.cmd_with_data(
spi,
@ -227,7 +228,7 @@ where
Ok(())
}
fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.init(spi, delay)
}
@ -252,7 +253,7 @@ where
spi: &mut SPI,
buffer: &[u8],
_delay: &mut DELAY,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.interface.cmd(spi, Command::DataStartTransmission1)?;
self.interface.data(spi, buffer)?;
@ -276,11 +277,11 @@ where
y: u32,
width: u32,
height: u32,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
Ok(())
}
fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.command(spi, Command::DisplayRefresh)?;
self.wait_until_idle();
@ -292,13 +293,13 @@ where
spi: &mut SPI,
buffer: &[u8],
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.update_frame(spi, buffer, delay)?;
self.display_frame(spi, delay)?;
Ok(())
}
fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.send_resolution(spi)?;
let color = DEFAULT_BACKGROUND_COLOR.get_byte_value();
@ -320,7 +321,7 @@ where
&mut self,
_spi: &mut SPI,
_refresh_rate: Option<RefreshLut>,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
Ok(())
}
@ -338,11 +339,11 @@ where
RST: OutputPin,
DELAY: DelayUs,
{
fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), SPI::Error> {
fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.interface.cmd(spi, command)
}
fn send_data(&mut self, spi: &mut SPI, data: &[u8]) -> Result<(), SPI::Error> {
fn send_data(&mut self, spi: &mut SPI, data: &[u8]) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.interface.data(spi, data)
}
@ -351,7 +352,7 @@ where
spi: &mut SPI,
command: Command,
data: &[u8],
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.interface.cmd_with_data(spi, command, data)
}
@ -359,7 +360,7 @@ where
let _ = self.interface.wait_until_idle(IS_BUSY_LOW);
}
fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
let w = self.width();
let h = self.height();
@ -371,7 +372,7 @@ where
}
/// Set the outer border of the display to the chosen color.
pub fn set_border_color(&mut self, spi: &mut SPI, color: TriColor) -> Result<(), SPI::Error> {
pub fn set_border_color(&mut self, spi: &mut SPI, color: TriColor) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
let border = match color {
TriColor::Black => BLACK_BORDER,
TriColor::White => WHITE_BORDER,

52
src/epd4in2/mod.rs

@ -49,7 +49,7 @@
//!
//! BE CAREFUL! The screen can get ghosting/burn-ins through the Partial Fast Update Drawing.
use crate::eh_prelude::*;
use crate::{eh_prelude::*, Error};
use crate::interface::DisplayInterface;
use crate::traits::{InternalWiAdditions, QuickRefresh, RefreshLut, WaveshareDisplay};
@ -96,9 +96,9 @@ where
RST: OutputPin,
DELAY: DelayUs,
{
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
// reset the device
self.interface.reset(delay, 10);
self.interface.reset(delay, 10)?;
// set the power settings
self.interface.cmd_with_data(
@ -113,7 +113,7 @@ where
// power on
self.command(spi, Command::PowerOn)?;
delay.delay_ms(5);
delay.delay_ms(5).map_err(|e| Error::Delay(e))?;
self.wait_until_idle();
// set the panel settings
@ -159,7 +159,7 @@ where
dc: DC,
rst: RST,
delay: &mut DELAY,
) -> Result<Self, SPI::Error> {
) -> Result<Self, Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
let interface = DisplayInterface::new(cs, busy, dc, rst);
let color = DEFAULT_BACKGROUND_COLOR;
@ -174,11 +174,11 @@ where
Ok(epd)
}
fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.init(spi, delay)
}
fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
self.interface
.cmd_with_data(spi, Command::VcomAndDataIntervalSetting, &[0x17])?; //border floating
@ -202,7 +202,7 @@ where
spi: &mut SPI,
buffer: &[u8],
_delay: &mut DELAY,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
let color_value = self.color.get_byte_value();
@ -223,7 +223,7 @@ where
y: u32,
width: u32,
height: u32,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
if buffer.len() as u32 != width / 8 * height {
//TODO: panic!! or sth like that
@ -261,7 +261,7 @@ where
Ok(())
}
fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
self.command(spi, Command::DisplayRefresh)?;
Ok(())
@ -272,13 +272,13 @@ where
spi: &mut SPI,
buffer: &[u8],
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.update_frame(spi, buffer, delay)?;
self.command(spi, Command::DisplayRefresh)?;
Ok(())
}
fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
self.send_resolution(spi)?;
@ -314,7 +314,7 @@ where
&mut self,
spi: &mut SPI,
refresh_rate: Option<RefreshLut>,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
if let Some(refresh_lut) = refresh_rate {
self.refresh = refresh_lut;
}
@ -347,11 +347,11 @@ where
RST: OutputPin,
DELAY: DelayUs,
{
fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), SPI::Error> {
fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.interface.cmd(spi, command)
}
fn send_data(&mut self, spi: &mut SPI, data: &[u8]) -> Result<(), SPI::Error> {
fn send_data(&mut self, spi: &mut SPI, data: &[u8]) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.interface.data(spi, data)
}
@ -360,7 +360,7 @@ where
spi: &mut SPI,
command: Command,
data: &[u8],
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.interface.cmd_with_data(spi, command, data)
}
@ -368,7 +368,7 @@ where
let _ = self.interface.wait_until_idle(IS_BUSY_LOW);
}
fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
let w = self.width();
let h = self.height();
@ -387,7 +387,7 @@ where
lut_bw: &[u8],
lut_wb: &[u8],
lut_bb: &[u8],
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
// LUT VCOM
self.cmd_with_data(spi, Command::LutForVcom, lut_vcom)?;
@ -415,7 +415,7 @@ where
y: u32,
width: u32,
height: u32,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.send_data(spi, &[(x >> 8) as u8])?;
let tmp = x & 0xf8;
self.send_data(spi, &[tmp as u8])?; // x should be the multiple of 8, the last 3 bit will always be ignored
@ -451,7 +451,7 @@ where
spi: &mut SPI,
buffer: &[u8],
_delay: &mut DELAY,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
self.interface.cmd(spi, Command::DataStartTransmission1)?;
@ -467,7 +467,7 @@ where
spi: &mut SPI,
buffer: &[u8],
_delay: &mut DELAY,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
// self.send_resolution(spi)?;
@ -480,7 +480,7 @@ where
/// This is a wrapper around `display_frame` for using this device as a true
/// `QuickRefresh` device.
fn display_new_frame(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
fn display_new_frame(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.display_frame(spi, delay)
}
@ -493,7 +493,7 @@ where
spi: &mut SPI,
buffer: &[u8],
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.update_new_frame(spi, buffer, delay)?;
self.display_frame(spi, delay)
}
@ -506,7 +506,7 @@ where
y: u32,
width: u32,
height: u32,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
if buffer.len() as u32 != width / 8 * height {
@ -536,7 +536,7 @@ where
y: u32,
width: u32,
height: u32,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
if buffer.len() as u32 != width / 8 * height {
//TODO: panic!! or sth like that
@ -560,7 +560,7 @@ where
y: u32,
width: u32,
height: u32,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
self.send_resolution(spi)?;

37
src/epd5in65f/mod.rs

@ -6,8 +6,9 @@
//! - [Waveshare C driver](https://github.com/waveshare/e-Paper/blob/master/RaspberryPi%26JetsonNano/c/lib/e-Paper/EPD_5in65f.c)
//! - [Waveshare Python driver](https://github.com/waveshare/e-Paper/blob/master/RaspberryPi%26JetsonNano/python/lib/waveshare_epd/epd5in65f.py)
use crate::Error;
use crate::color::OctColor;
use crate::eh_prelude::*;
use crate::{eh_prelude::*};
use crate::interface::DisplayInterface;
use crate::traits::{InternalWiAdditions, RefreshLut, WaveshareDisplay};
@ -46,9 +47,9 @@ where
RST: OutputPin,
DELAY: DelayUs,
{
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
// Reset the device
self.interface.reset(delay, 2);
self.interface.reset(delay, 2)?;
self.cmd_with_data(spi, Command::PanelSetting, &[0xEF, 0x08])?;
self.cmd_with_data(spi, Command::PowerSetting, &[0x37, 0x00, 0x23, 0x23])?;
@ -62,7 +63,7 @@ where
self.cmd_with_data(spi, Command::FlashMode, &[0xAA])?;
delay.delay_ms(100);
delay.delay_ms(100).map_err(|e| Error::Delay(e))?;
self.update_vcom(spi)?;
Ok(())
@ -87,7 +88,7 @@ where
dc: DC,
rst: RST,
delay: &mut DELAY,
) -> Result<Self, SPI::Error> {
) -> Result<Self, Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
let interface = DisplayInterface::new(cs, busy, dc, rst);
let color = DEFAULT_BACKGROUND_COLOR;
@ -98,11 +99,11 @@ where
Ok(epd)
}
fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.init(spi, delay)
}
fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.cmd_with_data(spi, Command::DeepSleep, &[0xA5])?;
Ok(())
}
@ -112,7 +113,7 @@ where
spi: &mut SPI,
buffer: &[u8],
_delay: &mut DELAY,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_busy_high();
self.update_vcom(spi)?;
self.send_resolution(spi)?;
@ -128,11 +129,11 @@ where
_y: u32,
_width: u32,
_height: u32,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
unimplemented!();
}
fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_busy_high();
self.command(spi, Command::PowerOn)?;
self.wait_busy_high();
@ -148,13 +149,13 @@ where
spi: &mut SPI,
buffer: &[u8],
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.update_frame(spi, buffer, delay)?;
self.display_frame(spi, delay)?;
Ok(())
}
fn clear_frame(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
fn clear_frame(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
let bg = OctColor::colors_byte(self.color, self.color);
self.wait_busy_high();
self.update_vcom(spi)?;
@ -185,7 +186,7 @@ where
&mut self,
_spi: &mut SPI,
_refresh_rate: Option<RefreshLut>,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
unimplemented!();
}
@ -203,11 +204,11 @@ where
RST: OutputPin,
DELAY: DelayUs,
{
fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), SPI::Error> {
fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.interface.cmd(spi, command)
}
fn send_data(&mut self, spi: &mut SPI, data: &[u8]) -> Result<(), SPI::Error> {
fn send_data(&mut self, spi: &mut SPI, data: &[u8]) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.interface.data(spi, data)
}
@ -216,7 +217,7 @@ where
spi: &mut SPI,
command: Command,
data: &[u8],
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.interface.cmd_with_data(spi, command, data)
}
@ -226,7 +227,7 @@ where
fn wait_busy_low(&mut self) {
let _ = self.interface.wait_until_idle(false);
}
fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
let w = self.width();
let h = self.height();
@ -237,7 +238,7 @@ where
self.send_data(spi, &[h as u8])
}
fn update_vcom(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
fn update_vcom(&mut self, spi: &mut SPI) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
let bg_color = (self.color.get_nibble() & 0b111) << 5;
self.cmd_with_data(spi, Command::VcomAndDataIntervalSetting, &[0x17 | bg_color])?;
Ok(())

36
src/epd7in5/mod.rs

@ -5,9 +5,9 @@
//! - [Datasheet](https://www.waveshare.com/wiki/7.5inch_e-Paper_HAT)
//! - [Waveshare C driver](https://github.com/waveshare/e-Paper/blob/702def06bcb75983c98b0f9d25d43c552c248eb0/RaspberryPi%26JetsonNano/c/lib/e-Paper/EPD_7in5.c)
//! - [Waveshare Python driver](https://github.com/waveshare/e-Paper/blob/702def06bcb75983c98b0f9d25d43c552c248eb0/RaspberryPi%26JetsonNano/python/lib/waveshare_epd/epd7in5.py)
use crate::Error;
use crate::color::Color;
use crate::eh_prelude::*;
use crate::{eh_prelude::*};
use crate::interface::DisplayInterface;
use crate::traits::{InternalWiAdditions, RefreshLut, WaveshareDisplay};
@ -46,9 +46,9 @@ where
RST: OutputPin,
DELAY: DelayUs,
{
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
// Reset the device
self.interface.reset(delay, 10);
self.interface.reset(delay, 10)?;
// Set the power settings
self.cmd_with_data(spi, Command::PowerSetting, &[0x37, 0x00])?;
@ -63,7 +63,7 @@ where
// Power on
self.command(spi, Command::PowerOn)?;
delay.delay_ms(5);
delay.delay_ms(5).map_err(|e| Error::Delay(e))?;
self.wait_until_idle();
// Set the clock frequency to 50Hz (default)
@ -110,7 +110,7 @@ where
dc: DC,
rst: RST,
delay: &mut DELAY,
) -> Result<Self, SPI::Error> {
) -> Result<Self, Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
let interface = DisplayInterface::new(cs, busy, dc, rst);
let color = DEFAULT_BACKGROUND_COLOR;
@ -121,11 +121,11 @@ where
Ok(epd)
}
fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.init(spi, delay)
}
fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
self.command(spi, Command::PowerOff)?;
self.wait_until_idle();
@ -138,7 +138,7 @@ where
spi: &mut SPI,
buffer: &[u8],
_delay: &mut DELAY,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
self.command(spi, Command::DataStartTransmission1)?;
for byte in buffer {
@ -163,11 +163,11 @@ where
_y: u32,
_width: u32,
_height: u32,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
unimplemented!();
}
fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
self.command(spi, Command::DisplayRefresh)?;
Ok(())
@ -178,13 +178,13 @@ where
spi: &mut SPI,
buffer: &[u8],
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.update_frame(spi, buffer, delay)?;
self.command(spi, Command::DisplayRefresh)?;
Ok(())
}
fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
self.send_resolution(spi)?;
@ -215,7 +215,7 @@ where
&mut self,
_spi: &mut SPI,
_refresh_rate: Option<RefreshLut>,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
unimplemented!();
}
@ -233,11 +233,11 @@ where
RST: OutputPin,
DELAY: DelayUs,
{
fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), SPI::Error> {
fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.interface.cmd(spi, command)
}
fn send_data(&mut self, spi: &mut SPI, data: &[u8]) -> Result<(), SPI::Error> {
fn send_data(&mut self, spi: &mut SPI, data: &[u8]) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.interface.data(spi, data)
}
@ -246,7 +246,7 @@ where
spi: &mut SPI,
command: Command,
data: &[u8],
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.interface.cmd_with_data(spi, command, data)
}
@ -254,7 +254,7 @@ where
let _ = self.interface.wait_until_idle(IS_BUSY_LOW);
}
fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
let w = self.width();
let h = self.height();

30
src/epd7in5_hd/mod.rs

@ -8,9 +8,9 @@
//!
//! - [Datasheet](https://www.waveshare.com/w/upload/2/27/7inch_HD_e-Paper_Specification.pdf)
//! - [Waveshare Python driver](https://github.com/waveshare/e-Paper/blob/master/RaspberryPi_JetsonNano/python/lib/waveshare_epd/epd7in5_HD.py)
//!
use crate::Error;
use crate::color::Color;
use crate::eh_prelude::*;
use crate::{eh_prelude::*};
use crate::interface::DisplayInterface;
use crate::traits::{InternalWiAdditions, RefreshLut, WaveshareDisplay};
@ -49,9 +49,9 @@ where
RST: OutputPin,
DELAY: DelayUs,
{
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
// Reset the device
self.interface.reset(delay, 2);
self.interface.reset(delay, 2)?;
// HD procedure as described here:
// https://github.com/waveshare/e-Paper/blob/master/RaspberryPi_JetsonNano/python/lib/waveshare_epd/epd7in5_HD.py
@ -110,7 +110,7 @@ where
dc: DC,
rst: RST,
delay: &mut DELAY,
) -> Result<Self, SPI::Error> {
) -> Result<Self, Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
let interface = DisplayInterface::new(cs, busy, dc, rst);
let color = DEFAULT_BACKGROUND_COLOR;
@ -121,11 +121,11 @@ where
Ok(epd)
}
fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.init(spi, delay)
}
fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
self.cmd_with_data(spi, Command::DeepSleep, &[0x01])?;
Ok(())
@ -136,7 +136,7 @@ where
spi: &mut SPI,
buffer: &[u8],
_delay: &mut DELAY,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle();
self.cmd_with_data(spi, Command::SetRamYAc, &[0x00, 0x00])?;
self.cmd_with_data(spi, Command::WriteRamBw, buffer)?;
@ -152,11 +152,11 @@ where
_y: u32,
_width: u32,
_height: u32,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
unimplemented!();
}
fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.command(spi, Command::MasterActivation)?;
self.wait_until_idle();
Ok(())
@ -167,13 +167,13 @@ where
spi: &mut SPI,
buffer: &[u8],
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.update_frame(spi, buffer, delay)?;
self.display_frame(spi, delay)?;
Ok(())
}
fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
let pixel_count = WIDTH * HEIGHT / 8;
let background_color_byte = self.color.get_byte_value();
@ -212,7 +212,7 @@ where
&mut self,
_spi: &mut SPI,
_refresh_rate: Option<RefreshLut>,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
unimplemented!();
}
@ -230,7 +230,7 @@ where
RST: OutputPin,
DELAY: DelayUs,
{
fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), SPI::Error> {
fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.interface.cmd(spi, command)
}
@ -239,7 +239,7 @@ where
spi: &mut SPI,
command: Command,
data: &[u8],
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.interface.cmd_with_data(spi, command, data)
}

38
src/epd7in5_v2/mod.rs

@ -9,9 +9,9 @@
//! Important note for V2:
//! Revision V2 has been released on 2019.11, the resolution is upgraded to 800×480, from 640×384 of V1.
//! The hardware and interface of V2 are compatible with V1, however, the related software should be updated.
use crate::Error;
use crate::color::Color;
use crate::eh_prelude::*;
use crate::{eh_prelude::*};
use crate::interface::DisplayInterface;
use crate::traits::{InternalWiAdditions, RefreshLut, WaveshareDisplay};
@ -50,9 +50,9 @@ where
RST: OutputPin,
DELAY: DelayUs,
{
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
// Reset the device
self.interface.reset(delay, 2);
self.interface.reset(delay, 2)?;
// V2 procedure as described here:
// https://github.com/waveshare/e-Paper/blob/master/RaspberryPi%26JetsonNano/python/lib/waveshare_epd/epd7in5bc_V2.py
@ -92,7 +92,7 @@ where
dc: DC,
rst: RST,
delay: &mut DELAY,
) -> Result<Self, SPI::Error> {
) -> Result<Self, Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
let interface = DisplayInterface::new(cs, busy, dc, rst);
let color = DEFAULT_BACKGROUND_COLOR;
@ -103,11 +103,11 @@ where
Ok(epd)
}
fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.init(spi, delay)
}
fn sleep(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
fn sleep(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle(spi, delay)?;
self.command(spi, Command::PowerOff)?;
self.wait_until_idle(spi, delay)?;
@ -120,7 +120,7 @@ where
spi: &mut SPI,
buffer: &[u8],
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle(spi, delay)?;
self.cmd_with_data(spi, Command::DataStartTransmission2, buffer)?;
Ok(())
@ -134,11 +134,11 @@ where
_y: u32,
_width: u32,
_height: u32,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
unimplemented!();
}
fn display_frame(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
fn display_frame(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle(spi, delay)?;
self.command(spi, Command::DisplayRefresh)?;
Ok(())
@ -149,13 +149,13 @@ where
spi: &mut SPI,
buffer: &[u8],
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.update_frame(spi, buffer, delay)?;
self.command(spi, Command::DisplayRefresh)?;
Ok(())
}
fn clear_frame(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
fn clear_frame(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.wait_until_idle(spi, delay)?;
self.send_resolution(spi)?;
@ -189,7 +189,7 @@ where
&mut self,
_spi: &mut SPI,
_refresh_rate: Option<RefreshLut>,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
unimplemented!();
}
@ -207,11 +207,11 @@ where
RST: OutputPin,
DELAY: DelayUs,
{
fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), SPI::Error> {
fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.interface.cmd(spi, command)
}
fn send_data(&mut self, spi: &mut SPI, data: &[u8]) -> Result<(), SPI::Error> {
fn send_data(&mut self, spi: &mut SPI, data: &[u8]) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.interface.data(spi, data)
}
@ -220,19 +220,19 @@ where
spi: &mut SPI,
command: Command,
data: &[u8],
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.interface.cmd_with_data(spi, command, data)
}
fn wait_until_idle(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
fn wait_until_idle(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
while self.interface.is_busy(IS_BUSY_LOW) {
self.interface.cmd(spi, Command::GetStatus)?;
delay.delay_ms(20);
delay.delay_ms(20).map_err(|e| Error::Delay(e))?;
}
Ok(())
}
fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
let w = self.width();
let h = self.height();

29
src/interface.rs

@ -1,4 +1,4 @@
use crate::eh_prelude::*;
use crate::{eh_prelude::*, Error};
use crate::traits::Command;
use core::marker::PhantomData;
@ -42,7 +42,7 @@ where
/// Basic function for sending [Commands](Command).
///
/// Enables direct interaction with the device with the help of [data()](DisplayInterface::data())
pub(crate) fn cmd<T: Command>(&mut self, spi: &mut SPI, command: T) -> Result<(), SPI::Error> {
pub(crate) fn cmd<T: Command>(&mut self, spi: &mut SPI, command: T) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
// low for commands
let _ = self.dc.set_low();
@ -53,7 +53,7 @@ where
/// Basic function for sending an array of u8-values of data over spi
///
/// Enables direct interaction with the device with the help of [command()](Epd4in2::command())
pub(crate) fn data(&mut self, spi: &mut SPI, data: &[u8]) -> Result<(), SPI::Error> {
pub(crate) fn data(&mut self, spi: &mut SPI, data: &[u8]) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
// high for data
let _ = self.dc.set_high();
@ -73,7 +73,7 @@ where
spi: &mut SPI,
command: T,
data: &[u8],
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
self.cmd(spi, command)?;
self.data(spi, data)
}
@ -86,7 +86,7 @@ where
spi: &mut SPI,
val: u8,
repetitions: u32,
) -> Result<(), SPI::Error> {
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
// high for data
let _ = self.dc.set_high();
// Transfer data (u8) over spi
@ -97,7 +97,7 @@ where
}
// spi write helper/abstraction function
fn write(&mut self, spi: &mut SPI, data: &[u8]) -> Result<(), SPI::Error> {
fn write(&mut self, spi: &mut SPI, data: &[u8]) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
// activate spi with cs low
let _ = self.cs.set_low();
@ -113,7 +113,7 @@ where
}
// deactivate spi with cs high
let _ = self.cs.set_high();
self.cs.set_high().map_err(|e| Error::CS(e))?;
Ok(())
}
@ -166,15 +166,16 @@ where
/// The timing of keeping the reset pin low seems to be important and different per device.
/// Most displays seem to require keeping it low for 10ms, but the 7in5_v2 only seems to reset
/// properly with 2ms
pub(crate) fn reset(&mut self, delay: &mut DELAY, duration: u32) {
let _ = self.rst.set_high();
delay.delay_ms(10);
pub(crate) fn reset(&mut self, delay: &mut DELAY, duration: u32) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>> {
self.rst.set_high().map_err(|e| Error::RST(e))?;
delay.delay_ms(10).map_err(|e| Error::Delay(e))?;
let _ = self.rst.set_low();
delay.delay_ms(duration);
let _ = self.rst.set_high();
self.rst.set_low().map_err(|e| Error::RST(e))?;
delay.delay_ms(duration).map_err(|e| Error::Delay(e))?;
self.rst.set_high().map_err(|e| Error::RST(e))?;
//TODO: the upstream libraries always sleep for 200ms here
// 10ms works fine with just for the 7in5_v2 but this needs to be validated for other devices
delay.delay_ms(200);
delay.delay_ms(200).map_err(|e| Error::Delay(e))?;
Ok(())
}
}

27
src/lib.rs

@ -124,7 +124,7 @@ pub const fn buffer_len(width: usize, height: usize) -> usize {
(width + 7) / 8 * height
}
use embedded_hal::spi::{Mode, Phase, Polarity};
use embedded_hal::{spi::{Mode, Phase, Polarity}};
/// SPI mode -
/// For more infos see [Requirements: SPI](index.html#spi)
@ -132,3 +132,28 @@ pub const SPI_MODE: Mode = Mode {
phase: Phase::CaptureOnFirstTransition,
polarity: Polarity::IdleLow,
};
#[derive(Debug)]
/// Error
pub enum Error<SPIError, CSError, BUSYError, DCError, RSTError, DELAYError> {
/// SPI Errors
Spi(SPIError),
/// Delay Errors
Delay(DELAYError),
/// CS Pin Error
CS(CSError),
/// Busy Pin Reading Error
BUSY(BUSYError),
/// Data Command Select Pin Error
DC(DCError),
/// Reset Pin Error
RST(RSTError),
}
impl <SPIError, CSError, BUSYError, DCError, RSTError, DELAYError> From<SPIError> for Error<SPIError, CSError, BUSYError, DCError, RSTError, DELAYError> {
fn from(spi: SPIError) -> Self {
Self::Spi(spi)
}
}

42
src/traits.rs

@ -1,4 +1,4 @@
use crate::eh_prelude::*;
use crate::{eh_prelude::*, Error};
use core::marker::Sized;
/// All commands need to have this trait which gives the address of the command
@ -42,7 +42,7 @@ where
/// This function calls [reset](WaveshareDisplay::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, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error>;
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>;
}
/// Functions to interact with three color panels
@ -64,19 +64,19 @@ where
spi: &mut SPI,
black: &[u8],
chromatic: &[u8],
) -> Result<(), SPI::Error>;
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>;
/// Update only the black/white data of the display.
///
/// This must be finished by calling `update_chromatic_frame`.
fn update_achromatic_frame(&mut self, spi: &mut SPI, black: &[u8]) -> Result<(), SPI::Error>;
fn update_achromatic_frame(&mut self, spi: &mut SPI, black: &[u8]) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>;
/// Update only the chromatic data of the display.
///
/// This should be preceded by a call to `update_achromatic_frame`.
/// This data takes precedence over the black/white data.
fn update_chromatic_frame(&mut self, spi: &mut SPI, chromatic: &[u8])
-> Result<(), SPI::Error>;
-> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>;
}
/// All the functions to interact with the EPDs
@ -144,19 +144,19 @@ where
dc: DC,
rst: RST,
delay: &mut DELAY,
) -> Result<Self, SPI::Error>
) -> Result<Self, Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>
where
Self: Sized;
/// Let the device enter deep-sleep mode to save power.
///
/// The deep sleep mode returns to standby with a hardware reset.
fn sleep(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error>;
fn sleep(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>;
/// Wakes the device up from sleep
///
/// Also reintialises the device if necessary.
fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error>;
fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>;
/// Sets the backgroundcolor for various commands like [clear_frame](WaveshareDisplay::clear_frame)
fn set_background_color(&mut self, color: Self::DisplayColor);
@ -176,7 +176,7 @@ where
spi: &mut SPI,
buffer: &[u8],
delay: &mut DELAY,
) -> Result<(), SPI::Error>;
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>;
/// Transmits partial data to the SRAM of the EPD
///
@ -191,12 +191,12 @@ where
y: u32,
width: u32,
height: u32,
) -> Result<(), SPI::Error>;
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>;
/// Displays the frame data from SRAM
///
/// This function waits until the device isn`t busy anymore
fn display_frame(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error>;
fn display_frame(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>;
/// Provide a combined update&display and save some time (skipping a busy check in between)
fn update_and_display_frame(
@ -204,12 +204,12 @@ where
spi: &mut SPI,
buffer: &[u8],
delay: &mut DELAY,
) -> Result<(), SPI::Error>;
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>;
/// Clears the frame buffer on the EPD with the declared background color
///
/// The background color can be changed with [`WaveshareDisplay::set_background_color`]
fn clear_frame(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error>;
fn clear_frame(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>;
/// Trait for using various Waveforms from different LUTs
/// E.g. for partial refreshes
@ -223,7 +223,7 @@ where
&mut self,
spi: &mut SPI,
refresh_rate: Option<RefreshLut>,
) -> Result<(), SPI::Error>;
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>;
/// Checks if the display is busy transmitting data
///
@ -293,7 +293,7 @@ where
spi: &mut SPI,
buffer: &[u8],
delay: &mut DELAY,
) -> Result<(), SPI::Error>;
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>;
/// Updates the new frame.
fn update_new_frame(
@ -301,10 +301,10 @@ where
spi: &mut SPI,
buffer: &[u8],
delay: &mut DELAY,
) -> Result<(), SPI::Error>;
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>;
/// Displays the new frame
fn display_new_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error>;
fn display_new_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>;
/// Updates and displays the new frame.
fn update_and_display_new_frame(
@ -312,7 +312,7 @@ where
spi: &mut SPI,
buffer: &[u8],
delay: &mut DELAY,
) -> Result<(), SPI::Error>;
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>;
/// Updates the old frame for a portion of the display.
fn update_partial_old_frame(
@ -323,7 +323,7 @@ where
y: u32,
width: u32,
height: u32,
) -> Result<(), SPI::Error>;
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>;
/// Updates the new frame for a portion of the display.
fn update_partial_new_frame(
@ -334,7 +334,7 @@ where
y: u32,
width: u32,
height: u32,
) -> Result<(), SPI::Error>;
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>;
/// Clears the partial frame buffer on the EPD with the declared background color
/// The background color can be changed with [`WaveshareDisplay::set_background_color`]
@ -345,5 +345,5 @@ where
y: u32,
width: u32,
height: u32,
) -> Result<(), SPI::Error>;
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>;
}

Loading…
Cancel
Save