Added support for embedded-graphics

This commit is contained in:
Zac Wilson 2025-12-18 11:51:30 +00:00
parent fdec84b0a7
commit 78b6442fe3
4 changed files with 111 additions and 0 deletions

66
Cargo.lock generated
View file

@ -2,15 +2,81 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 4 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]] [[package]]
name = "embedded-hal" name = "embedded-hal"
version = "1.0.0" version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "361a90feb7004eca4019fb28352a9465666b24f840f5c3cddf0ff13920590b89" 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]] [[package]]
name = "zel-gdeq031t10" name = "zel-gdeq031t10"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"embedded-graphics",
"embedded-hal", "embedded-hal",
] ]

View file

@ -4,4 +4,8 @@ version = "0.1.0"
edition = "2024" edition = "2024"
[dependencies] [dependencies]
embedded-graphics = { version = "0.8.1", optional = true }
embedded-hal = "1.0.0" embedded-hal = "1.0.0"
[features]
embedded-graphics = ["dep:embedded-graphics"]

View 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,
}
}

View file

@ -5,6 +5,9 @@
//! **Note**: 9-bit SPI mode (where the data/command is designated with an extra bit for each byte) //! **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. //! 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::{ use embedded_hal::{
delay::DelayNs, delay::DelayNs,
digital::{InputPin, OutputPin}, digital::{InputPin, OutputPin},