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?