From 2cbbf751bf32dbdc793f2dc4a01be4c13bd27fc0 Mon Sep 17 00:00:00 2001 From: Robin M Date: Sun, 19 Mar 2023 00:20:19 +0100 Subject: [PATCH] Deleted MyGPIO_Init Function -> ToDo --- drivers/Driver_GPIO.c | 67 +++++++++++++----------------------------- drivers/Driver_Timer.c | 0 drivers/Driver_Timer.h | 19 ++++++++++++ 3 files changed, 39 insertions(+), 47 deletions(-) create mode 100644 drivers/Driver_Timer.c create mode 100644 drivers/Driver_Timer.h diff --git a/drivers/Driver_GPIO.c b/drivers/Driver_GPIO.c index d41d350..7cc6bd5 100644 --- a/drivers/Driver_GPIO.c +++ b/drivers/Driver_GPIO.c @@ -1,41 +1,14 @@ #include "Driver_GPIO.h" #include "stm32f10x.h" -void test() { - int a = 20; -} - void MyGPIO_Init(MyGPIO_Struct_TypeDef * GPIOStructPtr) { - // Activation des horloges des ports A et C - RCC->APB2ENR |= (RCC_APB2ENR_IOPCEN); - RCC->APB2ENR |= (RCC_APB2ENR_IOPAEN); + // Activation des horloges des ports A et C + RCC->APB2ENR |= (RCC_APB2ENR_IOPCEN); + RCC->APB2ENR |= (RCC_APB2ENR_IOPAEN); + RCC->APB2ENR |= (RCC_APB2ENR_IOPBEN); + RCC->APB2ENR |= (RCC_APB2ENR_IOPDEN); - // On calcule la position de la broche à configurer en utilisant le numéro de broche contenu dans la structure GPIOStructPtr - uint32_t GPIO_Pin = 1 << GPIOStructPtr->GPIO_Pin; - - // On vérifie si la broche à configurer se trouve dans les 8 premières broches (CRL) ou les 8 dernières broches (CRH) - if (GPIOStructPtr->GPIO_Pin <= 7) { // Si la broche est dans les 8 premières broches (CRL) - // On réinitialise les 4 bits de configuration de la broche en utilisant un masque qui est décalé vers la gauche de (GPIOStructPtr->GPIO_Pin * 4) bits pour cibler la broche à configurer - GPIOStructPtr->GPIO->CRL &= ~(0xF << (GPIOStructPtr->GPIO_Pin * 4)); - // On configure la broche selon la configuration souhaitée en utilisant un masque qui est décalé vers la gauche de (GPIOStructPtr->GPIO_Pin * 4) bits pour cibler la broche à configurer - GPIOStructPtr->GPIO->CRL |= (GPIOStructPtr->GPIO_Conf << (GPIOStructPtr->GPIO_Pin * 4)); - } - else { // Si la broche est dans les 8 dernières broches (CRH) - // On réinitialise les 4 bits de configuration de la broche en utilisant un masque qui est décalé vers la gauche de ((GPIOStructPtr->GPIO_Pin - 8) * 4) bits pour cibler la broche à configurer - GPIOStructPtr->GPIO->CRH &= ~(0xF << ((GPIOStructPtr->GPIO_Pin - 8) * 4)); - // On configure la broche selon la configuration souhaitée en utilisant un masque qui est décalé vers la gauche de ((GPIOStructPtr->GPIO_Pin - 8) * 4) bits pour cibler la broche à configurer - GPIOStructPtr->GPIO->CRH |= (GPIOStructPtr->GPIO_Conf << ((GPIOStructPtr->GPIO_Pin - 8) * 4)); - } - - // Si la broche est en entrée, on la configure en input mode avec pull-up/pull-down désactivé - if (GPIOStructPtr->GPIO_Conf == In_Floating || GPIOStructPtr->GPIO_Conf == In_PullDown || GPIOStructPtr->GPIO_Conf == In_PullUp) { - // On met la broche en input mode en utilisant le registre BSRR de la GPIO - GPIOStructPtr->GPIO->BSRR = GPIO_Pin << 16; - } - else { // Si la broche est en sortie, on la configure en output mode et on met la broche à 0 (niveau bas) - // On met la broche en output mode en utilisant le registre BSRR de la GPIO - GPIOStructPtr->GPIO->BSRR = GPIO_Pin; - } + // To-Do } @@ -43,15 +16,15 @@ int MyGPIO_Read(GPIO_TypeDef * GPIO, char GPIO_Pin) { int bitstatus; - // Vérifier si le pin est haut ou bas en lisant l'état du bit correspondant dans le registre IDR - if ((GPIO->IDR & (1 << GPIO_Pin)) != 0) { - bitstatus = 1; // Si le bit est à 1, le pin est haut - } else { - bitstatus = 0; // Si le bit est à 0, le pin est bas - } + // Vérifier si le pin est haut ou bas en lisant l'état du bit correspondant dans le registre IDR + if ((GPIO->IDR & (1 << GPIO_Pin)) != 0) { + bitstatus = 1; // Si le bit est à 1, le pin est haut + } else { + bitstatus = 0; // Si le bit est à 0, le pin est bas + } - // Renvoyer l'état du GPIO (0 ou 1) - return bitstatus; + // Renvoyer l'état du GPIO (0 ou 1) + return bitstatus; } void MyGPIO_Set(GPIO_TypeDef * GPIO, char GPIO_Pin) { @@ -60,14 +33,14 @@ void MyGPIO_Set(GPIO_TypeDef * GPIO, char GPIO_Pin) { void MyGPIO_Reset(GPIO_TypeDef * GPIO, char GPIO_Pin) { - // Calcul de la valeur du masque à appliquer pour réinitialiser la broche - uint32_t mask = 1 << GPIO_Pin; // on décale le bit 1 de GPIO_Pin positions vers la gauche - - // Réinitialisation de la broche GPIO en niveau bas - GPIO->BRR = mask; // on met à 1 tous les bits correspondant aux broches à réinitialiser, ce qui les mettra à 0 (niveau bas) + // Calcul de la valeur du masque à appliquer pour réinitialiser la broche + uint32_t mask = 1 << GPIO_Pin; // on décale le bit 1 de GPIO_Pin positions vers la gauche + + // Réinitialisation de la broche GPIO en niveau bas + GPIO->BRR = mask; // on met à 1 tous les bits correspondant aux broches à réinitialiser, ce qui les mettra à 0 (niveau bas) } void MyGPIO_Toggle(GPIO_TypeDef * GPIO, char GPIO_Pin) { - GPIO->ODR ^= (1 << GPIO_Pin); // On fait un XOR pour toggle la pin correspondante + GPIO->ODR ^= (1 << GPIO_Pin); // On fait un XOR pour toggle la pin correspondante } \ No newline at end of file diff --git a/drivers/Driver_Timer.c b/drivers/Driver_Timer.c new file mode 100644 index 0000000..e69de29 diff --git a/drivers/Driver_Timer.h b/drivers/Driver_Timer.h new file mode 100644 index 0000000..18a439f --- /dev/null +++ b/drivers/Driver_Timer.h @@ -0,0 +1,19 @@ +#ifndef MYTIMER_H +#define MYTIMER_H + +#include "stm32f10x.h" + +typedef struct +{ + TIM_TypeDef * Timer; + unsigned short ARR; + unsigned short PSC; +} MyTimer_Struct_TypeDef; + + +void MyTimer_Base_Init(MyTimer_Struct_TypeDef * Timer); + +#define MyTimer_Base_Start(Timer) +#define MyTimer_Base_Stop(Timer) + +#endif \ No newline at end of file