1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-30 01:58:11 +00:00

fix(core): fix framebuffer switching, was too fast so the change was sometimes not visible

[no changelog]
This commit is contained in:
tychovrahe 2024-05-23 08:48:26 +02:00 committed by TychoVrahe
parent 88078db700
commit 0c4b1d6213
5 changed files with 61 additions and 26 deletions

View File

@ -22,4 +22,6 @@ void bg_copy_wait(void);
*/
void bg_copy_start_const_out_8(const uint8_t *src, uint8_t *dst, size_t size);
void bg_copy_abort(void);
#endif

View File

@ -84,7 +84,7 @@ void display_reinit(void) {
void display_finish_actions(void) {
#ifdef XFRAMEBUFFER
#ifndef BOARDLOADER
bg_copy_wait();
wait_for_fb_switch();
#endif
#endif
}

View File

@ -63,38 +63,35 @@ void display_physical_fb_clear(void) {
}
#ifndef BOARDLOADER
static volatile bool pending_fb_switch = false;
static volatile uint16_t pending_fb_switch = 0;
static volatile uint32_t last_fb_update_time = 0;
#endif
#ifndef BOARDLOADER
void DISPLAY_TE_INTERRUPT_HANDLER(void) {
HAL_NVIC_DisableIRQ(DISPLAY_TE_INTERRUPT_NUM);
if (current_frame_buffer == 1) {
bg_copy_start_const_out_8((uint8_t *)physical_frame_buffer_1,
(uint8_t *)DISPLAY_DATA_ADDRESS,
DISPLAY_RESX * DISPLAY_RESY * 2);
if (pending_fb_switch == 1) {
if (current_frame_buffer == 1) {
bg_copy_start_const_out_8((uint8_t *)physical_frame_buffer_1,
(uint8_t *)DISPLAY_DATA_ADDRESS,
DISPLAY_RESX * DISPLAY_RESY * 2);
} else {
bg_copy_start_const_out_8((uint8_t *)physical_frame_buffer_0,
(uint8_t *)DISPLAY_DATA_ADDRESS,
DISPLAY_RESX * DISPLAY_RESY * 2);
}
last_fb_update_time = HAL_GetTick();
pending_fb_switch = 2;
} else if (pending_fb_switch == 2) {
HAL_NVIC_DisableIRQ(DISPLAY_TE_INTERRUPT_NUM);
pending_fb_switch = 0;
} else {
bg_copy_start_const_out_8((uint8_t *)physical_frame_buffer_0,
(uint8_t *)DISPLAY_DATA_ADDRESS,
DISPLAY_RESX * DISPLAY_RESY * 2);
HAL_NVIC_DisableIRQ(DISPLAY_TE_INTERRUPT_NUM);
pending_fb_switch = 0;
}
pending_fb_switch = false;
last_fb_update_time = HAL_GetTick();
__HAL_GPIO_EXTI_CLEAR_FLAG(DISPLAY_TE_PIN);
}
static void wait_for_fb_switch(void) {
while (pending_fb_switch) {
__WFI();
}
bg_copy_wait();
}
#endif
static void copy_fb_to_display(const uint16_t *fb) {
for (int i = 0; i < DISPLAY_RESX * DISPLAY_RESY; i++) {
// 2 bytes per pixel because we're using RGB 5-6-5 format
@ -102,6 +99,25 @@ static void copy_fb_to_display(const uint16_t *fb) {
}
}
void wait_for_fb_switch(void) {
if (is_mode_handler()) {
if (pending_fb_switch != 0) {
if (current_frame_buffer == 0) {
copy_fb_to_display((uint16_t *)physical_frame_buffer_1);
} else {
copy_fb_to_display((uint16_t *)physical_frame_buffer_0);
}
pending_fb_switch = 0;
}
} else {
while (pending_fb_switch != 0) {
__WFI();
}
bg_copy_wait();
}
}
#endif
static void switch_fb_manually(void) {
// sync with the panel refresh
while (GPIO_PIN_SET == HAL_GPIO_ReadPin(DISPLAY_TE_PORT, DISPLAY_TE_PIN)) {
@ -131,7 +147,7 @@ static void switch_fb_in_background(void) {
memcpy(physical_frame_buffer_0, physical_frame_buffer_1,
sizeof(physical_frame_buffer_0));
pending_fb_switch = true;
pending_fb_switch = 1;
__HAL_GPIO_EXTI_CLEAR_FLAG(DISPLAY_TE_PIN);
svc_enableIRQ(DISPLAY_TE_INTERRUPT_NUM);
} else {
@ -139,7 +155,7 @@ static void switch_fb_in_background(void) {
memcpy(physical_frame_buffer_1, physical_frame_buffer_0,
sizeof(physical_frame_buffer_1));
pending_fb_switch = true;
pending_fb_switch = 1;
__HAL_GPIO_EXTI_CLEAR_FLAG(DISPLAY_TE_PIN);
svc_enableIRQ(DISPLAY_TE_INTERRUPT_NUM);
}
@ -165,12 +181,17 @@ display_fb_info_t display_get_frame_buffer(void) {
void display_refresh(void) {
#ifndef BOARDLOADER
wait_for_fb_switch();
display_panel_set_window(0, 0, DISPLAY_RESX - 1, DISPLAY_RESY - 1);
if (is_mode_handler()) {
if (pending_fb_switch != 0) {
pending_fb_switch = 0;
bg_copy_abort();
}
display_panel_set_window(0, 0, DISPLAY_RESX - 1, DISPLAY_RESY - 1);
switch_fb_manually();
} else {
wait_for_fb_switch();
display_panel_set_window(0, 0, DISPLAY_RESX - 1, DISPLAY_RESY - 1);
switch_fb_in_background();
}
#else

View File

@ -29,6 +29,8 @@ void display_physical_fb_clear(void);
void display_ensure_refreshed(void);
void wait_for_fb_switch(void);
#endif // XFRAMEBUFFER
#endif // TREZORHAL_DISPLAY_FB_H

View File

@ -95,3 +95,13 @@ void bg_copy_start_const_out_8(const uint8_t *src, uint8_t *dst, size_t size) {
HAL_DMA_Start_IT(&DMA_Handle, (uint32_t)src, (uint32_t)dst, data_to_send);
}
void bg_copy_abort(void) {
dma_transfer_remaining = 0;
dma_data_transferred = 0;
HAL_DMA_Abort(&DMA_Handle);
HAL_DMA_DeInit(&DMA_Handle);
HAL_NVIC_DisableIRQ(GPDMA1_Channel0_IRQn);
data_src = NULL;
data_dst = NULL;
}