diff --git a/ProjetsKEIL/Drivers/Source/Principale.c b/ProjetsKEIL/Drivers/Source/Principale.c
index 922498e..9b4d29a 100644
--- a/ProjetsKEIL/Drivers/Source/Principale.c
+++ b/ProjetsKEIL/Drivers/Source/Principale.c
@@ -3,7 +3,7 @@
int main ( void )
{
- MyGPIO_Struct_TypeDef gpioA_test = {GPIOA,13,Out_PullUp};
+ MyGPIO_Struct_TypeDef gpioA_test = {GPIOA,13,In_PullUp};
MyGPIO_Init(&gpioA_test);
do{
}while(1) ;
diff --git a/ProjetsKEIL/Drivers/gpiodriver.c b/ProjetsKEIL/Drivers/gpiodriver.c
index 68e9126..ed492b6 100644
--- a/ProjetsKEIL/Drivers/gpiodriver.c
+++ b/ProjetsKEIL/Drivers/gpiodriver.c
@@ -2,20 +2,24 @@
void MyGPIO_Init(MyGPIO_Struct_TypeDef * GPIOStructPtr)
{
- RCC->APB2ENR |= (0x01 << 2) | (0x01 << 3) | (0x01 << 4);
+ uint8_t voyons = GPIOStructPtr->GPIO_Pin;
+ RCC->APB2ENR |= GPIO2Int(GPIOStructPtr->GPIO);
+ //We get the pointer of the CRH/CRL depending on the IO_Pin number
volatile uint32_t * CRAny = GPIOStructPtr->GPIO_Pin > 0x08 ? &(GPIOStructPtr->GPIO->CRH):&(GPIOStructPtr->GPIO->CRL);
//setup high or low
*CRAny &= ~(0xF << (GPIOStructPtr->GPIO_Pin%8)*4); //reset
- *CRAny |= (GPIOStructPtr->GPIO_Conf << (GPIOStructPtr->GPIO_Pin%8)*4); //set pin mode
//for input pull or push
- if(!(GPIOStructPtr->GPIO_Conf%2) && (GPIOStructPtr->GPIO_Conf>0x04)) //si input mode et en pullpush
+ switch(GPIOStructPtr->GPIO_Conf)
{
- if(GPIOStructPtr->GPIO_Conf > In_PullDown)
- {
- GPIOStructPtr->GPIO->ODR &= ~(0x01 << GPIOStructPtr->GPIO_Pin);
- } else{
- GPIOStructPtr->GPIO->ODR |= (0x01 << GPIOStructPtr->GPIO_Pin);
- }
+ case In_PullUp:
+ GPIOStructPtr->GPIO->ODR |= (0x01 << GPIOStructPtr->GPIO_Pin); //if pullup -> ODR = 1
+ *CRAny |= (In_PullDown << (GPIOStructPtr->GPIO_Pin%8)*4); //set pin mode -> force to In_PullDown because PullDown is modified
+ break;
+ case In_PullDown:
+ GPIOStructPtr->GPIO->ODR &= ~(0x01 << GPIOStructPtr->GPIO_Pin); //if pullup -> ODR = 0
+ default:
+ *CRAny |= (GPIOStructPtr->GPIO_Conf << (GPIOStructPtr->GPIO_Pin%8)*4); //set pin mode for any input/output
+ break;
}
}
@@ -38,3 +42,25 @@ void MyGPIO_Toggle(GPIO_TypeDef * GPIO, uint8_t GPIO_Pin)
{
}
+
+int GPIO2Int(GPIO_TypeDef * GPIOX)
+{
+ if(GPIOX == GPIOA)
+ {
+ return (0x01 << 2);
+ } else if (GPIOX == GPIOB){
+ return (0x01 << 3);
+ } else if (GPIOX == GPIOC){
+ return (0x01 << 4);
+ } else if (GPIOX == GPIOD){
+ return (0x01 << 5);
+ } else if (GPIOX == GPIOE){
+ return (0x01 << 6);
+ } else if (GPIOX == GPIOF){
+ return (0x01 << 7);
+ } else if (GPIOX == GPIOE){
+ return (0x01 << 8);
+ } else {
+ return -1;
+ };
+}
diff --git a/ProjetsKEIL/Drivers/gpiodriver.h b/ProjetsKEIL/Drivers/gpiodriver.h
index 5577e20..65a297c 100644
--- a/ProjetsKEIL/Drivers/gpiodriver.h
+++ b/ProjetsKEIL/Drivers/gpiodriver.h
@@ -4,7 +4,7 @@
typedef struct
{
- GPIO_TypeDef * GPIO;
+ GPIO_TypeDef * GPIO; //GPIO A,B,C,D...
uint8_t GPIO_Pin; //numero de 0 à 15
uint8_t GPIO_Conf; //voir ci dessous
} MyGPIO_Struct_TypeDef;
@@ -18,6 +18,7 @@ typedef struct
#define AltOut_Ppull 0x09
#define AltOut_OD 0x0d
+int GPIO2Int(GPIO_TypeDef * GPIOX);
void MyGPIO_Init(MyGPIO_Struct_TypeDef * GPIOStructPtr);
int MyGPIO_Read(GPIO_TypeDef * GPIO, uint8_t GPIO_Pin);
void MyGPIO_Set(GPIO_TypeDef * GPIO, uint8_t GPIO_Pin);
diff --git a/ProjetsKEIL/Drivers/gpiodriver.uvoptx b/ProjetsKEIL/Drivers/gpiodriver.uvoptx
index 209328d..9d1f1df 100644
--- a/ProjetsKEIL/Drivers/gpiodriver.uvoptx
+++ b/ProjetsKEIL/Drivers/gpiodriver.uvoptx
@@ -125,7 +125,7 @@
0
DLGDARM
- (1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(100=-1,-1,-1,-1,0)(110=-1,-1,-1,-1,0)(111=-1,-1,-1,-1,0)(1011=-1,-1,-1,-1,0)(180=-1,-1,-1,-1,0)(120=932,137,1353,564,0)(121=-1,-1,-1,-1,0)(122=875,109,1296,536,0)(123=-1,-1,-1,-1,0)(140=-1,-1,-1,-1,0)(240=-1,-1,-1,-1,0)(190=-1,-1,-1,-1,0)(200=-1,-1,-1,-1,0)(170=-1,-1,-1,-1,0)(130=-1,-1,-1,-1,0)(131=-1,-1,-1,-1,0)(132=-1,-1,-1,-1,0)(133=-1,-1,-1,-1,0)(160=-1,-1,-1,-1,0)(161=-1,-1,-1,-1,0)(162=-1,-1,-1,-1,0)(210=-1,-1,-1,-1,0)(211=-1,-1,-1,-1,0)(220=-1,-1,-1,-1,0)(221=-1,-1,-1,-1,0)(230=-1,-1,-1,-1,0)(234=-1,-1,-1,-1,0)(231=-1,-1,-1,-1,0)(232=-1,-1,-1,-1,0)(233=-1,-1,-1,-1,0)(150=-1,-1,-1,-1,0)(151=-1,-1,-1,-1,0)
+ (1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(100=-1,-1,-1,-1,0)(110=-1,-1,-1,-1,0)(111=-1,-1,-1,-1,0)(1011=-1,-1,-1,-1,0)(180=-1,-1,-1,-1,0)(120=1508,115,1929,542,1)(121=-1,-1,-1,-1,0)(122=875,109,1296,536,0)(123=-1,-1,-1,-1,0)(140=-1,-1,-1,-1,0)(240=-1,-1,-1,-1,0)(190=-1,-1,-1,-1,0)(200=-1,-1,-1,-1,0)(170=-1,-1,-1,-1,0)(130=-1,-1,-1,-1,0)(131=-1,-1,-1,-1,0)(132=-1,-1,-1,-1,0)(133=-1,-1,-1,-1,0)(160=-1,-1,-1,-1,0)(161=-1,-1,-1,-1,0)(162=-1,-1,-1,-1,0)(210=-1,-1,-1,-1,0)(211=-1,-1,-1,-1,0)(220=-1,-1,-1,-1,0)(221=-1,-1,-1,-1,0)(230=-1,-1,-1,-1,0)(234=-1,-1,-1,-1,0)(231=-1,-1,-1,-1,0)(232=-1,-1,-1,-1,0)(233=-1,-1,-1,-1,0)(150=-1,-1,-1,-1,0)(151=-1,-1,-1,-1,0)
0
@@ -138,7 +138,79 @@
UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128 -FS08000000 -FL020000 -FP0($$Device:STM32F103RB$Flash\STM32F10x_128.FLM))
-
+
+
+ 0
+ 0
+ 23
+ 1
+ 134218316
+ 0
+ 0
+ 0
+ 0
+ 0
+ 1
+ .\gpiodriver.c
+
+ \\cool_Simule\gpiodriver.c\23
+
+
+ 1
+ 0
+ 4
+ 1
+ 134218164
+ 0
+ 0
+ 0
+ 0
+ 0
+ 1
+ .\gpiodriver.c
+
+ \\cool_Simule\gpiodriver.c\4
+
+
+ 2
+ 0
+ 11
+ 1
+ 134218228
+ 0
+ 0
+ 0
+ 0
+ 0
+ 1
+ .\gpiodriver.c
+
+ \\cool_Simule\gpiodriver.c\11
+
+
+ 3
+ 0
+ 22
+ 1
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ .\gpiodriver.c
+
+
+
+
+
+
+ 0
+ 1
+ voyons
+
+
0