Added a new Display Trait, but that is still in work and renamed a few other traitnames to make them more clear

digi-v2-tests
Christoph Groß 5 years ago
parent 36aa5118fc
commit c4ba7ffb21

@ -73,7 +73,8 @@ pub const SPI_MODE: Mode = Mode {
/// EPD4in2 driver
///
pub struct EPD4in2<SPI, CS, BUSY, DC, RST, D> {
pub struct EPD4in2<SPI, CS, BUSY, DC, RST, D>
{
/// Connection Interface
interface: ConnectionInterface<SPI, CS, BUSY, DC, RST, D>,
/// Width
@ -84,15 +85,17 @@ pub struct EPD4in2<SPI, CS, BUSY, DC, RST, D> {
color: Color,
}
impl<SPI, CS, BUSY, DC, RST, D, E> WaveshareInterface<SPI, CS, BUSY, DC, RST, D, E>
for EPD4in2<SPI, CS, BUSY, DC, RST, D>
where
SPI: Write<u8, Error = E>,
impl<SPI, CS, BUSY, DataCommand, RST, Delay, Error> WaveshareInterface<SPI, CS, BUSY, DataCommand, RST, Delay, Error>
for EPD4in2<SPI, CS, BUSY, DataCommand, RST, Delay>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
DataCommand: OutputPin,
RST: OutputPin,
D: DelayUs<u16> + DelayMs<u16>,
Delay: DelayUs<u16> + DelayMs<u16>,
{
fn get_width(&self) -> u16 {
self.width
@ -117,11 +120,11 @@ where
///
/// epd4in2.sleep();
/// ```
fn new(spi: SPI, cs: CS, busy: BUSY, dc: DC, rst: RST, delay: D) -> Result<Self, E> {
fn new(interface: ConnectionInterface<SPI, CS, BUSY, DataCommand, RST, Delay>) -> Result<Self, Error> {
let width = WIDTH as u16;
let height = HEIGHT as u16;
let interface = ConnectionInterface::new(spi, cs, busy, dc, rst, delay);
let color = Color::White;
let mut epd = EPD4in2 {
interface,
@ -135,7 +138,7 @@ where
Ok(epd)
}
fn init(&mut self) -> Result<(), E> {
fn init(&mut self) -> Result<(), Error> {
// reset the device
self.reset();

@ -12,6 +12,7 @@ use drawing::color::Color;
/// Interface for the physical connection between display and the controlling device
pub mod connection_interface;
use self::connection_interface::ConnectionInterface;
/// All commands need to have this trait which gives the address of the command
@ -21,6 +22,12 @@ pub(crate) trait Command {
}
pub trait Displays {
fn width(self) -> u8;
fn height(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
trait LUTSupport<Error> {
@ -30,14 +37,14 @@ trait LUTSupport<Error> {
}
pub trait WaveshareInterface<SPI, CS, BUSY, DC, RST, D, E>
pub trait WaveshareInterface<SPI, CS, BUSY, DataCommand, RST, Delay, Error>
where
SPI: Write<u8, Error = E>,
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
DataCommand: OutputPin,
RST: OutputPin,
D: DelayUs<u16> + DelayMs<u16>,
Delay: DelayUs<u16> + DelayMs<u16>,
{
/// Get the width of the display
fn get_width(&self) -> u16;
@ -49,13 +56,8 @@ pub trait WaveshareInterface<SPI, CS, BUSY, DC, RST, D, E>
///
/// This already initialises the device. That means [init()](WaveshareInterface::init()) isn't needed directly afterwards
fn new(
spi: SPI,
cs: CS,
busy: BUSY,
dc: DC,
rst: RST,
delay: D
) -> Result<Self, E>
interface: ConnectionInterface<SPI, CS, BUSY, DataCommand, RST, Delay>,
) -> Result<Self, Error>
where Self: Sized;
/// This initialises the EPD and powers it up
@ -65,13 +67,13 @@ pub trait WaveshareInterface<SPI, CS, BUSY, DC, RST, D, E>
/// This function calls [reset()](WaveshareInterface::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) -> Result<(), E>;
fn init(&mut self) -> Result<(), Error>;
// 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>;
fn update_frame(&mut self, buffer: &[u8]) -> Result<(), Error>;
//TODO: is dtm always used?
/// Transmit partial data to the SRAM of the EPD,
@ -81,18 +83,18 @@ pub trait WaveshareInterface<SPI, CS, BUSY, DC, RST, D, E>
/// 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>;
fn update_partial_frame(&mut self, buffer: &[u8], x: u16, y: u16, width: u16, height: u16) -> Result<(), Error>;
/// Displays the frame data from SRAM
fn display_frame(&mut self) -> Result<(), E>;
fn display_frame(&mut self) -> Result<(), Error>;
// 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<(), Error>;
/// Clears the frame from the buffer
///
/// Uses the chosen background color
fn clear_frame(&mut self) -> Result<(), E>;
fn clear_frame(&mut self) -> Result<(), Error>;
/// Sets the backgroundcolor for various commands like [clear_frame()](WaveshareInterface::clear_frame())
fn set_background_color(&mut self, color: Color);
@ -104,7 +106,7 @@ pub trait WaveshareInterface<SPI, CS, BUSY, DC, RST, D, E>
/// But you can also use [reset()](WaveshareInterface::reset()) to awaken.
/// But as you need to power it up once more anyway you can also just directly use [init()](WaveshareInterface::init()) for resetting
/// and initialising which already contains the reset
fn sleep(&mut self) -> Result<(), E>;
fn sleep(&mut self) -> Result<(), Error>;
/// Resets the device.
///

Loading…
Cancel
Save