From 6ede1da43494da3840b2f270de955f6bf11cbbf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Bj=C3=B6rnsson?= Date: Thu, 21 Jul 2022 17:30:57 +0200 Subject: [PATCH] samples: drivers: led_pwm: Update driver to remove DEVICE_DT_GET MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Update driver to use DEVICE_DT_GET and remove usage of DT_INST. Signed-off-by: Benjamin Björnsson --- samples/drivers/led_pwm/sample.yaml | 1 - samples/drivers/led_pwm/src/main.c | 18 ++++++------------ 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/samples/drivers/led_pwm/sample.yaml b/samples/drivers/led_pwm/sample.yaml index c6beedfa8d..fe9a3845ff 100644 --- a/samples/drivers/led_pwm/sample.yaml +++ b/samples/drivers/led_pwm/sample.yaml @@ -13,7 +13,6 @@ tests: type: multi_line ordered: true regex: - - "Found device \\S+" - "Testing LED \\d+" - "Turned on" - "Turned off" diff --git a/samples/drivers/led_pwm/src/main.c b/samples/drivers/led_pwm/src/main.c index 9d8885059b..393e580325 100644 --- a/samples/drivers/led_pwm/src/main.c +++ b/samples/drivers/led_pwm/src/main.c @@ -5,6 +5,7 @@ */ #include +#include #include #include #include @@ -13,12 +14,7 @@ #include LOG_MODULE_REGISTER(main, CONFIG_LOG_DEFAULT_LEVEL); -#if DT_NODE_HAS_STATUS(DT_INST(0, pwm_leds), okay) -#define LED_PWM_NODE_ID DT_INST(0, pwm_leds) -#define LED_PWM_DEV_NAME DEVICE_DT_NAME(LED_PWM_NODE_ID) -#else -#error "No LED PWM device found" -#endif +#define LED_PWM_NODE_ID DT_COMPAT_GET_ANY_STATUS_OKAY(pwm_leds) #define LED_PWM_LABEL(led_node_id) DT_PROP_OR(led_node_id, label, NULL), @@ -109,16 +105,14 @@ void main(void) const struct device *led_pwm; uint8_t led; - led_pwm = device_get_binding(LED_PWM_DEV_NAME); - if (led_pwm) { - LOG_INF("Found device %s", LED_PWM_DEV_NAME); - } else { - LOG_ERR("Device %s not found", LED_PWM_DEV_NAME); + led_pwm = DEVICE_DT_GET(LED_PWM_NODE_ID); + if (!device_is_ready(led_pwm)) { + LOG_ERR("Device %s is not ready", led_pwm->name); return; } if (!num_leds) { - LOG_ERR("No LEDs found for %s", LED_PWM_DEV_NAME); + LOG_ERR("No LEDs found for %s", led_pwm->name); return; }