#include "Driver_Timer.h" void MyTimer_Init(MyTimer_Struct_TypeDef *Timer) { // Activation de l'horloge correspondante au Timer if (Timer->Timer == TIM1) { RCC->APB2ENR |= RCC_APB2ENR_TIM1EN; // Voir p140 du manual } else if (Timer->Timer == TIM2) { RCC->APB1ENR |= RCC_APB1ENR_TIM2EN; } else if (Timer->Timer == TIM3) { RCC->APB1ENR |= RCC_APB1ENR_TIM3EN; } else if (Timer->Timer == TIM4) { RCC->APB1ENR |= RCC_APB1ENR_TIM4EN; } // Configuration du Timer // Le compteur du registre PSC commence à zéro, donc on soustrait 1 pour éviter les débordements. Timer->Timer->PSC = Timer->PSC - 1; // Valeur du prescaler Timer->Timer->ARR = Timer->ARR - 1; // Valeur de l'autoreload -> Quand cette valeur est atteinte le timer est réinitialisé Timer->Timer->CR1 |= TIM_CR1_ARPE; // Active "Autoreload preload" pour prendre en compte immédiatement les modifications de la valeur de l'autoreload (ARR) lors du prochain cycle de Timer. } 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 }