Fonctions associées au GPIO écrites

This commit is contained in:
Marino Benassai 2020-11-06 10:14:24 +01:00
parent 1020d3f997
commit db0406a4f5
6 changed files with 208 additions and 143 deletions

View file

@ -11,8 +11,25 @@ void GPIO_conf(GPIO_TypeDef * GPIOx, uint32_t PINx, uint32_t mode, uint32_t outp
else if (GPIOx == GPIOC) LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOC); else if (GPIOx == GPIOC) LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOC);
else if (GPIOx == GPIOD) LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOD); else if (GPIOx == GPIOD) LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOD);
//Configuration de la PIN //Configuration du PIN
LL_GPIO_StructInit(&init); LL_GPIO_StructInit(&init);
init.Pin = PINx; init.Pin = PINx;
init.Mode = mode;
//init.Speed = ;
init.OutputType = outputType;
init.Pull = pullMode;
LL_GPIO_Init(GPIOx, &init);
}
void GPIO_setPin(GPIO_TypeDef * GPIOx, uint32_t PINx, int output){
if (output) LL_GPIO_SetOutputPin(GPIOx, PINx);
else LL_GPIO_ResetOutputPin(GPIOx,PINx);
};
int GPIO_readPin(GPIO_TypeDef * GPIOx, uint32_t PINx){
return LL_GPIO_IsOutputPinSet(GPIOx, PINx);
} }

View file

@ -5,10 +5,19 @@
#include "stm32f1xx_ll_gpio.h" #include "stm32f1xx_ll_gpio.h"
#include "stm32f1xx_ll_bus.h" #include "stm32f1xx_ll_bus.h"
/**
* @brief Configure le GPIO considéré
* @note
* @param GPIO_TypeDef * GPIOx indique le GPIO à configurer : GPIOA, GPIOB, GPIOC ou GPIOD
uint32_t PINx indique le PIN à configurer, sous la forme LL_GPIO_PIN_x
Pour une liste des modes disponibles, consulter la librairie LL
* @retval None
*/
void GPIO_conf(GPIO_TypeDef * GPIOx, uint32_t PINx, uint32_t mode, uint32_t outputType, uint32_t pullMode); void GPIO_conf(GPIO_TypeDef * GPIOx, uint32_t PINx, uint32_t mode, uint32_t outputType, uint32_t pullMode);
void GPIO_setPin(GPIO_TypeDef GPIOx, uint32_t PINx, int output); void GPIO_setPin(GPIO_TypeDef * GPIOx, uint32_t PINx, int output);
void GPIO_readPin(GPIO_TypeDef GPIOx, uint32_t PINx); int GPIO_readPin(GPIO_TypeDef * GPIOx, uint32_t PINx);
#endif #endif

View file

@ -176,7 +176,7 @@ int getArrFromFreq(float freq_khz)
return (72000 / freq_khz) - 1; return (72000 / freq_khz) - 1;
} }
void PWMo_conf(TIM_TypeDef * timer, int channel, float freq_khz, float dutyCycle) void Timer_pwmo_conf(TIM_TypeDef * timer, int channel, float freq_khz, float dutyCycle)
{ {
const int arr = getArrFromFreq(freq_khz); const int arr = getArrFromFreq(freq_khz);
Timer_conf(timer, arr, 0); Timer_conf(timer, arr, 0);
@ -190,7 +190,7 @@ void PWMo_conf(TIM_TypeDef * timer, int channel, float freq_khz, float dutyCycle
LL_TIM_OC_Init(timer, channel, &init_struct); LL_TIM_OC_Init(timer, channel, &init_struct);
} }
void PWMo_setDutyCycle(TIM_TypeDef * timer, int channel, float freq_khz, float dutyCycle) void Timer_pwmo_setDutyCycle(TIM_TypeDef * timer, int channel, float freq_khz, float dutyCycle)
{ {
int compare = dutyCycle * getArrFromFreq(freq_khz); int compare = dutyCycle * getArrFromFreq(freq_khz);
if (channel == LL_TIM_CHANNEL_CH1) LL_TIM_OC_SetCompareCH1(timer, compare); if (channel == LL_TIM_CHANNEL_CH1) LL_TIM_OC_SetCompareCH1(timer, compare);
@ -203,12 +203,23 @@ void PWMo_setDutyCycle(TIM_TypeDef * timer, int channel, float freq_khz, float d
* ENCODER * ENCODER
***************************************************************************/ ***************************************************************************/
void Timer_encoder_conf(TIM_TypeDef * timer, int arr, int psc) void Timer_encoder_conf(TIM_TypeDef * timer)
{ {
Timer_conf(timer, 359, 0);
LL_TIM_ENCODER_InitTypeDef init_struct;
LL_TIM_ENCODER_StructInit(&init_struct);
init_struct.EncoderMode = LL_TIM_ENCODERMODE_X2_TI1;
LL_TIM_ENCODER_Init(timer, &init_struct);
} }
int Timer_encoder_get(TIM_TypeDef * timer) int Timer_encoder_getAngle(TIM_TypeDef * timer)
{ {
return 0; return LL_TIM_GetCounter(timer);
}
int Timer_encoder_getDirection(TIM_TypeDef * timer)
{
return LL_TIM_GetDirection(timer);
} }

View file

@ -60,24 +60,53 @@ int PWMi_getDutyCycle(TIM_TypeDef * timer, int channel);
* PWM OUTPUT * PWM OUTPUT
***************************************************************************/ ***************************************************************************/
void PWMo_conf(TIM_TypeDef * timer, int channel, float freq_khz, float dutyCycle); /**
* @brief Configure le timer en mode PWM output à la fréquence donnée
* @note
* @param TIM_TypeDef Timer : indique le timer à utiliser : TIM1, TIM2, TIM3 ou TIM4
* int channel : Le channel utilisé par la PWM
* float freq_khz : Fréquence en KHz
* float dutyCycle : Valeur entre 0 et 1
* @retval None
*/
void Timer_pwmo_conf(TIM_TypeDef * timer, int channel, float freq_khz, float dutyCycle);
/** /**
* @brief Arrêt le timer considéré * @brief Modifie le duty cycle de la PWM
* @note * @note
* @param TIM_TypeDef Timer : indique le timer à utiliser : TIM1, TIM2, TIM3 ou TIM4 * @param TIM_TypeDef Timer : indique le timer à utiliser : TIM1, TIM2, TIM3 ou TIM4
* int channel : Le channel utilisé par la PWM * int channel : Le channel utilisé par la PWM
* float dutyCycle : Valeur entre 0 et 1 * float dutyCycle : Valeur entre 0 et 1
* @retval None * @retval None
*/ */
void PWMo_setDutyCycle(TIM_TypeDef * timer, int channel, float freq_khz, float dutyCycle); void Timer_pwmo_setDutyCycle(TIM_TypeDef * timer, int channel, float freq_khz, float dutyCycle);
/**************************************************************************** /****************************************************************************
* ENCODER * ENCODER
***************************************************************************/ ***************************************************************************/
void Timer_encoder_conf(TIM_TypeDef * timer, int arr, int psc); /**
* @brief Configure le timer en mode encoder
* @note
* @param TIM_TypeDef Timer : indique le timer à utiliser : TIM1, TIM2, TIM3 ou TIM4
* @retval None
*/
void Timer_encoder_conf(TIM_TypeDef * timer);
int Timer_encoder_get(TIM_TypeDef * timer); /**
* @brief Récupère l'angle, en degrès
* @note
* @param TIM_TypeDef Timer : indique le timer à utiliser : TIM1, TIM2, TIM3 ou TIM4
* @retval None
*/
int Timer_encoder_getAngle(TIM_TypeDef * timer);
/**
* @brief Récupère la direction
* @note
* @param TIM_TypeDef Timer : indique le timer à utiliser : TIM1, TIM2, TIM3 ou TIM4
* @retval None
*/
int Timer_encoder_getDirection(TIM_TypeDef * timer);
#endif #endif

View file

@ -127,4 +127,3 @@ void Chrono_Task_10ms(void)
} }