diff --git a/card10-l0dable/src/framebuffer/mod.rs b/card10-l0dable/src/framebuffer/mod.rs index 8e7854626b9cbc6dfa89f1ce990297bb791bbbb3..663aaafffc81ece69185c2bbd54dd45426f6721b 100644 --- a/card10-l0dable/src/framebuffer/mod.rs +++ b/card10-l0dable/src/framebuffer/mod.rs @@ -3,7 +3,7 @@ use card10_sys::*; use core::mem::{transmute, uninitialized}; use core::ops::{Index, IndexMut}; -use embedded_graphics::pixelcolor::Rgb565; +use embedded_graphics::pixelcolor::{PixelColor, Rgb565}; use embedded_graphics::prelude::Pixel; use embedded_graphics::Drawing; @@ -76,10 +76,10 @@ impl<'d> IndexMut<(u16, u16)> for FrameBuffer<'d> { } /// `embedded-graphics` support -impl<'d> Drawing<Rgb565> for FrameBuffer<'d> { +impl<'d, C: PixelColor + Into<RawColor>> Drawing<C> for FrameBuffer<'d> { fn draw<T>(&mut self, item: T) where - T: IntoIterator<Item = Pixel<Rgb565>>, + T: IntoIterator<Item = Pixel<C>>, { for Pixel(coord, color) in item { let x = coord[0] as u16; @@ -145,9 +145,19 @@ impl RawColor { } } +impl PixelColor for RawColor {} + +/// Most similar format, just byte-swapped impl From<Rgb565> for RawColor { fn from(rgb: Rgb565) -> Self { let c = rgb.0; RawColor([(c >> 8) as u8, c as u8]) } } + +/// Dummy implementation required for impl Drawable +impl From<u8> for RawColor { + fn from(b: u8) -> Self { + RawColor([0, b]) + } +} diff --git a/rkanoid/src/main.rs b/rkanoid/src/main.rs index 043fe0d39559efd263bf1c7dee3ea13c10e6258f..0c5e91a0e8dd10e74551288ee749f8dab05bc23a 100644 --- a/rkanoid/src/main.rs +++ b/rkanoid/src/main.rs @@ -308,7 +308,7 @@ fn game(level: u16, mut score: u32) -> GameResult { // Ball fb.draw( Circle::new((ball_x, ball_y).into(), BALL_RADIUS) - .fill(Some((0x7f, 0x7f, 0xff).into())) + .fill(Some(RawColor::rgb8(0x7f, 0x7f, 0xff))) ); fb.send();