82 lines
2.1 KiB
C
82 lines
2.1 KiB
C
#include "Driver_GPIO.h"
|
|
|
|
|
|
//---------------------FONCTION D'INITIALISATION-----------------//
|
|
void MyGPIO_Init ( MyGPIO_Struct_TypeDef * GPIOStructPtr )
|
|
{
|
|
|
|
/* Activation de la clock liée au GPIO sélectionné */
|
|
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 & configuration de la pin avec le mode adéquat */
|
|
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));
|
|
}
|
|
|
|
/* Ecriture de l'ODR pour choisir entre pulldown & pushpull*/
|
|
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;
|
|
|
|
/* Verification de la valeur de l'IDR */
|
|
if((GPIO->IDR & (1<<GPIO_Pin))!=0){
|
|
etatbit = 1;
|
|
}
|
|
else{
|
|
etatbit = 0;
|
|
}
|
|
return etatbit ;
|
|
}
|
|
|
|
//---------------------SET-------------------//
|
|
void MyGPIO_Set ( GPIO_TypeDef * GPIO , char GPIO_Pin ){
|
|
|
|
/*Ecriture du 1 sur le numéro de la pin dans le registre BSRR*/
|
|
GPIO->BSRR |= (1 << GPIO_Pin);
|
|
}
|
|
|
|
//---------------------RESET-----------------//
|
|
void MyGPIO_Reset ( GPIO_TypeDef * GPIO , char GPIO_Pin ){
|
|
|
|
/*Ecriture du 1 sur le numéro de la pin dans le registre BRR*/
|
|
GPIO->BRR = (1 << GPIO_Pin);
|
|
}
|
|
|
|
//---------------------TOGGLE-----------------//
|
|
void MyGPIO_Toggle ( GPIO_TypeDef * GPIO , char GPIO_Pin ){
|
|
GPIO->ODR ^= (1 << GPIO_Pin);
|
|
}
|
|
|