1 use embedded_graphics::{
3 geometry::{Point, Size},
5 raw::{RawData, RawU16},
9 style::{PrimitiveStyle, Styled},
13 pub struct FrameBuffer<'a> {
14 buf: &'a mut [[u16; 320]; 240],
17 impl<'a> FrameBuffer<'a> {
18 pub fn new(raw: &'a mut [[u16; 320]; 240]) -> Self {
24 pub fn inner(&self) -> &[u16] {
26 core::slice::from_raw_parts(self.buf.as_ptr().cast::<u16>(), (self.width() * self.height()) as usize)
30 fn width(&self) -> u32 {
34 fn height(&self) -> u32 {
35 self.buf[0].len() as u32
39 impl<'a> DrawTarget<Rgb565> for FrameBuffer<'a>
43 fn size(&self) -> Size {
44 Size::new(self.width(), self.height())
47 fn draw_pixel(&mut self, pixel: Pixel<Rgb565>) -> Result<(), Self::Error> {
48 let Pixel(pos, color) = pixel;
50 if pos.x < 0 || pos.y < 0 || pos.x >= self.width() as i32 || pos.y >= self.height() as i32 {
54 self.buf[pos.y as usize][pos.x as usize] = swap(RawU16::from(color).into_inner());
59 const fn swap(inp: u16) -> u16 {