Generic GPIO set up in overlay file

I want to define an i/o generically in the overlay file, so I did the following:

/{
  rows{
    compatible = "nordic,nrf-gpio";
    gpio-controller;
    reg = <0x842800 0x300>;
    #gpio-cells = <2>;
    port = <1>;
    row0: row_0{
      gpio-hog;
      gpios = <4 GPIO_ACTIVE_HIGH>;
    };
    row1: row_1{
      gpio-hog;
      gpios = <5 GPIO_ACTIVE_HIGH>;
    };
  };
};
But I get the following squiggly line information: Nodes with reg properties must have a unit address
and build error: unit address and first address in 'reg' (0x842800) don't match for /rows
What is your guidance
  • Hi,

    I have tried various combinations as listed below but I am unable to get a binding in any of the overlay definitions.  I have also included the binding code... in case I am doing something wrong there.

    // &gpio1{

    // row0: row_0_node{
    // gpio-hog;
    // gpios = <4 GPIO_ACTIVE_HIGH>;
    // };
    // row1: row_1_node{
    // gpio-hog;
    // gpios = <5 GPIO_ACTIVE_HIGH>;
    // };
    // };

    // / {
    // rows@842800{
    // compatible = "nordic,nrf-gpio";
    // gpio-controller;
    // reg = <0x842800 0x300>;
    // #gpio-cells = <2>;
    // port = <1>;
    // row0: row_0_node{
    // gpio-hog;
    // gpios = <4 GPIO_ACTIVE_HIGH>;
    // };
    // row1: row_1_node{
    // gpio-hog;
    // gpios = <5 GPIO_ACTIVE_HIGH>;
    // };
    // };
    // };


    // / {
    // rows@842800{
    // compatible = "gpio-controller";
    // gpio-controller;
    // reg = <0x842800 0x300>;
    // #gpio-cells = <2>;
    // row0: row_0_node{
    // gpio-hog;
    // gpios = <4 GPIO_ACTIVE_HIGH>;
    // //gpios = <&gpio1 4 GPIO_ACTIVE_HIGH>;
    // };
    // row1: row_1_node{
    // gpio-hog;
    // gpios = <5 GPIO_ACTIVE_HIGH>;
    // };
    // };
    // };



    // &gpio1{
    // rows{
    // compatible = "gpio-controller";
    // gpio-controller;
    // #gpio-cells = <2>;
    // row0: row_0_node{
    // gpio-hog;
    // gpios = <4 GPIO_ACTIVE_HIGH>;
    // };
    // row1: row_1_node{
    // gpio-hog;
    // gpios = <5 GPIO_ACTIVE_HIGH>;
    // };
    // };
    // };

    //********************* Code **********************

    k_msleep(SLEEP_TIME_MS);

    const struct device *gpio_dev = device_get_binding("gpio");

    if (!gpio_dev) {
    printk("Error: Unable to get GPIO device bindings gpio\n");
    } else {
    printk("GPIO device bindings successful\n");
    /* Perform GPIO operations as needed */
    }
    const struct device *gpio_dev0 = device_get_binding("gpio1");

    if (!gpio_dev0) {
    printk("Error: Unable to get GPIO device bindings gpio1\n");
    } else {
    printk("GPIO device bindings successful\n");
    /* Perform GPIO operations as needed */
    }

    const struct device *gpio_dev1 = device_get_binding("rows");

    if (!gpio_dev1) {
    printk("Error: Unable to get GPIO device bindings rows\n");
    } else {
    printk("GPIO device bindings successful\n");
    /* Perform GPIO operations as needed */
    }

    const struct device *gpio_dev2 = device_get_binding("row0");

    if (!gpio_dev2) {
    printk("Error: Unable to get GPIO device bindings row0\n");
    } else {
    printk("GPIO device bindings successful\n");
    /* Perform GPIO operations as needed */
    }

    const struct device *gpio_dev3 = device_get_binding("row_0_node");

    if (!gpio_dev3) {
    printk("Error: Unable to get GPIO device bindings row_0_node\n");
    } else {
    printk("GPIO device bindings successful\n");
    /* Perform GPIO operations as needed */
    }
  • I got it to work as follows:

    //*********** OVERLAY FILE ***********

    /{
    rows{
    compatible = "gpio-leds";
    row0: row_0 {
    gpios = <&gpio1 4 GPIO_ACTIVE_HIGH>;
    };
    row1: row_1 {
    gpios = <&gpio1 5 GPIO_ACTIVE_HIGH>;
    };
    };
    };
    //************** CODE *******************
    #define ROW0_NODE DT_NODELABEL(row0) // ROW#_NODE = row# defined in the .dts file
    #define SLEEP_TIME_MS 1000

    int main(void) {
    int ret;

    static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(ROW1_NODE, gpios);
    if (!device_is_ready(led.port)) {
    printk("\nDevice not found");
    return -1;
    }

    ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE);
    if (ret < 0) {
    printk("\nDevice not configured");
    return -1;
    }

    while (1) {
    ret = gpio_pin_toggle_dt(&led);
    if (ret < 0) {
    return -1;
    }
    k_msleep(SLEEP_TIME_MS);
    }

    return -1;
    }
  • Is there a way to do it without using

    compatible = "gpio-leds";

    Maybe use: 

    compatible = "gpio-controller";
    or
    compatible = "gpio-nordic,nrf-gpio";
  • Hi Ali

    gpio-leds is the way to go for output pins, I did something similar for a hobby project of mine as you can see here.

    Any particular reason you don't want to use gpio-leds?

    Best regards
    Torbjørn 

Related