76 lines
2 KiB
C
76 lines
2 KiB
C
#include "Driver_GPIO.h"
|
|
|
|
|
|
//---------------------FONCTION D'INITIALISATION-----------------//
|
|
void MyGPIO_Init ( MyGPIO_Struct_TypeDef * GPIOStructPtr )
|
|
{
|
|
|
|
/* Activation of the GPIO port specific clock */
|
|
if (GPIOStructPtr->GPIO == GPIOA)
|
|
{
|
|
RCC->APB2ENR |= RCC_APB2ENR_IOPAEN;
|
|
}
|
|
else if (GPIOStructPtr->GPIO == GPIOB)
|
|
{
|
|
RCC->APB2ENR |= RCC_APB2ENR_IOPBEN;
|
|
}
|
|
else if (GPIOStructPtr->GPIO == GPIOC)
|
|
{
|
|
RCC->APB2ENR |= RCC_APB2ENR_IOPCEN;
|
|
}
|
|
else if (GPIOStructPtr->GPIO == GPIOD)
|
|
{
|
|
RCC->APB2ENR |= RCC_APB2ENR_IOPDEN;
|
|
}
|
|
|
|
|
|
/* Reset, and then configuration writing of the selected GPIO Pin */
|
|
if(GPIOStructPtr->GPIO_Pin <= 8)
|
|
{
|
|
GPIOStructPtr->GPIO->CRL &= ~0xF<<(4*(GPIOStructPtr->GPIO_Pin));
|
|
GPIOStructPtr->GPIO->CRL |= (GPIOStructPtr->GPIO_Conf)<<(4*(GPIOStructPtr->GPIO_Pin));
|
|
}
|
|
else
|
|
{
|
|
GPIOStructPtr->GPIO->CRH &= ~0xF<<(4*((GPIOStructPtr->GPIO_Pin)%8));
|
|
GPIOStructPtr->GPIO->CRH |= (GPIOStructPtr->GPIO_Conf)<<(4*((GPIOStructPtr->GPIO_Pin)%8));
|
|
}
|
|
|
|
if(GPIOStructPtr->GPIO_Conf == (char)In_PullDown)
|
|
{
|
|
GPIOStructPtr->GPIO->ODR &= ~(0x1<<(GPIOStructPtr->GPIO_Pin));
|
|
}
|
|
else if(GPIOStructPtr->GPIO_Conf == (char)In_PullUp)
|
|
{
|
|
GPIOStructPtr->GPIO->ODR |= 0x1<<(GPIOStructPtr->GPIO_Pin);
|
|
}
|
|
}
|
|
|
|
//----------------------------READ--------------------------//
|
|
int MyGPIO_Read ( GPIO_TypeDef * GPIO , char GPIO_Pin ){
|
|
int etatbit;
|
|
//On vérifie si la valeur lue dans l'IDR est un 0 ou un 1
|
|
if((GPIO->IDR & (1<<GPIO_Pin))!=0){
|
|
etatbit = 1;
|
|
}
|
|
else{
|
|
etatbit = 0;
|
|
}
|
|
return etatbit ;
|
|
}
|
|
|
|
//---------------------SET-------------------//
|
|
void MyGPIO_Set ( GPIO_TypeDef * GPIO , char GPIO_Pin ){
|
|
GPIO->BSRR |= (1 << GPIO_Pin);
|
|
}
|
|
|
|
//---------------------RESET-----------------//
|
|
void MyGPIO_Reset ( GPIO_TypeDef * GPIO , char GPIO_Pin ){
|
|
GPIO->BRR = (1 << GPIO_Pin);
|
|
//Pas besoin de | puisque les 0 n'impactent pas la fonction reset
|
|
}
|
|
|
|
//---------------------TOGGLE-----------------//
|
|
void MyGPIO_Toggle ( GPIO_TypeDef * GPIO , char GPIO_Pin ){
|
|
GPIO->ODR ^= (1 << GPIO_Pin);
|
|
}
|