Retrieving a GPIO's direction (input/output)

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Retrieving a GPIO's direction (input/output)

2,468 次查看
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.

标签 (1)
0 项奖励
回复
2 回复数

2,414 次查看
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.pngJulin_AragnM_0-1664814421548.png
Julin_AragnM_1-1664814421549.pngJulin_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 项奖励
回复

2,452 次查看
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.....