forked from trocache/RefKEIL
63 lines
1.2 KiB
C
63 lines
1.2 KiB
C
#include "stm32f10x.h"
|
|
#include "Driver_GPIO.h"
|
|
|
|
|
|
|
|
|
|
void MyGPIO_Init(MyGPIO_Struct_TypeDef * GPIOStructPtr)
|
|
{
|
|
if (GPIOStructPtr->GPIO==GPIOA)
|
|
{
|
|
RCC->APB2ENR |= RCC_APB2ENR_IOPAEN;
|
|
}
|
|
if (GPIOStructPtr->GPIO==GPIOB)
|
|
{
|
|
RCC->APB2ENR |= RCC_APB2ENR_IOPBEN;
|
|
}
|
|
if (GPIOStructPtr->GPIO==GPIOC)
|
|
{
|
|
RCC->APB2ENR |= RCC_APB2ENR_IOPCEN;
|
|
}
|
|
if (GPIOStructPtr->GPIO==GPIOD)
|
|
{
|
|
RCC->APB2ENR |= RCC_APB2ENR_IOPDEN;
|
|
}
|
|
|
|
|
|
if((GPIOStructPtr->GPIO_Pin)>7)
|
|
{
|
|
GPIOStructPtr->GPIO->CRH &= ~(0xF<<(GPIOStructPtr->GPIO_Pin%8)*4);
|
|
GPIOStructPtr->GPIO->CRH |= (GPIOStructPtr->GPIO_Conf)<<(GPIOStructPtr->GPIO_Pin%8)*4;
|
|
}else
|
|
{
|
|
GPIOStructPtr->GPIO->CRL &= ~(0xF<<(GPIOStructPtr->GPIO_Pin%8)*4);
|
|
GPIOStructPtr->GPIO->CRL |= (GPIOStructPtr->GPIO_Conf)<<(GPIOStructPtr->GPIO_Pin%8)*4;
|
|
}
|
|
}
|
|
|
|
|
|
int MyGPIO_Read (GPIO_TypeDef * GPIO , char GPIO_Pin)
|
|
{
|
|
int retour;
|
|
retour=(GPIO->IDR>>(GPIO_Pin));
|
|
retour&=0x1;
|
|
return retour ;
|
|
}
|
|
|
|
|
|
void MyGPIO_Set (GPIO_TypeDef * GPIO , char GPIO_Pin)
|
|
{
|
|
GPIO->ODR|=1<<GPIO_Pin;
|
|
}
|
|
|
|
|
|
void MyGPIO_Reset (GPIO_TypeDef * GPIO , char GPIO_Pin)
|
|
{
|
|
GPIO->ODR&=0<<GPIO_Pin;
|
|
}
|
|
|
|
|
|
void MyGPIO_Toggle (GPIO_TypeDef * GPIO , char GPIO_Pin)
|
|
{
|
|
GPIO->ODR^=1<<(GPIO_Pin);
|
|
}
|