diff --git a/core/embed/rust/src/trezorhal/display.rs b/core/embed/rust/src/trezorhal/display.rs index c614cb5556..5c3b51eb0c 100644 --- a/core/embed/rust/src/trezorhal/display.rs +++ b/core/embed/rust/src/trezorhal/display.rs @@ -55,7 +55,7 @@ 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, @@ -63,6 +63,10 @@ pub fn get_frame_buffer() -> (&'static mut [u8], usize) { 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, @@ -70,5 +74,5 @@ pub fn get_frame_buffer() -> (&'static mut [u8], usize) { ) }; - (fb, fb_info.stride) + Some((fb, fb_info.stride)) } diff --git a/core/embed/rust/src/ui/shape/display/fb_mono8.rs b/core/embed/rust/src/ui/shape/display/fb_mono8.rs index 42cd43fc29..7e8cd6c144 100644 --- a/core/embed/rust/src/ui/shape/display/fb_mono8.rs +++ b/core/embed/rust/src/ui/shape/display/fb_mono8.rs @@ -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), diff --git a/core/embed/rust/src/ui/shape/display/fb_rgb565.rs b/core/embed/rust/src/ui/shape/display/fb_rgb565.rs index 6c8600fee9..221b6125de 100644 --- a/core/embed/rust/src/ui/shape/display/fb_rgb565.rs +++ b/core/embed/rust/src/ui/shape/display/fb_rgb565.rs @@ -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), diff --git a/core/embed/rust/src/ui/shape/display/fb_rgba8888.rs b/core/embed/rust/src/ui/shape/display/fb_rgba8888.rs index 78975a198a..15d5303555 100644 --- a/core/embed/rust/src/ui/shape/display/fb_rgba8888.rs +++ b/core/embed/rust/src/ui/shape/display/fb_rgba8888.rs @@ -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),