mirror of
https://git.etud.insa-toulouse.fr/boujon/voilier-team-1.git
synced 2025-06-08 07:50:49 +02:00
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:
parent
15885e832a
commit
ee1bc88962
1 changed files with 28 additions and 1 deletions
|
@ -26,7 +26,7 @@ void MyTimer_Base_Init(MyTimer_Struct_Typedef * Timer) {
|
|||
|
||||
void MyTimer_ActiveIT(TIM_TypeDef * Timer, char Prio, void (*IT_function) (void)) {
|
||||
Timer->DIER |= TIM_DIER_UIE;
|
||||
if (Timer == TIM2) {
|
||||
if (Timer == TIM1) {
|
||||
NVIC_EnableIRQ(TIM1_BRK_IRQn);
|
||||
NVIC_SetPriority(TIM1_BRK_IRQn, Prio);
|
||||
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) {
|
||||
TIM1->SR &= ~TIM_SR_UIF;
|
||||
(*IT_Tim1)();
|
||||
|
|
Loading…
Add table
Reference in a new issue