Added the activation of the specific clock to the GPIO port, during their initialization.

Added comments.
This commit is contained in:
Manon Sanchez 2023-03-20 14:20:52 +01:00
parent 4521ebea42
commit 80977b8053
2 changed files with 26 additions and 2 deletions

View file

@ -1,9 +1,29 @@
#include "Driver_GPIO.h"
#include "stm32f10x.h"
#include "stdio.h"
/* GPIO init function */
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)
{
@ -24,18 +44,22 @@ void MyGPIO_Init ( MyGPIO_Struct_TypeDef * GPIOStructPtr )
GPIOStructPtr->GPIO->ODR |= 0x1<<(GPIOStructPtr->GPIO_Pin);
}
}
/* Read of the state of the GPIO */
int MyGPIO_Read ( GPIO_TypeDef * GPIO , char 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)
{
GPIO->ODR &= 0x1<<GPIO_Pin;
}
/* Reset the state of the GPIO */
void MyGPIO_Reset (GPIO_TypeDef * GPIO , char GPIO_Pin)
{
GPIO->ODR |= ~(0x1<<GPIO_Pin);
}
/* Toogle the state of the GPIO */
void MyGPIO_Toggle ( GPIO_TypeDef * GPIO , char GPIO_Pin )
{
if(MyGPIO_Read(GPIO, GPIO_Pin))