API change to partially fix #70

This commit is contained in:
Edwin Svensson
2021-04-04 22:10:50 +02:00
parent a252d074de
commit 9a1575b2ec
17 changed files with 451 additions and 354 deletions
+33 -27
View File
@@ -35,27 +35,24 @@ mod graphics;
pub use self::graphics::Display2in7b;
/// EPD2in7b driver
pub struct EPD2in7b<SPI, CS, BUSY, DC, RST> {
pub struct EPD2in7b<SPI, CS, BUSY, DC, RST, DELAY> {
/// Connection Interface
interface: DisplayInterface<SPI, CS, BUSY, DC, RST>,
interface: DisplayInterface<SPI, CS, BUSY, DC, RST, DELAY>,
/// Background Color
color: Color,
}
impl<SPI, CS, BUSY, DC, RST> InternalWiAdditions<SPI, CS, BUSY, DC, RST>
for EPD2in7b<SPI, CS, BUSY, DC, RST>
impl<SPI, CS, BUSY, DC, RST, DELAY> InternalWiAdditions<SPI, CS, BUSY, DC, RST, DELAY>
for EPD2in7b<SPI, CS, BUSY, DC, RST, DELAY>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
DELAY: DelayMs<u8>,
{
fn init<DELAY: DelayMs<u8>>(
&mut self,
spi: &mut SPI,
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
// reset the device
self.interface.reset(delay, 2);
@@ -111,17 +108,18 @@ where
}
}
impl<SPI, CS, BUSY, DC, RST> WaveshareDisplay<SPI, CS, BUSY, DC, RST>
for EPD2in7b<SPI, CS, BUSY, DC, RST>
impl<SPI, CS, BUSY, DC, RST, DELAY> WaveshareDisplay<SPI, CS, BUSY, DC, RST, DELAY>
for EPD2in7b<SPI, CS, BUSY, DC, RST, DELAY>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
DELAY: DelayMs<u8>,
{
type DisplayColor = Color;
fn new<DELAY: DelayMs<u8>>(
fn new(
spi: &mut SPI,
cs: CS,
busy: BUSY,
@@ -139,15 +137,11 @@ where
Ok(epd)
}
fn wake_up<DELAY: DelayMs<u8>>(
&mut self,
spi: &mut SPI,
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
self.init(spi, delay)
}
fn sleep(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
fn sleep(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
self.wait_until_idle();
self.interface
.cmd_with_data(spi, Command::VCOM_AND_DATA_INTERVAL_SETTING, &[0xf7])?;
@@ -159,7 +153,12 @@ where
Ok(())
}
fn update_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> {
fn update_frame(
&mut self,
spi: &mut SPI,
buffer: &[u8],
_delay: &mut DELAY,
) -> Result<(), SPI::Error> {
self.interface
.cmd(spi, Command::DATA_START_TRANSMISSION_1)?;
self.send_buffer_helper(spi, buffer)?;
@@ -201,19 +200,24 @@ where
self.interface.cmd(spi, Command::DATA_STOP)
}
fn display_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
self.command(spi, Command::DISPLAY_REFRESH)?;
self.wait_until_idle();
Ok(())
}
fn update_and_display_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> {
self.update_frame(spi, buffer)?;
fn update_and_display_frame(
&mut self,
spi: &mut SPI,
buffer: &[u8],
delay: &mut DELAY,
) -> Result<(), SPI::Error> {
self.update_frame(spi, buffer, delay)?;
self.command(spi, Command::DISPLAY_REFRESH)?;
Ok(())
}
fn clear_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> {
self.wait_until_idle();
let color_value = self.color.get_byte_value();
@@ -267,14 +271,15 @@ where
}
}
impl<SPI, CS, BUSY, DC, RST> WaveshareThreeColorDisplay<SPI, CS, BUSY, DC, RST>
for EPD2in7b<SPI, CS, BUSY, DC, RST>
impl<SPI, CS, BUSY, DC, RST, DELAY> WaveshareThreeColorDisplay<SPI, CS, BUSY, DC, RST, DELAY>
for EPD2in7b<SPI, CS, BUSY, DC, RST, DELAY>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
DELAY: DelayMs<u8>,
{
fn update_color_frame(
&mut self,
@@ -322,13 +327,14 @@ where
}
}
impl<SPI, CS, BUSY, DC, RST> EPD2in7b<SPI, CS, BUSY, DC, RST>
impl<SPI, CS, BUSY, DC, RST, DELAY> EPD2in7b<SPI, CS, BUSY, DC, RST, DELAY>
where
SPI: Write<u8>,
CS: OutputPin,
BUSY: InputPin,
DC: OutputPin,
RST: OutputPin,
DELAY: DelayMs<u8>,
{
fn command(&mut self, spi: &mut SPI, command: Command) -> Result<(), SPI::Error> {
self.interface.cmd(spi, command)
@@ -357,7 +363,7 @@ where
}
fn wait_until_idle(&mut self) {
self.interface.wait_until_idle(IS_BUSY_LOW)
let _ = self.interface.wait_until_idle(IS_BUSY_LOW, None);
}
/// Refresh display for partial frame