From d8cda927b533a7d3221f4f954f15e5685867c016 Mon Sep 17 00:00:00 2001 From: Aleksander Taban Date: Mon, 15 Dec 2025 23:36:07 +0100 Subject: [PATCH] =?UTF-8?q?Homog=C3=A9n=C3=A9isation=20visuelle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Lib_Com_Periph_2022.lib | Bin Pilotes/Source/DriverGPIO.c | 2 +- Pilotes/Source/Horloge.c | 3 +- Pilotes/Source/I2C.c | 8 +-- Pilotes/Source/MYGPIO.c | 17 +++--- Pilotes/Source/MyTimer.c | 14 ++--- Pilotes/Source/MyUart.c | 4 +- Pilotes/Source/PWM.c | 28 ++++----- Pilotes/Source/Timer.c | 2 +- Services/Source/Accelerometre.c | 57 ++++++++++-------- Services/Source/Girouette.c | 11 ++-- Services/Source/Servo.c | 14 +++-- 12 files changed, 87 insertions(+), 73 deletions(-) rename {Pilotes/Source => Objects}/Lib_Com_Periph_2022.lib (100%) diff --git a/Pilotes/Source/Lib_Com_Periph_2022.lib b/Objects/Lib_Com_Periph_2022.lib similarity index 100% rename from Pilotes/Source/Lib_Com_Periph_2022.lib rename to Objects/Lib_Com_Periph_2022.lib diff --git a/Pilotes/Source/DriverGPIO.c b/Pilotes/Source/DriverGPIO.c index fd1a4a0..54adbab 100644 --- a/Pilotes/Source/DriverGPIO.c +++ b/Pilotes/Source/DriverGPIO.c @@ -1,5 +1,5 @@ #include -#include +#include "DriverGPIO.h" // Constantes #define In_Floating 0x4 diff --git a/Pilotes/Source/Horloge.c b/Pilotes/Source/Horloge.c index b189a7f..4d2e30d 100644 --- a/Pilotes/Source/Horloge.c +++ b/Pilotes/Source/Horloge.c @@ -1,5 +1,5 @@ #include -#include +#include "Horloge.h" static void (*TIM2_Appel)(void) = 0; @@ -20,6 +20,7 @@ void Timer_Init(TIM_TypeDef *Timer, unsigned short Autoreload, unsigned short Pr Timer->EGR |= TIM_EGR_UG; } + //La fonction TIM2_IRQHandler existe déjà dans le processeur, on l'a juste redifint, tel qu'à chaque overflow on met un bit 1 dans GPIOA_ODR void TIM2_IRQHandler(void) { //On redefinit le IRQHandler qui est déjà ecrit dans le code source if (TIM2->SR & TIM_SR_UIF) { //On met le bit de overflow à un dès qu'on a overflow diff --git a/Pilotes/Source/I2C.c b/Pilotes/Source/I2C.c index 3e28fea..bce50e4 100644 --- a/Pilotes/Source/I2C.c +++ b/Pilotes/Source/I2C.c @@ -1,9 +1,9 @@ #include #include "I2C.h" -void initI2C(){ - RCC -> APB1ENR |= 0x1 << 21; // Enable clock - I2C1 -> CR1 |= 0x1 << 0; // Peripheral enable + +void initI2C() { + RCC -> APB1ENR |= 0x1 << 21; // Enable clock + I2C1 -> CR1 |= 0x1 << 0; // Peripheral enable I2C1 -> CR1 &= ~(0x1 << 1); // I2C mode - } \ No newline at end of file diff --git a/Pilotes/Source/MYGPIO.c b/Pilotes/Source/MYGPIO.c index ede345d..a8370d2 100644 --- a/Pilotes/Source/MYGPIO.c +++ b/Pilotes/Source/MYGPIO.c @@ -1,6 +1,6 @@ #include #include -#include +#include "MYGPIO.h" //FONCTIONS POUR LE DEL INTERNE @@ -28,19 +28,22 @@ void initGPIO_Interne(void) { } } + int boutonAppuye_Interne(void) { return BUTTON_GPIO_INTERNE->IDR &(1<ODR |= (0x01 << LED_PIN_INTERNE) ; //On essaie de mettre en position PA5 de GPIOC_ODR un 1 comme ca allume le LED GREEN - } - - void eteindreDEL_Interne(void) { - LED_GPIO_INTERNE->ODR &= ~(0x01 << LED_PIN_EXTERNE) ; //On essaie de mettre en position PA5 de GPIOC_ODR un 0 comme ca eteint le LED GREEN - //ALlumer un LED externe, PB8/D15 OUTPUT, Bouton Poussoir PB9/D14 } - + + +void eteindreDEL_Interne(void) { // Allumer un LED externe, PB8/D15 OUTPUT, Bouton Poussoir PB9/D14 + LED_GPIO_INTERNE->ODR &= ~(0x01 << LED_PIN_EXTERNE) ; //On essaie de mettre en position PA5 de GPIOC_ODR un 0 comme ca eteint le LED GREEN +} + + void commuterDEL_Interne(void) { LED_GPIO_INTERNE->ODR ^= (0x01 << LED_PIN_INTERNE); } diff --git a/Pilotes/Source/MyTimer.c b/Pilotes/Source/MyTimer.c index de6baef..4417459 100644 --- a/Pilotes/Source/MyTimer.c +++ b/Pilotes/Source/MyTimer.c @@ -1,9 +1,9 @@ #include -#include -#include -#include -#include -#include +#include "Timer.h" +#include "MyTimer.h" +#include "PWM.h" +#include "DriverGPIO.h" +#include "Horloge.h" // Constantes #define ARR_TIM1 0xFFAD @@ -23,7 +23,7 @@ void Test(void) { MyGPIO_Toggle(GPIOA, 8); } - +// LES COMMENTAIRES SONT POUR ACTIVER DES TIMERS QUE L'ON UTILISE PAS POUR LE MOMENT void ConfigureTimers() { // Config ARR & PSC //MyTimer_Base_Init(TIM2, ARR_TIM2, PSC_TIM2); @@ -40,7 +40,7 @@ void ConfigureTimers() { } -void ConfigureIT() { // Activate general interuption with a function and priority +void ConfigureIT() { // Activate general interuption with a function and priority //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 diff --git a/Pilotes/Source/MyUart.c b/Pilotes/Source/MyUart.c index 823b2d9..988dcef 100644 --- a/Pilotes/Source/MyUart.c +++ b/Pilotes/Source/MyUart.c @@ -1,6 +1,6 @@ #include -#include -#include +#include "DriverGPIO.h" +#include "MyTimer.h" void My_USART_Config(USART_TypeDef* USARTx, uint32_t baudrate) { //QUE POUR USART1 // Configuration PA9 (Tx) en Alternate Function Push-Pull diff --git a/Pilotes/Source/PWM.c b/Pilotes/Source/PWM.c index 885d42b..0a114fd 100644 --- a/Pilotes/Source/PWM.c +++ b/Pilotes/Source/PWM.c @@ -1,15 +1,15 @@ #include "stm32f10x.h" #include "PWM.h" -void MyTimer_PWM(TIM_TypeDef * Timer , int Channel){ + +void MyTimer_PWM(TIM_TypeDef * Timer, int Channel) { int pwrmd; #if POWERMODE //Powermode 1 pwrmd = 0b110; #else pwrmd = 0b111; //Powermode 2 #endif - - if (Channel == 1){ + if (Channel == 1){ Timer->CCMR1 &= ~(0b111<<4); //On clear les trois bits qui sont de pwm Timer->CCMR1 |= (pwrmd<<4); //On affecte le powermode au bits de lecture pour le µ-controlleur Timer->CCMR1 |= TIM_CCMR1_OC1PE; //Update preload, il n'affecte pas le valeur avant que la prochaine cycle @@ -66,20 +66,20 @@ void MyTimer_PWM(TIM_TypeDef * Timer , int Channel){ if (Timer == TIM2){GPIOA->CRL &= ~(0xF<<3*4); GPIOA->CRL |= (0xA<<3*4);} if (Timer == TIM3){GPIOB->CRL &= ~(0xF<<1*4); GPIOB->CRL |= (0xA<<1*4);} if (Timer == TIM4){GPIOB->CRH &= ~(0xF<<1*4); GPIOB->CRH |= (0xA<<1*4);} - } } + //Une fonction qui met le bon PWM voulu int Set_DutyCycle_PWM(TIM_TypeDef *Timer, int Channel, int DutyC){ - int CCR_VAL = (Timer -> ARR + 1) * DutyC / 100; - switch (Channel){ - case 1: Timer->CCR1 = CCR_VAL; - case 2: Timer->CCR2 = CCR_VAL; - case 3: Timer->CCR3 = CCR_VAL; - case 4: Timer->CCR4 = CCR_VAL; - default: break; -} -return 0; -Timer->EGR |= TIM_EGR_UG; + int CCR_VAL = (Timer -> ARR + 1) * DutyC / 100; + switch (Channel){ + case 1: Timer->CCR1 = CCR_VAL; + case 2: Timer->CCR2 = CCR_VAL; + case 3: Timer->CCR3 = CCR_VAL; + case 4: Timer->CCR4 = CCR_VAL; + default: break; + } + Timer->EGR |= TIM_EGR_UG; + return 0; } diff --git a/Pilotes/Source/Timer.c b/Pilotes/Source/Timer.c index 4f0faf4..e083f7f 100644 --- a/Pilotes/Source/Timer.c +++ b/Pilotes/Source/Timer.c @@ -1,5 +1,5 @@ #include -#include +#include "Timer.h" void MyTimer_Base_Init(TIM_TypeDef * Timer, unsigned short ValARR, unsigned short ValPSC) { // Configuration du timer diff --git a/Services/Source/Accelerometre.c b/Services/Source/Accelerometre.c index 9a5671c..c6a6ad0 100644 --- a/Services/Source/Accelerometre.c +++ b/Services/Source/Accelerometre.c @@ -1,36 +1,37 @@ #include -#include -#include -#include -#include -#include -#include +#include "Horloge.h" +#include "stdlib.h" +#include "MySPI.h" +#include "stdint.h" +#include "Accelerometre.h" +#include "Servo.h" + void initAccelo(void) { - //MySPI_Init(SPI1); + MySPI_Init(SPI1); + // Power_CTL register = 0x2D ? write 0x08 (MEASURE = 1) + MySPI_Clear_NSS(); + MySPI_Send(0x31); // DATA_FORMAT + MySPI_Send(0b00001101); // Justify met le MSB à gauche et b0 et b1 donne une resolution de +-2g + MySPI_Set_NSS(); - // Power_CTL register = 0x2D ? write 0x08 (MEASURE = 1) - //MySPI_Clear_NSS(); - //MySPI_Send(0x31); // DATA_FORMAT - //MySPI_Send(0b00001101); // Justify met le MSB à gauche et b0 et b1 donne une resolution de +-2g - //MySPI_Set_NSS(); - - //MySPI_Clear_NSS(); - //MySPI_Send(0x2D & 0x3F); // Écriture de l'adresse (pas de bit de read!) - //MySPI_Send(0x08); // Affectation du bit MEASURE - //MySPI_Set_NSS(); - RCC->APB2ENR |= RCC_APB2ENR_IOPBEN; // Activation de l'horloge Utiliser une service pour cela peut-être ??? - for (volatile int i = 0; i < 10000; i++); // small delay + MySPI_Clear_NSS(); + MySPI_Send(0x2D & 0x3F); // Écriture de l'adresse (pas de bit de read!) + MySPI_Send(0x08); // Affectation du bit MEASURE + MySPI_Set_NSS(); + RCC->APB2ENR |= RCC_APB2ENR_IOPBEN; // Activation de l'horloge Utiliser une service pour cela peut-être ??? + for (volatile int i = 0; i < 10000; i++); // small delay } + uint16_t * RecupAccelo(void) { // Recuperation des donnees de l'accelerometre static uint16_t Messie[3]; uint8_t buf[6]; - //MySPI_Clear_NSS(); + MySPI_Clear_NSS(); // Lecture multi-octet à partir de 0x32 (X0, X1, Y0, Y1, Z0 et Z1) - //MySPI_Send(0x80 | 0x40 | 0x32); // On envoie RW MB A5 ... A0 pour recuperer les données - //for (int i = 0; i < 6; i++) {buf[i] = (uint8_t)MySPI_Read();} // Lecture des 6 registres en séquenciel - //MySPI_Set_NSS(); + MySPI_Send(0x80 | 0x40 | 0x32); // On envoie RW MB A5 ... A0 pour recuperer les données + for (int i = 0; i < 6; i++) {buf[i] = (uint8_t)MySPI_Read();} // Lecture des 6 registres en séquenciel + MySPI_Set_NSS(); // Conversion des données récupérés en uint16_t Messie[0] = (uint16_t)(buf[1] << 8 | buf[0]); // X @@ -39,6 +40,7 @@ uint16_t * RecupAccelo(void) { // Recuperation des donnees de l'accelerometre return Messie; } + void initLacheur(void) { GPIOB->CRH &= ~(0xF << (0 * 4)); GPIOB->CRH |= (0xA << (0 * 4)); //On met GPIOB.8 en mode output 2Mhz, alternate pp @@ -46,19 +48,24 @@ void initLacheur(void) { Timer_Init(TIM4, 0xFFFF, 22); } + void LacheVoile(int AngelLim, uint16_t moyennen) { volatile uint16_t Val_lim = 0x1E20 - 60*AngelLim; if (moyennen= LONGUEUR_MOY) {i = 0;} // Géstion de la position i dans le tableau pour la moyenne glissante // return i; //} -//uint16_t moyenneGlissante(){ + + +//uint16_t moyenneGlissante() { // sum = 0; // for (int j = 0; j < LONGUEUR_MOY; j++){sum += moyenne[j];} moy = sum / LONGUEUR_MOY; // Calcul de la moyenne glissante // return(moy); diff --git a/Services/Source/Girouette.c b/Services/Source/Girouette.c index 398bcde..86683b6 100644 --- a/Services/Source/Girouette.c +++ b/Services/Source/Girouette.c @@ -8,7 +8,7 @@ #define POSITIONS (360*4) //0x5A0 -void configEncoder(TIM_TypeDef * Timer){ +void configEncoder(TIM_TypeDef * Timer) { // Timer EnableTimer(Timer); @@ -31,7 +31,7 @@ void configEncoder(TIM_TypeDef * Timer){ } -int angleVent (TIM_TypeDef * Timer){ // Returner l'angle du vent +int angleVent(TIM_TypeDef * Timer) { // Returner l'angle du vent int angle =(((Timer -> CNT*360)/POSITIONS )); if (angle > 180){ angle = 360 - angle; // Pour que l'angle soit entre 0 et 180 @@ -39,7 +39,8 @@ int angleVent (TIM_TypeDef * Timer){ // Returner l'angle du vent return(angle); } -int vent2voile(int angle){ // Conversion angle vent à angle voile + +int vent2voile(int angle) { // Conversion angle vent à angle voile if(angle < 45){ return 0; // Les voiles restent immobiles } @@ -48,8 +49,8 @@ int vent2voile(int angle){ // Conversion angle vent } } - // Localisation de z -void LocaliserZero(void){ + +void LocaliserZero(void) { // Localisation de z int Z_trouve = 0; while (Z_trouve != 1){ if(MyGPIO_Read(GPIOA,8)){ // Index diff --git a/Services/Source/Servo.c b/Services/Source/Servo.c index 881cdf1..00808f0 100644 --- a/Services/Source/Servo.c +++ b/Services/Source/Servo.c @@ -1,14 +1,16 @@ -#include -#include -#include -#include +#include "Servo.h" +#include "DriverGPIO.h" +#include "PWM.h" +#include "Horloge.h" -void Servo_Moteur(int angle, TIM_TypeDef * Timer, int Channel){ // Controle du moteur + +void Servo_Moteur(int angle, TIM_TypeDef * Timer, int Channel) { // Controle du moteur int dutyCycle = (5* angle + 5*90)/90; // 5-10 % Duty Cycle Set_DutyCycle_PWM(Timer, Channel, dutyCycle); } -void initServo(TIM_TypeDef * Timer, int Channel){ // Config du moteur servo + +void initServo(TIM_TypeDef * Timer, int Channel) { // Config du moteur servo if (Timer == TIM4) { Timer_Init(TIM4, 0xFFFF, 22); // Pour obtenir un période de 20 ms