Determine direction of GPIO pin

User avatar
kolban
Posts: 131
Joined: Tue Jun 16, 2015 1:09 pm
Location: Fort Worth, Texas, USA

Determine direction of GPIO pin

Postby kolban » Tue Sep 22, 2015 11:42 am

I can set a GPIO pin to be input or output using gpio_output_set(). My question is ... is there a way to determine the current input and output direction of a given pin?

For example, if I want to know whether GPIO0 is an input or an output pin ... is that possible?

tve
Posts: 123
Joined: Sun Feb 15, 2015 4:33 pm

Re: Determine direction of GPIO pin

Postby tve » Tue Sep 22, 2015 3:23 pm

I believe GPIO_PIN_CONFIG_GET in eagle_soc.h is your ticket. The config register can be read as well as written.

User avatar
kolban
Posts: 131
Joined: Tue Jun 16, 2015 1:09 pm
Location: Fort Worth, Texas, USA

Re: Determine direction of GPIO pin

Postby kolban » Tue Sep 22, 2015 8:55 pm

Howdy Tve,
Thanks for the response. I looked at GPIO_PIN_CONFIG_GET(x) and it appears to be an expression evaluation. Do you know of any docs on how to use these functions? I have a feeling that the methods I have been using (such as gpio_output_set and gpio_input_get) are high level wrappers and the functions in eagle_soc.h are lower level. If I can learn how these work, I'll write them up for the community.

Neil

dkinzer
Posts: 52
Joined: Fri Jul 31, 2015 7:37 am

Re: Determine direction of GPIO pin

Postby dkinzer » Tue Sep 22, 2015 11:13 pm

kolban wrote:[...]is there a way to determine the current input and output direction of a given pin?
The "direction" register is at offset 0x0c, given by GPIO_ENABLE_ADDRESS. The value resulting from GPIO_REG_READ(GPIO_ENABLE_ADDRESS) will have 1s in bit positions corresponding to pins that are outputs. This assumes, of course, that the IO MUX is set for the bit to be a GPIO.
Don Kinzer
Beaverton, OR, USA

Who is online

Users browsing this forum: No registered users and 5 guests