1 use embedded_graphics::{
5 raw::{RawData, RawU16},
11 pub struct FrameBuffer<'a> {
12 buf: &'a mut [[u16; 320]; 240],
16 impl<'a> FrameBuffer<'a> {
17 pub fn new(raw: &'a mut [[u16; 320]; 240]) -> Self {
24 pub fn inner(&mut self) -> Option<&[u16]> {
28 core::slice::from_raw_parts(
29 self.buf.as_ptr().cast::<u16>(),
30 (self.width() * self.height()) as usize,
38 fn width(&self) -> u32 {
39 self.buf[0].len() as u32
42 fn height(&self) -> u32 {
47 impl<'a> DrawTarget<Rgb565> for FrameBuffer<'a> {
50 fn size(&self) -> Size {
51 Size::new(self.width(), self.height())
54 fn draw_pixel(&mut self, pixel: Pixel<Rgb565>) -> Result<(), Self::Error> {
55 let Pixel(pos, color) = pixel;
57 if pos.x < 0 || pos.y < 0 || pos.x >= self.width() as i32 || pos.y >= self.height() as i32 {
61 self.buf[pos.y as usize][pos.x as usize] = swap(RawU16::from(color).into_inner());
66 const fn swap(inp: u16) -> u16 {
67 (inp & 0x00FF) << 8 | (inp & 0xFF00) >> 8