samples: osdp/control_panel: drop device_get_binding

Use GPIO_DT_SPEC_GET_OR.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
This commit is contained in:
Martí Bolívar 2021-04-26 09:09:04 -07:00 committed by Carles Cufí
commit 429fec477b

View file

@ -12,17 +12,12 @@
/* The devicetree node identifier for the "led0" alias. */
#define LED0_NODE DT_ALIAS(led0)
#if DT_NODE_HAS_STATUS(LED0_NODE, okay)
#define LED0 DT_GPIO_LABEL(LED0_NODE, gpios)
#define LED0_PIN DT_GPIO_PIN(LED0_NODE, gpios)
#define FLAGS DT_GPIO_FLAGS(LED0_NODE, gpios)
#else
#if !DT_NODE_HAS_STATUS(LED0_NODE, okay)
#error "BOARD does not define a debug LED"
#define LED0 ""
#define LED0_PIN 0
#define FLAGS 0
#endif
static const struct gpio_dt_spec led0 = GPIO_DT_SPEC_GET_OR(LED0_NODE, gpios, {0});
#define SLEEP_TIME_MS (20)
#define CNT_PER_SEC (1000 / SLEEP_TIME_MS)
#define COMMAND_WAIT_TIME_SEC (10)
@ -58,7 +53,6 @@ void main(void)
{
int ret, led_state;
uint32_t cnt = 0;
const struct device *dev;
struct osdp_cmd pulse_output = {
.id = OSDP_CMD_OUTPUT,
.output.output_no = 0, /* First output */
@ -66,13 +60,12 @@ void main(void)
.output.timer_count = 10, /* Timer: 10 * 100ms = 1 second */
};
dev = device_get_binding(LED0);
if (dev == NULL) {
printk("Failed to get LED0 binding\n");
if (!device_is_ready(led0.port)) {
printk("Failed to get LED GPIO port %s\n", led0.port->name);
return;
}
ret = gpio_pin_configure(dev, LED0_PIN, GPIO_OUTPUT_ACTIVE | FLAGS);
ret = gpio_pin_configure_dt(&led0, GPIO_OUTPUT_ACTIVE);
if (ret < 0) {
printk("Failed to configure gpio pin\n");
return;
@ -90,7 +83,7 @@ void main(void)
if ((cnt % COMMAND_WAIT_COUNT) == 0) {
osdp_cp_send_command(OSDP_PD_0, &pulse_output);
}
gpio_pin_set(dev, LED0_PIN, led_state);
gpio_pin_set(led0.port, led0.pin, led_state);
k_msleep(SLEEP_TIME_MS);
cnt++;
}