Small question about GPIO function

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Small question about GPIO function

1,238 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by zepedrowdp on Fri Apr 04 10:22:07 MST 2014
Hey!

While I was studying the files regarding the GPIO on LPCOpen2.10 I became intrigued with the way the parameter pGPIO works. It seems to be a pointer to a structure and it's described on the briefs of the function's headers as "The base of GPIO peripheral on the chip".

I was expecting that in case you wanted to change the state of a pin on port2 you would used LPC_GPIO2, or in case of port1 LPC_GPIO1. Although, the functions only seem to work when you assign LPC_GPIO as the pGPIO. I found it odd, because when I took a look at #define of LPC_GPIO, it has the base address of GPIO0, and LPC_GPIO1 the base address of GPIO1, and so on...



For example:

If want to set the pin P[1]31, with this function:

/**
 * @briefSet an individual GPIO output pin to the low state
 * @parampGPIO: The base of GPIO peripheral on the chip
 * @paramport: GPIO Port number where pin is located
 * @parampin: pin number (0..n) to set low
 * @returnNone
 * @noteAny bit set as a '0' will not have it's state changed. This only
 * applies to ports configured as an output.
 */
STATIC INLINE void Chip_GPIO_SetPinOutLow(LPC_GPIO_T *pGPIO, uint8_t port, uint8_t pin)



The expected code to write would be:

Chip_GPIO_SetPinOutLow(LPC_GPIO1, 1, 31);


But in fact it only works if you write:

Chip_GPIO_SetPinOutLow(LPC_GPIO, 1, 31);


Why does it happens?
Labels (1)
2 Replies

1,155 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Walker91 on Mon Jun 30 23:45:54 MST 2014
Hello,

When you have to manage two interruptions with gpio, how do you proceed to differentiate the register ?
Thank you.
0 Kudos

1,155 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by wellsk on Fri Apr 04 13:03:43 MST 2014

If you passed in the base of a specific GPIO port peripheral to the GPIO block, you wouldn't need the port number.
All GPIO driver functions use the same API with the same based address (LPC_GPIO) on all platforms. Implementation of those functions varies per platform (ie, some platforms only have 1 GPIO peripheral block that handles multiple ports).

This appears to be an oversight on the lpc17xx platform. The only definition that should be there and should plug into that function should be LPC_GPIO.
LPC_GPIO1, 2, 3, etc. shouldn't exist and will be removed in future packages to prevent any confusion with the GPIO calls....