Not all Type A screens are completly the same to the change to bring it all together was reverted.

This commit is contained in:
Christoph Groß
2018-08-06 13:34:33 +02:00
parent 230fb947cb
commit 6422142133
13 changed files with 689 additions and 62 deletions
+2 -2
View File
@@ -1,5 +1,5 @@
pub(crate) const WIDTH: usize = 400;
pub(crate) const HEIGHT: usize = 300;
pub(crate) const WIDTH: u16 = 400;
pub(crate) const HEIGHT: u16 = 300;
pub(crate) const LUT_VCOM0: [u8; 44] = [
0x00, 0x17, 0x00, 0x00, 0x00, 0x02,
+27 -20
View File
@@ -49,7 +49,6 @@
use hal::{
blocking::{delay::*, spi::Write},
digital::*,
spi::{Mode, Phase, Polarity},
};
use interface::{connection_interface::ConnectionInterface, WaveshareInterface};
@@ -65,6 +64,14 @@ pub use self::command::Command;
use epds::EPD;
pub(crate) fn new() -> EPD {
EPD::new(
constants::WIDTH,
constants::HEIGHT
)
}
/// EPD4in2 driver
///
pub struct EPD4in2<SPI, CS, BUSY, DC, RST, D>
@@ -81,10 +88,10 @@ pub struct EPD4in2<SPI, CS, BUSY, DC, RST, D>
impl<SPI, CS, BUSY, DataCommand, RST, Delay, SPI_Error> WaveshareInterface<SPI, CS, BUSY, DataCommand, RST, Delay, SPI_Error>
impl<SPI, CS, BUSY, DataCommand, RST, Delay, SpiError> WaveshareInterface<SPI, CS, BUSY, DataCommand, RST, Delay, SpiError>
for EPD4in2<SPI, CS, BUSY, DataCommand, RST, Delay>
where
SPI: Write<u8, Error = SPI_Error>,
SPI: Write<u8, Error = SpiError>,
CS: OutputPin,
BUSY: InputPin,
DataCommand: OutputPin,
@@ -114,7 +121,7 @@ where
///
/// epd4in2.sleep();
/// ```
fn new(interface: ConnectionInterface<SPI, CS, BUSY, DataCommand, RST, Delay>, epd: EPD) -> Result<Self, SPI_Error> {
fn new(interface: ConnectionInterface<SPI, CS, BUSY, DataCommand, RST, Delay>) -> Result<Self, SpiError> {
let width = WIDTH as u16;
let height = HEIGHT as u16;
@@ -132,7 +139,7 @@ where
Ok(epd)
}
fn init(&mut self) -> Result<(), SPI_Error> {
fn init(&mut self) -> Result<(), SpiError> {
// reset the device
self.reset();
@@ -179,7 +186,7 @@ where
Ok(())
}
fn sleep(&mut self) -> Result<(), SPI_Error> {
fn sleep(&mut self) -> Result<(), SpiError> {
self.send_command(Command::VCOM_AND_DATA_INTERVAL_SETTING)?;
self.send_data(0x17)?; //border floating
self.send_command(Command::VCM_DC_SETTING)?; // VCOM to 0V
@@ -208,7 +215,7 @@ where
self.interface.delay_ms(delay)
}
fn update_frame(&mut self, buffer: &[u8]) -> Result<(), SPI_Error> {
fn update_frame(&mut self, buffer: &[u8]) -> Result<(), SpiError> {
let color_value = self.color.get_byte_value();
self.send_resolution()?;
@@ -244,7 +251,7 @@ where
y: u16,
width: u16,
height: u16,
) -> Result<(), SPI_Error> {
) -> Result<(), SpiError> {
if buffer.len() as u16 != width / 8 * height {
//TODO: panic!! or sth like that
@@ -281,13 +288,13 @@ where
self.send_command(Command::PARTIAL_OUT)
}
fn update_and_display_frame(&mut self, buffer: &[u8]) -> Result<(), SPI_Error>{
fn update_and_display_frame(&mut self, buffer: &[u8]) -> Result<(), SpiError>{
self.update_frame(buffer)?;
self.display_frame()
}
fn display_frame(&mut self) -> Result<(), SPI_Error> {
fn display_frame(&mut self) -> Result<(), SpiError> {
self.send_command(Command::DISPLAY_REFRESH)?;
self.wait_until_idle();
@@ -297,7 +304,7 @@ where
// TODO: add this abstraction function
// fn update_and_display_frame(&mut self, buffer: &[u8]) -> Result<(), E>;
fn clear_frame(&mut self) -> Result<(), SPI_Error> {
fn clear_frame(&mut self) -> Result<(), SpiError> {
self.send_resolution()?;
let size = self.width / 8 * self.height;
@@ -325,24 +332,24 @@ where
}
}
impl<SPI, CS, BUSY, DC, RST, D, SPI_Error> EPD4in2<SPI, CS, BUSY, DC, RST, D>
impl<SPI, CS, BUSY, DC, RST, D, SpiError> EPD4in2<SPI, CS, BUSY, DC, RST, D>
where
SPI: Write<u8, Error = SPI_Error>,
SPI: Write<u8, Error = SpiError>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
D: DelayUs<u16> + DelayMs<u16>,
{
fn send_command(&mut self, command: Command) -> Result<(), SPI_Error> {
fn send_command(&mut self, command: Command) -> Result<(), SpiError> {
self.interface.send_command(command)
}
fn send_data(&mut self, val: u8) -> Result<(), SPI_Error> {
fn send_data(&mut self, val: u8) -> Result<(), SpiError> {
self.interface.send_data(val)
}
fn send_multiple_data(&mut self, data: &[u8]) -> Result<(), SPI_Error> {
fn send_multiple_data(&mut self, data: &[u8]) -> Result<(), SpiError> {
self.interface.send_multiple_data(data)
}
@@ -350,7 +357,7 @@ where
self.interface.wait_until_idle(true)
}
fn send_resolution(&mut self) -> Result<(), SPI_Error> {
fn send_resolution(&mut self) -> Result<(), SpiError> {
let w = self.get_width();
let h = self.get_height();
@@ -363,7 +370,7 @@ where
/// Fill the look-up table for the EPD
//TODO: make public?
fn set_lut(&mut self) -> Result<(), SPI_Error> {
fn set_lut(&mut self) -> Result<(), SpiError> {
self.set_lut_helper(&LUT_VCOM0, &LUT_WW, &LUT_BW, &LUT_WB, &LUT_BB)
}
@@ -372,7 +379,7 @@ where
/// Is automatically done by [EPD4in2::display_frame_quick()](EPD4in2::display_frame_quick())
/// //TODO: make public?
#[cfg(feature = "epd4in2_fast_update")]
fn set_lut_quick(&mut self) -> Result<(), SPI_Error> {
fn set_lut_quick(&mut self) -> Result<(), SpiError> {
self.set_lut_helper(
&LUT_VCOM0_QUICK,
&LUT_WW_QUICK,
@@ -389,7 +396,7 @@ where
lut_bw: &[u8],
lut_wb: &[u8],
lut_bb: &[u8],
) -> Result<(), SPI_Error> {
) -> Result<(), SpiError> {
// LUT VCOM
self.send_command(Command::LUT_FOR_VCOM)?;
self.send_multiple_data(lut_vcom)?;