cancel
Showing results for 
Search instead for 
Did you mean: 

What does (BitAction) do exactly?

Carter Lee
Associate III
Posted on September 08, 2017 at 17:23

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?

1 REPLY 1
Posted on September 08, 2017 at 17:42

>>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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..