#include "Driver_GPIO.h" void MyGPIO_Init(MyGPIO_Struct_TypeDef * Data){ char finalConf = Data->GPIO_Conf; GPIO_TypeDef * GPIO; GPIO = Data->GPIO; // Mise en place de la clock if (GPIO==GPIOA){ RCC->APB2ENR |= (0x01 << 2) ; } else if (GPIO==GPIOB){ RCC->APB2ENR |= (0x01 << 3) ; } else { RCC->APB2ENR |= (0x01 << 4) ; } // On regarde si on est en pull_up if (finalConf == 0x18){ Data->GPIO->ODR |= 0x01 << Data->GPIO_Pin; finalConf = 0x08; } // Initialisation de la bonne pin if (Data->GPIO_Pin < 8){ Data->GPIO->CRL &= ~(0xF << 4*Data->GPIO_Pin); // shifté de 4*numPin Data->GPIO->CRL |= (Data->GPIO_Conf << 4*Data->GPIO_Pin); } else { Data->GPIO->CRH &= ~(0xF << 4*(Data->GPIO_Pin -8)); // shifté de 4*numPin Data->GPIO->CRH |= (Data->GPIO_Conf << 4*(Data->GPIO_Pin -8)); } } int MyGPIO_Read(GPIO_TypeDef* GPIO, int GPIO_Pin) {// renvoie 0 ou autre chose different de 0 return ((GPIO->IDR >> GPIO_Pin) & 1); } void MyGPIO_Set(GPIO_TypeDef* GPIO, int GPIO_Pin){ // Bit 0 à 15 de BSRR c'est le set GPIO->BSRR |= 0x01 << GPIO_Pin; } void MyGPIO_Reset(GPIO_TypeDef* GPIO, int GPIO_Pin){ // Bit 16 à 31 de BSRR c'est le reset GPIO->BSRR |= ((0x01 << GPIO_Pin) << 0x10); } void MyGPIO_Toggle(GPIO_TypeDef* GPIO, int GPIO_Pin){ // Toggle : changer la valeur du ODR GPIO->ODR ^= 0x01 << GPIO_Pin; }