Commit e0b6eb05 authored by Astro's avatar Astro
Browse files

l0dable: add framebuffer

parent db24f516
use super::bindings::*;
use super::framebuffer::FrameBuffer;
#[derive(Debug, Clone, Copy)]
#[repr(C)]
......@@ -125,6 +126,10 @@ impl Display {
epic_disp_circ(x, y, rad, color.0, fillstyle as u32, pixelsize);
}
}
pub fn framebuffer<'d>(&'d self) -> FrameBuffer<'d> {
FrameBuffer::uninitialized(self)
}
}
impl Drop for Display {
......
use core::mem::{transmute, uninitialized};
use core::ops::{Deref, DerefMut};
use crate::bindings::*;
use crate::{Color, Display};
pub struct FrameBuffer<'d> {
_display: &'d Display,
buffer: disp_framebuffer,
}
impl<'d> FrameBuffer<'d> {
pub fn uninitialized(display: &'d Display) -> Self {
FrameBuffer {
_display: display,
buffer: unsafe {
uninitialized()
},
}
}
pub fn send(&mut self) {
unsafe {
epic_disp_framebuffer(&mut self.buffer);
}
}
}
impl<'d> Deref for FrameBuffer<'d> {
type Target = [[Color; Display::W as usize]; Display::H as usize];
fn deref(&self) -> &Self::Target {
unsafe { transmute(&self.buffer.raw) }
}
}
impl<'d> DerefMut for FrameBuffer<'d> {
fn deref_mut(&mut self) -> &mut Self::Target {
unsafe { transmute(&mut self.buffer.raw) }
}
}
......@@ -70,6 +70,7 @@ mod os;
pub use os::*;
mod display;
pub use display::{Display, Color, LineStyle, FillStyle};
pub mod framebuffer;
mod buttons;
pub use buttons::Buttons;
pub mod uart;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment