Unified all current peripheral implementation syntax with macros

This commit is contained in:
Ea-r-th
2025-09-15 01:20:33 -07:00
parent 25b56f9fcd
commit b2d10f5e5e
6 changed files with 45 additions and 12 deletions

View File

@@ -6,8 +6,7 @@
#include <cassert>
Timer::Timer(Timer_Key t) : TIMER_KEY(t){
TIM_RCC_Enable rcc = getTimerRCC(TIMER_KEY);
*rcc.busEnableReg |= (1 << rcc.offset);
}
Timer::Timer() : TIMER_KEY(Timer_Key::S_TIM_INVALID){
@@ -37,6 +36,14 @@ void Timer::enableInterrupt() {
NVIC_EnableIRQ(getIRQn(TIMER_KEY));
}
void Timer::init(uint32_t prescaler, uint32_t autoReload) {
TIM_RCC_Enable rcc = getTimerRCC(TIMER_KEY);
*rcc.busEnableReg |= (1 << rcc.offset);
setPrescaler(prescaler);
setARR(autoReload);
}
Timer &TimerManager::get(Timer_Key timer_key) {
@@ -52,3 +59,5 @@ Timer &TimerManager::get(Timer_Key timer_key) {
return timers[static_cast<int>(timer_key)];
}

View File

@@ -13,23 +13,20 @@ void tim2Handler(){
int main() {
//Setup UART2 (used by nucleo devices for USB comms)
SHAL_UART2.init(UART_Pair::Tx2A2_Rx2A3);
SHAL_UART2.begin(115200);
UART(2).init(UART_Pair::Tx2A2_Rx2A3);
UART(2).begin(115200);
//Use pin C3 to trigger a function on external interrupt
PIN(C3).useAsExternalInterrupt(TriggerMode::RISING_EDGE,c3Interrupt);
Timer timer2 = getTimer(Timer_Key::S_TIM2);
SHAL_TIM2.init(8000-1,1500-1);
SHAL_TIM2.setCallbackFunc(tim2Handler);
SHAL_TIM2.start();
PIN(A4).setPinMode(PinMode::OUTPUT_MODE);
PIN(A5).setPinMode(PinMode::OUTPUT_MODE);
timer2.setPrescaler(8000 - 1);
timer2.setARR(1500 - 1);
timer2.setCallbackFunc(tim2Handler);
timer2.start();
while (true) {
__WFI();
}