Compare commits
5 commits
05e927d0a8
...
78b6442fe3
| Author | SHA1 | Date | |
|---|---|---|---|
| 78b6442fe3 | |||
| fdec84b0a7 | |||
| 6e96359b44 | |||
| 32edbb8ce4 | |||
| 42e71fe3bd |
4 changed files with 141 additions and 9 deletions
66
Cargo.lock
generated
66
Cargo.lock
generated
|
|
@ -2,15 +2,81 @@
|
|||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
|
||||
|
||||
[[package]]
|
||||
name = "az"
|
||||
version = "1.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7b7e4c2464d97fe331d41de9d5db0def0a96f4d823b8b32a2efd503578988973"
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
|
||||
|
||||
[[package]]
|
||||
name = "embedded-graphics"
|
||||
version = "0.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0649998afacf6d575d126d83e68b78c0ab0e00ca2ac7e9b3db11b4cbe8274ef0"
|
||||
dependencies = [
|
||||
"az",
|
||||
"byteorder",
|
||||
"embedded-graphics-core",
|
||||
"float-cmp",
|
||||
"micromath",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "embedded-graphics-core"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ba9ecd261f991856250d2207f6d8376946cd9f412a2165d3b75bc87a0bc7a044"
|
||||
dependencies = [
|
||||
"az",
|
||||
"byteorder",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "embedded-hal"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "361a90feb7004eca4019fb28352a9465666b24f840f5c3cddf0ff13920590b89"
|
||||
|
||||
[[package]]
|
||||
name = "float-cmp"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "98de4bbd547a563b716d8dfa9aad1cb19bfab00f4fa09a6a4ed21dbcf44ce9c4"
|
||||
dependencies = [
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "micromath"
|
||||
version = "2.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c3c8dda44ff03a2f238717214da50f65d5a53b45cd213a7370424ffdb6fae815"
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zel-gdeq031t10"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"embedded-graphics",
|
||||
"embedded-hal",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -4,4 +4,8 @@ version = "0.1.0"
|
|||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
embedded-graphics = { version = "0.8.1", optional = true }
|
||||
embedded-hal = "1.0.0"
|
||||
|
||||
[features]
|
||||
embedded-graphics = ["dep:embedded-graphics"]
|
||||
|
|
|
|||
38
src/embedded_graphics_impl.rs
Normal file
38
src/embedded_graphics_impl.rs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
use embedded_graphics::{
|
||||
pixelcolor::BinaryColor,
|
||||
prelude::{DrawTarget, OriginDimensions, Size},
|
||||
};
|
||||
impl<PartialWindow: crate::ApplyPartialWindow> OriginDimensions
|
||||
for crate::DoubleFrame<PartialWindow>
|
||||
{
|
||||
fn size(&self) -> Size {
|
||||
Size {
|
||||
width: crate::EPD_WIDTH as u32,
|
||||
height: crate::EPD_HEIGHT as u32,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<PartialWindow: crate::ApplyPartialWindow> DrawTarget for crate::DoubleFrame<PartialWindow> {
|
||||
type Color = BinaryColor;
|
||||
|
||||
type Error = core::convert::Infallible;
|
||||
|
||||
fn draw_iter<I>(&mut self, pixels: I) -> Result<(), Self::Error>
|
||||
where
|
||||
I: IntoIterator<Item = embedded_graphics::Pixel<Self::Color>>,
|
||||
{
|
||||
for pixel in pixels {
|
||||
self.draw_pixel(pixel.0.x as u16, pixel.0.y as u16, convert_colour(pixel.1));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn convert_colour(colour: BinaryColor) -> crate::PixelColour {
|
||||
match colour {
|
||||
BinaryColor::Off => crate::PixelColour::Black,
|
||||
BinaryColor::On => crate::PixelColour::White,
|
||||
}
|
||||
}
|
||||
42
src/lib.rs
42
src/lib.rs
|
|
@ -5,6 +5,9 @@
|
|||
//! **Note**: 9-bit SPI mode (where the data/command is designated with an extra bit for each byte)
|
||||
//! is not supported by this driver. Only the mode with a dedicated data/command line is supported.
|
||||
|
||||
#[cfg(feature = "embedded-graphics")]
|
||||
mod embedded_graphics_impl;
|
||||
|
||||
use embedded_hal::{
|
||||
delay::DelayNs,
|
||||
digital::{InputPin, OutputPin},
|
||||
|
|
@ -64,12 +67,20 @@ pub struct DoubleFrame<PartialWindow> {
|
|||
partial_window: PartialWindow,
|
||||
}
|
||||
|
||||
/// The colour of a given pixel.
|
||||
///
|
||||
/// Since the GDEQ031T10 is pure black-and-white (no greyscale), this is just a two-state enum.S
|
||||
pub enum PixelColour {
|
||||
Black = 0,
|
||||
White = 1,
|
||||
}
|
||||
|
||||
pub trait ApplyParitalWindow: private::Sealed {
|
||||
/// A trait for partial window strategies for use with [DoubleFrame].
|
||||
///
|
||||
/// This trait is sealed, so the only strategies available are [NoPartialWindow]
|
||||
/// and [AutomaticPartialWindow].
|
||||
pub trait ApplyPartialWindow: private::Sealed {
|
||||
/// Applies the given window to the display so that its next update will only refresh part of the display.
|
||||
fn apply<
|
||||
BusyPin: InputPin,
|
||||
ResetPin: OutputPin,
|
||||
|
|
@ -81,22 +92,29 @@ pub trait ApplyParitalWindow: private::Sealed {
|
|||
display: &mut EPaperDisplay<BusyPin, ResetPin, DcPin, Spi, Delay>,
|
||||
);
|
||||
|
||||
/// Add a new bounding box which must be covered by the partial window.
|
||||
///
|
||||
/// Calls to this method accumulate, meaning all bounding boxes will be covered by the
|
||||
/// partial window until [ApplyPartialWindow::reset_partial_window] is called.
|
||||
fn update_partial_window(&mut self, min_x: u16, max_x: u16, min_y: u16, max_y: u16);
|
||||
|
||||
/// Resets the partial window to be empty.
|
||||
fn reset_partial_window(&mut self);
|
||||
}
|
||||
|
||||
mod private {
|
||||
pub(super) trait Sealed {}
|
||||
pub trait Sealed {}
|
||||
|
||||
impl Sealed for super::NoPartialWindow {}
|
||||
|
||||
impl Sealed for super::AutomaticPartialWindow {}
|
||||
}
|
||||
|
||||
/// A partial window strategy which doesn't do any window tracking and simply updates
|
||||
/// the entire display.
|
||||
pub struct NoPartialWindow;
|
||||
|
||||
impl ApplyParitalWindow for NoPartialWindow {
|
||||
impl ApplyPartialWindow for NoPartialWindow {
|
||||
fn apply<
|
||||
BusyPin: InputPin,
|
||||
ResetPin: OutputPin,
|
||||
|
|
@ -114,6 +132,8 @@ impl ApplyParitalWindow for NoPartialWindow {
|
|||
fn reset_partial_window(&mut self) {}
|
||||
}
|
||||
|
||||
/// A partial window strategy which tracks the bounding box of all changes made to the display
|
||||
/// since the last display update and only updates that region.
|
||||
pub struct AutomaticPartialWindow {
|
||||
min_x: u16,
|
||||
max_x: u16,
|
||||
|
|
@ -121,7 +141,7 @@ pub struct AutomaticPartialWindow {
|
|||
max_y: u16,
|
||||
}
|
||||
|
||||
impl ApplyParitalWindow for AutomaticPartialWindow {
|
||||
impl ApplyPartialWindow for AutomaticPartialWindow {
|
||||
fn apply<
|
||||
BusyPin: InputPin,
|
||||
ResetPin: OutputPin,
|
||||
|
|
@ -171,10 +191,6 @@ impl DoubleFrame<NoPartialWindow> {
|
|||
partial_window: NoPartialWindow,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn draw_pixel(&mut self, x: usize, y: usize, colour: PixelColour) {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl DoubleFrame<AutomaticPartialWindow> {
|
||||
|
|
@ -192,6 +208,12 @@ impl DoubleFrame<AutomaticPartialWindow> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<PartialWindow: ApplyPartialWindow> DoubleFrame<PartialWindow> {
|
||||
pub fn draw_pixel(&mut self, x: u16, y: u16, colour: PixelColour) {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl<BusyPin: InputPin, ResetPin: OutputPin, DcPin: OutputPin, Spi: SpiDevice, Delay: DelayNs>
|
||||
EPaperDisplay<BusyPin, ResetPin, DcPin, Spi, Delay>
|
||||
{
|
||||
|
|
@ -272,7 +294,7 @@ impl<BusyPin: InputPin, ResetPin: OutputPin, DcPin: OutputPin, Spi: SpiDevice, D
|
|||
self.wait_for_display();
|
||||
}
|
||||
|
||||
pub fn draw_full_frame<PartialWindow: ApplyParitalWindow>(&mut self, double_frame: &mut DoubleFrame<PartialWindow>) {
|
||||
pub fn draw_full_frame<PartialWindow: ApplyPartialWindow>(&mut self, double_frame: &mut DoubleFrame<PartialWindow>) {
|
||||
double_frame.partial_window.apply(self);
|
||||
self.write_command(0x10);
|
||||
for byte in double_frame.old.0 {
|
||||
|
|
@ -299,10 +321,12 @@ impl<BusyPin: InputPin, ResetPin: OutputPin, DcPin: OutputPin, Spi: SpiDevice, D
|
|||
self.write_data(0xA5);
|
||||
}
|
||||
|
||||
/// Enables partial updates based on whichever strategy was chosen at time of display initialisation.
|
||||
pub fn enable_partial_mode(&mut self) {
|
||||
self.write_command(0x91);
|
||||
}
|
||||
|
||||
/// Disable partial updates; all updates will refresh the entire display.
|
||||
pub fn disable_partial_mode(&mut self) {
|
||||
self.write_command(0x92);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue