From 3f0770b4e11dd1b618eb262a9e52d87e18bdb322 Mon Sep 17 00:00:00 2001 From: cepetr Date: Tue, 25 Jun 2024 08:45:43 +0200 Subject: [PATCH] fix(core/embed): fix backlight pwm settings during display deinit [no changelog] --- core/embed/trezorhal/stm32f4/backlight_pwm.c | 34 +++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/core/embed/trezorhal/stm32f4/backlight_pwm.c b/core/embed/trezorhal/stm32f4/backlight_pwm.c index a65e84e0fb..47d88000b1 100644 --- a/core/embed/trezorhal/stm32f4/backlight_pwm.c +++ b/core/embed/trezorhal/stm32f4/backlight_pwm.c @@ -198,28 +198,38 @@ void backlight_pwm_deinit(backlight_action_t action) { return; } - if (action == BACKLIGHT_RETAIN) { - // We keep both the GPIO and the timer running - #ifdef TREZOR_MODEL_T - // This code here is for backward compatibility with the old - // bootloader that used a different PWM settings. + // This code is for backward compatibility with the older + // bootloader/firmware on model T that used different + // PWM settings and relies on proper settings from the + // previous stage during boot. // about 10Hz (with PSC = (SystemCoreClock / 1000000) - 1) #define LED_PWM_SLOW_TIM_PERIOD (10000) #define LED_PWM_PRESCALER_SLOW (SystemCoreClock / 1000000 - 1) // 1 MHz - BACKLIGHT_PWM_TIM->PSC = LED_PWM_PRESCALER_SLOW; - BACKLIGHT_PWM_TIM->CR1 |= TIM_CR1_ARPE; - BACKLIGHT_PWM_TIM->CR2 |= TIM_CR2_CCPC; - BACKLIGHT_PWM_TIM->ARR = LED_PWM_SLOW_TIM_PERIOD - 1; + BACKLIGHT_PWM_TIM->PSC = LED_PWM_PRESCALER_SLOW; + BACKLIGHT_PWM_TIM->CR1 |= TIM_CR1_ARPE; + BACKLIGHT_PWM_TIM->CR2 |= TIM_CR2_CCPC; + BACKLIGHT_PWM_TIM->ARR = LED_PWM_SLOW_TIM_PERIOD - 1; + + if (action == BACKLIGHT_RESET) { + BACKLIGHT_PWM_TIM->BACKLIGHT_PWM_TIM_CCR = 0; + } else { // action == BACKLIGHT_RETAIN BACKLIGHT_PWM_TIM->BACKLIGHT_PWM_TIM_CCR = (LED_PWM_SLOW_TIM_PERIOD * drv->current_level) / 255; -#endif - } else { - // TODO: deinitialize GPIOs and the TIMER } +#else + if (action == BACKLIGHT_RESET) { + // TODO: reset TIMER and GPIO + BACKLIGHT_PWM_TIM->BACKLIGHT_PWM_TIM_CCR = 0; + } else { // action == BACKLIGHT_RETAIN + BACKLIGHT_PWM_TIM->BACKLIGHT_PWM_TIM_CCR = + (LED_PWM_TIM_PERIOD * drv->current_level) / 255; + } +#endif + drv->initialized = false; }