#include "timerdriver.h" void MyTimer_Base_Init(MyTimer_Struct_TypeDef * Timer) { //TIM1 uses the APB2ENR register from RCC. The others uses the APB1ENR, so we check this value. if(Timer->Timer == TIM1) { RCC->APB2ENR |= TimerX2Int(Timer->Timer); } else { RCC->APB1ENR |= TimerX2Int(Timer->Timer); } Timer->Timer->ARR = Timer->ARR; Timer->Timer->PSC = Timer->PSC; } int TimerX2Int(TIM_TypeDef * TimerX) { if(TimerX == TIM1) { return (0x01 << 11); } else if (TimerX == TIM2){ return (0x01 << 0); } else if (TimerX == TIM3){ return (0x01 << 1); } else if (TimerX == TIM4){ return (0x01 << 2); } /*else if (TimerX == TIM5){ return (0x01 << 3); } else if (TimerX == TIM6){ return (0x01 << 4); } else if (TimerX == TIM7){ return (0x01 << 5); } else if (TimerX == TIM8){ return (0x01 << 13); } else if (TimerX == TIM9){ //For now we dont do timer > 4 return (0x01 << 19); } else if (TimerX == TIM10){ return (0x01 << 20); } else if (TimerX == TIM11){ return (0x01 << 21); } else if (TimerX == TIM12){ return (0x01 << 6); } else if (TimerX == TIM13){ return (0x01 << 7); } else if (TimerX == TIM14){ return (0x01 << 8); }*/ else { return -1; }; }