46 行
无行尾
1.5 KiB
C
46 行
无行尾
1.5 KiB
C
#include "Driver_GPIO.h"
|
|
#include "stm32f10x.h"
|
|
|
|
void MyGPIO_Init(MyGPIO_Struct_TypeDef * GPIOStructPtr) {
|
|
// Activation des horloges des ports A et C
|
|
RCC->APB2ENR |= (RCC_APB2ENR_IOPCEN);
|
|
RCC->APB2ENR |= (RCC_APB2ENR_IOPAEN);
|
|
RCC->APB2ENR |= (RCC_APB2ENR_IOPBEN);
|
|
RCC->APB2ENR |= (RCC_APB2ENR_IOPDEN);
|
|
|
|
// To-Do
|
|
}
|
|
|
|
|
|
int MyGPIO_Read(GPIO_TypeDef * GPIO, char GPIO_Pin) {
|
|
|
|
int bitstatus;
|
|
|
|
// Vérifier si le pin est haut ou bas en lisant l'état du bit correspondant dans le registre IDR
|
|
if ((GPIO->IDR & (1 << GPIO_Pin)) != 0) {
|
|
bitstatus = 1; // Si le bit est à 1, le pin est haut
|
|
} else {
|
|
bitstatus = 0; // Si le bit est à 0, le pin est bas
|
|
}
|
|
|
|
// Renvoyer l'état du GPIO (0 ou 1)
|
|
return bitstatus;
|
|
}
|
|
|
|
void MyGPIO_Set(GPIO_TypeDef * GPIO, char GPIO_Pin) {
|
|
GPIO->BSRR |= (uint32_t)(1 << GPIO_Pin); // Set la pin correspondante en écrivant un 1 dans le bit correspondant de BSRR
|
|
}
|
|
|
|
void MyGPIO_Reset(GPIO_TypeDef * GPIO, char GPIO_Pin)
|
|
{
|
|
// Calcul de la valeur du masque à appliquer pour réinitialiser la broche
|
|
uint32_t mask = 1 << GPIO_Pin; // on décale le bit 1 de GPIO_Pin positions vers la gauche
|
|
|
|
// Réinitialisation de la broche GPIO en niveau bas
|
|
GPIO->BRR = mask; // on met à 1 tous les bits correspondant aux broches à réinitialiser, ce qui les mettra à 0 (niveau bas)
|
|
}
|
|
|
|
|
|
void MyGPIO_Toggle(GPIO_TypeDef * GPIO, char GPIO_Pin) {
|
|
GPIO->ODR ^= (1 << GPIO_Pin); // On fait un XOR pour toggle la pin correspondante
|
|
} |