Re: Unable to get GPIO controller handle from gpio node using DT_GPIO_CTLR

Bolivar, Marti

Hi Jason,

On Wed, Mar 16 2022, Jason Bens via lists zephyrproject org wrote:
I'd like to get the GPIO controller handle, and figured I could do it with something like the following:
static const struct device *gpio_dev =
DT_GPIO_CTLR(DT_NODELABEL(button_sel_role), gpios);
DT_GPIO_CTLR returns a node identifier:

And node identifiers are not values:

You can't do anything useful with a node identifier at runtime -- the
devicetree has "vanished" at that point (see for what I mean by

You need to convert the node identifier to a device pointer with

static const struct device *gpio_dev =
DEVICE_DT_GET(DT_GPIO_CTLR(DT_NODELABEL(button_sel_role), gpios));

Hope this helps,

Join to automatically receive all group messages.