Skip to content

Commit

Permalink
fixup! feat(core): add basic support for efficient frame buffer graphics
Browse files Browse the repository at this point in the history
  • Loading branch information
TychoVrahe committed Oct 4, 2023
1 parent 6569e78 commit c37f89d
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions core/embed/rust/src/trezorhal/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ pub use ffi::{
DISPLAY_FRAMEBUFFER_WIDTH,
};

#[cfg(all(feature = "framebuffer", not(feature = "framebuffer32bit")))]
#[derive(Copy, Clone)]
pub struct FrameBuffer(*mut u16);

#[cfg(all(feature = "framebuffer", feature = "framebuffer32bit"))]
#[derive(Copy, Clone)]
pub struct FrameBuffer(*mut u32);

#[derive(PartialEq, Debug, Eq, FromPrimitive, Clone, Copy)]
pub enum ToifFormat {
FullColorBE = ffi::toif_format_t_TOIF_FULL_COLOR_BE as _,
Expand Down Expand Up @@ -89,8 +97,8 @@ pub fn pixeldata(c: u16) {
}

#[cfg(feature = "framebuffer")]
pub fn get_fb_addr() -> u32 {
unsafe { ffi::display_get_fb_addr() as u32 }
pub fn get_fb_addr() -> FrameBuffer {
unsafe { FrameBuffer(ffi::display_get_fb_addr() as _) }
}

#[inline(always)]
Expand All @@ -104,27 +112,25 @@ pub fn pixeldata(c: u16) {

#[inline(always)]
#[cfg(all(feature = "framebuffer", not(feature = "framebuffer32bit")))]
pub fn pixel(fb: u32, x: i16, y: i16, c: u16) {
pub fn pixel(fb: FrameBuffer, x: i16, y: i16, c: u16) {
unsafe {
let addr = fb
+ ((y as u32 + DISPLAY_FRAMEBUFFER_OFFSET_Y) * DISPLAY_FRAMEBUFFER_WIDTH
+ (x as u32 + DISPLAY_FRAMEBUFFER_OFFSET_X))
* 2;
let ptr = addr as *mut u16;
ptr.write_volatile(c);
let addr = fb.0.offset(
((y as u32 + DISPLAY_FRAMEBUFFER_OFFSET_Y) * DISPLAY_FRAMEBUFFER_WIDTH
+ (x as u32 + DISPLAY_FRAMEBUFFER_OFFSET_X)) as isize,
);
addr.write_volatile(c);
}
}

#[inline(always)]
#[cfg(all(feature = "framebuffer", feature = "framebuffer32bit"))]
pub fn pixel(fb: u32, x: i16, y: i16, c: u32) {
pub fn pixel(fb: FrameBuffer, x: i16, y: i16, c: u32) {
unsafe {
let addr = fb
+ ((y as u32 + DISPLAY_FRAMEBUFFER_OFFSET_Y) * DISPLAY_FRAMEBUFFER_WIDTH
+ (x as u32 + DISPLAY_FRAMEBUFFER_OFFSET_X))
* 4;
let ptr = addr as *mut u32;
ptr.write_volatile(c);
let addr = fb.0.offset(
((y as u32 + DISPLAY_FRAMEBUFFER_OFFSET_Y) * DISPLAY_FRAMEBUFFER_WIDTH
+ (x as u32 + DISPLAY_FRAMEBUFFER_OFFSET_X)) as isize,
);
addr.write_volatile(c);
}
}

Expand Down

0 comments on commit c37f89d

Please sign in to comment.