This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Zephyr, nrf5340 and pin number

Hi,

I am using the nrfx GPIOTE driver to manage the output, input and interrupt on a nRF5340 on top of Zephyr Framework.

I know I can use the GPIO Api from Zephyr, but this is not my case.

I would like to retrieve the absolute pin numbers starting from the device tree definition and provide them to the functions of GPIOTE driver.

In order to do that i need to retrieve also the port number.

As far i can see the port number is contained in the data structure gpio_nrfx_cfg pointed by member void* config of the structure  gpio_dt_spec.port.

The data type gpio_nrfx_cfg  is defined in gpio_nrfx.c, so not publicly exposed.

Is there a more elegant way to retrieve the absolute pin number (port number * 32 + pin number) starting from the device tree definition ?

Thanks in advance!

Kind regards

Riccardo

Parents Reply
  • Hi,

    i came out with this approach:

    #define GPIO_PORT(pin)    DT_PROP_BY_PHANDLE_IDX(DT_NODELABEL(pin), gpios, 0, port)
    #define GPIO_PIN(pin)     DT_GPIO_PIN(DT_ALIAS(pin), gpios)
    #define GPIO_ABS_PIN(pin) NRF_GPIO_PIN_MAP(GPIO_PORT(pin), GPIO_PIN(pin))

    where pin is the label used (in bold) in the device tree file (see below).

    leds {
            compatible = "gpio-leds";
            led0: led_0 {
                gpios = <&gpio1 7 GPIO_ACTIVE_LOW>;
                label = "Green LED 0";
            };
Children
Related