39 lines
846 B
C
39 lines
846 B
C
#include "stm32f10x.h"
|
|
|
|
|
|
void GPIO_configure(GPIO_TypeDef *GPIO ,int pin, char mode){
|
|
if (mode == 1) { // output push pull 2MHZ
|
|
GPIO->CRL = (GPIO->CRL & ~(0xF<<pin*4)) | (0x2<<pin*4);
|
|
}
|
|
if (mode == 2) { // input pullup
|
|
GPIO->CRL = (GPIO->CRL & ~(0xF<<pin*4)) | (0x8<<pin*4);
|
|
GPIO->ODR |= (1<<pin);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void allume_led (GPIO_TypeDef *GPIO , char GPIO_Pin){
|
|
GPIO->ODR |= (1<<GPIO_Pin);
|
|
};
|
|
|
|
void eteindre_led (GPIO_TypeDef *GPIO , char GPIO_Pin){
|
|
GPIO->ODR &= ~(1<<GPIO_Pin);
|
|
};
|
|
|
|
void toggle_pin (GPIO_TypeDef *GPIO , char GPIO_Pin){
|
|
if ((GPIO->ODR & (1<<GPIO_Pin)) == 0)
|
|
GPIO->ODR |= (1<<GPIO_Pin);
|
|
else
|
|
GPIO->ODR &= ~(1<<GPIO_Pin);
|
|
};
|
|
|
|
|
|
int GPIO_bouton_read (GPIO_TypeDef *GPIO , char GPIO_Pin ){
|
|
if ((GPIO->IDR & (1<<GPIO_Pin)) == 0) {
|
|
return 0;
|
|
}
|
|
else{
|
|
return 1;
|
|
}
|
|
};
|