From 7c815376aaa1109c578a5ea9c81817409a7c250b Mon Sep 17 00:00:00 2001 From: andber1 <82754113+andber1@users.noreply.github.com> Date: Tue, 29 Oct 2024 21:27:59 +0100 Subject: [PATCH 1/2] Implement PixelColor for Color and TriColor --- src/color.rs | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/color.rs b/src/color.rs index da0b00e6..c54a0573 100644 --- a/src/color.rs +++ b/src/color.rs @@ -288,9 +288,21 @@ impl From for Color { } } +#[cfg(feature = "graphics")] +impl From for Color { + fn from(b: embedded_graphics_core::pixelcolor::raw::RawU1) -> Self { + use embedded_graphics_core::prelude::RawData; + if b.into_inner() == 0 { + Color::White + } else { + Color::Black + } + } +} + #[cfg(feature = "graphics")] impl PixelColor for Color { - type Raw = (); + type Raw = embedded_graphics_core::pixelcolor::raw::RawU1; } #[cfg(feature = "graphics")] @@ -351,9 +363,23 @@ impl TriColor { } } +#[cfg(feature = "graphics")] +impl From for TriColor { + fn from(b: embedded_graphics_core::pixelcolor::raw::RawU2) -> Self { + use embedded_graphics_core::prelude::RawData; + if b.into_inner() == 0b00 { + TriColor::White + } else if b.into_inner() == 0b01 { + TriColor::Black + } else { + TriColor::Chromatic + } + } +} + #[cfg(feature = "graphics")] impl PixelColor for TriColor { - type Raw = (); + type Raw = embedded_graphics_core::pixelcolor::raw::RawU2; } #[cfg(feature = "graphics")] From b01193a11847d7df277062dd6815a51b77b1981e Mon Sep 17 00:00:00 2001 From: andber1 <82754113+andber1@users.noreply.github.com> Date: Tue, 29 Oct 2024 21:57:35 +0100 Subject: [PATCH 2/2] Remove unnecessary color_converted in example --- examples/epd7in5_v2.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/epd7in5_v2.rs b/examples/epd7in5_v2.rs index b2ba074f..61a1583f 100644 --- a/examples/epd7in5_v2.rs +++ b/examples/epd7in5_v2.rs @@ -8,7 +8,6 @@ use embedded_graphics::{ primitives::{Circle, Line, PrimitiveStyleBuilder}, text::{Baseline, Text, TextStyleBuilder}, }; -use embedded_graphics_core::pixelcolor::{BinaryColor, PixelColor}; use embedded_hal::delay::DelayNs; #[cfg(feature = "graphics")] use epd_waveshare::{color::Color, epd7in5_v2::*, graphics::DisplayRotation, prelude::*}; @@ -147,9 +146,9 @@ fn main() -> Result<(), SPIError> { println!("Draw Ferris"); display.clear(Color::Black).ok(); let data = include_bytes!("./assets/ferris.raw"); - let raw_image = ImageRaw::::new(data, 460); + let raw_image = ImageRaw::::new(data, 460); let image = Image::new(&raw_image, Point::zero()); - image.draw(&mut display.color_converted()).unwrap(); + image.draw(&mut display).unwrap(); epd7in5.update_and_display_frame(&mut spi, display.buffer(), &mut delay)?; // Clear and sleep