Supprimer GPIO.c

This commit is contained in:
Oskar Orvik 2025-11-04 09:33:37 +01:00
parent 6c0d2d1123
commit dcc879d1e1

96
GPIO.c
View file

@ -1,96 +0,0 @@
#include "stm32f10x.h"
#include <stdlib.h>
int ChercherEtat(GPIO_TypeDef * GPIO, int pin){
return((GPIO -> IDR & (0x01 << pin)));
}
void ResetBroche(uint32_t GPIO, int Broche){
GPIO -> BSRR |= BSBroche;
}
void SetBroche(uint32_t GPIO, int Broche){
GPIO -> BSRR |= BSBroche << 16;
}
void ConfigureGPIO(uint32_t GPIO, int Broche, int IO, char Mode){
//Start clock
if(GPIO == GPIOA){
RCC -> APB2ENR |= RCC_APB2ENR_IOPAEN;
}
else if(GPIO == GPIOB){
RCC -> APB2ENR |= RCC_APB2ENR_IOPBEN;
}
else if(GPIO == GPIOC){
RCC -> APB2ENR |= RCC_APB2ENR_IOPCEN;
}
else if(GPIO == GPIOD){
RCC -> APB2ENR |= RCC_APB2ENR_IOPDEN;
}
if (Broche < 8) {
GPIO -> CRL &= ~(0x1 << Broche *4) & ~(0x1 << Broche *4 +1) & ~(0x1 << Broche *4 + 2) & ~(0x1 << Broche *4 + 3); // Clean bits
if (IO == 0){ //Input
if (strcmp(Mode,"Floating")) {
GPIO -> CRL |= (0x1 << Broche *4) | (0x1 << Broche * 4 + 1);
}
else if (strcmp(Mode,"Pull-Up") || strcmp(Mode,"Pull-Down")){
GPIO -> CRL |= (0x1 << 6*4 + 1);
}
else {
}
}
else if ( IO < 5) { // Output
GPIO -> CRL |= (0xIO << Broche * 4 + 2); // Frequency mode
if (strcmp(Mode, "Open-Drain")){
GPIO -> CRL |= (0x1 << Broche *4);
}
else if (strcmp(Mode, "Push-Pull Alterne")){
GPIO -> CRL |= (0x1 << Broche *4 + 1);
RCC->APB2ENR |= RCC_APB2ENR_AFIOEN; // Alternate Function I/O clock enable GPIOA
}
else if (strcmp(Mode, "Open-Drain Alterne")){
GPIO -> CRL |= (0x1 << Broche * 4) | (0x1 << Broche * 4 + 1);
}
else {
}
}
else{
return;
}
}
else if (Broche < 16) {
GPIO -> CRH &= ~(0x1 << Broche *4) & ~(0x1 << Broche *4 +1) & ~(0x1 << Broche *4 + 2) & ~(0x1 << Broche *4 + 3); // Clean bits
if (IO == 0){ //Input
if (strcmp(Mode,"Floating")) {
GPIO -> CRH |= (0x1 << Broche *4) | (0x1 << Broche * 4 + 1);
}
else if (strcmp(Mode,"Pull-Up") || strcmp(Mode,"Pull-Down")){
GPIO -> CRH |= (0x1 << 6*4 + 1);
}
else {
}
}
else if ( IO < 5) { // Output
GPIO -> CRH |= (0xIO << Broche * 4 + 2); // Frequency mode
if (strcmp(Mode, "Open-Drain")){
GPIO -> CRH |= (0x1 << Broche *4);
}
else if (strcmp(Mode, "Push-Pull Alterne")){
GPIO -> CRH |= (0x1 << Broche *4 + 1);
}
else if (strcmp(Mode, "Open-Drain Alterne")){
GPIO -> CRH |= (0x1 << Broche * 4) | (0x1 << Broche * 4 + 1);
}
else {
}
}
else{
return; // IO invalid
}
}
else{
return; // Pin number invalid
}
}