I use the following macro functions for my MSP430 to check the status of GPIO pins:
#define PIN(port) port##IN // register name
#define IN_(port,pin,act) PIN(port) & (1<<(pin)) // request pin status
#define IN(name) IN_(name) // final macro function call
Then I am able to get the status of a GPIO pin like:
enum {ACT_LOW = 0 , ACT_HIGH};
#define STATUS_LED P3,0,ACT_LOW // P3 ... port name,
// 0 ... associated port pin,
// ACT_LOW ... pin intended for active low action
void main()
{
if(!IN(STATUS_LED))
printf("Status LED connected to P3.0 is switched on");
else
printf("Status LED connected to P3.0 is switched off");
}
Now I want to take the active state for my pin into account in order not to bother while programming that my LED is switched low side ('0' = LED is switched on). My approach was then the following instead of the aforementioned 2nd line:
#define IN_(port,pin,act) \
do{ \
if((act) == ACT_HIGH) \
PIN(port) & (1<<(pin)); \
else \
~(PIN(port) & (1<<(pin))); \
}while(0)
However, the compiler 'expects an expression'. What's my mistake? What do I get wrong?