-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a2f86b2
commit b682b00
Showing
6 changed files
with
157 additions
and
119 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[package] | ||
name = "epd_display" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
airquamon_domain = { path = "../airquamon_domain" } | ||
display_themes = { path = "../display_themes" } | ||
embedded-graphics = "0.8.1" | ||
embedded-hal = "1.0.0-rc.1" | ||
epd-waveshare = { path = "/home/brendan/dev/projects/epd-waveshare" } | ||
log = { version = "0.4.18" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
#![no_std] | ||
|
||
use epd_waveshare::{prelude::*, graphics}; | ||
use embedded_hal::spi::SpiDevice; | ||
use embedded_hal::delay::DelayUs; | ||
use embedded_graphics::prelude::*; | ||
use core::fmt; | ||
use airquamon_domain::Data; | ||
use display_themes::Theme; | ||
use log::info; | ||
|
||
pub trait ChromaticBuffer { | ||
fn bw_buffer(&self) -> &[u8]; | ||
fn chromatic_buffer(&self) -> &[u8]; | ||
} | ||
|
||
impl< | ||
const WIDTH: u32, | ||
const HEIGHT: u32, | ||
const BWRBIT: bool, | ||
const BYTECOUNT: usize, | ||
> ChromaticBuffer for graphics::Display<WIDTH, HEIGHT, BWRBIT, BYTECOUNT, TriColor> { | ||
|
||
fn bw_buffer(&self) -> &[u8] { | ||
self.bw_buffer() | ||
} | ||
|
||
fn chromatic_buffer(&self) -> &[u8] { | ||
self.chromatic_buffer() | ||
} | ||
} | ||
|
||
pub struct Display<SPI, EPD, DRAWTARGET, DELAY, THEME> | ||
where | ||
SPI: SpiDevice, | ||
EPD: WaveshareThreeColorDisplayV2<SPI, DELAY>, | ||
DRAWTARGET: DrawTarget<Color = TriColor> + ChromaticBuffer, | ||
DRAWTARGET::Error: fmt::Debug, | ||
DELAY: DelayUs, | ||
THEME: Theme<TriColor> | ||
|
||
{ | ||
spi: SPI, | ||
epd: EPD, | ||
draw_target: DRAWTARGET, | ||
delay: DELAY, | ||
theme: THEME, | ||
} | ||
|
||
impl<SPI, EPD, DRAWTARGET, DELAY, THEME> Display<SPI, EPD, DRAWTARGET, DELAY, THEME> | ||
where | ||
SPI: SpiDevice, | ||
EPD: WaveshareThreeColorDisplayV2<SPI, DELAY>, | ||
DRAWTARGET: DrawTarget<Color = TriColor> + ChromaticBuffer, | ||
DRAWTARGET::Error: fmt::Debug, | ||
DELAY: DelayUs, | ||
THEME: Theme<TriColor> { | ||
pub fn new(spi: SPI, epd: EPD, draw_target: DRAWTARGET, delay: DELAY, theme: THEME) -> Self { | ||
Self { | ||
spi, | ||
draw_target, | ||
epd, | ||
delay, | ||
theme, | ||
} | ||
} | ||
} | ||
|
||
pub trait DisplayTheme { | ||
|
||
type Error; | ||
|
||
fn draw(&mut self, data: &Data) -> Result<(), Self::Error>; | ||
} | ||
|
||
impl<SPI, EPD, DRAWTARGET, DELAY, THEME> DisplayTheme for Display<SPI, EPD, DRAWTARGET, DELAY, THEME> | ||
where | ||
SPI: SpiDevice, | ||
EPD: WaveshareThreeColorDisplayV2<SPI, DELAY>, | ||
SPI: SpiDevice, | ||
DRAWTARGET: DrawTarget<Color = TriColor> + ChromaticBuffer + OriginDimensions, | ||
DRAWTARGET::Error: fmt::Debug, | ||
DELAY: DelayUs, | ||
THEME: Theme<TriColor> | ||
{ | ||
type Error = SPI::Error; | ||
|
||
fn draw(&mut self, data: &Data) -> Result<(), Self::Error> { | ||
let _ = self.theme.draw(data, &mut self.draw_target); | ||
draw_to_epd(&mut self.spi, &mut self.epd, &mut self.draw_target, &mut self.delay)?; | ||
Ok(()) | ||
} | ||
} | ||
|
||
fn draw_to_epd<'a, SPI, EPD, BUFFER, DELAY>(spi: &mut SPI, epd: &mut EPD, buffer: &mut BUFFER, delay: &mut DELAY) -> Result<(), SPI::Error> | ||
where | ||
SPI: SpiDevice, | ||
EPD: WaveshareThreeColorDisplayV2<SPI, DELAY>, | ||
BUFFER: ChromaticBuffer, | ||
DELAY: DelayUs { | ||
info!("waking up display"); | ||
epd.wake_up(spi, delay)?; | ||
|
||
epd.wait_until_idle(spi, delay)?; | ||
|
||
|
||
info!("updating display frame"); | ||
epd.update_color_frame(spi, delay, buffer.bw_buffer(), buffer.chromatic_buffer())?; | ||
epd.display_frame(spi, delay)?; | ||
|
||
// Set the EPD to sleep | ||
epd.sleep(spi, delay)?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters