Projet_Voilier/ProjetsKEIL/Drivers/Driver_timers.c
2023-03-31 12:19:05 +02:00

38 lines
No EOL
1 KiB
C

#include "Driver_timers.h"
void timer_init(MyTimer_Struct_TypeDef * Timer){
if(Timer->Timer == TIM1){
RCC->APB2ENR |= RCC_APB2ENR_TIM1EN;
}
if(Timer->Timer == TIM2){
RCC->APB1ENR |= RCC_APB1ENR_TIM2EN;
}
if(Timer->Timer == TIM3){
RCC->APB1ENR |= RCC_APB1ENR_TIM3EN;
}
if(Timer->Timer == TIM4){
RCC->APB1ENR |= RCC_APB1ENR_TIM4EN;
}
}
void MyTimer_Start(MyTimer_Struct_TypeDef *Timer)
{
Timer->Timer->CR1 |= TIM_CR1_CEN; // Démarre le Timer
}
void MyTimer_Stop(MyTimer_Struct_TypeDef *Timer)
{
Timer->Timer->CR1 &= ~TIM_CR1_CEN; // Arrête le Timer
}
void MyTimer_EnableInterrupt(MyTimer_Struct_TypeDef *Timer) {
Timer->Timer->DIER |= TIM_DIER_UIE; // Active l'interruption "Update" du Timer
NVIC->ISER[Timer->IRQn / 32] = (1 << Timer->IRQn); // Pour que ce soit générique : On divise IRQn par 32 pour avoir le ISER[] correspondant. On fait également le modulo 32 de IRQn pour avoir un nombre entre 0 et 31 correspondant au setting
}
void MyTimer_PWM( MyTimer_Struct_TypeDef * Timer , char Channel){
}