Added support for embedded-graphics
This commit is contained in:
parent
fdec84b0a7
commit
78b6442fe3
4 changed files with 111 additions and 0 deletions
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,
|
||||
}
|
||||
}
|
||||
|
|
@ -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},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue