Start timer abstractions
This commit is contained in:
33
Core/Src/Reg/SHAL_TIM.cpp
Normal file
33
Core/Src/Reg/SHAL_TIM.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
//
|
||||
// Created by Luca on 8/28/2025.
|
||||
//
|
||||
|
||||
#include "SHAL_TIM.h"
|
||||
|
||||
Timer::Timer(Timer_Key t) : timer(t), timer_reg(getTimerRegister(t)){
|
||||
RCC_Peripheral rcc = getTimerRCC(timer);
|
||||
*rcc.reg |= rcc.bitmask;
|
||||
}
|
||||
|
||||
void Timer::start() {
|
||||
timer_reg->CR1 |= TIM_CR1_CEN;
|
||||
}
|
||||
|
||||
void Timer::stop() {
|
||||
timer_reg->CR1 &= ~TIM_CR1_CEN;
|
||||
}
|
||||
|
||||
void Timer::setPrescaler(uint16_t presc) {
|
||||
timer_reg->PSC = presc;
|
||||
}
|
||||
|
||||
void Timer::setARR(uint16_t arr) {
|
||||
timer_reg->ARR = arr;
|
||||
}
|
||||
|
||||
void Timer::enableInterrupt() {
|
||||
timer_reg->DIER |= TIM_DIER_UIE;
|
||||
NVIC_EnableIRQ(getIRQn(timer));
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,9 @@ extern "C" void EXTI0_1_IRQHandler(void) {
|
||||
int main() {
|
||||
RCC->AHBENR |= RCC_AHBENR_GPIOAEN;
|
||||
RCC->AHBENR |= RCC_AHBENR_GPIOBEN;
|
||||
|
||||
RCC->APB1ENR |= RCC_APB1ENR_TIM2EN;
|
||||
|
||||
RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN; // Enable SYSCFG clock (needed for EXTI)
|
||||
|
||||
TIM2->EGR |= TIM_EGR_UG; //Force update to load PSC/ARR
|
||||
|
||||
Reference in New Issue
Block a user