1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-24 22:31:35 +00:00

feat(core): add display_init return value

[no changelog]
This commit is contained in:
cepetr 2024-12-19 12:08:57 +01:00
parent b8a1d85c8b
commit 5138c10320
6 changed files with 22 additions and 11 deletions

View File

@ -59,7 +59,9 @@ typedef enum {
// //
// If `mode` is `DISPLAY_RETAIN_CONTENT`, ensure the driver was previously // If `mode` is `DISPLAY_RETAIN_CONTENT`, ensure the driver was previously
// initialized and `display_deinit(DISPLAY_RETAIN_CONTENT)` was called. // initialized and `display_deinit(DISPLAY_RETAIN_CONTENT)` was called.
void display_init(display_content_mode_t mode); //
// Returns `true` if the initialization was successful.
bool display_init(display_content_mode_t mode);
// Deinitializes the display controller. // Deinitializes the display controller.
// //

View File

@ -265,9 +265,13 @@ bool display_set_fb(uint32_t fb_addr) {
} }
// Fully initializes the display controller. // Fully initializes the display controller.
void display_init(display_content_mode_t mode) { bool display_init(display_content_mode_t mode) {
display_driver_t *drv = &g_display_driver; display_driver_t *drv = &g_display_driver;
if (drv->initialized) {
return true;
}
GPIO_InitTypeDef GPIO_InitStructure = {0}; GPIO_InitTypeDef GPIO_InitStructure = {0};
__HAL_RCC_DSI_FORCE_RESET(); __HAL_RCC_DSI_FORCE_RESET();
@ -353,7 +357,7 @@ void display_init(display_content_mode_t mode) {
__HAL_LTDC_ENABLE_IT(&drv->hlcd_ltdc, LTDC_IT_LI | LTDC_IT_FU | LTDC_IT_TE); __HAL_LTDC_ENABLE_IT(&drv->hlcd_ltdc, LTDC_IT_LI | LTDC_IT_FU | LTDC_IT_TE);
drv->initialized = true; drv->initialized = true;
return; return true;
cleanup: cleanup:
NVIC_DisableIRQ(LTDC_IRQn); NVIC_DisableIRQ(LTDC_IRQn);
@ -371,6 +375,7 @@ cleanup:
#endif #endif
drv->initialized = false; drv->initialized = false;
return false;
} }
int display_set_backlight(int level) { int display_set_backlight(int level) {

View File

@ -47,11 +47,11 @@ display_driver_t g_display_driver = {
.initialized = false, .initialized = false,
}; };
void display_init(display_content_mode_t mode) { bool display_init(display_content_mode_t mode) {
display_driver_t* drv = &g_display_driver; display_driver_t* drv = &g_display_driver;
if (drv->initialized) { if (drv->initialized) {
return; return true;
} }
memset(drv, 0, sizeof(display_driver_t)); memset(drv, 0, sizeof(display_driver_t));
@ -84,6 +84,7 @@ void display_init(display_content_mode_t mode) {
#endif #endif
drv->initialized = true; drv->initialized = true;
return true;
} }
void display_deinit(display_content_mode_t mode) { void display_deinit(display_content_mode_t mode) {

View File

@ -50,11 +50,11 @@ static display_driver_t g_display_driver = {
.initialized = false, .initialized = false,
}; };
void display_init(display_content_mode_t mode) { bool display_init(display_content_mode_t mode) {
display_driver_t *drv = &g_display_driver; display_driver_t *drv = &g_display_driver;
if (drv->initialized) { if (drv->initialized) {
return; return true;
} }
memset(drv, 0, sizeof(display_driver_t)); memset(drv, 0, sizeof(display_driver_t));
@ -68,6 +68,7 @@ void display_init(display_content_mode_t mode) {
} }
drv->initialized = true; drv->initialized = true;
return true;
} }
void display_deinit(display_content_mode_t mode) { void display_deinit(display_content_mode_t mode) {

View File

@ -89,11 +89,11 @@ static void display_exit_handler(void) {
display_deinit(DISPLAY_RESET_CONTENT); display_deinit(DISPLAY_RESET_CONTENT);
} }
void display_init(display_content_mode_t mode) { bool display_init(display_content_mode_t mode) {
display_driver_t *drv = &g_display_driver; display_driver_t *drv = &g_display_driver;
if (drv->initialized) { if (drv->initialized) {
return; return true;
} }
if (SDL_Init(SDL_INIT_VIDEO) != 0) { if (SDL_Init(SDL_INIT_VIDEO) != 0) {
@ -179,6 +179,7 @@ void display_init(display_content_mode_t mode) {
drv->orientation_angle = 0; drv->orientation_angle = 0;
#endif #endif
drv->initialized = true; drv->initialized = true;
return true;
} }
void display_deinit(display_content_mode_t mode) { void display_deinit(display_content_mode_t mode) {

View File

@ -243,11 +243,11 @@ static void display_sync_with_fb(display_driver_t *drv) {
HAL_GPIO_WritePin(OLED_DC_PORT, OLED_DC_PIN, GPIO_PIN_RESET); HAL_GPIO_WritePin(OLED_DC_PORT, OLED_DC_PIN, GPIO_PIN_RESET);
} }
void display_init(display_content_mode_t mode) { bool display_init(display_content_mode_t mode) {
display_driver_t *drv = &g_display_driver; display_driver_t *drv = &g_display_driver;
if (drv->initialized) { if (drv->initialized) {
return; return true;
} }
memset(drv, 0, sizeof(display_driver_t)); memset(drv, 0, sizeof(display_driver_t));
@ -319,6 +319,7 @@ void display_init(display_content_mode_t mode) {
} }
drv->initialized = true; drv->initialized = true;
return true;
} }
void display_deinit(display_content_mode_t mode) { void display_deinit(display_content_mode_t mode) {