Retrieving a GPIO's direction (input/output)

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

Retrieving a GPIO's direction (input/output)

2,445 Views
nadavintel
Contributor I

Hello friends,

During run-time, I want to get the direction (input/output) of a GPIO pin.

I was expecting something like: gpio_pin_direction_t F(GPIO_Type *base, uint32_t port).

Was searching fsl_gpio.hReference Manual: GPIO. No such method is found :[

Is there any way to retrieve a GPIO pin direction during run-time?

Thank you.

Labels (1)
0 Kudos
Reply
2 Replies

2,391 Views
Julián_AragónM
NXP TechSupport
NXP TechSupport

Currently there is no API function that specifically reads the direction from a GPIO pin;

The GDIR register functions as direction control when the IOMUXC is in GPIO mode. Each bit specifies the direction of a one-bit signal.

Julin_AragnM_0-1664814421548.png
Julin_AragnM_1-1664814421549.png

The GDIR register is a read/write register which you can read during run-time to store or obtain the direction (input/output) of a GPIO pin.  The example you provided (gpio_pin_direction_t F(GPIO_Type *base, uint32_t port)) is a good way of implementing this function.

I hope you find this helpful! If you have any doubts about the register do not hesitate to ask.

Best regards, Julian

0 Kudos
Reply

2,429 Views
carstengroen
Senior Contributor II

Look in the users manual for the chip or look in the fsl_gpio.c file ? There is no guarantee that there is a function in the SDK for every single use of the registers.
Hint: look at GDIR register for the specific port.....