Skip to content
Snippets Groups Projects
Commit eb7a8bb1 authored by Astro's avatar Astro :gear:
Browse files

l0dable: impl PixelColor for RawColor

parent 29fb4b24
No related branches found
No related tags found
No related merge requests found
...@@ -3,7 +3,7 @@ use card10_sys::*; ...@@ -3,7 +3,7 @@ use card10_sys::*;
use core::mem::{transmute, uninitialized}; use core::mem::{transmute, uninitialized};
use core::ops::{Index, IndexMut}; use core::ops::{Index, IndexMut};
use embedded_graphics::pixelcolor::Rgb565; use embedded_graphics::pixelcolor::{PixelColor, Rgb565};
use embedded_graphics::prelude::Pixel; use embedded_graphics::prelude::Pixel;
use embedded_graphics::Drawing; use embedded_graphics::Drawing;
...@@ -76,10 +76,10 @@ impl<'d> IndexMut<(u16, u16)> for FrameBuffer<'d> { ...@@ -76,10 +76,10 @@ impl<'d> IndexMut<(u16, u16)> for FrameBuffer<'d> {
} }
/// `embedded-graphics` support /// `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) fn draw<T>(&mut self, item: T)
where where
T: IntoIterator<Item = Pixel<Rgb565>>, T: IntoIterator<Item = Pixel<C>>,
{ {
for Pixel(coord, color) in item { for Pixel(coord, color) in item {
let x = coord[0] as u16; let x = coord[0] as u16;
...@@ -145,9 +145,19 @@ impl RawColor { ...@@ -145,9 +145,19 @@ impl RawColor {
} }
} }
impl PixelColor for RawColor {}
/// Most similar format, just byte-swapped
impl From<Rgb565> for RawColor { impl From<Rgb565> for RawColor {
fn from(rgb: Rgb565) -> Self { fn from(rgb: Rgb565) -> Self {
let c = rgb.0; let c = rgb.0;
RawColor([(c >> 8) as u8, c as u8]) 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])
}
}
...@@ -308,7 +308,7 @@ fn game(level: u16, mut score: u32) -> GameResult { ...@@ -308,7 +308,7 @@ fn game(level: u16, mut score: u32) -> GameResult {
// Ball // Ball
fb.draw( fb.draw(
Circle::new((ball_x, ball_y).into(), BALL_RADIUS) Circle::new((ball_x, ball_y).into(), BALL_RADIUS)
.fill(Some((0x7f, 0x7f, 0xff).into())) .fill(Some(RawColor::rgb8(0x7f, 0x7f, 0xff)))
); );
fb.send(); fb.send();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment