1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-23 13:51:00 +00:00

feat(core): improve pwm backlight driver peripherals init/deinit

[no changelog]
This commit is contained in:
cepetr 2024-12-19 12:08:57 +01:00
parent e1843873d2
commit a5aee9f124
4 changed files with 27 additions and 6 deletions

View File

@ -68,11 +68,9 @@ void backlight_pwm_init(backlight_action_t action) {
}
}
// Enable peripheral clocks
BACKLIGHT_PWM_PORT_CLK_EN();
BACKLIGHT_PWM_TIM_CLK_EN();
// Initialize PWM GPIO
BACKLIGHT_PWM_PORT_CLK_EN();
GPIO_InitTypeDef GPIO_InitStructure = {0};
GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
GPIO_InitStructure.Pull = GPIO_NOPULL;
@ -82,6 +80,9 @@ void backlight_pwm_init(backlight_action_t action) {
HAL_GPIO_Init(BACKLIGHT_PWM_PORT, &GPIO_InitStructure);
// Initialize PWM timer
BACKLIGHT_PWM_TIM_FORCE_RESET();
BACKLIGHT_PWM_TIM_RELEASE_RESET();
BACKLIGHT_PWM_TIM_CLK_EN();
uint32_t tmpcr1 = 0;
@ -220,8 +221,19 @@ void backlight_pwm_deinit(backlight_action_t action) {
#else
if (action == BACKLIGHT_RESET) {
// TODO: reset TIMER and GPIO
BACKLIGHT_PWM_TIM->BACKLIGHT_PWM_TIM_CCR = 0;
// Deinitialize PWM GPIO
GPIO_InitTypeDef GPIO_InitStructure = {0};
GPIO_InitStructure.Mode = GPIO_MODE_ANALOG;
GPIO_InitStructure.Pull = GPIO_NOPULL;
GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStructure.Pin = BACKLIGHT_PWM_PIN;
HAL_GPIO_Init(BACKLIGHT_PWM_PORT, &GPIO_InitStructure);
// Deinitialize PWM timer
BACKLIGHT_PWM_TIM_FORCE_RESET();
BACKLIGHT_PWM_TIM_RELEASE_RESET();
BACKLIGHT_PWM_TIM_CLK_DIS();
} else { // action == BACKLIGHT_RETAIN
BACKLIGHT_PWM_TIM->BACKLIGHT_PWM_TIM_CCR =
(LED_PWM_TIM_PERIOD * drv->current_level) / 255;

View File

@ -11,6 +11,9 @@
#define BACKLIGHT_PWM_FREQ 10000
#define BACKLIGHT_PWM_TIM TIM1
#define BACKLIGHT_PWM_TIM_CLK_EN __HAL_RCC_TIM1_CLK_ENABLE
#define BACKLIGHT_PWM_TIM_CLK_DIS __HAL_RCC_TIM1_CLK_DISABLE
#define BACKLIGHT_PWM_TIM_FORCE_RESET __HAL_RCC_TIM1_FORCE_RESET
#define BACKLIGHT_PWM_TIM_RELEASE_RESET __HAL_RCC_TIM1_RELEASE_RESET
#define BACKLIGHT_PWM_TIM_AF GPIO_AF1_TIM1
#define BACKLIGHT_PWM_TIM_OCMODE TIM_OCMODE_PWM2
#define BACKLIGHT_PWM_TIM_CHANNEL TIM_CHANNEL_1

View File

@ -18,6 +18,9 @@
#define BACKLIGHT_PWM_FREQ 12500
#define BACKLIGHT_PWM_TIM TIM17
#define BACKLIGHT_PWM_TIM_CLK_EN __HAL_RCC_TIM17_CLK_ENABLE
#define BACKLIGHT_PWM_TIM_CLK_DIS __HAL_RCC_TIM17_CLK_DISABLE
#define BACKLIGHT_PWM_TIM_FORCE_RESET __HAL_RCC_TIM17_FORCE_RESET
#define BACKLIGHT_PWM_TIM_RELEASE_RESET __HAL_RCC_TIM17_RELEASE_RESET
#define BACKLIGHT_PWM_TIM_AF GPIO_AF14_TIM17
#define BACKLIGHT_PWM_TIM_OCMODE TIM_OCMODE_PWM1
#define BACKLIGHT_PWM_TIM_CHANNEL TIM_CHANNEL_1

View File

@ -25,6 +25,9 @@
#define BACKLIGHT_PWM_FREQ 1000
#define BACKLIGHT_PWM_TIM TIM17
#define BACKLIGHT_PWM_TIM_CLK_EN __HAL_RCC_TIM17_CLK_ENABLE
#define BACKLIGHT_PWM_TIM_CLK_DIS __HAL_RCC_TIM17_CLK_DISABLE
#define BACKLIGHT_PWM_TIM_FORCE_RESET __HAL_RCC_TIM17_FORCE_RESET
#define BACKLIGHT_PWM_TIM_RELEASE_RESET __HAL_RCC_TIM17_RELEASE_RESET
#define BACKLIGHT_PWM_TIM_AF GPIO_AF14_TIM17
#define BACKLIGHT_PWM_TIM_OCMODE TIM_OCMODE_PWM1
#define BACKLIGHT_PWM_TIM_CHANNEL TIM_CHANNEL_1