Made timer constructor unaccessable by user

This commit is contained in:
2025-08-28 22:02:08 -07:00
parent 1e966f0688
commit d092ccd362
4 changed files with 60 additions and 12 deletions

View File

@@ -3,12 +3,17 @@
//
#include "SHAL_TIM.h"
#include <cassert>
Timer::Timer(Timer_Key t) : timer(t), timer_reg(getTimerRegister(t)){
RCC_Peripheral rcc = getTimerRCC(timer);
*rcc.reg |= rcc.bitmask;
}
Timer::Timer() : timer(Timer_Key::S_TIM_INVALID), timer_reg(nullptr){
}
void Timer::start() {
timer_reg->CR1 |= TIM_CR1_CEN;
timer_reg->EGR |= TIM_EGR_UG; //load prescaler reg and ARR
@@ -33,3 +38,17 @@ void Timer::enableInterrupt() {
}
Timer &TimerManager::get(Timer_Key timer_key) {
//Ensure that we don't try to get invalid timers
assert(timer_key != Timer_Key::S_TIM_INVALID && timer_key != Timer_Key::NUM_TIMERS);
Timer& selected = timers[static_cast<int>(timer_key)];
//Timer queried is not initialized yet (defaults to invalid)
if(selected.timer == Timer_Key::S_TIM_INVALID){
timers[static_cast<int>(timer_key)] = Timer(timer_key); //Initialize timer
}
return timers[static_cast<int>(timer_key)];
}