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

gpio_pin_configure_dt() vs gpio_pin_configure() in Button / Blinky Examples

Hi,

this is something of a follow on question from https://devzone.nordicsemi.com/f/nordic-q-a/85892/basic-gpio-on-nrf52840-development-kit

I'm working with NRF Connect for SDK on a NRF52840 DK.

In working through the Button and Blinky examples, I noticed there were seemingly two different ways of interacting with GPIO pins - one with the _dt suffix and one without.

The first seems to run something along these lines:

#define LED0_NODE DT_ALIAS(led0)
#if DT_NODE_HAS_STATUS(LED0_NODE, okay)
#define LED0 DT_GPIO_LABEL(LED0_NODE, gpios)
#define PIN DT_GPIO_PIN(LED0_NODE, gpios)
#define FLAGS DT_GPIO_FLAGS(LED0_NODE, gpios)

const struct device *dev;

dev = device_get_binding(LED0);

gpio_pin_configure(dev, PIN, GPIO_OUTPUT_ACTIVE | FLAGS);

gpio_pin_set(dev, PIN, 1);

and the other like this:

#define LED0_NODE DT_ALIAS(led0)

static struct gpio_dt_spec led = GPIO_DT_SPEC_GET_OR(LED0_NODE, gpios, {0});

gpio_pin_configure_dt(&led, GPIO_OUTPUT);

gpio_pin_set_dt(&led, 1);

What is the difference between the two, and is there any reason to use one method over the other?

Parents
  • Hi,

    There are no real difference between gpio_pin_configure() and gpio_pin_configure_dt() except for how the parameters the functions requires are bundled. The variation with dt-suffix configures the pin through the gpio_dt_spec struct which has the public members of *port, pin and dt_flags. While the required parameters for the suffix-less variation is *port, pin and flags, i.e the same parameters that are in the dt_spec struct as members!

    I hope this helps clarify things for you! Let me know if you have any follow up questions to this.

    Kind regards,
    Andreas

Reply
  • Hi,

    There are no real difference between gpio_pin_configure() and gpio_pin_configure_dt() except for how the parameters the functions requires are bundled. The variation with dt-suffix configures the pin through the gpio_dt_spec struct which has the public members of *port, pin and dt_flags. While the required parameters for the suffix-less variation is *port, pin and flags, i.e the same parameters that are in the dt_spec struct as members!

    I hope this helps clarify things for you! Let me know if you have any follow up questions to this.

    Kind regards,
    Andreas

Children
Related