Added GPIOFromPWM which returns a GPIO config linked to a given PWM

This commit is contained in:
Yohan Boujon 2023-03-21 23:52:48 +01:00
parent df5fe51a62
commit 2e68fa64bf
4 changed files with 35 additions and 11 deletions

View file

@ -1,5 +1,4 @@
#include "timerdriver.h"
#include "gpiodriver.h"
void (* pFnc) (void); /* déclaration dun pointeur de fonction */
@ -53,6 +52,32 @@ void MyTimer_PWM_Init(MyPWM_Struct_TypeDef * PWM)
PWM->Timer->CCER |= (1<<4*(PWM->channel-1)); //enable capture/compare registers
}
MyGPIO_Struct_TypeDef GPIOFromPWM(MyPWM_Struct_TypeDef PWM)
{
//use of C99 compound literal for return statement, may not work on C90.
if(PWM.Timer == TIM2)
{
//PA0 -> TIM2,CH1... iteration
return (MyGPIO_Struct_TypeDef){GPIOA,PWM.channel-1,AltOut_Ppull};
}
else if(PWM.Timer == TIM3)
{
if(PWM.channel > 2) {
return (MyGPIO_Struct_TypeDef){GPIOB,PWM.channel-3,AltOut_Ppull}; //PB0 -> TIM3,CH3;PB1 -> TIM3,CH4
}
else {
return (MyGPIO_Struct_TypeDef){GPIOA,PWM.channel+5,AltOut_Ppull}; //PA6 -> TIM3,CH1;PA7 -> TIM3,CH2
}
}
else if(PWM.Timer == TIM4)
{
return (MyGPIO_Struct_TypeDef){GPIOB,PWM.channel+5,AltOut_Ppull}; //PB6 -> TIM4,CH1... iteration
}
else { //TIM1 case
return (MyGPIO_Struct_TypeDef){GPIOA,PWM.channel+7,AltOut_Ppull};//PA8 -> TIM1,CH1... iteration
}
}
int TimerX2Int(TIM_TypeDef * TimerX)
{
if(TimerX == TIM1)

View file

@ -1,6 +1,7 @@
#ifndef TIMERDRIVER_H
#define TIMERDRIVER_H
#include "stm32f10x.h"
#include "gpiodriver.h"
#define CEN 0x0
#define UIE 0x0
@ -28,6 +29,7 @@ uint8_t TimerIT2UInt(TIM_TypeDef * TimerX);
void MyTimer_ActiveIT(TIM_TypeDef * TimerX, uint8_t Prio);
void Init_Periph (void (* ptrFonction)(void));
void MyTimer_PWM_Init(MyPWM_Struct_TypeDef * PWM);
MyGPIO_Struct_TypeDef GPIOFromPWM(MyPWM_Struct_TypeDef PWM);
#define MyTimer_Base_Start(Timer) (Timer->CR1 |= (0x01<<CEN))
#define MyTimer_Base_Stop(Timer) (Timer->CR1 &= ~(0x01<<CEN))

View file

@ -10,12 +10,10 @@ void ToggleLed(void)
int main (void)
{
MyGPIO_Struct_TypeDef led = {GPIOA,5,Out_PullUp}; //led
MyGPIO_Struct_TypeDef pwm1timer1 = {GPIOA,1,AltOut_Ppull};
MyTimer_Struct_TypeDef timer2 = {TIM2,499,7199}; //timer
//init & start LED, PWM, Timer
MyGPIO_Init(&led);
MyGPIO_Init(&pwm1timer1);
MyTimer_Base_Init(&timer2);
MyTimer_Base_Start(TIM2);
@ -24,13 +22,12 @@ int main (void)
MyTimer_ActiveIT(TIM2,2);
//PWM enable
MyPWM_Struct_TypeDef timer2channel2 = {TIM2,1,400};
MyTimer_PWM_Init(&timer2channel2);
MyPWM_Base_Start(TIM2);
//TIM2->CCMR1 |= (0x6<<12);
//TIM2->BDTR |= (1<<MOE);
//TIM2->CCR2 = 10;
//TIM2->CCER |= (1<<4); //0 pour CC1E, 4 pour CC2E // 4*(channel-1)
MyPWM_Struct_TypeDef PWMTIM2 = {TIM2,3,400}; //creation of PWM
MyTimer_PWM_Init(&PWMTIM2); //Init useful registers
MyGPIO_Struct_TypeDef gpioPWMTIM2 = GPIOFromPWM(PWMTIM2); //Returns the GPIO from the given PWM (Timer + Channel)
MyGPIO_Init(&gpioPWMTIM2); //Init the GPIO
MyPWM_Base_Start(TIM2); //STart the TIMER
do{
}while(1) ;

View file

@ -125,7 +125,7 @@
<SetRegEntry>
<Number>0</Number>
<Key>DLGDARM</Key>
<Name>(1010=895,198,1271,755,1)(1007=105,137,292,412,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(100=-1,-1,-1,-1,0)(110=-1,-1,-1,-1,0)(111=-1,-1,-1,-1,0)(1011=-1,-1,-1,-1,0)(180=-1,-1,-1,-1,0)(120=498,100,919,527,1)(121=491,538,912,965,1)(122=875,109,1296,536,0)(123=-1,-1,-1,-1,0)(140=-1,-1,-1,-1,0)(240=105,137,504,482,0)(190=-1,-1,-1,-1,0)(200=-1,-1,-1,-1,0)(170=-1,-1,-1,-1,0)(130=-1,-1,-1,-1,0)(131=1175,164,1769,915,1)(132=1172,171,1766,922,1)(133=-1,-1,-1,-1,0)(160=-1,-1,-1,-1,0)(161=-1,-1,-1,-1,0)(162=-1,-1,-1,-1,0)(210=-1,-1,-1,-1,0)(211=-1,-1,-1,-1,0)(220=-1,-1,-1,-1,0)(221=-1,-1,-1,-1,0)(230=-1,-1,-1,-1,0)(234=-1,-1,-1,-1,0)(231=-1,-1,-1,-1,0)(232=-1,-1,-1,-1,0)(233=-1,-1,-1,-1,0)(150=-1,-1,-1,-1,0)(151=-1,-1,-1,-1,0)</Name>
<Name>(1010=895,198,1271,755,1)(1007=105,137,292,412,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(100=-1,-1,-1,-1,0)(110=-1,-1,-1,-1,0)(111=-1,-1,-1,-1,0)(1011=-1,-1,-1,-1,0)(180=-1,-1,-1,-1,0)(120=771,85,1192,512,1)(121=791,523,1212,950,1)(122=875,109,1296,536,0)(123=-1,-1,-1,-1,0)(140=-1,-1,-1,-1,0)(240=105,137,504,482,0)(190=-1,-1,-1,-1,0)(200=-1,-1,-1,-1,0)(170=-1,-1,-1,-1,0)(130=-1,-1,-1,-1,0)(131=1175,164,1769,915,1)(132=1172,171,1766,922,0)(133=-1,-1,-1,-1,0)(160=-1,-1,-1,-1,0)(161=-1,-1,-1,-1,0)(162=-1,-1,-1,-1,0)(210=-1,-1,-1,-1,0)(211=-1,-1,-1,-1,0)(220=-1,-1,-1,-1,0)(221=-1,-1,-1,-1,0)(230=-1,-1,-1,-1,0)(234=-1,-1,-1,-1,0)(231=-1,-1,-1,-1,0)(232=-1,-1,-1,-1,0)(233=-1,-1,-1,-1,0)(150=-1,-1,-1,-1,0)(151=-1,-1,-1,-1,0)</Name>
</SetRegEntry>
<SetRegEntry>
<Number>0</Number>