diff --git a/core/embed/rust/src/trezorhal/display.rs b/core/embed/rust/src/trezorhal/display.rs index 27775fe927..a798b3de12 100644 --- a/core/embed/rust/src/trezorhal/display.rs +++ b/core/embed/rust/src/trezorhal/display.rs @@ -185,7 +185,12 @@ pub fn clear() { #[cfg(feature = "xframebuffer")] pub fn get_frame_buffer() -> (&'static mut [u8], usize) { - let fb_info = unsafe { ffi::display_get_frame_buffer() }; + let mut fb_info = ffi::display_fb_info_t { + ptr: ptr::null_mut(), + stride: 0, + }; + + unsafe { ffi::display_get_frame_buffer(&mut fb_info) }; let fb = unsafe { core::slice::from_raw_parts_mut( diff --git a/core/embed/trezorhal/stm32f4/syscall_dispatch.c b/core/embed/trezorhal/stm32f4/syscall_dispatch.c index bd80c746c3..a6fd697ec2 100644 --- a/core/embed/trezorhal/stm32f4/syscall_dispatch.c +++ b/core/embed/trezorhal/stm32f4/syscall_dispatch.c @@ -177,8 +177,8 @@ __attribute((no_stack_protector)) void syscall_handler(uint32_t *args, #if XFRAMEBUFFER case SYSCALL_DISPLAY_GET_FB_INFO: { - display_fb_info_t *info = (display_fb_info_t *)args[0]; - *info = display_get_frame_buffer(); + display_fb_info_t *fb = (display_fb_info_t *)args[0]; + args[0] = (uint32_t)display_get_frame_buffer(fb); } break; #else case SYSCALL_DISPLAY_WAIT_FOR_SYNC: { diff --git a/core/embed/trezorhal/stm32f4/syscall_stubs.c b/core/embed/trezorhal/stm32f4/syscall_stubs.c index 877d7ec938..792523f6df 100644 --- a/core/embed/trezorhal/stm32f4/syscall_stubs.c +++ b/core/embed/trezorhal/stm32f4/syscall_stubs.c @@ -148,10 +148,8 @@ int display_get_orientation(void) { #ifdef XFRAMEBUFFER -display_fb_info_t display_get_frame_buffer(void) { - display_fb_info_t info; - syscall_invoke1((uint32_t)&info, SYSCALL_DISPLAY_GET_FB_INFO); - return info; +bool display_get_frame_buffer(display_fb_info_t *fb) { + return (bool)syscall_invoke1((uint32_t)fb, SYSCALL_DISPLAY_GET_FB_INFO); } #else // XFRAMEBUFFER diff --git a/core/embed/trezorhal/stm32f4/xdisplay/st-7789/display_fb.c b/core/embed/trezorhal/stm32f4/xdisplay/st-7789/display_fb.c index 8e5fecb7d2..b9580fd633 100644 --- a/core/embed/trezorhal/stm32f4/xdisplay/st-7789/display_fb.c +++ b/core/embed/trezorhal/stm32f4/xdisplay/st-7789/display_fb.c @@ -144,15 +144,13 @@ void DISPLAY_TE_INTERRUPT_HANDLER(void) { } #endif -display_fb_info_t display_get_frame_buffer(void) { +bool display_get_frame_buffer(display_fb_info_t *fb) { display_driver_t *drv = &g_display_driver; if (!drv->initialized) { - display_fb_info_t fb = { - .ptr = NULL, - .stride = 0, - }; - return fb; + fb->ptr = NULL; + fb->stride = 0; + return false; } frame_buffer_state_t state; @@ -177,12 +175,10 @@ display_fb_info_t display_get_frame_buffer(void) { drv->queue.entry[drv->queue.wix] = FB_STATE_PREPARING; - display_fb_info_t fb = { - .ptr = get_fb_ptr(drv->queue.wix), - .stride = DISPLAY_RESX * sizeof(uint16_t), - }; + fb->ptr = get_fb_ptr(drv->queue.wix); + fb->stride = DISPLAY_RESX * sizeof(uint16_t); - return fb; + return true; } // Copies the frame buffer with the given index to the display @@ -289,9 +285,9 @@ void display_ensure_refreshed(void) { } void display_fill(const gfx_bitblt_t *bb) { - display_fb_info_t fb = display_get_frame_buffer(); + display_fb_info_t fb; - if (fb.ptr == NULL) { + if (!display_get_frame_buffer(&fb)) { return; } @@ -303,9 +299,9 @@ void display_fill(const gfx_bitblt_t *bb) { } void display_copy_rgb565(const gfx_bitblt_t *bb) { - display_fb_info_t fb = display_get_frame_buffer(); + display_fb_info_t fb; - if (fb.ptr == NULL) { + if (!display_get_frame_buffer(&fb)) { return; } @@ -317,9 +313,9 @@ void display_copy_rgb565(const gfx_bitblt_t *bb) { } void display_copy_mono1p(const gfx_bitblt_t *bb) { - display_fb_info_t fb = display_get_frame_buffer(); + display_fb_info_t fb; - if (fb.ptr == NULL) { + if (!display_get_frame_buffer(&fb)) { return; } @@ -331,9 +327,9 @@ void display_copy_mono1p(const gfx_bitblt_t *bb) { } void display_copy_mono4(const gfx_bitblt_t *bb) { - display_fb_info_t fb = display_get_frame_buffer(); + display_fb_info_t fb; - if (fb.ptr == NULL) { + if (!display_get_frame_buffer(&fb)) { return; } diff --git a/core/embed/trezorhal/stm32f4/xdisplay/stm32f429i-disc1/display_driver.c b/core/embed/trezorhal/stm32f4/xdisplay/stm32f429i-disc1/display_driver.c index 1198f897b8..8030eb2b30 100644 --- a/core/embed/trezorhal/stm32f4/xdisplay/stm32f429i-disc1/display_driver.c +++ b/core/embed/trezorhal/stm32f4/xdisplay/stm32f429i-disc1/display_driver.c @@ -123,21 +123,17 @@ int display_get_orientation(void) { return drv->orientation_angle; } -display_fb_info_t display_get_frame_buffer(void) { +bool display_get_frame_buffer(display_fb_info_t *fb) { display_driver_t *drv = &g_display_driver; if (!drv->initialized) { - display_fb_info_t fb = { - .ptr = NULL, - .stride = 0, - }; - return fb; + fb->ptr = NULL; + fb->stride = 0; + return false; } else { - display_fb_info_t fb = { - .ptr = (void *)drv->framebuf, - .stride = DISPLAY_RESX * sizeof(uint16_t), - }; - return fb; + fb->ptr = (void *)drv->framebuf; + fb->stride = DISPLAY_RESX * sizeof(uint16_t); + return true; } } diff --git a/core/embed/trezorhal/stm32f4/xdisplay/ug-2828/display_driver.c b/core/embed/trezorhal/stm32f4/xdisplay/ug-2828/display_driver.c index dfdf9041c8..bf924ad098 100644 --- a/core/embed/trezorhal/stm32f4/xdisplay/ug-2828/display_driver.c +++ b/core/embed/trezorhal/stm32f4/xdisplay/ug-2828/display_driver.c @@ -390,21 +390,17 @@ int display_get_orientation(void) { return drv->orientation_angle; } -display_fb_info_t display_get_frame_buffer(void) { +bool display_get_frame_buffer(display_fb_info_t *fb) { display_driver_t *drv = &g_display_driver; if (!drv->initialized) { - const static display_fb_info_t fb = { - .ptr = NULL, - .stride = 0, - }; - return fb; + fb->ptr = NULL; + fb->stride = 0; + return false; } else { - display_fb_info_t fb = { - .ptr = &drv->framebuf[0], - .stride = DISPLAY_RESX, - }; - return fb; + fb->ptr = &drv->framebuf[0]; + fb->stride = DISPLAY_RESX; + return true; } } diff --git a/core/embed/trezorhal/stm32f4/xdisplay/vg-2864/display_driver.c b/core/embed/trezorhal/stm32f4/xdisplay/vg-2864/display_driver.c index bdcf47157b..5ed52592b5 100644 --- a/core/embed/trezorhal/stm32f4/xdisplay/vg-2864/display_driver.c +++ b/core/embed/trezorhal/stm32f4/xdisplay/vg-2864/display_driver.c @@ -359,21 +359,17 @@ int display_get_orientation(void) { return drv->orientation_angle; } -display_fb_info_t display_get_frame_buffer(void) { +bool display_get_frame_buffer(display_fb_info_t *fb) { display_driver_t *drv = &g_display_driver; if (!drv->initialized) { - static const display_fb_info_t fb = { - .ptr = NULL, - .stride = 0, - }; - return fb; + fb->ptr = NULL; + fb->stride = 0; + return false; } else { - display_fb_info_t fb = { - .ptr = &drv->framebuf[0], - .stride = DISPLAY_RESX, - }; - return fb; + fb->ptr = &drv->framebuf[0]; + fb->stride = DISPLAY_RESX; + return true; } } @@ -395,9 +391,9 @@ void display_refresh(void) { } void display_fill(const gfx_bitblt_t *bb) { - display_fb_info_t fb = display_get_frame_buffer(); + display_fb_info_t fb; - if (fb.ptr == NULL) { + if (!display_get_frame_buffer(&fb)) { return; } @@ -409,9 +405,9 @@ void display_fill(const gfx_bitblt_t *bb) { } void display_copy_mono1p(const gfx_bitblt_t *bb) { - display_fb_info_t fb = display_get_frame_buffer(); + display_fb_info_t fb; - if (fb.ptr == NULL) { + if (!display_get_frame_buffer(&fb)) { return; } diff --git a/core/embed/trezorhal/stm32u5/xdisplay/stm32u5a9j-dk/display_driver.c b/core/embed/trezorhal/stm32u5/xdisplay/stm32u5a9j-dk/display_driver.c index 714f6ae30f..6bb01934a2 100644 --- a/core/embed/trezorhal/stm32u5/xdisplay/stm32u5a9j-dk/display_driver.c +++ b/core/embed/trezorhal/stm32u5/xdisplay/stm32u5a9j-dk/display_driver.c @@ -161,9 +161,9 @@ int display_get_orientation(void) { } void display_fill(const gfx_bitblt_t *bb) { - display_fb_info_t fb = display_get_frame_buffer(); + display_fb_info_t fb; - if (fb.ptr == NULL) { + if (!display_get_frame_buffer(&fb)) { return; } @@ -175,9 +175,9 @@ void display_fill(const gfx_bitblt_t *bb) { } void display_copy_rgb565(const gfx_bitblt_t *bb) { - display_fb_info_t fb = display_get_frame_buffer(); + display_fb_info_t fb; - if (fb.ptr == NULL) { + if (!display_get_frame_buffer(&fb)) { return; } @@ -189,9 +189,9 @@ void display_copy_rgb565(const gfx_bitblt_t *bb) { } void display_copy_mono1p(const gfx_bitblt_t *bb) { - display_fb_info_t fb = display_get_frame_buffer(); + display_fb_info_t fb; - if (fb.ptr == NULL) { + if (!display_get_frame_buffer(&fb)) { return; } @@ -203,9 +203,9 @@ void display_copy_mono1p(const gfx_bitblt_t *bb) { } void display_copy_mono4(const gfx_bitblt_t *bb) { - display_fb_info_t fb = display_get_frame_buffer(); + display_fb_info_t fb; - if (fb.ptr == NULL) { + if (!display_get_frame_buffer(&fb)) { return; } diff --git a/core/embed/trezorhal/stm32u5/xdisplay/stm32u5a9j-dk/display_fb.c b/core/embed/trezorhal/stm32u5/xdisplay/stm32u5a9j-dk/display_fb.c index 7d96ea80a6..1ca991fbe8 100644 --- a/core/embed/trezorhal/stm32u5/xdisplay/stm32u5a9j-dk/display_fb.c +++ b/core/embed/trezorhal/stm32u5/xdisplay/stm32u5a9j-dk/display_fb.c @@ -40,15 +40,13 @@ ALIGN_32BYTES(uint32_t physical_frame_buffer_1[PHYSICAL_FRAME_BUFFER_SIZE]); __attribute__((section(".framebuffer_select"))) uint32_t current_frame_buffer = 0; -display_fb_info_t display_get_frame_buffer(void) { +bool display_get_frame_buffer(display_fb_info_t *fb) { display_driver_t *drv = &g_display_driver; if (!drv->initialized) { - display_fb_info_t fb = { - .ptr = NULL, - .stride = 0, - }; - return fb; + fb->ptr = NULL; + fb->stride = 0; + return false; } uintptr_t addr; @@ -66,12 +64,10 @@ display_fb_info_t display_get_frame_buffer(void) { addr += (480 - DISPLAY_RESY) / 2 * sizeof(uint32_t); addr += (480 - DISPLAY_RESX) / 2 * fb_stride; - display_fb_info_t fb = { - .ptr = (void *)addr, - .stride = fb_stride, - }; + fb->ptr = (void *)addr; + fb->stride = fb_stride; - return fb; + return true; } void display_refresh(void) { diff --git a/core/embed/trezorhal/unix/display_driver.c b/core/embed/trezorhal/unix/display_driver.c index 5a23218264..e74ce83082 100644 --- a/core/embed/trezorhal/unix/display_driver.c +++ b/core/embed/trezorhal/unix/display_driver.c @@ -245,28 +245,22 @@ int display_get_orientation(void) { } #ifdef XFRAMEBUFFER -display_fb_info_t display_get_frame_buffer(void) { +bool display_get_frame_buffer(display_fb_info_t *fb) { display_driver_t *drv = &g_display_driver; if (!drv->initialized) { - display_fb_info_t fb = { - .ptr = NULL, - .stride = 0, - }; - return fb; + fb->ptr = NULL; + fb->stride = 0; + return false; } else { #ifdef DISPLAY_MONO - display_fb_info_t fb = { - .ptr = drv->mono_framebuf, - .stride = DISPLAY_RESX, - }; + fb->ptr = drv->mono_framebuf; + fb->stride = DISPLAY_RESX; #else - display_fb_info_t fb = { - .ptr = drv->buffer->pixels, - .stride = DISPLAY_RESX * sizeof(uint16_t), - }; + fb->ptr = drv->buffer->pixels; + fb->stride = DISPLAY_RESX * sizeof(uint16_t); #endif - return fb; + return true; } } diff --git a/core/embed/trezorhal/xdisplay.h b/core/embed/trezorhal/xdisplay.h index 472c5a472c..faf9edacaa 100644 --- a/core/embed/trezorhal/xdisplay.h +++ b/core/embed/trezorhal/xdisplay.h @@ -114,7 +114,9 @@ typedef struct { // // If framebuffer is not available yet due to display refreshing etc., // the function may block until the buffer is ready to write. -display_fb_info_t display_get_frame_buffer(void); +// +// Return `false` if the framebuffer is not available. +bool display_get_frame_buffer(display_fb_info_t *fb); #else // XFRAMEBUFFER