Finished Timer IRQ abstraction

This commit is contained in:
2025-08-28 20:56:51 -07:00
parent 55ca8d5360
commit 1e966f0688
6 changed files with 46 additions and 34 deletions

View File

@@ -7,7 +7,8 @@
enum class Bus {
AHB,
APB1,
APB2
APB2,
INVALID
};
struct RCC_Peripheral {
@@ -23,9 +24,11 @@ enum class Timer_Key { //For STM32F072
S_TIM14,
S_TIM15,
S_TIM16,
S_TIM17
S_TIM17,
NUM_TIMERS
};
//Get timer peripheral struct including bus register, enable mask, timer mask
constexpr RCC_Peripheral getTimerRCC(Timer_Key t) {
switch(t) {
@@ -36,6 +39,7 @@ constexpr RCC_Peripheral getTimerRCC(Timer_Key t) {
case Timer_Key::S_TIM15: return {Bus::APB2, &RCC->APB2ENR, RCC_APB2ENR_TIM15EN};
case Timer_Key::S_TIM16: return {Bus::APB2, &RCC->APB2ENR, RCC_APB2ENR_TIM16EN};
case Timer_Key::S_TIM17: return {Bus::APB2, &RCC->APB2ENR, RCC_APB2ENR_TIM17EN};
case Timer_Key::NUM_TIMERS: return {Bus::INVALID, nullptr, 0};;
}
return {Bus::APB2, &RCC->APB2ENR, RCC_APB2ENR_TIM1EN};
@@ -51,6 +55,7 @@ constexpr volatile TIM_TypeDef* getTimerRegister(Timer_Key t) {
case Timer_Key::S_TIM15: return TIM15;
case Timer_Key::S_TIM16: return TIM16;
case Timer_Key::S_TIM17: return TIM17;
case Timer_Key::NUM_TIMERS: return nullptr;
}
return TIM1;
}
@@ -64,6 +69,7 @@ constexpr IRQn_Type getIRQn(Timer_Key t) {
case Timer_Key::S_TIM15: return TIM15_IRQn;
case Timer_Key::S_TIM16: return TIM16_IRQn;
case Timer_Key::S_TIM17: return TIM17_IRQn;
case Timer_Key::NUM_TIMERS: return TIM1_BRK_UP_TRG_COM_IRQn;
}
return TIM1_BRK_UP_TRG_COM_IRQn;
}