mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-03 19:31:02 +00:00
refactor(core): extract backlight driver to separate module
[no changelog]
This commit is contained in:
parent
9d1d06218c
commit
4e74d2852b
@ -17,8 +17,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TREZORHAL_BACKLIGHT_H
|
||||
#define TREZORHAL_BACKLIGHT_H
|
||||
#pragma once
|
||||
|
||||
// Action to be taken when initializing or
|
||||
// deinitializing the backlight driver
|
||||
@ -32,7 +31,7 @@ typedef enum {
|
||||
// If the action is set to `BACKLIGHT_RESET`, the backlight level
|
||||
// is set to zero level. If the action is set to `BACKLIGHT_RETAIN`,
|
||||
// the backlight level is not changed (if possible).
|
||||
void backlight_pwm_init(backlight_action_t action);
|
||||
void backlight_init(backlight_action_t action);
|
||||
|
||||
// Deinitialize the backlight driver
|
||||
//
|
||||
@ -40,18 +39,16 @@ void backlight_pwm_init(backlight_action_t action);
|
||||
// is completely deinitialized. If the action is set to `BACKLIGHT_RETAIN`,
|
||||
// the driver is deinitialized as much as possible but the backlight
|
||||
// is kept on.
|
||||
void backlight_pwm_deinit(backlight_action_t action);
|
||||
void backlight_deinit(backlight_action_t action);
|
||||
|
||||
// Sets the backlight level in range 0-255 and returns the actual level set.
|
||||
//
|
||||
// If the level is outside the range, the function has no effect
|
||||
// and just returns the actual level set. If the backlight driver
|
||||
// is not initialized, the function returns 0.
|
||||
int backlight_pwm_set(int val);
|
||||
int backlight_set(int val);
|
||||
|
||||
// Gets the backlight level in range 0-255
|
||||
//
|
||||
// Returns 0 if the backlight driver is not initialized.
|
||||
int backlight_pwm_get(void);
|
||||
|
||||
#endif // TREZORHAL_BACKLIGHT_H
|
||||
int backlight_get(void);
|
@ -22,14 +22,14 @@
|
||||
|
||||
#include <sys/systick.h>
|
||||
|
||||
#include "../backlight/backlight_pwm.h"
|
||||
#include <io/backlight.h>
|
||||
|
||||
// Requested PWM Timer clock frequency [Hz]
|
||||
#define TIM_FREQ 10000000
|
||||
// Prescaler divider for the PWM Timer
|
||||
#define LED_PWM_PRESCALER (SystemCoreClock / TIM_FREQ - 1)
|
||||
// Period of the PWM Timer
|
||||
#define LED_PWM_TIM_PERIOD (TIM_FREQ / BACKLIGHT_PWM_FREQ)
|
||||
#define LED_PWM_TIM_PERIOD (TIM_FREQ / TPS61043_FREQ)
|
||||
|
||||
// Backlight driver state
|
||||
typedef struct {
|
||||
@ -45,7 +45,7 @@ static backlight_driver_t g_backlight_driver = {
|
||||
.initialized = false,
|
||||
};
|
||||
|
||||
void backlight_pwm_init(backlight_action_t action) {
|
||||
void backlight_init(backlight_action_t action) {
|
||||
backlight_driver_t *drv = &g_backlight_driver;
|
||||
|
||||
if (drv->initialized) {
|
||||
@ -57,10 +57,10 @@ void backlight_pwm_init(backlight_action_t action) {
|
||||
int initial_level = 0;
|
||||
|
||||
if (action == BACKLIGHT_RETAIN) {
|
||||
// We expect the BACKLIGHT_PWM_TIM to be already initialized
|
||||
// We expect the TPS61043_TIM to be already initialized
|
||||
// (e.g. by the bootloader or boardloader)
|
||||
uint32_t prev_arr = BACKLIGHT_PWM_TIM->ARR;
|
||||
uint32_t prev_ccr1 = BACKLIGHT_PWM_TIM->BACKLIGHT_PWM_TIM_CCR;
|
||||
uint32_t prev_arr = TPS61043_TIM->ARR;
|
||||
uint32_t prev_ccr1 = TPS61043_TIM->TPS61043_TIM_CCR;
|
||||
|
||||
initial_level = (prev_ccr1 * 255) / (prev_arr + 1);
|
||||
if (initial_level > 255) {
|
||||
@ -69,20 +69,20 @@ void backlight_pwm_init(backlight_action_t action) {
|
||||
}
|
||||
|
||||
// Initialize PWM GPIO
|
||||
BACKLIGHT_PWM_PORT_CLK_EN();
|
||||
TPS61043_PORT_CLK_EN();
|
||||
|
||||
GPIO_InitTypeDef GPIO_InitStructure = {0};
|
||||
GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStructure.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
GPIO_InitStructure.Alternate = BACKLIGHT_PWM_TIM_AF;
|
||||
GPIO_InitStructure.Pin = BACKLIGHT_PWM_PIN;
|
||||
HAL_GPIO_Init(BACKLIGHT_PWM_PORT, &GPIO_InitStructure);
|
||||
GPIO_InitStructure.Alternate = TPS61043_TIM_AF;
|
||||
GPIO_InitStructure.Pin = TPS61043_PIN;
|
||||
HAL_GPIO_Init(TPS61043_PORT, &GPIO_InitStructure);
|
||||
|
||||
// Initialize PWM timer
|
||||
BACKLIGHT_PWM_TIM_FORCE_RESET();
|
||||
BACKLIGHT_PWM_TIM_RELEASE_RESET();
|
||||
BACKLIGHT_PWM_TIM_CLK_EN();
|
||||
TPS61043_TIM_FORCE_RESET();
|
||||
TPS61043_TIM_RELEASE_RESET();
|
||||
TPS61043_TIM_CLK_EN();
|
||||
|
||||
uint32_t tmpcr1 = 0;
|
||||
|
||||
@ -97,57 +97,57 @@ void backlight_pwm_init(backlight_action_t action) {
|
||||
tmpcr1 |= TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||
#endif
|
||||
|
||||
BACKLIGHT_PWM_TIM->CR1 = tmpcr1;
|
||||
TPS61043_TIM->CR1 = tmpcr1;
|
||||
|
||||
// Set the Autoreload value
|
||||
BACKLIGHT_PWM_TIM->ARR = (uint32_t)LED_PWM_TIM_PERIOD - 1;
|
||||
TPS61043_TIM->ARR = (uint32_t)LED_PWM_TIM_PERIOD - 1;
|
||||
|
||||
// Set the Prescaler value
|
||||
BACKLIGHT_PWM_TIM->PSC = LED_PWM_PRESCALER;
|
||||
TPS61043_TIM->PSC = LED_PWM_PRESCALER;
|
||||
|
||||
// Set the Repetition Counter value
|
||||
BACKLIGHT_PWM_TIM->RCR = 0;
|
||||
TPS61043_TIM->RCR = 0;
|
||||
|
||||
// Generate an update event to reload the Prescaler
|
||||
// and the repetition counter (only for advanced timer) value immediately
|
||||
BACKLIGHT_PWM_TIM->EGR = TIM_EGR_UG;
|
||||
TPS61043_TIM->EGR = TIM_EGR_UG;
|
||||
|
||||
// Set the Preload enable bit for channel1
|
||||
BACKLIGHT_PWM_TIM->CCMR1 |= TIM_CCMR1_OC1PE;
|
||||
TPS61043_TIM->CCMR1 |= TIM_CCMR1_OC1PE;
|
||||
|
||||
// Configure the Output Fast mode
|
||||
BACKLIGHT_PWM_TIM->CCMR1 &= ~TIM_CCMR1_OC1FE;
|
||||
BACKLIGHT_PWM_TIM->CCMR1 |= TIM_OCFAST_DISABLE;
|
||||
TPS61043_TIM->CCMR1 &= ~TIM_CCMR1_OC1FE;
|
||||
TPS61043_TIM->CCMR1 |= TIM_OCFAST_DISABLE;
|
||||
|
||||
uint32_t tmpccmrx;
|
||||
uint32_t tmpccer;
|
||||
uint32_t tmpcr2;
|
||||
|
||||
// Get the TIMx CCER register value
|
||||
tmpccer = BACKLIGHT_PWM_TIM->CCER;
|
||||
tmpccer = TPS61043_TIM->CCER;
|
||||
|
||||
// Disable the Channel 1: Reset the CC1E Bit
|
||||
BACKLIGHT_PWM_TIM->CCER &= ~TIM_CCER_CC1E;
|
||||
TPS61043_TIM->CCER &= ~TIM_CCER_CC1E;
|
||||
tmpccer |= TIM_CCER_CC1E;
|
||||
|
||||
// Get the TIMx CR2 register value
|
||||
tmpcr2 = BACKLIGHT_PWM_TIM->CR2;
|
||||
tmpcr2 = TPS61043_TIM->CR2;
|
||||
|
||||
// Get the TIMx CCMR1 register value
|
||||
tmpccmrx = BACKLIGHT_PWM_TIM->CCMR1;
|
||||
tmpccmrx = TPS61043_TIM->CCMR1;
|
||||
|
||||
// Reset the Output Compare Mode Bits
|
||||
tmpccmrx &= ~TIM_CCMR1_OC1M;
|
||||
tmpccmrx &= ~TIM_CCMR1_CC1S;
|
||||
// Select the Output Compare Mode
|
||||
tmpccmrx |= BACKLIGHT_PWM_TIM_OCMODE;
|
||||
tmpccmrx |= TPS61043_TIM_OCMODE;
|
||||
|
||||
// Reset the Output Polarity level
|
||||
tmpccer &= ~TIM_CCER_CC1P;
|
||||
// Set the Output Compare Polarity
|
||||
tmpccer |= TIM_OCPOLARITY_HIGH;
|
||||
|
||||
if (IS_TIM_CCXN_INSTANCE(BACKLIGHT_PWM_TIM, TIM_CHANNEL_1)) {
|
||||
if (IS_TIM_CCXN_INSTANCE(TPS61043_TIM, TIM_CHANNEL_1)) {
|
||||
// Check parameters
|
||||
assert_param(IS_TIM_OCN_POLARITY(OC_Config->OCNPolarity));
|
||||
|
||||
@ -159,7 +159,7 @@ void backlight_pwm_init(backlight_action_t action) {
|
||||
tmpccer |= TIM_CCER_CC1NE;
|
||||
}
|
||||
|
||||
if (IS_TIM_BREAK_INSTANCE(BACKLIGHT_PWM_TIM)) {
|
||||
if (IS_TIM_BREAK_INSTANCE(TPS61043_TIM)) {
|
||||
// Check parameters
|
||||
assert_param(IS_TIM_OCNIDLE_STATE(OC_Config->OCNIdleState));
|
||||
assert_param(IS_TIM_OCIDLE_STATE(OC_Config->OCIdleState));
|
||||
@ -174,23 +174,23 @@ void backlight_pwm_init(backlight_action_t action) {
|
||||
}
|
||||
|
||||
// Write to TIMx CR2
|
||||
BACKLIGHT_PWM_TIM->CR2 = tmpcr2;
|
||||
TPS61043_TIM->CR2 = tmpcr2;
|
||||
// Write to TIMx CCMR1
|
||||
BACKLIGHT_PWM_TIM->CCMR1 = tmpccmrx;
|
||||
TPS61043_TIM->CCMR1 = tmpccmrx;
|
||||
// Set the Capture Compare Register value
|
||||
BACKLIGHT_PWM_TIM->CCR1 = 0;
|
||||
TPS61043_TIM->CCR1 = 0;
|
||||
// Write to TIMx CCER
|
||||
BACKLIGHT_PWM_TIM->CCER = tmpccer;
|
||||
TPS61043_TIM->CCER = tmpccer;
|
||||
|
||||
BACKLIGHT_PWM_TIM->BDTR |= TIM_BDTR_MOE;
|
||||
BACKLIGHT_PWM_TIM->CR1 |= TIM_CR1_CEN;
|
||||
TPS61043_TIM->BDTR |= TIM_BDTR_MOE;
|
||||
TPS61043_TIM->CR1 |= TIM_CR1_CEN;
|
||||
|
||||
drv->initialized = true;
|
||||
|
||||
backlight_pwm_set(initial_level);
|
||||
backlight_set(initial_level);
|
||||
}
|
||||
|
||||
void backlight_pwm_deinit(backlight_action_t action) {
|
||||
void backlight_deinit(backlight_action_t action) {
|
||||
backlight_driver_t *drv = &g_backlight_driver;
|
||||
|
||||
if (!drv->initialized) {
|
||||
@ -207,15 +207,15 @@ void backlight_pwm_deinit(backlight_action_t action) {
|
||||
#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;
|
||||
TPS61043_TIM->PSC = LED_PWM_PRESCALER_SLOW;
|
||||
TPS61043_TIM->CR1 |= TIM_CR1_ARPE;
|
||||
TPS61043_TIM->CR2 |= TIM_CR2_CCPC;
|
||||
TPS61043_TIM->ARR = LED_PWM_SLOW_TIM_PERIOD - 1;
|
||||
|
||||
if (action == BACKLIGHT_RESET) {
|
||||
BACKLIGHT_PWM_TIM->BACKLIGHT_PWM_TIM_CCR = 0;
|
||||
TPS61043_TIM->TPS61043_TIM_CCR = 0;
|
||||
} else { // action == BACKLIGHT_RETAIN
|
||||
BACKLIGHT_PWM_TIM->BACKLIGHT_PWM_TIM_CCR =
|
||||
TPS61043_TIM->TPS61043_TIM_CCR =
|
||||
(LED_PWM_SLOW_TIM_PERIOD * drv->current_level) / 255;
|
||||
}
|
||||
|
||||
@ -226,16 +226,16 @@ void backlight_pwm_deinit(backlight_action_t action) {
|
||||
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);
|
||||
GPIO_InitStructure.Pin = TPS61043_PIN;
|
||||
HAL_GPIO_Init(TPS61043_PORT, &GPIO_InitStructure);
|
||||
|
||||
// Deinitialize PWM timer
|
||||
BACKLIGHT_PWM_TIM_FORCE_RESET();
|
||||
BACKLIGHT_PWM_TIM_RELEASE_RESET();
|
||||
BACKLIGHT_PWM_TIM_CLK_DIS();
|
||||
TPS61043_TIM_FORCE_RESET();
|
||||
TPS61043_TIM_RELEASE_RESET();
|
||||
TPS61043_TIM_CLK_DIS();
|
||||
|
||||
} else { // action == BACKLIGHT_RETAIN
|
||||
BACKLIGHT_PWM_TIM->BACKLIGHT_PWM_TIM_CCR =
|
||||
TPS61043_TIM->TPS61043_TIM_CCR =
|
||||
(LED_PWM_TIM_PERIOD * drv->current_level) / 255;
|
||||
}
|
||||
#endif
|
||||
@ -244,28 +244,28 @@ void backlight_pwm_deinit(backlight_action_t action) {
|
||||
}
|
||||
|
||||
// Generate a pulse on the backlight control pin to wake up the TPS61043
|
||||
static void backlight_pwm_wakeup_pulse(void) {
|
||||
static void backlight_wakeup_pulse(void) {
|
||||
GPIO_InitTypeDef GPIO_InitStructure = {0};
|
||||
|
||||
HAL_GPIO_WritePin(BACKLIGHT_PWM_PORT, BACKLIGHT_PWM_PIN, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(TPS61043_PORT, TPS61043_PIN, GPIO_PIN_SET);
|
||||
|
||||
GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStructure.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
GPIO_InitStructure.Pin = BACKLIGHT_PWM_PIN;
|
||||
HAL_GPIO_Init(BACKLIGHT_PWM_PORT, &GPIO_InitStructure);
|
||||
GPIO_InitStructure.Pin = TPS61043_PIN;
|
||||
HAL_GPIO_Init(TPS61043_PORT, &GPIO_InitStructure);
|
||||
|
||||
hal_delay_us(500);
|
||||
|
||||
GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStructure.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
GPIO_InitStructure.Alternate = BACKLIGHT_PWM_TIM_AF;
|
||||
GPIO_InitStructure.Pin = BACKLIGHT_PWM_PIN;
|
||||
HAL_GPIO_Init(BACKLIGHT_PWM_PORT, &GPIO_InitStructure);
|
||||
GPIO_InitStructure.Alternate = TPS61043_TIM_AF;
|
||||
GPIO_InitStructure.Pin = TPS61043_PIN;
|
||||
HAL_GPIO_Init(TPS61043_PORT, &GPIO_InitStructure);
|
||||
}
|
||||
|
||||
int backlight_pwm_set(int level) {
|
||||
int backlight_set(int level) {
|
||||
backlight_driver_t *drv = &g_backlight_driver;
|
||||
|
||||
if (!drv->initialized) {
|
||||
@ -276,11 +276,11 @@ int backlight_pwm_set(int level) {
|
||||
// TPS61043 goes to shutdown when duty cycle is 0 (after 32ms),
|
||||
// so we need to set GPIO to high for at least 500us
|
||||
// to wake it up.
|
||||
if (BACKLIGHT_PWM_TIM->BACKLIGHT_PWM_TIM_CCR == 0 && level != 0) {
|
||||
backlight_pwm_wakeup_pulse();
|
||||
if (TPS61043_TIM->TPS61043_TIM_CCR == 0 && level != 0) {
|
||||
backlight_wakeup_pulse();
|
||||
}
|
||||
|
||||
BACKLIGHT_PWM_TIM->CCR1 = (LED_PWM_TIM_PERIOD * level) / 255;
|
||||
TPS61043_TIM->CCR1 = (LED_PWM_TIM_PERIOD * level) / 255;
|
||||
|
||||
drv->current_level = level;
|
||||
}
|
||||
@ -288,7 +288,7 @@ int backlight_pwm_set(int level) {
|
||||
return drv->current_level;
|
||||
}
|
||||
|
||||
int backlight_pwm_get(void) {
|
||||
int backlight_get(void) {
|
||||
backlight_driver_t *drv = &g_backlight_driver;
|
||||
|
||||
if (!drv->initialized) {
|
@ -30,7 +30,7 @@
|
||||
#include <sys/systick.h>
|
||||
|
||||
#ifdef USE_BACKLIGHT
|
||||
#include "../backlight/backlight_pwm.h"
|
||||
#include <io/backlight.h>
|
||||
#endif
|
||||
|
||||
#include "display_internal.h"
|
||||
@ -367,7 +367,7 @@ bool display_init(display_content_mode_t mode) {
|
||||
#endif
|
||||
|
||||
#ifdef USE_BACKLIGHT
|
||||
backlight_pwm_init(BACKLIGHT_RESET);
|
||||
backlight_init(BACKLIGHT_RESET);
|
||||
#endif
|
||||
|
||||
uint32_t fb_addr = display_fb_init();
|
||||
@ -430,16 +430,16 @@ void display_deinit(display_content_mode_t mode) {
|
||||
NVIC_DisableIRQ(LTDC_IRQn);
|
||||
NVIC_DisableIRQ(LTDC_ER_IRQn);
|
||||
|
||||
#ifdef DISPLAY_BACKLIGHT_PIN
|
||||
#ifdef BACKLIGHT_PIN_PIN
|
||||
GPIO_InitStructure.Mode = GPIO_MODE_ANALOG;
|
||||
GPIO_InitStructure.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStructure.Speed = GPIO_SPEED_LOW;
|
||||
GPIO_InitStructure.Pin = DISPLAY_BACKLIGHT_PIN;
|
||||
HAL_GPIO_Init(DISPLAY_BACKLIGHT_PORT, &GPIO_InitStructure);
|
||||
GPIO_InitStructure.Pin = BACKLIGHT_PIN_PIN;
|
||||
HAL_GPIO_Init(BACKLIGHT_PIN_PORT, &GPIO_InitStructure);
|
||||
#endif
|
||||
|
||||
#ifdef USE_BACKLIGHT
|
||||
backlight_pwm_deinit(BACKLIGHT_RESET);
|
||||
backlight_deinit(BACKLIGHT_RESET);
|
||||
#endif
|
||||
|
||||
display_dsi_deinit(drv);
|
||||
@ -478,11 +478,11 @@ int display_set_backlight(int level) {
|
||||
}
|
||||
|
||||
#ifdef USE_BACKLIGHT
|
||||
if (level > backlight_pwm_get()) {
|
||||
if (level > backlight_get()) {
|
||||
display_ensure_refreshed();
|
||||
}
|
||||
|
||||
return backlight_pwm_set(level);
|
||||
return backlight_set(level);
|
||||
#else
|
||||
// Just emulation, not doing anything
|
||||
drv->backlight_level = level;
|
||||
@ -497,7 +497,7 @@ int display_get_backlight(void) {
|
||||
return 0;
|
||||
}
|
||||
#ifdef USE_BACKLIGHT
|
||||
return backlight_pwm_get();
|
||||
return backlight_get();
|
||||
#else
|
||||
return drv->backlight_level;
|
||||
#endif
|
||||
|
@ -27,7 +27,7 @@
|
||||
#include "display_io.h"
|
||||
#include "display_panel.h"
|
||||
|
||||
#include "../backlight/backlight_pwm.h"
|
||||
#include <io/backlight.h>
|
||||
|
||||
#ifndef BOARDLOADER
|
||||
#include "../bg_copy/bg_copy.h"
|
||||
@ -71,7 +71,7 @@ bool display_init(display_content_mode_t mode) {
|
||||
display_io_init_fmc();
|
||||
display_panel_init();
|
||||
display_panel_set_little_endian();
|
||||
backlight_pwm_init(BACKLIGHT_RESET);
|
||||
backlight_init(BACKLIGHT_RESET);
|
||||
} else {
|
||||
// Reinitialize FMC to set correct timing
|
||||
// We have to do this in reinit because boardloader is fixed.
|
||||
@ -80,7 +80,7 @@ bool display_init(display_content_mode_t mode) {
|
||||
// Important for model T as this is not set in boardloader
|
||||
display_panel_set_little_endian();
|
||||
display_panel_reinit();
|
||||
backlight_pwm_init(BACKLIGHT_RETAIN);
|
||||
backlight_init(BACKLIGHT_RETAIN);
|
||||
}
|
||||
|
||||
#ifdef FRAMEBUFFER
|
||||
@ -116,8 +116,8 @@ void display_deinit(display_content_mode_t mode) {
|
||||
|
||||
mpu_set_active_fb(NULL, 0);
|
||||
|
||||
backlight_pwm_deinit(mode == DISPLAY_RESET_CONTENT ? BACKLIGHT_RESET
|
||||
: BACKLIGHT_RETAIN);
|
||||
backlight_deinit(mode == DISPLAY_RESET_CONTENT ? BACKLIGHT_RESET
|
||||
: BACKLIGHT_RETAIN);
|
||||
|
||||
#ifdef TREZOR_MODEL_T2T1
|
||||
// This ensures backward compatibility with legacy bootloader/firmware
|
||||
@ -140,15 +140,15 @@ int display_set_backlight(int level) {
|
||||
|
||||
#ifndef BOARDLOADER
|
||||
// if turning on the backlight, wait until the panel is refreshed
|
||||
if (backlight_pwm_get() < level && !is_mode_exception()) {
|
||||
if (backlight_get() < level && !is_mode_exception()) {
|
||||
display_ensure_refreshed();
|
||||
}
|
||||
#endif
|
||||
|
||||
return backlight_pwm_set(level);
|
||||
return backlight_set(level);
|
||||
}
|
||||
|
||||
int display_get_backlight(void) { return backlight_pwm_get(); }
|
||||
int display_get_backlight(void) { return backlight_get(); }
|
||||
|
||||
int display_set_orientation(int angle) {
|
||||
display_driver_t* drv = &g_display_driver;
|
||||
|
@ -8,19 +8,19 @@
|
||||
#define DISPLAY_TE_PIN GPIO_PIN_12
|
||||
#define DISPLAY_I8080_8BIT_DW 1
|
||||
|
||||
#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
|
||||
#define BACKLIGHT_PWM_TIM_CCR CCR1
|
||||
#define BACKLIGHT_PWM_PIN GPIO_PIN_7
|
||||
#define BACKLIGHT_PWM_PORT GPIOA
|
||||
#define BACKLIGHT_PWM_PORT_CLK_EN __HAL_RCC_GPIOA_CLK_ENABLE
|
||||
#define TPS61043_FREQ 10000
|
||||
#define TPS61043_TIM TIM1
|
||||
#define TPS61043_TIM_CLK_EN __HAL_RCC_TIM1_CLK_ENABLE
|
||||
#define TPS61043_TIM_CLK_DIS __HAL_RCC_TIM1_CLK_DISABLE
|
||||
#define TPS61043_TIM_FORCE_RESET __HAL_RCC_TIM1_FORCE_RESET
|
||||
#define TPS61043_TIM_RELEASE_RESET __HAL_RCC_TIM1_RELEASE_RESET
|
||||
#define TPS61043_TIM_AF GPIO_AF1_TIM1
|
||||
#define TPS61043_TIM_OCMODE TIM_OCMODE_PWM2
|
||||
#define TPS61043_TIM_CHANNEL TIM_CHANNEL_1
|
||||
#define TPS61043_TIM_CCR CCR1
|
||||
#define TPS61043_PIN GPIO_PIN_7
|
||||
#define TPS61043_PORT GPIOA
|
||||
#define TPS61043_PORT_CLK_EN __HAL_RCC_GPIOA_CLK_ENABLE
|
||||
|
||||
#define I2C_COUNT 1
|
||||
#define I2C_INSTANCE_0 I2C1
|
||||
|
@ -15,19 +15,19 @@
|
||||
#define DISPLAY_TE_INTERRUPT_GPIOSEL EXTI_GPIOD
|
||||
#define DISPLAY_TE_INTERRUPT_EXTI_LINE EXTI_LINE_12
|
||||
|
||||
#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
|
||||
#define BACKLIGHT_PWM_TIM_CCR CCR1
|
||||
#define BACKLIGHT_PWM_PIN GPIO_PIN_1
|
||||
#define BACKLIGHT_PWM_PORT GPIOE
|
||||
#define BACKLIGHT_PWM_PORT_CLK_EN __HAL_RCC_GPIOE_CLK_ENABLE
|
||||
#define TPS61043_FREQ 12500
|
||||
#define TPS61043_TIM TIM17
|
||||
#define TPS61043_TIM_CLK_EN __HAL_RCC_TIM17_CLK_ENABLE
|
||||
#define TPS61043_TIM_CLK_DIS __HAL_RCC_TIM17_CLK_DISABLE
|
||||
#define TPS61043_TIM_FORCE_RESET __HAL_RCC_TIM17_FORCE_RESET
|
||||
#define TPS61043_TIM_RELEASE_RESET __HAL_RCC_TIM17_RELEASE_RESET
|
||||
#define TPS61043_TIM_AF GPIO_AF14_TIM17
|
||||
#define TPS61043_TIM_OCMODE TIM_OCMODE_PWM1
|
||||
#define TPS61043_TIM_CHANNEL TIM_CHANNEL_1
|
||||
#define TPS61043_TIM_CCR CCR1
|
||||
#define TPS61043_PIN GPIO_PIN_1
|
||||
#define TPS61043_PORT GPIOE
|
||||
#define TPS61043_PORT_CLK_EN __HAL_RCC_GPIOE_CLK_ENABLE
|
||||
|
||||
#define I2C_COUNT 3
|
||||
#define I2C_INSTANCE_0 I2C1
|
||||
|
@ -23,19 +23,19 @@
|
||||
#define DISPLAY_PWREN_PORT GPIOE
|
||||
#define DISPLAY_PWREN_CLK_ENA __HAL_RCC_GPIOE_CLK_ENABLE
|
||||
|
||||
#define BACKLIGHT_PWM_FREQ 200
|
||||
#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
|
||||
#define BACKLIGHT_PWM_TIM_CCR CCR1
|
||||
#define BACKLIGHT_PWM_PIN GPIO_PIN_9
|
||||
#define BACKLIGHT_PWM_PORT GPIOB
|
||||
#define BACKLIGHT_PWM_PORT_CLK_EN __HAL_RCC_GPIOB_CLK_ENABLE
|
||||
#define TPS61043_FREQ 200
|
||||
#define TPS61043_TIM TIM17
|
||||
#define TPS61043_TIM_CLK_EN __HAL_RCC_TIM17_CLK_ENABLE
|
||||
#define TPS61043_TIM_CLK_DIS __HAL_RCC_TIM17_CLK_DISABLE
|
||||
#define TPS61043_TIM_FORCE_RESET __HAL_RCC_TIM17_FORCE_RESET
|
||||
#define TPS61043_TIM_RELEASE_RESET __HAL_RCC_TIM17_RELEASE_RESET
|
||||
#define TPS61043_TIM_AF GPIO_AF14_TIM17
|
||||
#define TPS61043_TIM_OCMODE TIM_OCMODE_PWM1
|
||||
#define TPS61043_TIM_CHANNEL TIM_CHANNEL_1
|
||||
#define TPS61043_TIM_CCR CCR1
|
||||
#define TPS61043_PIN GPIO_PIN_9
|
||||
#define TPS61043_PORT GPIOB
|
||||
#define TPS61043_PORT_CLK_EN __HAL_RCC_GPIOB_CLK_ENABLE
|
||||
|
||||
#define NPM1300_I2C_INSTANCE 0
|
||||
|
||||
|
@ -22,19 +22,19 @@
|
||||
#define DISPLAY_PWREN_PORT GPIOE
|
||||
#define DISPLAY_PWREN_CLK_ENA __HAL_RCC_GPIOE_CLK_ENABLE
|
||||
|
||||
#define BACKLIGHT_PWM_FREQ 200
|
||||
#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
|
||||
#define BACKLIGHT_PWM_TIM_CCR CCR1
|
||||
#define BACKLIGHT_PWM_PIN GPIO_PIN_9
|
||||
#define BACKLIGHT_PWM_PORT GPIOB
|
||||
#define BACKLIGHT_PWM_PORT_CLK_EN __HAL_RCC_GPIOB_CLK_ENABLE
|
||||
#define TPS61043_FREQ 200
|
||||
#define TPS61043_TIM TIM17
|
||||
#define TPS61043_TIM_CLK_EN __HAL_RCC_TIM17_CLK_ENABLE
|
||||
#define TPS61043_TIM_CLK_DIS __HAL_RCC_TIM17_CLK_DISABLE
|
||||
#define TPS61043_TIM_FORCE_RESET __HAL_RCC_TIM17_FORCE_RESET
|
||||
#define TPS61043_TIM_RELEASE_RESET __HAL_RCC_TIM17_RELEASE_RESET
|
||||
#define TPS61043_TIM_AF GPIO_AF14_TIM17
|
||||
#define TPS61043_TIM_OCMODE TIM_OCMODE_PWM1
|
||||
#define TPS61043_TIM_CHANNEL TIM_CHANNEL_1
|
||||
#define TPS61043_TIM_CCR CCR1
|
||||
#define TPS61043_PIN GPIO_PIN_9
|
||||
#define TPS61043_PORT GPIOB
|
||||
#define TPS61043_PORT_CLK_EN __HAL_RCC_GPIOB_CLK_ENABLE
|
||||
|
||||
#define NPM1300_I2C_INSTANCE 0
|
||||
|
||||
|
@ -23,19 +23,19 @@
|
||||
#define DISPLAY_PWREN_PORT GPIOG
|
||||
#define DISPLAY_PWREN_CLK_ENA __HAL_RCC_GPIOG_CLK_ENABLE
|
||||
|
||||
#define BACKLIGHT_PWM_FREQ 200
|
||||
#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
|
||||
#define BACKLIGHT_PWM_TIM_CCR CCR1
|
||||
#define BACKLIGHT_PWM_PIN GPIO_PIN_9
|
||||
#define BACKLIGHT_PWM_PORT GPIOB
|
||||
#define BACKLIGHT_PWM_PORT_CLK_EN __HAL_RCC_GPIOB_CLK_ENABLE
|
||||
#define TPS61043_FREQ 200
|
||||
#define TPS61043_TIM TIM17
|
||||
#define TPS61043_TIM_CLK_EN __HAL_RCC_TIM17_CLK_ENABLE
|
||||
#define TPS61043_TIM_CLK_DIS __HAL_RCC_TIM17_CLK_DISABLE
|
||||
#define TPS61043_TIM_FORCE_RESET __HAL_RCC_TIM17_FORCE_RESET
|
||||
#define TPS61043_TIM_RELEASE_RESET __HAL_RCC_TIM17_RELEASE_RESET
|
||||
#define TPS61043_TIM_AF GPIO_AF14_TIM17
|
||||
#define TPS61043_TIM_OCMODE TIM_OCMODE_PWM1
|
||||
#define TPS61043_TIM_CHANNEL TIM_CHANNEL_1
|
||||
#define TPS61043_TIM_CCR CCR1
|
||||
#define TPS61043_PIN GPIO_PIN_9
|
||||
#define TPS61043_PORT GPIOB
|
||||
#define TPS61043_PORT_CLK_EN __HAL_RCC_GPIOB_CLK_ENABLE
|
||||
|
||||
#define NPM1300_I2C_INSTANCE 0
|
||||
|
||||
|
@ -52,9 +52,9 @@ void PVD_PVM_IRQHandler(void) {
|
||||
void PVD_IRQHandler(void) {
|
||||
#endif
|
||||
mpu_reconfig(MPU_MODE_DEFAULT);
|
||||
#ifdef BACKLIGHT_PWM_TIM
|
||||
#ifdef TPS61043_TIM
|
||||
// Turn off display backlight
|
||||
BACKLIGHT_PWM_TIM->BACKLIGHT_PWM_TIM_CCR = 0;
|
||||
TPS61043_TIM->TPS61043_TIM_CCR = 0;
|
||||
#endif
|
||||
error_shutdown("PVD IRQ");
|
||||
}
|
||||
|
@ -55,10 +55,10 @@ def configure(
|
||||
sources += ["embed/io/display/st-7789/panels/lx154a2422.c"]
|
||||
paths += ["embed/io/display/inc"]
|
||||
|
||||
sources += ["embed/io/display/backlight/stm32/backlight_pwm.c"]
|
||||
|
||||
features_available.append("backlight")
|
||||
defines += [("USE_BACKLIGHT", "1")]
|
||||
sources += ["embed/io/backlight/stm32/tps61043.c"]
|
||||
paths += ["embed/io/backlight/inc"]
|
||||
|
||||
if "input" in features_wanted:
|
||||
sources += ["embed/io/i2c_bus/stm32f4/i2c_bus.c"]
|
||||
|
@ -54,9 +54,10 @@ def configure(
|
||||
sources += ["embed/io/display/fb_queue/fb_queue.c"]
|
||||
paths += ["embed/io/display/inc"]
|
||||
|
||||
sources += ["embed/io/display/backlight/stm32/backlight_pwm.c"]
|
||||
features_available.append("backlight")
|
||||
defines += [("USE_BACKLIGHT", "1")]
|
||||
sources += ["embed/io/backlight/stm32/tps61043.c"]
|
||||
paths += ["embed/io/backlight/inc"]
|
||||
|
||||
env_constraints = env.get("CONSTRAINTS")
|
||||
if not (env_constraints and "limited_util_s" in env_constraints):
|
||||
|
@ -46,12 +46,13 @@ def configure(
|
||||
"embed/io/display/ltdc_dsi/display_fb_rgb888.c",
|
||||
"embed/io/display/ltdc_dsi/display_gfxmmu.c",
|
||||
"embed/io/display/fb_queue/fb_queue.c",
|
||||
"embed/io/display/backlight/stm32/backlight_pwm.c",
|
||||
]
|
||||
|
||||
paths += ["embed/io/display/inc"]
|
||||
|
||||
features_available.append("backlight")
|
||||
defines += [("USE_BACKLIGHT", "1")]
|
||||
sources += ["embed/io/backlight/stm32/tps61043.c"]
|
||||
paths += ["embed/io/backlight/inc"]
|
||||
|
||||
if "input" in features_wanted:
|
||||
sources += ["embed/io/touch/ft6x36/ft6x36.c"]
|
||||
|
@ -45,12 +45,13 @@ def configure(
|
||||
"embed/io/display/ltdc_dsi/display_fb.c",
|
||||
"embed/io/display/ltdc_dsi/display_fb_rgb565.c",
|
||||
"embed/io/display/fb_queue/fb_queue.c",
|
||||
"embed/io/display/backlight/stm32/backlight_pwm.c",
|
||||
]
|
||||
|
||||
paths += ["embed/io/display/inc"]
|
||||
|
||||
features_available.append("backlight")
|
||||
defines += [("USE_BACKLIGHT", "1")]
|
||||
sources += ["embed/io/backlight/stm32/tps61043.c"]
|
||||
paths += ["embed/io/backlight/inc"]
|
||||
|
||||
if "input" in features_wanted:
|
||||
sources += ["embed/io/touch/ft6x36/ft6x36.c"]
|
||||
|
@ -46,12 +46,13 @@ def configure(
|
||||
"embed/io/display/ltdc_dsi/display_fb_rgb888.c",
|
||||
"embed/io/display/ltdc_dsi/display_gfxmmu.c",
|
||||
"embed/io/display/fb_queue/fb_queue.c",
|
||||
"embed/io/display/backlight/stm32/backlight_pwm.c",
|
||||
]
|
||||
|
||||
paths += ["embed/io/display/inc"]
|
||||
|
||||
features_available.append("backlight")
|
||||
defines += [("USE_BACKLIGHT", "1")]
|
||||
sources += ["embed/io/backlight/stm32/tps61043.c"]
|
||||
paths += ["embed/io/backlight/inc"]
|
||||
|
||||
if "input" in features_wanted:
|
||||
sources += ["embed/io/touch/ft6x36/ft6x36.c"]
|
||||
|
Loading…
Reference in New Issue
Block a user