1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-16 19:38:09 +00:00

move timer1_get_source_freq to display-stmhal.h

This commit is contained in:
Pavol Rusnak 2016-10-03 17:49:45 +02:00
parent 7e5d5a9164
commit 18c2066d83
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
2 changed files with 13 additions and 24 deletions

View File

@ -67,27 +67,6 @@ void SysTick_Handler(void) {
#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) {

View File

@ -7,8 +7,6 @@
#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_ST7789V 1
@ -20,6 +18,18 @@ void DATAS(const void *bytes, int len);
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) {
__GPIOE_CLK_ENABLE();
__TIM1_CLK_ENABLE();
@ -58,7 +68,7 @@ void display_sram_init(void) {
// enable PWM timer
TIM1_Handle.Instance = TIM1;
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.CounterMode = TIM_COUNTERMODE_UP;
TIM1_Handle.Init.RepetitionCounter = 0;