Les fichiers Driver_SPI sont des versions personnelles non fonctionelle de la gestion du SPI. C'est la bibliothèque MySPI qui est utilisée dans le projet. Ajout de commentaires dans tous les fichiers driver en format doxygen.
72 行
1.7 KiB
C
72 行
1.7 KiB
C
#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)
|
|
{
|
|
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));
|
|
}
|
|
|
|
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 of the state of the GPIO */
|
|
int MyGPIO_Read ( GPIO_TypeDef * GPIO , char GPIO_Pin )
|
|
{
|
|
return ((GPIO->IDR & (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 )
|
|
{
|
|
GPIO->ODR ^= 0x1<<GPIO_Pin;
|
|
}
|