70 lines
1.7 KiB
C
70 lines
1.7 KiB
C
#include "GPIO.h"
|
|
|
|
void MyGPIO_Init ( MyGPIO_Struct_TypeDef * GPIOStructPtr )
|
|
{
|
|
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;
|
|
}
|
|
|
|
if(GPIOStructPtr->GPIO_Conf==0x9)
|
|
{
|
|
GPIOStructPtr->GPIO_Conf=GPIOStructPtr->GPIO_Conf-1;
|
|
GPIOStructPtr->GPIO->ODR |= 0x1<<(((GPIOStructPtr->GPIO_Pin)));
|
|
}
|
|
else if(GPIOStructPtr->GPIO_Conf==0x8)
|
|
{
|
|
GPIOStructPtr->GPIO->ODR &= ~0x1<<(((GPIOStructPtr->GPIO_Pin)));
|
|
}
|
|
if(GPIOStructPtr->GPIO_Pin>=8)
|
|
{
|
|
GPIOStructPtr->GPIO->CRH &= ~0xF<<(4*((GPIOStructPtr->GPIO_Pin)%8)); //on met a 0 les bit de config du pin
|
|
GPIOStructPtr->GPIO->CRH |= GPIOStructPtr->GPIO_Conf<<(4*((GPIOStructPtr->GPIO_Pin)%8));
|
|
}
|
|
else
|
|
{
|
|
GPIOStructPtr->GPIO->CRL &= ~0xF<<(4*((GPIOStructPtr->GPIO_Pin)%8)); //on met a 0 les bit de config du pin
|
|
GPIOStructPtr->GPIO->CRL |= GPIOStructPtr->GPIO_Conf<<(4*((GPIOStructPtr->GPIO_Pin)%8)); //on met a 0 les bit de config du pin
|
|
}
|
|
}
|
|
|
|
int MyGPIO_Read ( GPIO_TypeDef * GPIO , char GPIO_Pin ) // renvoie 0 ou autre chose different de 0
|
|
{
|
|
int bit=0;
|
|
bit = (GPIO->IDR>>GPIO_Pin)&0x01;
|
|
return bit;
|
|
}
|
|
void MyGPIO_Set ( GPIO_TypeDef * GPIO , char GPIO_Pin )
|
|
{
|
|
GPIO->ODR |=(0x01<<GPIO_Pin);
|
|
}
|
|
|
|
void MyGPIO_Reset ( GPIO_TypeDef * GPIO , char GPIO_Pin )
|
|
{
|
|
GPIO->ODR &= ((~0x01)<<GPIO_Pin);
|
|
}
|
|
|
|
void MyGPIO_Toggle ( GPIO_TypeDef * GPIO , char GPIO_Pin )
|
|
{
|
|
if((((GPIO->ODR)>>GPIO_Pin)&0x01)==1)
|
|
{
|
|
MyGPIO_Reset(GPIO,GPIO_Pin);
|
|
}
|
|
else
|
|
{
|
|
MyGPIO_Set(GPIO,GPIO_Pin);
|
|
}
|
|
}
|
|
|