Skip to content

Commit

Permalink
fix(core): resolve crashes when running without display or with unini…
Browse files Browse the repository at this point in the history
…tialized display

[no changelog]
  • Loading branch information
TychoVrahe committed Dec 11, 2024
1 parent e6802bd commit 0d3407b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
8 changes: 6 additions & 2 deletions core/embed/rust/src/trezorhal/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,24 @@ pub fn refresh() {
}

#[cfg(feature = "framebuffer")]
pub fn get_frame_buffer() -> (&'static mut [u8], usize) {
pub fn get_frame_buffer() -> Option<(&'static mut [u8], usize)> {
let mut fb_info = ffi::display_fb_info_t {
ptr: ptr::null_mut(),
stride: 0,
};

unsafe { ffi::display_get_frame_buffer(&mut fb_info) };

if fb_info.ptr.is_null() {
return None;
}

let fb = unsafe {
core::slice::from_raw_parts_mut(
fb_info.ptr as *mut u8,
DISPLAY_RESY as usize * fb_info.stride,
)
};

(fb, fb_info.stride)
Some((fb, fb_info.stride))
}
8 changes: 7 additions & 1 deletion core/embed/rust/src/ui/shape/display/fb_mono8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ where

let cache = DrawingCache::new(bump, bump);

let (fb, fb_stride) = display::get_frame_buffer();
let fb_info = display::get_frame_buffer();

if fb_info.is_none() {
return;
}

let (fb, fb_stride) = fb_info.unwrap();

let mut canvas = unwrap!(Mono8Canvas::new(
Offset::new(width, height),
Expand Down
8 changes: 7 additions & 1 deletion core/embed/rust/src/ui/shape/display/fb_rgb565.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ where

let cache = DrawingCache::new(bump_a, bump_b);

let (fb, fb_stride) = display::get_frame_buffer();
let fb_info = display::get_frame_buffer();

if fb_info.is_none() {
return;
}

let (fb, fb_stride) = fb_info.unwrap();

let mut canvas = unwrap!(Rgb565Canvas::new(
Offset::new(width, height),
Expand Down
8 changes: 7 additions & 1 deletion core/embed/rust/src/ui/shape/display/fb_rgba8888.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ where

let cache = DrawingCache::new(bump_a, bump_b);

let (fb, fb_stride) = display::get_frame_buffer();
let fb_info = display::get_frame_buffer();

if fb_info.is_none() {
return;
}

let (fb, fb_stride) = fb_info.unwrap();

let mut canvas = unwrap!(Rgba8888Canvas::new(
Offset::new(width, height),
Expand Down

0 comments on commit 0d3407b

Please sign in to comment.