Added GPIOFromPWM function which can be used to optimise the GPIO selection, Fixed MyTimer_ActiveIT which wouldn't work for TIM1

This commit is contained in:
Yohan Boujon 2023-04-13 11:19:42 +02:00
parent 15885e832a
commit ee1bc88962

View file

@ -26,7 +26,7 @@ void MyTimer_Base_Init(MyTimer_Struct_Typedef * Timer) {
void MyTimer_ActiveIT(TIM_TypeDef * Timer, char Prio, void (*IT_function) (void)) { void MyTimer_ActiveIT(TIM_TypeDef * Timer, char Prio, void (*IT_function) (void)) {
Timer->DIER |= TIM_DIER_UIE; Timer->DIER |= TIM_DIER_UIE;
if (Timer == TIM2) { if (Timer == TIM1) {
NVIC_EnableIRQ(TIM1_BRK_IRQn); NVIC_EnableIRQ(TIM1_BRK_IRQn);
NVIC_SetPriority(TIM1_BRK_IRQn, Prio); NVIC_SetPriority(TIM1_BRK_IRQn, Prio);
IT_Tim1 = IT_function; IT_Tim1 = IT_function;
@ -48,6 +48,33 @@ void MyTimer_ActiveIT(TIM_TypeDef * Timer, char Prio, void (*IT_function) (void)
} }
} }
MyGPIO_Struct_TypeDef GPIOFromPWM(TIM_TypeDef * Timer, int channel)
{
//use of C99 compound literal for return statement, may not work on C90.
if(Timer == TIM2)
{
//PA0 -> TIM2,CH1... iteration
return (MyGPIO_Struct_TypeDef){GPIOA,channel-1,AltOut_Ppull};
}
else if(Timer == TIM3)
{
if(channel > 2) {
return (MyGPIO_Struct_TypeDef){GPIOB,channel-3,AltOut_Ppull}; //PB0 -> TIM3,CH3;PB1 -> TIM3,CH4
}
else {
return (MyGPIO_Struct_TypeDef){GPIOA,channel+5,AltOut_Ppull}; //PA6 -> TIM3,CH1;PA7 -> TIM3,CH2
}
}
else if(Timer == TIM4)
{
return (MyGPIO_Struct_TypeDef){GPIOB,channel+5,AltOut_Ppull}; //PB6 -> TIM4,CH1... iteration
}
else { //TIM1 case
return (MyGPIO_Struct_TypeDef){GPIOA,channel+7,AltOut_Ppull};//PA8 -> TIM1,CH1... iteration
}
}
void TIM1_IRQHandler(void) { void TIM1_IRQHandler(void) {
TIM1->SR &= ~TIM_SR_UIF; TIM1->SR &= ~TIM_SR_UIF;
(*IT_Tim1)(); (*IT_Tim1)();