|
|
|
@ -48,8 +48,9 @@
|
|
|
|
|
|
|
|
|
|
use embedded_hal::{
|
|
|
|
|
blocking::{delay::*, spi::Write},
|
|
|
|
|
digital::*,
|
|
|
|
|
digital::v2::*,
|
|
|
|
|
};
|
|
|
|
|
use crate::Error;
|
|
|
|
|
|
|
|
|
|
use crate::interface::DisplayInterface;
|
|
|
|
|
use crate::traits::{InternalWiAdditions, RefreshLUT, WaveshareDisplay};
|
|
|
|
@ -77,54 +78,56 @@ pub use self::graphics::Display4in2;
|
|
|
|
|
///
|
|
|
|
|
pub struct EPD4in2<SPI, CS, BUSY, DC, RST> {
|
|
|
|
|
/// Connection Interface
|
|
|
|
|
interface: DisplayInterface<SPI, CS, BUSY, DC, RST>,
|
|
|
|
|
di: DisplayInterface<SPI, CS, BUSY, DC, RST>,
|
|
|
|
|
/// Background Color
|
|
|
|
|
color: Color,
|
|
|
|
|
/// Refresh LUT
|
|
|
|
|
refresh: RefreshLUT,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<SPI, CS, BUSY, DC, RST> InternalWiAdditions<SPI, CS, BUSY, DC, RST>
|
|
|
|
|
impl<SPI, CS, BUSY, DC, RST, SpiE, PinRE, PinWE> InternalWiAdditions<SPI, CS, BUSY, DC, RST, SpiE, PinRE, PinWE>
|
|
|
|
|
for EPD4in2<SPI, CS, BUSY, DC, RST>
|
|
|
|
|
where
|
|
|
|
|
SPI: Write<u8>,
|
|
|
|
|
CS: OutputPin,
|
|
|
|
|
BUSY: InputPin,
|
|
|
|
|
DC: OutputPin,
|
|
|
|
|
RST: OutputPin,
|
|
|
|
|
SPI: Write<u8, Error = SpiE>,
|
|
|
|
|
CS: OutputPin<Error = PinWE>,
|
|
|
|
|
BUSY: InputPin<Error = PinRE>,
|
|
|
|
|
DC: OutputPin<Error = PinWE>,
|
|
|
|
|
RST: OutputPin<Error = PinWE>,
|
|
|
|
|
{
|
|
|
|
|
type Error = Error<SpiE, PinRE, PinWE>;
|
|
|
|
|
|
|
|
|
|
fn init<DELAY: DelayMs<u8>>(
|
|
|
|
|
&mut self,
|
|
|
|
|
spi: &mut SPI,
|
|
|
|
|
delay: &mut DELAY,
|
|
|
|
|
) -> Result<(), SPI::Error> {
|
|
|
|
|
) -> Result<(), Self::Error> {
|
|
|
|
|
// reset the device
|
|
|
|
|
self.interface.reset(delay);
|
|
|
|
|
self.di.reset(delay);
|
|
|
|
|
|
|
|
|
|
// set the power settings
|
|
|
|
|
self.interface.cmd_with_data(
|
|
|
|
|
self.di.cmd_with_data(
|
|
|
|
|
spi,
|
|
|
|
|
Command::POWER_SETTING,
|
|
|
|
|
&[0x03, 0x00, 0x2b, 0x2b, 0xff],
|
|
|
|
|
)?;
|
|
|
|
|
|
|
|
|
|
// start the booster
|
|
|
|
|
self.interface
|
|
|
|
|
self.di
|
|
|
|
|
.cmd_with_data(spi, Command::BOOSTER_SOFT_START, &[0x17, 0x17, 0x17])?;
|
|
|
|
|
|
|
|
|
|
// power on
|
|
|
|
|
self.command(spi, Command::POWER_ON)?;
|
|
|
|
|
self.di.cmd(spi, Command::POWER_ON)?;
|
|
|
|
|
delay.delay_ms(5);
|
|
|
|
|
self.wait_until_idle();
|
|
|
|
|
|
|
|
|
|
// set the panel settings
|
|
|
|
|
self.cmd_with_data(spi, Command::PANEL_SETTING, &[0x3F])?;
|
|
|
|
|
self.di.cmd_with_data(spi, Command::PANEL_SETTING, &[0x3F])?;
|
|
|
|
|
|
|
|
|
|
// Set Frequency, 200 Hz didn't work on my board
|
|
|
|
|
// 150Hz and 171Hz wasn't tested yet
|
|
|
|
|
// TODO: Test these other frequencies
|
|
|
|
|
// 3A 100HZ 29 150Hz 39 200HZ 31 171HZ DEFAULT: 3c 50Hz
|
|
|
|
|
self.cmd_with_data(spi, Command::PLL_CONTROL, &[0x3A])?;
|
|
|
|
|
self.di.cmd_with_data(spi, Command::PLL_CONTROL, &[0x3A])?;
|
|
|
|
|
|
|
|
|
|
self.set_lut(spi, None)?;
|
|
|
|
|
|
|
|
|
@ -133,15 +136,17 @@ where
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<SPI, CS, BUSY, DC, RST> WaveshareDisplay<SPI, CS, BUSY, DC, RST>
|
|
|
|
|
impl<SPI, CS, BUSY, DC, RST, SpiE, PinRE, PinWE> WaveshareDisplay<SPI, CS, BUSY, DC, RST, SpiE, PinRE, PinWE>
|
|
|
|
|
for EPD4in2<SPI, CS, BUSY, DC, RST>
|
|
|
|
|
where
|
|
|
|
|
SPI: Write<u8>,
|
|
|
|
|
CS: OutputPin,
|
|
|
|
|
BUSY: InputPin,
|
|
|
|
|
DC: OutputPin,
|
|
|
|
|
RST: OutputPin,
|
|
|
|
|
SPI: Write<u8, Error = SpiE>,
|
|
|
|
|
CS: OutputPin<Error = PinWE>,
|
|
|
|
|
BUSY: InputPin<Error = PinRE>,
|
|
|
|
|
DC: OutputPin<Error = PinWE>,
|
|
|
|
|
RST: OutputPin<Error = PinWE>,
|
|
|
|
|
{
|
|
|
|
|
type Error = Error<SpiE, PinRE, PinWE>;
|
|
|
|
|
|
|
|
|
|
/// Creates a new driver from a SPI peripheral, CS Pin, Busy InputPin, DC
|
|
|
|
|
///
|
|
|
|
|
/// This already initialises the device. That means [init()](init()) isn't needed directly afterwards
|
|
|
|
@ -165,11 +170,11 @@ where
|
|
|
|
|
rst: RST,
|
|
|
|
|
delay: &mut DELAY,
|
|
|
|
|
) -> Result<Self, SPI::Error> {
|
|
|
|
|
let interface = DisplayInterface::new(cs, busy, dc, rst);
|
|
|
|
|
let di = DisplayInterface::new(cs, busy, dc, rst);
|
|
|
|
|
let color = DEFAULT_BACKGROUND_COLOR;
|
|
|
|
|
|
|
|
|
|
let mut epd = EPD4in2 {
|
|
|
|
|
interface,
|
|
|
|
|
di,
|
|
|
|
|
color,
|
|
|
|
|
refresh: RefreshLUT::FULL,
|
|
|
|
|
};
|
|
|
|
@ -188,19 +193,19 @@ where
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn sleep(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
|
|
|
|
|
self.interface
|
|
|
|
|
self.di
|
|
|
|
|
.cmd_with_data(spi, Command::VCOM_AND_DATA_INTERVAL_SETTING, &[0x17])?; //border floating
|
|
|
|
|
self.command(spi, Command::VCM_DC_SETTING)?; // VCOM to 0V
|
|
|
|
|
self.command(spi, Command::PANEL_SETTING)?;
|
|
|
|
|
self.di.cmd(spi, Command::VCM_DC_SETTING)?; // VCOM to 0V
|
|
|
|
|
self.di.cmd(spi, Command::PANEL_SETTING)?;
|
|
|
|
|
|
|
|
|
|
self.command(spi, Command::POWER_SETTING)?; //VG&VS to 0V fast
|
|
|
|
|
self.di.cmd(spi, Command::POWER_SETTING)?; //VG&VS to 0V fast
|
|
|
|
|
for _ in 0..4 {
|
|
|
|
|
self.send_data(spi, &[0x00])?;
|
|
|
|
|
self.di.data(spi, &[0x00])?;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
self.command(spi, Command::POWER_OFF)?;
|
|
|
|
|
self.di.cmd(spi, Command::POWER_OFF)?;
|
|
|
|
|
self.wait_until_idle();
|
|
|
|
|
self.interface
|
|
|
|
|
self.di
|
|
|
|
|
.cmd_with_data(spi, Command::DEEP_SLEEP, &[0xA5])?;
|
|
|
|
|
|
|
|
|
|
self.wait_until_idle();
|
|
|
|
@ -212,19 +217,19 @@ where
|
|
|
|
|
|
|
|
|
|
self.send_resolution(spi)?;
|
|
|
|
|
|
|
|
|
|
self.interface
|
|
|
|
|
self.di
|
|
|
|
|
.cmd_with_data(spi, Command::VCM_DC_SETTING, &[0x12])?;
|
|
|
|
|
|
|
|
|
|
//VBDF 17|D7 VBDW 97 VBDB 57 VBDF F7 VBDW 77 VBDB 37 VBDR B7
|
|
|
|
|
self.interface
|
|
|
|
|
self.di
|
|
|
|
|
.cmd_with_data(spi, Command::VCOM_AND_DATA_INTERVAL_SETTING, &[0x97])?;
|
|
|
|
|
|
|
|
|
|
self.interface
|
|
|
|
|
self.di
|
|
|
|
|
.cmd(spi, Command::DATA_START_TRANSMISSION_1)?;
|
|
|
|
|
self.interface
|
|
|
|
|
self.di
|
|
|
|
|
.data_x_times(spi, color_value, WIDTH / 8 * HEIGHT)?;
|
|
|
|
|
|
|
|
|
|
self.interface
|
|
|
|
|
self.di
|
|
|
|
|
.cmd_with_data(spi, Command::DATA_START_TRANSMISSION_2, buffer)?;
|
|
|
|
|
|
|
|
|
|
self.wait_until_idle();
|
|
|
|
@ -245,41 +250,41 @@ where
|
|
|
|
|
//return Err("Wrong buffersize");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
self.command(spi, Command::PARTIAL_IN)?;
|
|
|
|
|
self.command(spi, Command::PARTIAL_WINDOW)?;
|
|
|
|
|
self.send_data(spi, &[(x >> 8) as u8])?;
|
|
|
|
|
self.di.cmd(spi, Command::PARTIAL_IN)?;
|
|
|
|
|
self.di.cmd(spi, Command::PARTIAL_WINDOW)?;
|
|
|
|
|
self.di.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
|
|
|
|
|
self.di.data(spi, &[tmp as u8])?; // x should be the multiple of 8, the last 3 bit will always be ignored
|
|
|
|
|
let tmp = tmp + width - 1;
|
|
|
|
|
self.send_data(spi, &[(tmp >> 8) as u8])?;
|
|
|
|
|
self.send_data(spi, &[(tmp | 0x07) as u8])?;
|
|
|
|
|
self.di.data(spi, &[(tmp >> 8) as u8])?;
|
|
|
|
|
self.di.data(spi, &[(tmp | 0x07) as u8])?;
|
|
|
|
|
|
|
|
|
|
self.send_data(spi, &[(y >> 8) as u8])?;
|
|
|
|
|
self.send_data(spi, &[y as u8])?;
|
|
|
|
|
self.di.data(spi, &[(y >> 8) as u8])?;
|
|
|
|
|
self.di.data(spi, &[y as u8])?;
|
|
|
|
|
|
|
|
|
|
self.send_data(spi, &[((y + height - 1) >> 8) as u8])?;
|
|
|
|
|
self.send_data(spi, &[(y + height - 1) as u8])?;
|
|
|
|
|
self.di.data(spi, &[((y + height - 1) >> 8) as u8])?;
|
|
|
|
|
self.di.data(spi, &[(y + height - 1) as u8])?;
|
|
|
|
|
|
|
|
|
|
self.send_data(spi, &[0x01])?; // Gates scan both inside and outside of the partial window. (default)
|
|
|
|
|
self.di.data(spi, &[0x01])?; // Gates scan both inside and outside of the partial window. (default)
|
|
|
|
|
|
|
|
|
|
//TODO: handle dtm somehow
|
|
|
|
|
let is_dtm1 = false;
|
|
|
|
|
if is_dtm1 {
|
|
|
|
|
self.command(spi, Command::DATA_START_TRANSMISSION_1)? //TODO: check if data_start transmission 1 also needs "old"/background data here
|
|
|
|
|
self.di.cmd(spi, Command::DATA_START_TRANSMISSION_1)? //TODO: check if data_start transmission 1 also needs "old"/background data here
|
|
|
|
|
} else {
|
|
|
|
|
self.command(spi, Command::DATA_START_TRANSMISSION_2)?
|
|
|
|
|
self.di.cmd(spi, Command::DATA_START_TRANSMISSION_2)?
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
self.send_data(spi, buffer)?;
|
|
|
|
|
self.di.data(spi, buffer)?;
|
|
|
|
|
|
|
|
|
|
self.command(spi, Command::PARTIAL_OUT)?;
|
|
|
|
|
self.di.cmd(spi, Command::PARTIAL_OUT)?;
|
|
|
|
|
|
|
|
|
|
self.wait_until_idle();
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn display_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
|
|
|
|
|
self.command(spi, Command::DISPLAY_REFRESH)?;
|
|
|
|
|
self.di.cmd(spi, Command::DISPLAY_REFRESH)?;
|
|
|
|
|
|
|
|
|
|
self.wait_until_idle();
|
|
|
|
|
Ok(())
|
|
|
|
@ -290,14 +295,14 @@ where
|
|
|
|
|
|
|
|
|
|
let color_value = self.color.get_byte_value();
|
|
|
|
|
|
|
|
|
|
self.interface
|
|
|
|
|
self.di
|
|
|
|
|
.cmd(spi, Command::DATA_START_TRANSMISSION_1)?;
|
|
|
|
|
self.interface
|
|
|
|
|
self.di
|
|
|
|
|
.data_x_times(spi, color_value, WIDTH / 8 * HEIGHT)?;
|
|
|
|
|
|
|
|
|
|
self.interface
|
|
|
|
|
self.di
|
|
|
|
|
.cmd(spi, Command::DATA_START_TRANSMISSION_2)?;
|
|
|
|
|
self.interface
|
|
|
|
|
self.di
|
|
|
|
|
.data_x_times(spi, color_value, WIDTH / 8 * HEIGHT)?;
|
|
|
|
|
|
|
|
|
|
self.wait_until_idle();
|
|
|
|
@ -344,48 +349,33 @@ where
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn is_busy(&self) -> bool {
|
|
|
|
|
self.interface.is_busy(IS_BUSY_LOW)
|
|
|
|
|
self.di.is_busy(IS_BUSY_LOW)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<SPI, CS, BUSY, DC, RST> EPD4in2<SPI, CS, BUSY, DC, RST>
|
|
|
|
|
impl<SPI, CS, BUSY, DC, RST, SpiE, PinRE, PinWE> EPD4in2<SPI, CS, BUSY, DC, RST>
|
|
|
|
|
where
|
|
|
|
|
SPI: Write<u8>,
|
|
|
|
|
CS: OutputPin,
|
|
|
|
|
BUSY: InputPin,
|
|
|
|
|
DC: OutputPin,
|
|
|
|
|
RST: OutputPin,
|
|
|
|
|
SPI: Write<u8, Error = SpiE>,
|
|
|
|
|
CS: OutputPin<Error = PinWE>,
|
|
|
|
|
BUSY: InputPin<Error = PinRE>,
|
|
|
|
|
DC: OutputPin<Error = PinWE>,
|
|
|
|
|
RST: OutputPin<Error = PinWE>,
|
|
|
|
|
{
|
|
|
|
|
fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), SPI::Error> {
|
|
|
|
|
self.interface.cmd(spi, command)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn send_data(&mut self, spi: &mut SPI, data: &[u8]) -> Result<(), SPI::Error> {
|
|
|
|
|
self.interface.data(spi, data)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn cmd_with_data(
|
|
|
|
|
&mut self,
|
|
|
|
|
spi: &mut SPI,
|
|
|
|
|
command: Command,
|
|
|
|
|
data: &[u8],
|
|
|
|
|
) -> Result<(), SPI::Error> {
|
|
|
|
|
self.interface.cmd_with_data(spi, command, data)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn wait_until_idle(&mut self) {
|
|
|
|
|
self.interface.wait_until_idle(IS_BUSY_LOW)
|
|
|
|
|
self.di.wait_until_idle(IS_BUSY_LOW)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn send_resolution(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
|
|
|
|
|
let w = self.width();
|
|
|
|
|
let h = self.height();
|
|
|
|
|
|
|
|
|
|
self.command(spi, Command::RESOLUTION_SETTING)?;
|
|
|
|
|
self.send_data(spi, &[(w >> 8) as u8])?;
|
|
|
|
|
self.send_data(spi, &[w as u8])?;
|
|
|
|
|
self.send_data(spi, &[(h >> 8) as u8])?;
|
|
|
|
|
self.send_data(spi, &[h as u8])
|
|
|
|
|
self.di.cmd(spi, Command::RESOLUTION_SETTING)?;
|
|
|
|
|
self.di.data(spi, &[(w >> 8) as u8])?;
|
|
|
|
|
self.di.data(spi, &[w as u8])?;
|
|
|
|
|
self.di.data(spi, &[(h >> 8) as u8])?;
|
|
|
|
|
self.di.data(spi, &[h as u8])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn set_lut_helper(
|
|
|
|
@ -398,21 +388,21 @@ where
|
|
|
|
|
lut_bb: &[u8],
|
|
|
|
|
) -> Result<(), SPI::Error> {
|
|
|
|
|
// LUT VCOM
|
|
|
|
|
self.cmd_with_data(spi, Command::LUT_FOR_VCOM, lut_vcom)?;
|
|
|
|
|
self.di.cmd_with_data(spi, Command::LUT_FOR_VCOM, lut_vcom)?;
|
|
|
|
|
|
|
|
|
|
// LUT WHITE to WHITE
|
|
|
|
|
self.cmd_with_data(spi, Command::LUT_WHITE_TO_WHITE, lut_ww)?;
|
|
|
|
|
self.di.cmd_with_data(spi, Command::LUT_WHITE_TO_WHITE, lut_ww)?;
|
|
|
|
|
|
|
|
|
|
// LUT BLACK to WHITE
|
|
|
|
|
self.cmd_with_data(spi, Command::LUT_BLACK_TO_WHITE, lut_bw)?;
|
|
|
|
|
self.di.cmd_with_data(spi, Command::LUT_BLACK_TO_WHITE, lut_bw)?;
|
|
|
|
|
|
|
|
|
|
// LUT WHITE to BLACK
|
|
|
|
|
self.cmd_with_data(spi, Command::LUT_WHITE_TO_BLACK, lut_wb)?;
|
|
|
|
|
self.di.cmd_with_data(spi, Command::LUT_WHITE_TO_BLACK, lut_wb)?;
|
|
|
|
|
|
|
|
|
|
// LUT BLACK to BLACK
|
|
|
|
|
self.cmd_with_data(spi, Command::LUT_BLACK_TO_BLACK, lut_bb)?;
|
|
|
|
|
self.di.cmd_with_data(spi, Command::LUT_BLACK_TO_BLACK, lut_bb)?;
|
|
|
|
|
|
|
|
|
|
self.wait_until_idle();
|
|
|
|
|
self.di.wait_until_idle(IS_BUSY_LOW);
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|