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

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)
//! 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},