From cd739176a326bca33127eb490afa11448813d9ad Mon Sep 17 00:00:00 2001 From: Oskar Date: Sun, 9 Nov 2025 22:28:11 +0100 Subject: [PATCH] Ajouter des commentaires et enlever des redondances --- CantoOrvikPilotes/Include/GPIO.h | 4 ++++ CantoOrvikPilotes/Include/MyTimer.h | 17 ++++----------- CantoOrvikPilotes/Include/Nucleo.h | 3 ++- CantoOrvikPilotes/Include/PWM.h | 3 ++- CantoOrvikPilotes/Include/Timer.h | 8 ++++++- CantoOrvikPilotes/Source/GPIO.c | 5 +++++ CantoOrvikPilotes/Source/MyTimer.c | 31 +++----------------------- CantoOrvikPilotes/Source/Nucleo.c | 34 +++++++++++++++++------------ CantoOrvikPilotes/Source/PWM.c | 2 +- CantoOrvikPilotes/Source/Timer.c | 2 +- 10 files changed, 49 insertions(+), 60 deletions(-) diff --git a/CantoOrvikPilotes/Include/GPIO.h b/CantoOrvikPilotes/Include/GPIO.h index 9565222..21cdbb6 100644 --- a/CantoOrvikPilotes/Include/GPIO.h +++ b/CantoOrvikPilotes/Include/GPIO.h @@ -1,4 +1,8 @@ +// Gestion des signaux extern int ChercherEtat(GPIO_TypeDef * GPIO, int pin); extern void ResetBroche(uint32_t GPIO, int Broche); extern void SetBroche(uint32_t GPIO, int Broche); +extern void TogglePin(GPIO_TypeDef*GPIO, int Broche); +// Config des broches extern void ConfigureBroche(uint32_t GPIO, int Broche, int IO, char Mode); + diff --git a/CantoOrvikPilotes/Include/MyTimer.h b/CantoOrvikPilotes/Include/MyTimer.h index c4f72ec..e911627 100644 --- a/CantoOrvikPilotes/Include/MyTimer.h +++ b/CantoOrvikPilotes/Include/MyTimer.h @@ -1,20 +1,11 @@ #include "stm32f10x.h" -//TIMERS -extern void MyTimer_Base_Init ( TIM_TypeDef * Timer , unsigned short ValARR , unsigned short ValPSC ); -extern void EnableTimer(void); -extern void ConfigureBroches(); -extern void ConfigureTimers(); +//TIMERS start #define MyTimer_Base_Start(Timer) (Timer->CR1 |= TIM_CR1_CEN) #define MyTimer_Base_Stop(Timer) (Timer -> CR1 =(0x0)) +// IT extern volatile int g_tick_count; // Declara que a variável existe em outro arquivo -extern void TIM2_IRQHandler(void); -extern void TIM3_IRQHandler(void); -extern void TIM4_IRQHandler(void); -extern void MyTimer_ActiveIT(TIM_TypeDef *Timer, char Prio,void(*IT_function)(void)); -//PWM -extern void MyTimer_PWM(TIM_TypeDef *Timer, char Channel); -extern void MyTimer_Set_DutyCycle(TIM_TypeDef *Timer, char Channel, float DutyCycle_Percent); void Test(void); void ConfigureIT(); -void ConfigurePWM(); \ No newline at end of file +// PWM +void ConfigurePWM(); diff --git a/CantoOrvikPilotes/Include/Nucleo.h b/CantoOrvikPilotes/Include/Nucleo.h index 6eebacb..49fb743 100644 --- a/CantoOrvikPilotes/Include/Nucleo.h +++ b/CantoOrvikPilotes/Include/Nucleo.h @@ -1,7 +1,8 @@ #include "stm32f10x.h" +// Config extern void ConfigHorloge(void); extern void ConfigBroche(void); +// Gestion des IO Spesifiques extern int BoutonAppuye(void); extern void AllumerLED(void); extern void EteindreLED(void); -extern void TogglePin(GPIO_TypeDef*GPIO, int Broche); \ No newline at end of file diff --git a/CantoOrvikPilotes/Include/PWM.h b/CantoOrvikPilotes/Include/PWM.h index 4c6de71..049b49f 100644 --- a/CantoOrvikPilotes/Include/PWM.h +++ b/CantoOrvikPilotes/Include/PWM.h @@ -1,3 +1,4 @@ #include "stm32f10x.h" +// Config extern void MyTimer_PWM(TIM_TypeDef *Timer, char Channel); -extern void MyTimer_Set_DutyCycle(TIM_TypeDef *Timer, char Channel, float DutyCycle_Percent); \ No newline at end of file +extern void MyTimer_Set_DutyCycle(TIM_TypeDef *Timer, char Channel, float DutyCycle_Percent); diff --git a/CantoOrvikPilotes/Include/Timer.h b/CantoOrvikPilotes/Include/Timer.h index d48e766..cb5a7ed 100644 --- a/CantoOrvikPilotes/Include/Timer.h +++ b/CantoOrvikPilotes/Include/Timer.h @@ -1,6 +1,12 @@ #include "stm32f10x.h" +// Config de timer extern void MyTimer_Base_Init(TIM_TypeDef *Timer , unsigned short ValARR , unsigned short ValPSC ); extern void MyTimer_ActiveIT(TIM_TypeDef *Timer, char Prio,void(*IT_function)(void)); -extern void EnableTimer(); +// Fonctions d'interruption +extern void TIM2_IRQHandler(void); +extern void TIM3_IRQHandler(void); +extern void TIM4_IRQHandler(void); extern void TIM1_CC_IRQnHandler(void); extern void TIM1_UP_IRQnHandler(void); +// Enable timers +extern void EnableTimer(); diff --git a/CantoOrvikPilotes/Source/GPIO.c b/CantoOrvikPilotes/Source/GPIO.c index 1fe79a1..a3e2f31 100644 --- a/CantoOrvikPilotes/Source/GPIO.c +++ b/CantoOrvikPilotes/Source/GPIO.c @@ -1,5 +1,6 @@ #include "stm32f10x.h" #include +#include "../Include/GPIO.h" int ChercherEtat(GPIO_TypeDef * GPIO, int pin){ // Trouvons la valeur d'un broche sur un certain GPIO return((GPIO -> IDR & (0x01 << pin))); @@ -13,6 +14,10 @@ void SetBroche(uint32_t GPIO, int Broche){ // Mettre à zero d'un certain broche GPIO -> BSRR |= BSBroche << 16; } +void TogglePin(GPIO_TypeDef*GPIO, int Broche){ // Inverser la valueur de broche sur GPIO + GPIO -> ODR = GPIO -> ODR ^ (0x1 << Broche); +} + void ConfigureGPIO(uint32_t GPIO, int Broche, int IO, char Mode){ // Mettre un broche d'un GPIO sur un mode // Possble de améliorer avec des int à la place de string //Start clock pour les GPIO concernés diff --git a/CantoOrvikPilotes/Source/MyTimer.c b/CantoOrvikPilotes/Source/MyTimer.c index c333761..21e0846 100644 --- a/CantoOrvikPilotes/Source/MyTimer.c +++ b/CantoOrvikPilotes/Source/MyTimer.c @@ -1,8 +1,7 @@ #include "stm32f10x.h" -#include "Nucleo.h" -#include "Timer.h" -#include "PWM.h" -#include "GPIO.h" +#include "../Include/Timer.h" +#include "../Include/PWM.h" +#include "../Include/GPIO.h" // Variables #define ARR_TIM1 0xFFAD #define PSC_TIM1 0xFF @@ -18,30 +17,6 @@ void Test(void){ TogglePin(GPIOA, 8); } - -void ConfigureBroches(){ - ConfigureGPIO(GPIOA, 6, 4, Push-Pull); // Cela équivaut à : - // GPIOA->CRL &= ~(0xF << 6*4); // clean pin 6 - // GPIOA->CRL |= (0xB << 6*4); // Alternate Function output, Push-Pull max 50 Hz - // Exemples d'_tilisation - //Mettre Broche 5 sur input Pull-up/down - ConfigureGPIO(GPIOC, 3, 0, Pull-Up); - //GPIOC ->CRL &= ~(0xF << (4 *3)); - //GPIOC ->CRL |= (0x1 << (4 *3)); - - //Mettre Broche 5 sur input Pull-up/down - ConfigureGPIO(GPIOA, 5, 0, Pull-Up); - //GPIOA ->CRL &= ~(0xF << (4 *5)); - //GPIOA ->CRL |= (0x3 << (4 *5)); - - //Mettre Broche D7 sur input Open drain - ConfigureGPIO(GPIOA, 0, 0, Open-Drain); - //GPIOA ->CRH &= ~(0xF << (4 *0)); - //GPIOA ->CRH |= (0x7 << (4 *0)); - -} - - void ConfigureTimers(){ MyTimer_Base_Init(TIM2, ARR_TIM2, PSC_TIM2); MyTimer_Base_Init(TIM1, ARR_TIM1, PSC_TIM1); diff --git a/CantoOrvikPilotes/Source/Nucleo.c b/CantoOrvikPilotes/Source/Nucleo.c index 2e42339..127f47a 100644 --- a/CantoOrvikPilotes/Source/Nucleo.c +++ b/CantoOrvikPilotes/Source/Nucleo.c @@ -1,31 +1,37 @@ #include "stm32f10x.h" +#include "../Include/Nucleo.h" +#include "GPIO.h" void ConfigHorloge(void) { // Peut-être redondant ?? RCC->APB2ENR |= (0x01 << 2) | (0x01 << 3) | (0x01 << 4) | RCC_APB2ENR_IOPCEN | RCC_APB2ENR_TIM1EN; }; -void ConfigBroche(void){ // +void ConfigBroche(void){ // //Mettre Broche 5 GPIOA à output push-pull - GPIOA ->CRL &= ~(0x1 << (5*4 + 2)); //0x44144444; - GPIOA ->CRL |= (0x1 << 5*4); //0x44144444; - - //Mettre Broche 5 sur input Pull-up/down - GPIOA ->CRH &= ~(0x1 << (4 + 2)); - GPIOA ->CRH |= (0x1 << (4 + 3)); + ConfigureGPIO(GPIOA, 5, 4, Push-Pull); + // Equivaut à : + //GPIOA ->CRL &= ~(0x1 << (5*4 + 2)); //0x44144444; + //GPIOA ->CRL |= (0x1 << 5*4); //0x44144444; //Mettre broche 8 sur GPIOA à output open drain - GPIOA ->CRH |= (0x1 ); + ConfigureGPIO(GPIOA, 8, 4, Open-Drain); + // Equivaut à : + //GPIOA ->CRH |= (0x1 ); }; int BoutonAppuye(void){ // Peut être modifié avec ChercherEtat - return((GPIOA -> IDR & (0x01 << 9))); + ChercherEtat(GPIOA, 9); + // Equivaut à + //return((GPIOA -> IDR & (0x01 << 9))); } void AllumerLED(void){ - GPIOA -> ODR &= ~(0x1 << 8); // Peut être modifié avec SetBroche + SetBroche(GPIOA, 8); + // Equivaut à : + //GPIOA -> ODR &= ~(0x1 << 8); // Peut être modifié avec SetBroche } void EteindreLED(void){ - GPIOA -> ODR |= (0x1 << 8); // Peut être modifié avec ResetBroche -} -void TogglePin(GPIO_TypeDef*GPIO, int Broche){ // Redondant -GPIO -> ODR = GPIO -> ODR ^ (0x1 << Broche); + ResetBroche(GPIOA, 8); + // Equivaut à : + //GPIOA -> ODR |= (0x1 << 8); // Peut être modifié avec ResetBroche } + diff --git a/CantoOrvikPilotes/Source/PWM.c b/CantoOrvikPilotes/Source/PWM.c index b38cf8d..a66a5b2 100644 --- a/CantoOrvikPilotes/Source/PWM.c +++ b/CantoOrvikPilotes/Source/PWM.c @@ -1,5 +1,5 @@ #include "stm32f10x.h" -#include "PWM.h" +#include "../Include/PWM.h" void MyTimer_PWM(TIM_TypeDef *Timer, char Channel) { // Activer PWM sur un output diff --git a/CantoOrvikPilotes/Source/Timer.c b/CantoOrvikPilotes/Source/Timer.c index 0781478..d3bd90f 100644 --- a/CantoOrvikPilotes/Source/Timer.c +++ b/CantoOrvikPilotes/Source/Timer.c @@ -1,5 +1,5 @@ #include "stm32f10x.h" -#include "Nucleo.h" +#include "../Include/Timer.h" //REMEMBER TO ENALBLE TIMERS //EXAMPLES