mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-07-12 09:38:08 +00:00
move timer1_get_source_freq to display-stmhal.h
This commit is contained in:
parent
7e5d5a9164
commit
18c2066d83
@ -67,27 +67,6 @@ void SysTick_Handler(void) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ### from timer.c
|
|
||||||
|
|
||||||
uint32_t timer_get_source_freq(uint32_t tim_id) {
|
|
||||||
uint32_t source;
|
|
||||||
if (tim_id == 1 || (8 <= tim_id && tim_id <= 11)) {
|
|
||||||
// TIM{1,8,9,10,11} are on APB2
|
|
||||||
source = HAL_RCC_GetPCLK2Freq();
|
|
||||||
if ((uint32_t)((RCC->CFGR & RCC_CFGR_PPRE2) >> 3) != RCC_HCLK_DIV1) {
|
|
||||||
source *= 2;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// TIM{2,3,4,5,6,7,12,13,14} are on APB1
|
|
||||||
source = HAL_RCC_GetPCLK1Freq();
|
|
||||||
if ((uint32_t)(RCC->CFGR & RCC_CFGR_PPRE1) != RCC_HCLK_DIV1) {
|
|
||||||
source *= 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return source;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ###
|
// ###
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
|
@ -7,8 +7,6 @@
|
|||||||
|
|
||||||
#include STM32_HAL_H
|
#include STM32_HAL_H
|
||||||
|
|
||||||
#define LED_PWM_TIM_PERIOD (10000)
|
|
||||||
extern uint32_t timer_get_source_freq(uint32_t tim_id);
|
|
||||||
|
|
||||||
#define DISPLAY_ILI9341V 0
|
#define DISPLAY_ILI9341V 0
|
||||||
#define DISPLAY_ST7789V 1
|
#define DISPLAY_ST7789V 1
|
||||||
@ -20,6 +18,18 @@ void DATAS(const void *bytes, int len);
|
|||||||
|
|
||||||
static TIM_HandleTypeDef TIM1_Handle;
|
static TIM_HandleTypeDef TIM1_Handle;
|
||||||
|
|
||||||
|
#define LED_PWM_TIM_PERIOD (10000)
|
||||||
|
|
||||||
|
static uint32_t timer1_get_source_freq() {
|
||||||
|
uint32_t source;
|
||||||
|
// TIM1 is on APB2
|
||||||
|
source = HAL_RCC_GetPCLK2Freq();
|
||||||
|
if ((uint32_t)((RCC->CFGR & RCC_CFGR_PPRE2) >> 3) != RCC_HCLK_DIV1) {
|
||||||
|
source *= 2;
|
||||||
|
}
|
||||||
|
return source;
|
||||||
|
}
|
||||||
|
|
||||||
void display_sram_init(void) {
|
void display_sram_init(void) {
|
||||||
__GPIOE_CLK_ENABLE();
|
__GPIOE_CLK_ENABLE();
|
||||||
__TIM1_CLK_ENABLE();
|
__TIM1_CLK_ENABLE();
|
||||||
@ -58,7 +68,7 @@ void display_sram_init(void) {
|
|||||||
// enable PWM timer
|
// enable PWM timer
|
||||||
TIM1_Handle.Instance = TIM1;
|
TIM1_Handle.Instance = TIM1;
|
||||||
TIM1_Handle.Init.Period = LED_PWM_TIM_PERIOD - 1;
|
TIM1_Handle.Init.Period = LED_PWM_TIM_PERIOD - 1;
|
||||||
TIM1_Handle.Init.Prescaler = timer_get_source_freq(1) / 1000000 - 1; // TIM runs at 1MHz
|
TIM1_Handle.Init.Prescaler = timer1_get_source_freq() / 1000000 - 1; // TIM runs at 1MHz
|
||||||
TIM1_Handle.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
TIM1_Handle.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||||
TIM1_Handle.Init.CounterMode = TIM_COUNTERMODE_UP;
|
TIM1_Handle.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||||
TIM1_Handle.Init.RepetitionCounter = 0;
|
TIM1_Handle.Init.RepetitionCounter = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user