AnsweredAssumed Answered

GPIO.h input/output configuration correct ?

Question asked by Kas Lewis on Dec 23, 2014
Latest reply on Dec 23, 2014 by Kas Lewis

I was looking in the GPIO.h file for the KEA family and I saw the below code to set input/output for the ports, but something does not look correct to me.

 

#define CONFIG_PIN_AS_GPIO(port,register_number,mode)    XCONFIG_PIN_AS_GPIO(port,register_number,mode)

#define XCONFIG_PIN_AS_GPIO(port,register_number,mode)   (mode == 0) ? (GPIO##port##_PDDR |= 0 << register_number) : (GPIO##port##_PDDR |= 1 << register_number)

 

The first option in the conditional statement (second line) looks incorrect. If the port was previously set as an output (mode = 1) and then you try set the port as an input, you would be doing 1 | 0 which we know is equal to 1 -> output. Should the correct code not be

 

#define XCONFIG_PIN_AS_GPIO(port,register_number,mode)   (mode == 0) ? (GPIO##port##_PDDR &= ~(1 << register_number)) : (GPIO##port##_PDDR |= 1 << register_number)

 

please let me know if I am understanding this incorrectly or if this really is an issue.

 

 

 

Thanks

Kas

Outcomes