2017-09-08 08:23 AM
Hi
I'm analyzing the code as the below and came across that code when I was googling.
GPIO_WriteBit(GPIOG, GPIO_Pin_11,(BitAction)(1-GPIO_ReadOutputDataBit(GPIOG, GPIO_Pin_11)));
But I can't understand what do '
BitAction' and '1-' do exactly?
I've found declaration
.
typedef enum
{ Bit_RESET = 0, Bit_SET}BitAction;then I can guess that code working such as
GPIO_WriteBit(GPIOG, GPIO_Pin_11,
(BitAction)(1-0));
GPIO_WriteBit(GPIOG, GPIO_Pin_11,
(BitAction)(1-1));
But I can't understand what does exactly BitAction do?
And what is the common purpose of GPIO_WriteBit(GPIOG, GPIO_Pin_11,
(BitAction)(1-GPIO_ReadOutputDataBit(GPIOG, GPIO_Pin_11))); code?
Is this purpose for just toggling?
2017-09-08 08:42 AM
>>Is this purpose for just toggling?
Yes, 1-1 = 0, 1-0 = 1
Normative usage:
GPIO_WriteBit(GPIOG, GPIO_Pin_11,Bit_RESET);
GPIO_WriteBit(GPIOG, GPIO_Pin_11,
Bit_SET);
BitAction is an enumeration, (BitAction) is a cast into that enumeration, prevents a warning/error from the compiler. Review C Language definition.