diff --git a/CantoOrvikPilotes/Source/ADC.c b/CantoOrvikPilotes/Source/ADC.c index 06d7405..e69de29 100644 Binary files a/CantoOrvikPilotes/Source/ADC.c and b/CantoOrvikPilotes/Source/ADC.c differ diff --git a/CantoOrvikPilotes/Source/GPIO.c b/CantoOrvikPilotes/Source/GPIO.c index 89de2cb..1fe79a1 100644 --- a/CantoOrvikPilotes/Source/GPIO.c +++ b/CantoOrvikPilotes/Source/GPIO.c @@ -1,20 +1,21 @@ #include "stm32f10x.h" #include -int ChercherEtat(GPIO_TypeDef * GPIO, int pin){ +int ChercherEtat(GPIO_TypeDef * GPIO, int pin){ // Trouvons la valeur d'un broche sur un certain GPIO return((GPIO -> IDR & (0x01 << pin))); } -void ResetBroche(uint32_t GPIO, int Broche){ +void ResetBroche(uint32_t GPIO, int Broche){ // Mettre à zero d'un certain broche d'un certain GPIO GPIO -> BSRR |= BSBroche; } -void SetBroche(uint32_t GPIO, int Broche){ +void SetBroche(uint32_t GPIO, int Broche){ // Mettre à zero d'un certain broche d'un certain GPIO GPIO -> BSRR |= BSBroche << 16; } -void ConfigureGPIO(uint32_t GPIO, int Broche, int IO, char Mode){ - //Start clock +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 if(GPIO == GPIOA){ RCC -> APB2ENR |= RCC_APB2ENR_IOPAEN; } @@ -27,7 +28,7 @@ else if(GPIO == GPIOC){ else if(GPIO == GPIOD){ RCC -> APB2ENR |= RCC_APB2ENR_IOPDEN; } - + // Cas d'u CRL, broche 0 à 7 if (Broche < 8) { GPIO -> CRL &= ~(0x1 << Broche *4) & ~(0x1 << Broche *4 +1) & ~(0x1 << Broche *4 + 2) & ~(0x1 << Broche *4 + 3); // Clean bits if (IO == 0){ //Input @@ -38,6 +39,7 @@ else if(GPIO == GPIOD){ GPIO -> CRL |= (0x1 << 6*4 + 1); } else { + return; // Mode invalid } } else if ( IO < 5) { // Output @@ -53,6 +55,7 @@ else if(GPIO == GPIOD){ GPIO -> CRL |= (0x1 << Broche * 4) | (0x1 << Broche * 4 + 1); } else { + return; // Mode invalid } } else{ @@ -68,7 +71,8 @@ else if(GPIO == GPIOD){ else if (strcmp(Mode,"Pull-Up") || strcmp(Mode,"Pull-Down")){ GPIO -> CRH |= (0x1 << 6*4 + 1); } - else { + else { + return; // Mode invalid or doesn't exist } } else if ( IO < 5) { // Output @@ -83,6 +87,7 @@ else if(GPIO == GPIOD){ GPIO -> CRH |= (0x1 << Broche * 4) | (0x1 << Broche * 4 + 1); } else { + return; // Mode invalid or doesn't exits } } else{ diff --git a/CantoOrvikPilotes/Source/MyTimer.c b/CantoOrvikPilotes/Source/MyTimer.c index 17b0536..c333761 100644 --- a/CantoOrvikPilotes/Source/MyTimer.c +++ b/CantoOrvikPilotes/Source/MyTimer.c @@ -3,6 +3,7 @@ #include "Timer.h" #include "PWM.h" #include "GPIO.h" +// Variables #define ARR_TIM1 0xFFAD #define PSC_TIM1 0xFF #define ARR_TIM2 0xFFAD @@ -11,7 +12,6 @@ #define PSC_TIM3 0x0 volatile int g_tick_count; - void Test(void){ // Signal g_tick_count++; @@ -20,10 +20,10 @@ void Test(void){ void ConfigureBroches(){ - ConfigureGPIO(GPIOA, 6, 4, Push-Pull); - //GPIOA->CRL &= ~(0xF << 6*4); // clean pin 6 - //GPIOA->CRL |= (0xB << 6*4); // Alternate Function output, Push-Pull max 50 Hz - + 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)); @@ -51,9 +51,7 @@ void ConfigureIT(){ //MyTimer_ActiveIT(TIM2, 4, Test); //start interruption with priority 4 //MyTimer_ActiveIT(TIM1, 4, Test); //start interruption with priority 4 MyTimer_ActiveIT(TIM3, 4, Test); //start interruption with priority 4 - } - void ConfigurePWM(){ MyTimer_PWM(TIM1, 1); MyTimer_Set_DutyCycle(TIM1, 1, 20.0); diff --git a/CantoOrvikPilotes/Source/Nucleo.c b/CantoOrvikPilotes/Source/Nucleo.c index 786830d..2e42339 100644 --- a/CantoOrvikPilotes/Source/Nucleo.c +++ b/CantoOrvikPilotes/Source/Nucleo.c @@ -1,10 +1,10 @@ #include "stm32f10x.h" -void ConfigHorloge(void) { +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; @@ -17,16 +17,15 @@ void ConfigBroche(void){ GPIOA ->CRH |= (0x1 ); }; -int BoutonAppuye(void){ +int BoutonAppuye(void){ // Peut être modifié avec ChercherEtat return((GPIOA -> IDR & (0x01 << 9))); - //return(ChercherEtat(GPIOA, 9)); } void AllumerLED(void){ - GPIOA -> ODR &= ~(0x1 << 8); + GPIOA -> ODR &= ~(0x1 << 8); // Peut être modifié avec SetBroche } void EteindreLED(void){ - GPIOA -> ODR |= (0x1 << 8); + GPIOA -> ODR |= (0x1 << 8); // Peut être modifié avec ResetBroche } -void TogglePin(GPIO_TypeDef*GPIO, int Broche){ +void TogglePin(GPIO_TypeDef*GPIO, int Broche){ // Redondant GPIO -> ODR = GPIO -> ODR ^ (0x1 << Broche); -} \ No newline at end of file +} diff --git a/CantoOrvikPilotes/Source/PWM.c b/CantoOrvikPilotes/Source/PWM.c index 6abfb6f..b38cf8d 100644 --- a/CantoOrvikPilotes/Source/PWM.c +++ b/CantoOrvikPilotes/Source/PWM.c @@ -2,7 +2,7 @@ #include "PWM.h" -void MyTimer_PWM(TIM_TypeDef *Timer, char Channel) { +void MyTimer_PWM(TIM_TypeDef *Timer, char Channel) { // Activer PWM sur un output // preload Timer->CR1 |= TIM_CR1_ARPE; @@ -41,17 +41,15 @@ void MyTimer_PWM(TIM_TypeDef *Timer, char Channel) { Timer->BDTR |= TIM_BDTR_MOE; } } - void MyTimer_Set_DutyCycle(TIM_TypeDef *Timer, char Channel, float DutyCycle_Percent) { unsigned short ccr_value; // Percentages between 0 and 100 if (DutyCycle_Percent > 100.0) DutyCycle_Percent = 100.0; if (DutyCycle_Percent < 0.0) DutyCycle_Percent = 0.0; - // calcule of crr ccr_value = (unsigned short)((DutyCycle_Percent / 100.0) * (Timer->ARR)); - + // Assigner le valaur pour le registre de comparison pour le channel qui est pertient switch (Channel) { case 1: Timer->CCR1 = ccr_value; diff --git a/CantoOrvikPilotes/Source/Timer.c b/CantoOrvikPilotes/Source/Timer.c index 5790335..0781478 100644 --- a/CantoOrvikPilotes/Source/Timer.c +++ b/CantoOrvikPilotes/Source/Timer.c @@ -6,21 +6,20 @@ //RCC -> APB1ENR |= RCC_APB1ENR_TIM2EN | RCC_APB1ENR_TIM3EN; // Enable TIM2 //RCC->APB2ENR |= RCC_APB2ENR_TIM1EN; // Enable TIM1 -void MyTimer_Base_Init( TIM_TypeDef * Timer , unsigned short ValARR , unsigned short ValPSC ) { +void MyTimer_Base_Init( TIM_TypeDef * Timer , unsigned short ValARR , unsigned short ValPSC ) { // Configuration du timer Timer -> PSC=(ValPSC); Timer-> ARR = (ValARR); - Timer->EGR |= TIM_EGR_UG; }; -static void (*p_IT_functions[4])(void); +static void (*p_IT_functions[4])(void); // Pour créer l'array des fonctions void MyTimer_ActiveIT(TIM_TypeDef *Timer, char Prio,void(*IT_function)(void)) { //Enable interruption requisition Timer->DIER |= TIM_DIER_UIE; // Update interrupt enable - //Id the interruption timer routine + //Id the interruption timer routine IRQn_Type IRQn; int timer_index = -1; // Indice pour notre array des pointeurs @@ -56,15 +55,14 @@ void TIM2_IRQHandler(void) { if (p_IT_functions[0] != 0) { p_IT_functions[0](); // Execute fonction } - // TogglePin(GPIOA, 5); // Sans utiliser l'array de pointeurs }; void TIM3_IRQHandler(void) { - // Clean flag - TIM3->SR &= ~TIM_SR_UIF; - //Call function - if (p_IT_functions[1] != 0) { - p_IT_functions[1](); // Execute function - } + // Clean flag + TIM3->SR &= ~TIM_SR_UIF; + //Call function + if (p_IT_functions[1] != 0) { + p_IT_functions[1](); // Execute function + } }; void TIM4_IRQHandler(void) { // Clean flag @@ -74,16 +72,12 @@ void TIM4_IRQHandler(void) { p_IT_functions[2](); // Execute function } }; - // IT PWM void TIM1_CC_IRQHandler(void) { // Clean flag TIM1 -> DIER &= ~TIM_DIER_CC1IE; - //Set bit - GPIOA -> ODR |= (0x1 << 8); - }; void TIM1_UP_IRQHandler(void) { @@ -94,8 +88,6 @@ void TIM1_UP_IRQHandler(void) { GPIOA -> ODR &= ~(0x1 << 8); }; - - void EnableTimer(TIM_TypeDef *Timer){ if(Timer == TIM2){ RCC -> APB1ENR |= RCC_APB1ENR_TIM2EN;