Skip to content

Devicetree API - Getting GPIO details from pin #31853

@stoberblog

Description

@stoberblog

Is your enhancement proposal related to a problem? Please describe.
I'm hoping there could be documentation (or an implementation if required) to allow extraction of GPIO details from a pin defined in the device tree.

Devices such as uart declare pins using a number such as <34>. In the case of the nrf52840, this translates to P1.02. I'm hoping there is a device tree API that can extract the GPIO-device (GPIO_1) and GPIO-pin (2) from the pin in the device tree. I've looked at https://docs.zephyrproject.org/latest/reference/devicetree/api.html#gpio and cannot find any macros to extact this.

Describe the solution you'd like
Simply documentation on how to do this, as there must be code already implemented as this must be what the UART and SPI drivers already do.

Describe alternatives you've considered
I've considered writing my own conversion functions, but this would not be portable as not all devices have say 32pins per port (for nordic devices, Pa.b translates to pin a*32 + b).

Additional context
For background, I'm aiming to implement an SDI-12 driver that uses UART for most communication however one of the requirements of SDI-12 is to have 'breaks' that hold the line in a logic low state (SDI-12 is active low and idles high) for a specific period of time, I'll need to use the GPIO to directly control the pin during this period before switching back to uart control. My alternative is to bit bang the whole driver, but using a hardware uart will be less process intensive.

Metadata

Metadata

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions