forked from johnse/BE_VOILIER
Add enable logic
This commit is contained in:
parent
b855e0aea1
commit
6c0d2d1123
1 changed files with 96 additions and 0 deletions
96
GPIO.c
Normal file
96
GPIO.c
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
#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
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in a new issue