cargo fmt
parent
53bfeab6cc
commit
c93d69ebbc
|
|
@ -1,21 +1,30 @@
|
|||
#![deny(warnings)]
|
||||
|
||||
use core::convert::Infallible;
|
||||
use embedded_hal::delay::blocking::DelayUs;
|
||||
use epd_waveshare::{epd1in54::Epd1in54, prelude::*};
|
||||
use linux_embedded_hal::SPIError;
|
||||
use linux_embedded_hal::{
|
||||
spidev::{self, SpidevOptions},
|
||||
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<(), 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>> {
|
||||
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")?;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#![deny(warnings)]
|
||||
|
||||
use core::convert::Infallible;
|
||||
use embedded_graphics::{
|
||||
mono_font::MonoTextStyleBuilder,
|
||||
prelude::*,
|
||||
|
|
@ -13,20 +14,28 @@ use epd_waveshare::{
|
|||
graphics::DisplayRotation,
|
||||
prelude::*,
|
||||
};
|
||||
use linux_embedded_hal::SPIError;
|
||||
use linux_embedded_hal::{
|
||||
spidev::{self, SpidevOptions},
|
||||
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<(), 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>> {
|
||||
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");
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#![deny(warnings)]
|
||||
|
||||
use core::convert::Infallible;
|
||||
use embedded_graphics::{
|
||||
mono_font::MonoTextStyleBuilder,
|
||||
prelude::*,
|
||||
|
|
@ -13,14 +14,12 @@ use epd_waveshare::{
|
|||
graphics::{DisplayRotation, TriDisplay},
|
||||
prelude::*,
|
||||
};
|
||||
use linux_embedded_hal::SPIError;
|
||||
use linux_embedded_hal::{
|
||||
spidev::{self, SpidevOptions},
|
||||
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
|
||||
|
|
@ -37,7 +36,17 @@ use linux_embedded_hal::SPIError;
|
|||
//
|
||||
// after finishing, put the display to sleep
|
||||
|
||||
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>> {
|
||||
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() {}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#![deny(warnings)]
|
||||
|
||||
use core::convert::Infallible;
|
||||
use embedded_graphics::{
|
||||
mono_font::MonoTextStyleBuilder,
|
||||
prelude::*,
|
||||
|
|
@ -13,19 +14,28 @@ use epd_waveshare::{
|
|||
graphics::DisplayRotation,
|
||||
prelude::*,
|
||||
};
|
||||
use linux_embedded_hal::SPIError;
|
||||
use linux_embedded_hal::{
|
||||
spidev::{self, SpidevOptions},
|
||||
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<(), 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>> {
|
||||
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");
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#![deny(warnings)]
|
||||
#![deny(warnings)]
|
||||
|
||||
use core::convert::Infallible;
|
||||
use embedded_graphics::{
|
||||
mono_font::MonoTextStyleBuilder,
|
||||
prelude::*,
|
||||
|
|
@ -14,21 +15,28 @@ use epd_waveshare::{
|
|||
graphics::{Display, DisplayRotation, VarDisplay},
|
||||
prelude::*,
|
||||
};
|
||||
use linux_embedded_hal::SPIError;
|
||||
use linux_embedded_hal::{
|
||||
spidev::{self, SpidevOptions},
|
||||
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<(), 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>> {
|
||||
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");
|
||||
|
|
|
|||
|
|
@ -53,13 +53,13 @@ pub const DEFAULT_BACKGROUND_COLOR: Color = Color::White;
|
|||
//const DPI: u16 = 184;
|
||||
const IS_BUSY_LOW: bool = false;
|
||||
|
||||
use crate::color::Color;
|
||||
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::{RefreshLut, WaveshareDisplay};
|
||||
|
||||
|
|
@ -80,8 +80,6 @@ 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>,
|
||||
|
|
@ -91,7 +89,12 @@ where
|
|||
RST: OutputPin,
|
||||
DELAY: DelayUs,
|
||||
{
|
||||
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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>>
|
||||
{
|
||||
self.interface.reset(delay, 10)?;
|
||||
|
||||
// 3 Databytes:
|
||||
|
|
@ -163,7 +166,8 @@ where
|
|||
dc: DC,
|
||||
rst: RST,
|
||||
delay: &mut DELAY,
|
||||
) -> Result<Self, Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 {
|
||||
|
|
@ -177,11 +181,21 @@ where
|
|||
Ok(epd)
|
||||
}
|
||||
|
||||
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>>{
|
||||
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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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?
|
||||
|
|
@ -195,7 +209,8 @@ where
|
|||
spi: &mut SPI,
|
||||
buffer: &[u8],
|
||||
_delay: &mut DELAY,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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
|
||||
|
|
@ -212,7 +227,8 @@ where
|
|||
y: u32,
|
||||
width: u32,
|
||||
height: u32,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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)?;
|
||||
|
|
@ -222,7 +238,12 @@ where
|
|||
Ok(())
|
||||
}
|
||||
|
||||
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>>{
|
||||
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)
|
||||
|
|
@ -241,13 +262,19 @@ where
|
|||
spi: &mut SPI,
|
||||
buffer: &[u8],
|
||||
delay: &mut DELAY,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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)?;
|
||||
|
||||
|
|
@ -272,7 +299,8 @@ where
|
|||
&mut self,
|
||||
spi: &mut SPI,
|
||||
refresh_rate: Option<RefreshLut>,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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;
|
||||
}
|
||||
|
|
@ -300,7 +328,11 @@ where
|
|||
let _ = self.interface.wait_until_idle(IS_BUSY_LOW);
|
||||
}
|
||||
|
||||
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>>{
|
||||
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)?;
|
||||
|
||||
|
|
@ -315,7 +347,8 @@ where
|
|||
start_y: u32,
|
||||
end_x: u32,
|
||||
end_y: u32,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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);
|
||||
|
|
@ -347,7 +380,8 @@ where
|
|||
spi: &mut SPI,
|
||||
x: u32,
|
||||
y: u32,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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
|
||||
|
|
@ -363,7 +397,12 @@ where
|
|||
Ok(())
|
||||
}
|
||||
|
||||
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>>{
|
||||
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);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
//! A simple Driver for the Waveshare 1.54" (B) E-Ink Display via SPI
|
||||
|
||||
use crate::{eh_prelude::*, Error};
|
||||
use crate::interface::DisplayInterface;
|
||||
use crate::traits::{
|
||||
InternalWiAdditions, RefreshLut, WaveshareDisplay, WaveshareThreeColorDisplay,
|
||||
};
|
||||
use crate::{eh_prelude::*, Error};
|
||||
|
||||
//The Lookup Tables for the Display
|
||||
mod constants;
|
||||
|
|
@ -44,7 +44,12 @@ where
|
|||
RST: OutputPin,
|
||||
DELAY: DelayUs,
|
||||
{
|
||||
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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>>
|
||||
{
|
||||
self.interface.reset(delay, 10)?;
|
||||
|
||||
// set the power settings
|
||||
|
|
@ -96,12 +101,18 @@ where
|
|||
spi: &mut SPI,
|
||||
black: &[u8],
|
||||
chromatic: &[u8],
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +129,8 @@ where
|
|||
&mut self,
|
||||
spi: &mut SPI,
|
||||
chromatic: &[u8],
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +155,8 @@ where
|
|||
dc: DC,
|
||||
rst: RST,
|
||||
delay: &mut DELAY,
|
||||
) -> Result<Self, Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +167,12 @@ where
|
|||
Ok(epd)
|
||||
}
|
||||
|
||||
fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +192,12 @@ where
|
|||
Ok(())
|
||||
}
|
||||
|
||||
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>>{
|
||||
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 +222,8 @@ where
|
|||
spi: &mut SPI,
|
||||
buffer: &[u8],
|
||||
_delay: &mut DELAY,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +257,17 @@ where
|
|||
y: u32,
|
||||
width: u32,
|
||||
height: u32,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +278,19 @@ where
|
|||
spi: &mut SPI,
|
||||
buffer: &[u8],
|
||||
delay: &mut DELAY,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +314,8 @@ where
|
|||
&mut self,
|
||||
spi: &mut SPI,
|
||||
_refresh_rate: Option<RefreshLut>,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +348,21 @@ where
|
|||
RST: OutputPin,
|
||||
DELAY: DelayUs,
|
||||
{
|
||||
fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +371,8 @@ where
|
|||
spi: &mut SPI,
|
||||
command: Command,
|
||||
data: &[u8],
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +380,11 @@ where
|
|||
let _ = self.interface.wait_until_idle(IS_BUSY_LOW);
|
||||
}
|
||||
|
||||
fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
//! A simple Driver for the Waveshare 1.54" (C) E-Ink Display via SPI
|
||||
|
||||
use crate::{eh_prelude::*, Error};
|
||||
use crate::interface::DisplayInterface;
|
||||
use crate::traits::{
|
||||
InternalWiAdditions, RefreshLut, WaveshareDisplay, WaveshareThreeColorDisplay,
|
||||
};
|
||||
use crate::{eh_prelude::*, Error};
|
||||
|
||||
/// Width of epd1in54 in pixels
|
||||
pub const WIDTH: u32 = 152;
|
||||
|
|
@ -42,7 +42,12 @@ where
|
|||
RST: OutputPin,
|
||||
DELAY: DelayUs,
|
||||
{
|
||||
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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:
|
||||
|
|
@ -84,12 +89,18 @@ where
|
|||
spi: &mut SPI,
|
||||
black: &[u8],
|
||||
chromatic: &[u8],
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +111,8 @@ where
|
|||
&mut self,
|
||||
spi: &mut SPI,
|
||||
chromatic: &[u8],
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +138,8 @@ where
|
|||
dc: DC,
|
||||
rst: RST,
|
||||
delay: &mut DELAY,
|
||||
) -> Result<Self, Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +150,12 @@ where
|
|||
Ok(epd)
|
||||
}
|
||||
|
||||
fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +165,12 @@ where
|
|||
Ok(())
|
||||
}
|
||||
|
||||
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>>{
|
||||
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 +195,8 @@ where
|
|||
spi: &mut SPI,
|
||||
buffer: &[u8],
|
||||
_delay: &mut DELAY,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +217,17 @@ where
|
|||
y: u32,
|
||||
width: u32,
|
||||
height: u32,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +239,20 @@ where
|
|||
spi: &mut SPI,
|
||||
buffer: &[u8],
|
||||
delay: &mut DELAY,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +271,8 @@ where
|
|||
&mut self,
|
||||
_spi: &mut SPI,
|
||||
_refresh_rate: Option<RefreshLut>,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>
|
||||
{
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -253,11 +290,21 @@ where
|
|||
RST: OutputPin,
|
||||
DELAY: DelayUs,
|
||||
{
|
||||
fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +313,8 @@ where
|
|||
spi: &mut SPI,
|
||||
command: Command,
|
||||
data: &[u8],
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +322,11 @@ where
|
|||
let _ = self.interface.wait_until_idle(IS_BUSY_LOW);
|
||||
}
|
||||
|
||||
fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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();
|
||||
|
||||
|
|
|
|||
|
|
@ -8,11 +8,12 @@
|
|||
//! - [Controller Datasheet SS1780](http://www.e-paper-display.com/download_detail/downloadsId=682.html)
|
||||
//!
|
||||
|
||||
use crate::{buffer_len};use crate::Error;
|
||||
use crate::buffer_len;
|
||||
use crate::color::Color;
|
||||
use crate::eh_prelude::*;
|
||||
use crate::interface::DisplayInterface;
|
||||
use crate::traits::{InternalWiAdditions, RefreshLut, WaveshareDisplay};
|
||||
use crate::Error;
|
||||
|
||||
pub(crate) mod command;
|
||||
use self::command::{
|
||||
|
|
@ -62,7 +63,12 @@ where
|
|||
RST: OutputPin,
|
||||
DELAY: DelayUs,
|
||||
{
|
||||
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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)?;
|
||||
|
||||
|
|
@ -164,7 +170,8 @@ where
|
|||
dc: DC,
|
||||
rst: RST,
|
||||
delay: &mut DELAY,
|
||||
) -> Result<Self, Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +183,21 @@ where
|
|||
Ok(epd)
|
||||
}
|
||||
|
||||
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>>{
|
||||
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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +220,8 @@ where
|
|||
spi: &mut SPI,
|
||||
buffer: &[u8],
|
||||
_delay: &mut DELAY,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +249,8 @@ where
|
|||
y: u32,
|
||||
width: u32,
|
||||
height: u32,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +279,12 @@ 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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +309,8 @@ where
|
|||
spi: &mut SPI,
|
||||
buffer: &[u8],
|
||||
delay: &mut DELAY,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +320,12 @@ where
|
|||
Ok(())
|
||||
}
|
||||
|
||||
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>>{
|
||||
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 +373,8 @@ where
|
|||
&mut self,
|
||||
spi: &mut SPI,
|
||||
refresh_rate: Option<RefreshLut>,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +403,8 @@ where
|
|||
&mut self,
|
||||
spi: &mut SPI,
|
||||
buffer: &[u8],
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +425,8 @@ where
|
|||
spi: &mut SPI,
|
||||
delay: &mut DELAY,
|
||||
refresh: RefreshLut,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +438,8 @@ where
|
|||
&mut self,
|
||||
spi: &mut SPI,
|
||||
start: u16,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +452,8 @@ where
|
|||
&mut self,
|
||||
spi: &mut SPI,
|
||||
borderwaveform: BorderWaveForm,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>
|
||||
{
|
||||
self.cmd_with_data(
|
||||
spi,
|
||||
Command::BorderWaveformControl,
|
||||
|
|
@ -426,7 +461,12 @@ where
|
|||
)
|
||||
}
|
||||
|
||||
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>>{
|
||||
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 +474,8 @@ where
|
|||
&mut self,
|
||||
spi: &mut SPI,
|
||||
voltage: GateDrivingVoltage,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +483,18 @@ where
|
|||
&mut self,
|
||||
spi: &mut SPI,
|
||||
number_of_lines: u8,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +505,8 @@ where
|
|||
vsh1: SourceDrivingVoltage,
|
||||
vsh2: SourceDrivingVoltage,
|
||||
vsl: SourceDrivingVoltage,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>
|
||||
{
|
||||
self.cmd_with_data(
|
||||
spi,
|
||||
Command::SourceDrivingVoltageCtrl,
|
||||
|
|
@ -472,16 +520,27 @@ where
|
|||
&mut self,
|
||||
spi: &mut SPI,
|
||||
value: DisplayUpdateControl2,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +551,8 @@ where
|
|||
spi: &mut SPI,
|
||||
counter_incr_mode: DataEntryModeIncr,
|
||||
counter_direction: DataEntryModeDir,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +565,8 @@ where
|
|||
start_y: u32,
|
||||
end_x: u32,
|
||||
end_y: u32,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>
|
||||
{
|
||||
self.cmd_with_data(
|
||||
spi,
|
||||
Command::SetRamXAddressStartEndPosition,
|
||||
|
|
@ -530,7 +591,8 @@ where
|
|||
spi: &mut SPI,
|
||||
x: u32,
|
||||
y: u32,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +604,12 @@ where
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +618,8 @@ where
|
|||
spi: &mut SPI,
|
||||
command: Command,
|
||||
data: &[u8],
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>
|
||||
{
|
||||
self.interface.cmd_with_data(spi, command, data)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -50,11 +50,11 @@
|
|||
//!# }
|
||||
//!```
|
||||
|
||||
use crate::{eh_prelude::*, Error};
|
||||
use crate::interface::DisplayInterface;
|
||||
use crate::traits::{
|
||||
InternalWiAdditions, RefreshLut, WaveshareDisplay, WaveshareThreeColorDisplay,
|
||||
};
|
||||
use crate::{eh_prelude::*, Error};
|
||||
|
||||
/// Width of epd2in13bc in pixels
|
||||
pub const WIDTH: u32 = 104;
|
||||
|
|
@ -99,7 +99,12 @@ where
|
|||
RST: OutputPin,
|
||||
DELAY: DelayUs,
|
||||
{
|
||||
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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)?;
|
||||
|
|
@ -148,7 +153,8 @@ where
|
|||
spi: &mut SPI,
|
||||
black: &[u8],
|
||||
chromatic: &[u8],
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +162,12 @@ 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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +180,8 @@ where
|
|||
&mut self,
|
||||
spi: &mut SPI,
|
||||
chromatic: &[u8],
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +208,8 @@ where
|
|||
dc: DC,
|
||||
rst: RST,
|
||||
delay: &mut DELAY,
|
||||
) -> Result<Self, Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +220,12 @@ where
|
|||
Ok(epd)
|
||||
}
|
||||
|
||||
fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +242,12 @@ where
|
|||
Ok(())
|
||||
}
|
||||
|
||||
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>>{
|
||||
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 +272,8 @@ where
|
|||
spi: &mut SPI,
|
||||
buffer: &[u8],
|
||||
_delay: &mut DELAY,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +297,17 @@ where
|
|||
y: u32,
|
||||
width: u32,
|
||||
height: u32,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +319,19 @@ where
|
|||
spi: &mut SPI,
|
||||
buffer: &[u8],
|
||||
delay: &mut DELAY,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +353,8 @@ where
|
|||
&mut self,
|
||||
_spi: &mut SPI,
|
||||
_refresh_rate: Option<RefreshLut>,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>
|
||||
{
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -335,11 +372,21 @@ where
|
|||
RST: OutputPin,
|
||||
DELAY: DelayUs,
|
||||
{
|
||||
fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +395,8 @@ where
|
|||
spi: &mut SPI,
|
||||
command: Command,
|
||||
data: &[u8],
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +404,11 @@ where
|
|||
let _ = self.interface.wait_until_idle(IS_BUSY_LOW);
|
||||
}
|
||||
|
||||
fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +420,12 @@ 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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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,
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@
|
|||
//!
|
||||
//! [Documentation](https://www.waveshare.com/wiki/2.7inch_e-Paper_HAT_(B))
|
||||
|
||||
use crate::{eh_prelude::*, Error};
|
||||
use crate::interface::DisplayInterface;
|
||||
use crate::traits::{
|
||||
InternalWiAdditions, RefreshLut, WaveshareDisplay, WaveshareThreeColorDisplay,
|
||||
};
|
||||
use crate::{eh_prelude::*, Error};
|
||||
|
||||
// The Lookup Tables for the Display
|
||||
mod constants;
|
||||
|
|
@ -48,7 +48,12 @@ where
|
|||
RST: OutputPin,
|
||||
DELAY: DelayUs,
|
||||
{
|
||||
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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)?;
|
||||
|
||||
|
|
@ -122,7 +127,8 @@ where
|
|||
dc: DC,
|
||||
rst: RST,
|
||||
delay: &mut DELAY,
|
||||
) -> Result<Self, Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +139,21 @@ where
|
|||
Ok(epd)
|
||||
}
|
||||
|
||||
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>>{
|
||||
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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +170,8 @@ where
|
|||
spi: &mut SPI,
|
||||
buffer: &[u8],
|
||||
_delay: &mut DELAY,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +192,8 @@ where
|
|||
y: u32,
|
||||
width: u32,
|
||||
height: u32,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>
|
||||
{
|
||||
self.interface
|
||||
.cmd(spi, Command::PartialDataStartTransmission1)?;
|
||||
|
||||
|
|
@ -194,7 +212,12 @@ where
|
|||
self.interface.cmd(spi, Command::DataStop)
|
||||
}
|
||||
|
||||
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>>{
|
||||
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 +228,19 @@ where
|
|||
spi: &mut SPI,
|
||||
buffer: &[u8],
|
||||
delay: &mut DELAY,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +277,8 @@ where
|
|||
&mut self,
|
||||
spi: &mut SPI,
|
||||
_refresh_rate: Option<RefreshLut>,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +308,8 @@ where
|
|||
spi: &mut SPI,
|
||||
black: &[u8],
|
||||
chromatic: &[u8],
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +321,8 @@ where
|
|||
&mut self,
|
||||
spi: &mut SPI,
|
||||
achromatic: &[u8],
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +337,8 @@ where
|
|||
&mut self,
|
||||
spi: &mut SPI,
|
||||
chromatic: &[u8],
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +359,30 @@ where
|
|||
RST: OutputPin,
|
||||
DELAY: DelayUs,
|
||||
{
|
||||
fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +396,8 @@ where
|
|||
spi: &mut SPI,
|
||||
command: Command,
|
||||
data: &[u8],
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +413,8 @@ where
|
|||
y: u32,
|
||||
width: u32,
|
||||
height: u32,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +437,8 @@ where
|
|||
y: u32,
|
||||
width: u32,
|
||||
height: u32,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +468,8 @@ where
|
|||
y: u32,
|
||||
width: u32,
|
||||
height: u32,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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])?;
|
||||
|
|
|
|||
|
|
@ -49,13 +49,13 @@ 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::color::Color;
|
||||
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,7 +86,12 @@ where
|
|||
RST: OutputPin,
|
||||
DELAY: DelayUs,
|
||||
{
|
||||
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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>>
|
||||
{
|
||||
self.interface.reset(delay, 10)?;
|
||||
|
||||
self.wait_until_idle();
|
||||
|
|
@ -154,7 +159,8 @@ where
|
|||
dc: DC,
|
||||
rst: RST,
|
||||
delay: &mut DELAY,
|
||||
) -> Result<Self, Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +174,12 @@ where
|
|||
Ok(epd)
|
||||
}
|
||||
|
||||
fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +188,12 @@ where
|
|||
Ok(())
|
||||
}
|
||||
|
||||
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>>{
|
||||
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 +204,8 @@ where
|
|||
spi: &mut SPI,
|
||||
buffer: &[u8],
|
||||
_delay: &mut DELAY,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +223,8 @@ where
|
|||
y: u32,
|
||||
width: u32,
|
||||
height: u32,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +234,12 @@ where
|
|||
Ok(())
|
||||
}
|
||||
|
||||
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>>{
|
||||
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 +258,19 @@ where
|
|||
spi: &mut SPI,
|
||||
buffer: &[u8],
|
||||
delay: &mut DELAY,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +295,8 @@ where
|
|||
&mut self,
|
||||
spi: &mut SPI,
|
||||
refresh_rate: Option<RefreshLut>,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +324,11 @@ where
|
|||
let _ = self.interface.wait_until_idle(IS_BUSY_LOW);
|
||||
}
|
||||
|
||||
fn use_full_frame(&mut self, spi: &mut SPI) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +343,8 @@ where
|
|||
start_y: u32,
|
||||
end_x: u32,
|
||||
end_y: u32,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +369,13 @@ where
|
|||
)
|
||||
}
|
||||
|
||||
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>>{
|
||||
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 +392,12 @@ 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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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
|
||||
|
|
|
|||
|
|
@ -74,10 +74,10 @@ const LUT_PARTIAL_2IN9: [u8; 153] = [
|
|||
0x22, 0x0, 0x0, 0x0,
|
||||
];
|
||||
|
||||
use crate::{eh_prelude::*};
|
||||
use crate::color::Color;
|
||||
use crate::eh_prelude::*;
|
||||
use crate::type_a::command::Command;
|
||||
use crate::Error;
|
||||
use crate::color::Color;
|
||||
|
||||
use crate::traits::*;
|
||||
|
||||
|
|
@ -109,7 +109,12 @@ where
|
|||
RST: OutputPin,
|
||||
DELAY: DelayUs,
|
||||
{
|
||||
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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>>
|
||||
{
|
||||
self.interface.reset(delay, 2)?;
|
||||
|
||||
self.wait_until_idle();
|
||||
|
|
@ -167,7 +172,8 @@ where
|
|||
dc: DC,
|
||||
rst: RST,
|
||||
delay: &mut DELAY,
|
||||
) -> Result<Self, Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +187,12 @@ where
|
|||
Ok(epd)
|
||||
}
|
||||
|
||||
fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +200,12 @@ where
|
|||
Ok(())
|
||||
}
|
||||
|
||||
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>>{
|
||||
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 +215,8 @@ where
|
|||
spi: &mut SPI,
|
||||
buffer: &[u8],
|
||||
_delay: &mut DELAY,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +229,8 @@ where
|
|||
y: u32,
|
||||
width: u32,
|
||||
height: u32,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +241,12 @@ where
|
|||
Ok(())
|
||||
}
|
||||
|
||||
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>>{
|
||||
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 +261,19 @@ where
|
|||
spi: &mut SPI,
|
||||
buffer: &[u8],
|
||||
delay: &mut DELAY,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +295,8 @@ where
|
|||
&mut self,
|
||||
_spi: &mut SPI,
|
||||
refresh_rate: Option<RefreshLut>,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +321,11 @@ where
|
|||
self.interface.wait_until_idle(IS_BUSY_LOW);
|
||||
}
|
||||
|
||||
fn use_full_frame(&mut self, spi: &mut SPI) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +340,8 @@ where
|
|||
start_y: u32,
|
||||
end_x: u32,
|
||||
end_y: u32,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +366,13 @@ where
|
|||
)
|
||||
}
|
||||
|
||||
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>>{
|
||||
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 +389,12 @@ 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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +419,8 @@ where
|
|||
spi: &mut SPI,
|
||||
buffer: &[u8],
|
||||
_delay: &mut DELAY,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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,7 +434,8 @@ where
|
|||
spi: &mut SPI,
|
||||
buffer: &[u8],
|
||||
delay: &mut DELAY,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>
|
||||
{
|
||||
self.wait_until_idle();
|
||||
self.interface.reset(delay, 2)?;
|
||||
|
||||
|
|
@ -413,7 +461,12 @@ 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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +481,8 @@ where
|
|||
spi: &mut SPI,
|
||||
buffer: &[u8],
|
||||
delay: &mut DELAY,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +498,8 @@ where
|
|||
y: u32,
|
||||
width: u32,
|
||||
height: u32,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>
|
||||
{
|
||||
//TODO supported by display?
|
||||
unimplemented!()
|
||||
}
|
||||
|
|
@ -459,7 +514,8 @@ where
|
|||
y: u32,
|
||||
width: u32,
|
||||
height: u32,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>
|
||||
{
|
||||
//TODO supported by display?
|
||||
unimplemented!()
|
||||
}
|
||||
|
|
@ -473,7 +529,8 @@ where
|
|||
y: u32,
|
||||
width: u32,
|
||||
height: u32,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>
|
||||
{
|
||||
//TODO supported by display?
|
||||
unimplemented!()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,11 +54,11 @@
|
|||
//!# }
|
||||
//!```
|
||||
//!
|
||||
use crate::{eh_prelude::*, Error};
|
||||
use crate::interface::DisplayInterface;
|
||||
use crate::traits::{
|
||||
InternalWiAdditions, RefreshLut, WaveshareDisplay, WaveshareThreeColorDisplay,
|
||||
};
|
||||
use crate::{eh_prelude::*, Error};
|
||||
|
||||
/// Width of epd2in9bc in pixels
|
||||
pub const WIDTH: u32 = 128;
|
||||
|
|
@ -76,7 +76,6 @@ const BLACK_BORDER: u8 = 0x30;
|
|||
const CHROMATIC_BORDER: u8 = 0xb0;
|
||||
const FLOATING_BORDER: u8 = 0xF0;
|
||||
|
||||
|
||||
use crate::color::{Color, TriColor};
|
||||
|
||||
pub(crate) mod command;
|
||||
|
|
@ -103,7 +102,12 @@ where
|
|||
RST: OutputPin,
|
||||
DELAY: DelayUs,
|
||||
{
|
||||
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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)?;
|
||||
|
|
@ -152,7 +156,8 @@ where
|
|||
spi: &mut SPI,
|
||||
black: &[u8],
|
||||
chromatic: &[u8],
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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)
|
||||
}
|
||||
|
|
@ -160,7 +165,12 @@ 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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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(())
|
||||
|
|
@ -173,7 +183,8 @@ where
|
|||
&mut self,
|
||||
spi: &mut SPI,
|
||||
chromatic: &[u8],
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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)?;
|
||||
|
||||
|
|
@ -200,7 +211,8 @@ where
|
|||
dc: DC,
|
||||
rst: RST,
|
||||
delay: &mut DELAY,
|
||||
) -> Result<Self, Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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;
|
||||
|
||||
|
|
@ -211,7 +223,12 @@ where
|
|||
Ok(epd)
|
||||
}
|
||||
|
||||
fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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,
|
||||
|
|
@ -228,7 +245,12 @@ where
|
|||
Ok(())
|
||||
}
|
||||
|
||||
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>>{
|
||||
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)
|
||||
}
|
||||
|
||||
|
|
@ -253,7 +275,8 @@ where
|
|||
spi: &mut SPI,
|
||||
buffer: &[u8],
|
||||
_delay: &mut DELAY,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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)?;
|
||||
|
|
@ -277,11 +300,17 @@ where
|
|||
y: u32,
|
||||
width: u32,
|
||||
height: u32,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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();
|
||||
|
|
@ -293,13 +322,19 @@ where
|
|||
spi: &mut SPI,
|
||||
buffer: &[u8],
|
||||
delay: &mut DELAY,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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();
|
||||
|
|
@ -321,7 +356,8 @@ where
|
|||
&mut self,
|
||||
_spi: &mut SPI,
|
||||
_refresh_rate: Option<RefreshLut>,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>
|
||||
{
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -339,11 +375,21 @@ where
|
|||
RST: OutputPin,
|
||||
DELAY: DelayUs,
|
||||
{
|
||||
fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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)
|
||||
}
|
||||
|
||||
|
|
@ -352,7 +398,8 @@ where
|
|||
spi: &mut SPI,
|
||||
command: Command,
|
||||
data: &[u8],
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>
|
||||
{
|
||||
self.interface.cmd_with_data(spi, command, data)
|
||||
}
|
||||
|
||||
|
|
@ -360,7 +407,11 @@ where
|
|||
let _ = self.interface.wait_until_idle(IS_BUSY_LOW);
|
||||
}
|
||||
|
||||
fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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();
|
||||
|
||||
|
|
@ -372,7 +423,12 @@ 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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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,
|
||||
|
|
|
|||
|
|
@ -49,9 +49,9 @@
|
|||
//!
|
||||
//! BE CAREFUL! The screen can get ghosting/burn-ins through the Partial Fast Update Drawing.
|
||||
|
||||
use crate::{eh_prelude::*, Error};
|
||||
use crate::interface::DisplayInterface;
|
||||
use crate::traits::{InternalWiAdditions, QuickRefresh, RefreshLut, WaveshareDisplay};
|
||||
use crate::{eh_prelude::*, Error};
|
||||
|
||||
//The Lookup Tables for the Display
|
||||
mod constants;
|
||||
|
|
@ -96,7 +96,12 @@ where
|
|||
RST: OutputPin,
|
||||
DELAY: DelayUs,
|
||||
{
|
||||
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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)?;
|
||||
|
||||
|
|
@ -159,7 +164,8 @@ where
|
|||
dc: DC,
|
||||
rst: RST,
|
||||
delay: &mut DELAY,
|
||||
) -> Result<Self, Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +180,21 @@ where
|
|||
Ok(epd)
|
||||
}
|
||||
|
||||
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>>{
|
||||
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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +218,8 @@ where
|
|||
spi: &mut SPI,
|
||||
buffer: &[u8],
|
||||
_delay: &mut DELAY,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +240,8 @@ where
|
|||
y: u32,
|
||||
width: u32,
|
||||
height: u32,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +279,12 @@ where
|
|||
Ok(())
|
||||
}
|
||||
|
||||
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>>{
|
||||
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 +295,19 @@ where
|
|||
spi: &mut SPI,
|
||||
buffer: &[u8],
|
||||
delay: &mut DELAY,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +343,8 @@ where
|
|||
&mut self,
|
||||
spi: &mut SPI,
|
||||
refresh_rate: Option<RefreshLut>,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +377,21 @@ where
|
|||
RST: OutputPin,
|
||||
DELAY: DelayUs,
|
||||
{
|
||||
fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +400,8 @@ where
|
|||
spi: &mut SPI,
|
||||
command: Command,
|
||||
data: &[u8],
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +409,11 @@ where
|
|||
let _ = self.interface.wait_until_idle(IS_BUSY_LOW);
|
||||
}
|
||||
|
||||
fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +432,8 @@ where
|
|||
lut_bw: &[u8],
|
||||
lut_wb: &[u8],
|
||||
lut_bb: &[u8],
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +461,8 @@ where
|
|||
y: u32,
|
||||
width: u32,
|
||||
height: u32,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +498,8 @@ where
|
|||
spi: &mut SPI,
|
||||
buffer: &[u8],
|
||||
_delay: &mut DELAY,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +515,8 @@ where
|
|||
spi: &mut SPI,
|
||||
buffer: &[u8],
|
||||
_delay: &mut DELAY,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +529,12 @@ 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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +547,8 @@ where
|
|||
spi: &mut SPI,
|
||||
buffer: &[u8],
|
||||
delay: &mut DELAY,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +561,8 @@ where
|
|||
y: u32,
|
||||
width: u32,
|
||||
height: u32,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +592,8 @@ where
|
|||
y: u32,
|
||||
width: u32,
|
||||
height: u32,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +617,8 @@ where
|
|||
y: u32,
|
||||
width: u32,
|
||||
height: u32,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>
|
||||
{
|
||||
self.wait_until_idle();
|
||||
self.send_resolution(spi)?;
|
||||
|
||||
|
|
|
|||
|
|
@ -6,11 +6,11 @@
|
|||
//! - [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};
|
||||
use crate::Error;
|
||||
|
||||
pub(crate) mod command;
|
||||
use self::command::Command;
|
||||
|
|
@ -47,7 +47,12 @@ where
|
|||
RST: OutputPin,
|
||||
DELAY: DelayUs,
|
||||
{
|
||||
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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)?;
|
||||
|
||||
|
|
@ -88,7 +93,8 @@ where
|
|||
dc: DC,
|
||||
rst: RST,
|
||||
delay: &mut DELAY,
|
||||
) -> Result<Self, Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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;
|
||||
|
||||
|
|
@ -99,11 +105,21 @@ where
|
|||
Ok(epd)
|
||||
}
|
||||
|
||||
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>>{
|
||||
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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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(())
|
||||
}
|
||||
|
|
@ -113,7 +129,8 @@ where
|
|||
spi: &mut SPI,
|
||||
buffer: &[u8],
|
||||
_delay: &mut DELAY,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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)?;
|
||||
|
|
@ -129,11 +146,17 @@ where
|
|||
_y: u32,
|
||||
_width: u32,
|
||||
_height: u32,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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();
|
||||
|
|
@ -149,13 +172,19 @@ where
|
|||
spi: &mut SPI,
|
||||
buffer: &[u8],
|
||||
delay: &mut DELAY,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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)?;
|
||||
|
|
@ -186,7 +215,8 @@ where
|
|||
&mut self,
|
||||
_spi: &mut SPI,
|
||||
_refresh_rate: Option<RefreshLut>,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>
|
||||
{
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
|
|
@ -204,11 +234,21 @@ where
|
|||
RST: OutputPin,
|
||||
DELAY: DelayUs,
|
||||
{
|
||||
fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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)
|
||||
}
|
||||
|
||||
|
|
@ -217,7 +257,8 @@ where
|
|||
spi: &mut SPI,
|
||||
command: Command,
|
||||
data: &[u8],
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>
|
||||
{
|
||||
self.interface.cmd_with_data(spi, command, data)
|
||||
}
|
||||
|
||||
|
|
@ -227,7 +268,11 @@ where
|
|||
fn wait_busy_low(&mut self) {
|
||||
let _ = self.interface.wait_until_idle(false);
|
||||
}
|
||||
fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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();
|
||||
|
||||
|
|
@ -238,7 +283,11 @@ where
|
|||
self.send_data(spi, &[h as u8])
|
||||
}
|
||||
|
||||
fn update_vcom(&mut self, spi: &mut SPI) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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(())
|
||||
|
|
|
|||
|
|
@ -5,11 +5,11 @@
|
|||
//! - [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};
|
||||
use crate::Error;
|
||||
|
||||
pub(crate) mod command;
|
||||
use self::command::Command;
|
||||
|
|
@ -46,7 +46,12 @@ where
|
|||
RST: OutputPin,
|
||||
DELAY: DelayUs,
|
||||
{
|
||||
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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)?;
|
||||
|
||||
|
|
@ -110,7 +115,8 @@ where
|
|||
dc: DC,
|
||||
rst: RST,
|
||||
delay: &mut DELAY,
|
||||
) -> Result<Self, Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +127,21 @@ where
|
|||
Ok(epd)
|
||||
}
|
||||
|
||||
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>>{
|
||||
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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +154,8 @@ where
|
|||
spi: &mut SPI,
|
||||
buffer: &[u8],
|
||||
_delay: &mut DELAY,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +180,17 @@ where
|
|||
_y: u32,
|
||||
_width: u32,
|
||||
_height: u32,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +201,19 @@ where
|
|||
spi: &mut SPI,
|
||||
buffer: &[u8],
|
||||
delay: &mut DELAY,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +244,8 @@ where
|
|||
&mut self,
|
||||
_spi: &mut SPI,
|
||||
_refresh_rate: Option<RefreshLut>,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>
|
||||
{
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
|
|
@ -233,11 +263,21 @@ where
|
|||
RST: OutputPin,
|
||||
DELAY: DelayUs,
|
||||
{
|
||||
fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +286,8 @@ where
|
|||
spi: &mut SPI,
|
||||
command: Command,
|
||||
data: &[u8],
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +295,11 @@ where
|
|||
let _ = self.interface.wait_until_idle(IS_BUSY_LOW);
|
||||
}
|
||||
|
||||
fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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();
|
||||
|
||||
|
|
|
|||
|
|
@ -8,11 +8,11 @@
|
|||
//!
|
||||
//! - [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};
|
||||
use crate::Error;
|
||||
|
||||
pub(crate) mod command;
|
||||
use self::command::Command;
|
||||
|
|
@ -49,7 +49,12 @@ where
|
|||
RST: OutputPin,
|
||||
DELAY: DelayUs,
|
||||
{
|
||||
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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)?;
|
||||
|
||||
|
|
@ -110,7 +115,8 @@ where
|
|||
dc: DC,
|
||||
rst: RST,
|
||||
delay: &mut DELAY,
|
||||
) -> Result<Self, Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +127,21 @@ where
|
|||
Ok(epd)
|
||||
}
|
||||
|
||||
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>>{
|
||||
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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +152,8 @@ where
|
|||
spi: &mut SPI,
|
||||
buffer: &[u8],
|
||||
_delay: &mut DELAY,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +169,17 @@ where
|
|||
_y: u32,
|
||||
_width: u32,
|
||||
_height: u32,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +190,19 @@ where
|
|||
spi: &mut SPI,
|
||||
buffer: &[u8],
|
||||
delay: &mut DELAY,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +241,8 @@ where
|
|||
&mut self,
|
||||
_spi: &mut SPI,
|
||||
_refresh_rate: Option<RefreshLut>,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>
|
||||
{
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
|
|
@ -230,7 +260,12 @@ where
|
|||
RST: OutputPin,
|
||||
DELAY: DelayUs,
|
||||
{
|
||||
fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +274,8 @@ where
|
|||
spi: &mut SPI,
|
||||
command: Command,
|
||||
data: &[u8],
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>
|
||||
{
|
||||
self.interface.cmd_with_data(spi, command, data)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,11 +9,11 @@
|
|||
//! 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};
|
||||
use crate::Error;
|
||||
|
||||
pub(crate) mod command;
|
||||
use self::command::Command;
|
||||
|
|
@ -50,7 +50,12 @@ where
|
|||
RST: OutputPin,
|
||||
DELAY: DelayUs,
|
||||
{
|
||||
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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)?;
|
||||
|
||||
|
|
@ -92,7 +97,8 @@ where
|
|||
dc: DC,
|
||||
rst: RST,
|
||||
delay: &mut DELAY,
|
||||
) -> Result<Self, Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +109,21 @@ where
|
|||
Ok(epd)
|
||||
}
|
||||
|
||||
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>>{
|
||||
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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +136,8 @@ where
|
|||
spi: &mut SPI,
|
||||
buffer: &[u8],
|
||||
delay: &mut DELAY,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +151,17 @@ where
|
|||
_y: u32,
|
||||
_width: u32,
|
||||
_height: u32,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +172,19 @@ where
|
|||
spi: &mut SPI,
|
||||
buffer: &[u8],
|
||||
delay: &mut DELAY,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +218,8 @@ where
|
|||
&mut self,
|
||||
_spi: &mut SPI,
|
||||
_refresh_rate: Option<RefreshLut>,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>{
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>
|
||||
{
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
|
|
@ -207,11 +237,21 @@ where
|
|||
RST: OutputPin,
|
||||
DELAY: DelayUs,
|
||||
{
|
||||
fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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,11 +260,17 @@ where
|
|||
spi: &mut SPI,
|
||||
command: Command,
|
||||
data: &[u8],
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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).map_err(|e| Error::Delay(e))?;
|
||||
|
|
@ -232,7 +278,11 @@ where
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{eh_prelude::*, Error};
|
||||
use crate::traits::Command;
|
||||
use crate::{eh_prelude::*, Error};
|
||||
use core::marker::PhantomData;
|
||||
|
||||
/// The Connection Interface of all (?) Waveshare EPD-Devices
|
||||
|
|
@ -42,7 +42,12 @@ 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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +58,12 @@ 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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +83,8 @@ where
|
|||
spi: &mut SPI,
|
||||
command: T,
|
||||
data: &[u8],
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +97,8 @@ where
|
|||
spi: &mut SPI,
|
||||
val: u8,
|
||||
repetitions: u32,
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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 +109,12 @@ where
|
|||
}
|
||||
|
||||
// spi write helper/abstraction function
|
||||
fn write(&mut self, spi: &mut SPI, data: &[u8]) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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();
|
||||
|
||||
|
|
@ -166,7 +183,12 @@ 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) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>> {
|
||||
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))?;
|
||||
|
||||
|
|
|
|||
10
src/lib.rs
10
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)
|
||||
|
|
@ -133,7 +133,7 @@ pub const SPI_MODE: Mode = Mode {
|
|||
polarity: Polarity::IdleLow,
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug)]
|
||||
/// Error
|
||||
pub enum Error<SPIError, CSError, BUSYError, DCError, RSTError, DELAYError> {
|
||||
/// SPI Errors
|
||||
|
|
@ -150,10 +150,10 @@ pub enum Error<SPIError, CSError, BUSYError, DCError, RSTError, DELAYError> {
|
|||
RST(RSTError),
|
||||
}
|
||||
|
||||
impl <SPIError, CSError, BUSYError, DCError, RSTError, DELAYError> From<SPIError> for Error<SPIError, CSError, BUSYError, DCError, RSTError, DELAYError> {
|
||||
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,7 +42,11 @@ 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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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
|
||||
|
|
@ -69,14 +73,21 @@ where
|
|||
/// 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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>;
|
||||
fn update_chromatic_frame(
|
||||
&mut self,
|
||||
spi: &mut SPI,
|
||||
chromatic: &[u8],
|
||||
) -> Result<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::Error>>;
|
||||
}
|
||||
|
||||
/// All the functions to interact with the EPDs
|
||||
|
|
@ -151,12 +162,20 @@ where
|
|||
/// 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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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);
|
||||
|
|
@ -196,7 +215,11 @@ where
|
|||
/// 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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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(
|
||||
|
|
@ -209,7 +232,11 @@ where
|
|||
/// 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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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
|
||||
|
|
@ -304,7 +331,11 @@ where
|
|||
) -> 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<(), Error<SPI::Error, CS::Error, BUSY::Error, DC::Error, RST::Error, DELAY::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(
|
||||
|
|
|
|||
Loading…
Reference in New Issue