forked from trocache/RefKEIL
Some bug fixes with In_PullUp/Down, now only activate the clock for a given GPIO
This commit is contained in:
parent
71027e893f
commit
8bb9290fa5
4 changed files with 112 additions and 13 deletions
|
@ -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) ;
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -125,7 +125,7 @@
|
|||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
<Key>DLGDARM</Key>
|
||||
<Name>(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)</Name>
|
||||
<Name>(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)</Name>
|
||||
</SetRegEntry>
|
||||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
|
@ -138,7 +138,79 @@
|
|||
<Name>UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128 -FS08000000 -FL020000 -FP0($$Device:STM32F103RB$Flash\STM32F10x_128.FLM))</Name>
|
||||
</SetRegEntry>
|
||||
</TargetDriverDllRegistry>
|
||||
<Breakpoint/>
|
||||
<Breakpoint>
|
||||
<Bp>
|
||||
<Number>0</Number>
|
||||
<Type>0</Type>
|
||||
<LineNumber>23</LineNumber>
|
||||
<EnabledFlag>1</EnabledFlag>
|
||||
<Address>134218316</Address>
|
||||
<ByteObject>0</ByteObject>
|
||||
<HtxType>0</HtxType>
|
||||
<ManyObjects>0</ManyObjects>
|
||||
<SizeOfObject>0</SizeOfObject>
|
||||
<BreakByAccess>0</BreakByAccess>
|
||||
<BreakIfRCount>1</BreakIfRCount>
|
||||
<Filename>.\gpiodriver.c</Filename>
|
||||
<ExecCommand></ExecCommand>
|
||||
<Expression>\\cool_Simule\gpiodriver.c\23</Expression>
|
||||
</Bp>
|
||||
<Bp>
|
||||
<Number>1</Number>
|
||||
<Type>0</Type>
|
||||
<LineNumber>4</LineNumber>
|
||||
<EnabledFlag>1</EnabledFlag>
|
||||
<Address>134218164</Address>
|
||||
<ByteObject>0</ByteObject>
|
||||
<HtxType>0</HtxType>
|
||||
<ManyObjects>0</ManyObjects>
|
||||
<SizeOfObject>0</SizeOfObject>
|
||||
<BreakByAccess>0</BreakByAccess>
|
||||
<BreakIfRCount>1</BreakIfRCount>
|
||||
<Filename>.\gpiodriver.c</Filename>
|
||||
<ExecCommand></ExecCommand>
|
||||
<Expression>\\cool_Simule\gpiodriver.c\4</Expression>
|
||||
</Bp>
|
||||
<Bp>
|
||||
<Number>2</Number>
|
||||
<Type>0</Type>
|
||||
<LineNumber>11</LineNumber>
|
||||
<EnabledFlag>1</EnabledFlag>
|
||||
<Address>134218228</Address>
|
||||
<ByteObject>0</ByteObject>
|
||||
<HtxType>0</HtxType>
|
||||
<ManyObjects>0</ManyObjects>
|
||||
<SizeOfObject>0</SizeOfObject>
|
||||
<BreakByAccess>0</BreakByAccess>
|
||||
<BreakIfRCount>1</BreakIfRCount>
|
||||
<Filename>.\gpiodriver.c</Filename>
|
||||
<ExecCommand></ExecCommand>
|
||||
<Expression>\\cool_Simule\gpiodriver.c\11</Expression>
|
||||
</Bp>
|
||||
<Bp>
|
||||
<Number>3</Number>
|
||||
<Type>0</Type>
|
||||
<LineNumber>22</LineNumber>
|
||||
<EnabledFlag>1</EnabledFlag>
|
||||
<Address>0</Address>
|
||||
<ByteObject>0</ByteObject>
|
||||
<HtxType>0</HtxType>
|
||||
<ManyObjects>0</ManyObjects>
|
||||
<SizeOfObject>0</SizeOfObject>
|
||||
<BreakByAccess>0</BreakByAccess>
|
||||
<BreakIfRCount>0</BreakIfRCount>
|
||||
<Filename>.\gpiodriver.c</Filename>
|
||||
<ExecCommand></ExecCommand>
|
||||
<Expression></Expression>
|
||||
</Bp>
|
||||
</Breakpoint>
|
||||
<WatchWindow1>
|
||||
<Ww>
|
||||
<count>0</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>voyons</ItemText>
|
||||
</Ww>
|
||||
</WatchWindow1>
|
||||
<Tracepoint>
|
||||
<THDelay>0</THDelay>
|
||||
</Tracepoint>
|
||||
|
|
Loading…
Reference in a new issue