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

@ -21,110 +21,109 @@ static TIM_TypeDef * Chrono_Timer=TIM1; // init par d
void Chrono_Task_10ms(void); void Chrono_Task_10ms(void);
/** /**
* @brief Configure le chronomètre. * @brief Configure le chronomètre.
* @note A lancer avant toute autre fonction. * @note A lancer avant toute autre fonction.
* @param Timer : indique le timer à utiliser par le chronomètre, TIM1, TIM2, TIM3 ou TIM4 * @param Timer : indique le timer à utiliser par le chronomètre, TIM1, TIM2, TIM3 ou TIM4
* @retval None * @retval None
*/ */
void Chrono_Conf(TIM_TypeDef * Timer) void Chrono_Conf(TIM_TypeDef * Timer)
{ {
// Reset Time // Reset Time
Chrono_Time.Hund = 0; Chrono_Time.Hund = 0;
Chrono_Time.Sec = 0; Chrono_Time.Sec = 0;
Chrono_Time.Min = 0; Chrono_Time.Min = 0;
// Fixation du Timer // Fixation du Timer
Chrono_Timer = Timer; Chrono_Timer = Timer;
// Réglage Timer pour un débordement à 10ms // Réglage Timer pour un débordement à 10ms
Timer_conf(Chrono_Timer, 999, 719); Timer_conf(Chrono_Timer, 999, 719);
// Réglage des interruptions // Réglage des interruptions
Timer_IT_conf(Chrono_Timer, Chrono_Task_10ms, 3); Timer_IT_conf(Chrono_Timer, Chrono_Task_10ms, 3);
Timer_IT_enable(Chrono_Timer); Timer_IT_enable(Chrono_Timer);
} }
/** /**
* @brief Démarre le chronomètre. * @brief Démarre le chronomètre.
* @note si la durée dépasse 59mn 59sec 99 Hund, elle est remise à zéro et repart * @note si la durée dépasse 59mn 59sec 99 Hund, elle est remise à zéro et repart
* @param Aucun * @param Aucun
* @retval Aucun * @retval Aucun
*/ */
void Chrono_Start(void) void Chrono_Start(void)
{ {
Timer_start(Chrono_Timer); Timer_start(Chrono_Timer);
} }
/** /**
* @brief Arrête le chronomètre. * @brief Arrête le chronomètre.
* @note * @note
* @param Aucun * @param Aucun
* @retval Aucun * @retval Aucun
*/ */
void Chrono_Stop(void) void Chrono_Stop(void)
{ {
Timer_stop(Chrono_Timer); Timer_stop(Chrono_Timer);
} }
/** /**
* @brief Remet le chronomètre à 0 * @brief Remet le chronomètre à 0
* @note * @note
* @param Aucun * @param Aucun
* @retval Aucun * @retval Aucun
*/ */
void Chrono_Reset(void) void Chrono_Reset(void)
{ {
// Arrêt Chrono // Arrêt Chrono
Timer_stop(Chrono_Timer); Timer_stop(Chrono_Timer);
// Reset Time // Reset Time
Chrono_Time.Hund=0; Chrono_Time.Hund=0;
Chrono_Time.Sec=0; Chrono_Time.Sec=0;
Chrono_Time.Min=0; Chrono_Time.Min=0;
} }
/** /**
* @brief Renvoie l'adresse de la variable Time privée gérée dans le module Chrono.c * @brief Renvoie l'adresse de la variable Time privée gérée dans le module Chrono.c
* @note * @note
* @param Aucun * @param Aucun
* @retval adresse de la variable Time * @retval adresse de la variable Time
*/ */
Time * Chrono_Read(void) Time * Chrono_Read(void)
{ {
return &Chrono_Time; return &Chrono_Time;
} }
/** /**
* @brief incrémente la variable privée Chron_Time modulo 60mn * @brief incrémente la variable privée Chron_Time modulo 60mn
* @note * @note
* @param Aucun * @param Aucun
* @retval Aucun * @retval Aucun
*/ */
void Chrono_Task_10ms(void) void Chrono_Task_10ms(void)
{ {
Chrono_Time.Hund++; Chrono_Time.Hund++;
if (Chrono_Time.Hund==100) if (Chrono_Time.Hund==100)
{ {
Chrono_Time.Sec++; Chrono_Time.Sec++;
Chrono_Time.Hund=0; Chrono_Time.Hund=0;
} }
if (Chrono_Time.Sec==60) if (Chrono_Time.Sec==60)
{ {
Chrono_Time.Min++; Chrono_Time.Min++;
Chrono_Time.Sec=0; Chrono_Time.Sec=0;
} }
if (Chrono_Time.Min==60) if (Chrono_Time.Min==60)
{ {
Chrono_Time.Hund=0; Chrono_Time.Hund=0;
} }
} }