Using an overlay, we define a node compatible with the gpio-leds driver. This allows us to define child nodes representing LEDs on the pins to which the LEDs are connected. Each child node has a single property called gpios, where we specify the port, the pin, and whether the LED is active high (1) or active low (0).

Note that it is not possible to explicitly define the pin as an input because this configuration is intended to work only as an output with an LED connected.

main.c

/* Include libraries */
#include <zephyr/kernel.h>
#include <zephyr/drivers/gpio.h>

/* Get the node identifiers "myLed_0", note we need to use lower case letters only*/
#define LED0 DT_NODELABEL(myled_0)
#define LED1 DT_NODELABEL(myled_1)

/* Get GPIO specification for led0 and led1 from devicetree */
const struct gpio_dt_spec led0 = GPIO_DT_SPEC_GET(LED0, gpios);
const struct gpio_dt_spec led1 = GPIO_DT_SPEC_GET(LED1, gpios);

int main( void )
{
    /* Configure led0 and led1 as output */
    gpio_pin_configure_dt(&led0, GPIO_OUTPUT_ACTIVE);
    gpio_pin_configure_dt(&led1, GPIO_OUTPUT);

    while(1)
    {
        /* Toggle LEDs from devicetree */
        gpio_pin_toggle_dt(&led0);
        gpio_pin_toggle_dt(&led1);
        /* Delay for 1000ms */
        k_msleep(1000);
    }
    return 0;
}

app.overlay

/ {
    /* Create a node and called leds */
    myLeds: myLeds {
        /* We indicate the pins configured in here are are be used with the gpio-leds driver */
        compatible = "gpio-leds";
        /* Sub-node for one led in gpio2 pin 9, with the led been turn on
        with a high logic level */
        myLed_0: myLed-0 {
            gpios= <&gpio2 9 GPIO_ACTIVE_HIGH>;
            label = "User LD0";
        };
        /* Sub-node for one single led in gpio2 pin 7, with the led been turn on
        with a high logic level */
        myLed_1: myLed-1 {
            gpios = <&gpio1 7 GPIO_ACTIVE_HIGH>;
            label = "User LD1";
        };
    };
};

prj.conf

# Disable optimizations
CONFIG_NO_OPTIMIZATIONS=y
# Include GPIO driver in system config ( Kconfig )
CONFIG_GPIO=y