GPIO pin configuration using Devicetree

Hello. 

I have several custom boards based on NRF52832 QFAA chip. Pin mappings on these boards are slightly different, but the purposes are the same, so I want to use one project with different pinouts. AFAIK, the right way to do it is creating dts/overlay file for each board and using different build configurations for each one. Am I  on a right way?

So, the question itself is: for example, I need to control power supply using GPIO pin. On each board pin number of this pin varies (e.g. GPIO10 on one board and GPIO11 on another). The function of this pin is to toggle MOSFET switch (Output, Push-Pull). I want to give a name to this exact pin in dts/overlay file and to reference it from code by name, so if I want to select another board,  I don't need to change my code, just select another board. So in theory it should work like this: 

1. Add child node that represents the pin to gpio0 label in overlay file:

&gpio0 {
    status = "okay";
    gpio_power_pin : power_pin {
        gpios = <&gpio0 10 (GPIO_ACTIVE_HIGH | GPIO_PUSH_PULL)>;
    };
};

2. Reference it from code by node id: 

const struct device *power_pin_dev = DEVICE_DT_GET(DT_NODELABEL(gpio_power_pin));

3. Use it in a common way.

But this does not works. On building, I get the following error:

C:\ncs\v2.2.0\zephyr\include\zephyr\device.h:83:41: error: '__device_dts_ord_DT_N_NODELABEL_gpio_power_pin_ORD' undeclared here (not in a function)
83 | #define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id)

In which way do I need to modify my project to get it work?

Related