Stablised traits and interfaces, converted epd4in2 to it, and started real work on epd2in9

This commit is contained in:
Christoph Groß
2018-07-19 16:46:15 +02:00
parent 80e5c0ffb1
commit 5e03c3c39a
9 changed files with 364 additions and 415 deletions
@@ -10,7 +10,7 @@ use interface::Command;
/// EPD4in2 driver
///
pub(crate) struct DataInterface<SPI, CS, BUSY, DC, RST, D> {
pub(crate) struct ConnectionInterface<SPI, CS, BUSY, DC, RST, D> {
/// SPI
spi: SPI,
/// CS for SPI
@@ -26,7 +26,7 @@ pub(crate) struct DataInterface<SPI, CS, BUSY, DC, RST, D> {
}
impl<SPI, CS, BUSY, DC, RST, D, E> DataInterface<SPI, CS, BUSY, DC, RST, D>
impl<SPI, CS, BUSY, DC, RST, D, E> ConnectionInterface<SPI, CS, BUSY, DC, RST, D>
where
SPI: Write<u8, Error = E>,
CS: OutputPin,
@@ -36,12 +36,12 @@ where
D: DelayUs<u16> + DelayMs<u16>,
{
pub(crate) fn new(spi: SPI, cs: CS, busy: BUSY, dc: DC, rst: RST, delay: D) -> Self {
DataInterface {spi, cs, busy, dc, rst, delay }
ConnectionInterface {spi, cs, busy, dc, rst, delay }
}
/// Basic function for sending [Commands](Command).
///
/// Enables direct interaction with the device with the help of [EPD4in2::send_data()](EPD4in2::send_data())
/// Enables direct interaction with the device with the help of [send_data()](ConnectionInterface::send_data())
/// Should rarely be needed!
/// //TODO: make public?
pub(crate) fn send_command<T: Command>(&mut self, command: T) -> Result<(), E> {
@@ -56,7 +56,7 @@ where
/// Basic function for sending a single u8 of data over spi
///
/// Enables direct interaction with the device with the help of [EPD4in2::send_command()](EPD4in2::send_command())
/// Enables direct interaction with the device with the help of [Esend_command()](ConnectionInterface::send_command())
///
/// Should rarely be needed!
/// //TODO: make public?
@@ -72,7 +72,7 @@ where
/// Basic function for sending an array of u8-values of data over spi
///
/// Enables direct interaction with the device with the help of [EPD4in2::send_command()](EPD4in2::send_command())
/// Enables direct interaction with the device with the help of [send_command()](EPD4in2::send_command())
///
/// Should rarely be needed!
/// //TODO: make public?
@@ -107,11 +107,18 @@ where
/// This is normally handled by the more complicated commands themselves,
/// but in the case you send data and commands directly you might need to check
/// if the device is still busy
pub(crate) fn wait_until_idle(&mut self) {
///
/// is_busy_low
/// - TRUE for epd4in2, epd1in54, epd2in13, epd2in7, epd5in83, epd7in5
///
/// - FALSE for epd2in9
/// Most likely there was a mistake with the 2in9 busy connection
pub(crate) fn wait_until_idle(&mut self, is_busy_low: bool) {
self.delay_ms(1);
//low: busy, high: idle
while self.busy.is_low() {
while (is_busy_low && self.busy.is_low()) || (!is_busy_low && self.busy.is_high()) {
//TODO: shorten the time? it was 100 in the beginning
self.delay_ms(10);
self.delay_ms(5);
}
}
+26 -7
View File
@@ -9,7 +9,7 @@ use hal::{
use drawing::color::Color;
pub mod data_interface;
pub mod connection_interface;
//TODO: test spi mode
/// SPI mode -
@@ -25,6 +25,18 @@ pub(crate) trait Command {
fn address(self) -> u8;
}
//TODO add LUT trait with set_fast_lut
// and set_manual_lut and set_normal_lut or sth like that
// for partial updates
pub trait LUTSupport<Error> {
fn set_lut(&mut self) -> Result<(), Error>;
fn set_lut_quick(&mut self) -> Result<(), Error>;
fn set_lut_manual(&mut self, data: &[u8]) -> Result<(), Error>;
}
pub trait WaveshareInterface<SPI, CS, BUSY, DC, RST, D, E>
where
SPI: Write<u8, Error = E>,
@@ -63,16 +75,26 @@ pub trait WaveshareInterface<SPI, CS, BUSY, DC, RST, D, E>
fn init(&mut self) -> Result<(), E>;
// void DisplayFrame(const unsigned char* frame_buffer);
/// Transmit a full frame to the SRAM of the DPD
///
fn update_frame(&mut self, buffer: &[u8]) -> Result<(), E>;
//TODO: is dtm always used?
/// Transmit partial data to the SRAM of the EPD,
/// the final parameter dtm chooses between the 2
/// internal buffers
///
/// Normally it should be dtm2, so use false
///
/// BUFFER needs to be of size: w / 8 * l !
fn update_partial_frame(&mut self, buffer: &[u8], x: u16, y: u16, width: u16, height: u16) -> Result<(), E>;
/// Displays the frame data from SRAM
fn display_frame(&mut self) -> Result<(), E>;
// TODO: add this abstraction function
// fn update_and_display_frame(&mut self, buffer: &[u8]) -> Result<(), E>;
fn update_and_display_frame(&mut self, buffer: &[u8]) -> Result<(), E>;
/// Clears the frame from the buffer
///
@@ -102,10 +124,7 @@ pub trait WaveshareInterface<SPI, CS, BUSY, DC, RST, D, E>
fn delay_ms(&mut self, delay: u16);
/*
-display_frame
-clear_frame
-set_full_frame
-set_partial_frame
//
-set_quick_lut?