forked from trocache/RefKEIL
Added the activation of the specific clock to the GPIO port, during their initialization.
Added comments.
This commit is contained in:
parent
4521ebea42
commit
80977b8053
2 changed files with 26 additions and 2 deletions
|
@ -1,9 +1,29 @@
|
||||||
#include "Driver_GPIO.h"
|
#include "Driver_GPIO.h"
|
||||||
#include "stm32f10x.h"
|
#include "stm32f10x.h"
|
||||||
#include "stdio.h"
|
#include "stdio.h"
|
||||||
|
/* GPIO init function */
|
||||||
void MyGPIO_Init ( MyGPIO_Struct_TypeDef * GPIOStructPtr )
|
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 */
|
/* Reset, and then configuration writing of the selected GPIO Pin */
|
||||||
if(GPIOStructPtr->GPIO_Pin <= 8)
|
if(GPIOStructPtr->GPIO_Pin <= 8)
|
||||||
{
|
{
|
||||||
|
@ -24,18 +44,22 @@ void MyGPIO_Init ( MyGPIO_Struct_TypeDef * GPIOStructPtr )
|
||||||
GPIOStructPtr->GPIO->ODR |= 0x1<<(GPIOStructPtr->GPIO_Pin);
|
GPIOStructPtr->GPIO->ODR |= 0x1<<(GPIOStructPtr->GPIO_Pin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/* Read of the state of the GPIO */
|
||||||
int MyGPIO_Read ( GPIO_TypeDef * GPIO , char GPIO_Pin )
|
int MyGPIO_Read ( GPIO_TypeDef * GPIO , char GPIO_Pin )
|
||||||
{
|
{
|
||||||
return ((GPIO->ODR & (0x1<<GPIO_Pin))>>GPIO_Pin);
|
return ((GPIO->ODR & (0x1<<GPIO_Pin))>>GPIO_Pin);
|
||||||
}
|
}
|
||||||
|
/* Set the state of the GPIO */
|
||||||
void MyGPIO_Set (GPIO_TypeDef * GPIO , char GPIO_Pin)
|
void MyGPIO_Set (GPIO_TypeDef * GPIO , char GPIO_Pin)
|
||||||
{
|
{
|
||||||
GPIO->ODR &= 0x1<<GPIO_Pin;
|
GPIO->ODR &= 0x1<<GPIO_Pin;
|
||||||
}
|
}
|
||||||
|
/* Reset the state of the GPIO */
|
||||||
void MyGPIO_Reset (GPIO_TypeDef * GPIO , char GPIO_Pin)
|
void MyGPIO_Reset (GPIO_TypeDef * GPIO , char GPIO_Pin)
|
||||||
{
|
{
|
||||||
GPIO->ODR |= ~(0x1<<GPIO_Pin);
|
GPIO->ODR |= ~(0x1<<GPIO_Pin);
|
||||||
}
|
}
|
||||||
|
/* Toogle the state of the GPIO */
|
||||||
void MyGPIO_Toggle ( GPIO_TypeDef * GPIO , char GPIO_Pin )
|
void MyGPIO_Toggle ( GPIO_TypeDef * GPIO , char GPIO_Pin )
|
||||||
{
|
{
|
||||||
if(MyGPIO_Read(GPIO, GPIO_Pin))
|
if(MyGPIO_Read(GPIO, GPIO_Pin))
|
||||||
|
|
|
@ -18,7 +18,7 @@ typedef struct
|
||||||
#define AltOut_OD 0x1110
|
#define AltOut_OD 0x1110
|
||||||
|
|
||||||
void MyGPIO_Init ( MyGPIO_Struct_TypeDef * GPIOStructPtr ) ;
|
void MyGPIO_Init ( MyGPIO_Struct_TypeDef * GPIOStructPtr ) ;
|
||||||
int MyGPIO_Read ( GPIO_TypeDef * GPIO , char GPIO_Pin ) ; // re nv oie 0 ou a u t re chose d i f f e r e n t de 0
|
int MyGPIO_Read ( GPIO_TypeDef * GPIO , char GPIO_Pin ) ; // renvoie 0 ou autre chose different de 0
|
||||||
void MyGPIO_Set ( GPIO_TypeDef * GPIO , char GPIO_Pin ) ;
|
void MyGPIO_Set ( GPIO_TypeDef * GPIO , char GPIO_Pin ) ;
|
||||||
void MyGPIO_Reset ( GPIO_TypeDef * GPIO , char GPIO_Pin ) ;
|
void MyGPIO_Reset ( GPIO_TypeDef * GPIO , char GPIO_Pin ) ;
|
||||||
void MyGPIO_Toggle ( GPIO_TypeDef * GPIO , char GPIO_Pin ) ;
|
void MyGPIO_Toggle ( GPIO_TypeDef * GPIO , char GPIO_Pin ) ;
|
||||||
|
|
Loading…
Reference in a new issue