Commit 187a8ad0 authored by Luca Burelli's avatar Luca Burelli Committed by Benjamin Cabé
Browse files

samples: fade_led: fix build error when PWM is not enabled

Some boards may define LEDs but disable them by default due to conflicts
with other peripherals. In this case, the new sample code introduced in
a5fd92b0 ("samples: fade_led: use all available LEDs") fails to build
with a missing symbol error.

Fix this by checking if the PWM device (the parent of the LED alias) is
enabled before using it. This implicitly discards invalid aliases.

Signed-off-by: default avatarLuca Burelli <l.burelli@arduino.cc>
parent ac018793
Loading
Loading
Loading
Loading
+2 −2
Changes for samples/basic/fade_led/src/main.c: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -15,8 +15,8 @@
#include <zephyr/drivers/pwm.h>

#define PWM_LED_ALIAS(i) DT_ALIAS(_CONCAT(pwm_led, i))
#define PWM_LED(i, _)                                                                              \
	IF_ENABLED(DT_NODE_EXISTS(PWM_LED_ALIAS(i)), (PWM_DT_SPEC_GET(PWM_LED_ALIAS(i)),))
#define PWM_LED_IS_OKAY(i) DT_NODE_HAS_STATUS_OKAY(DT_PARENT(PWM_LED_ALIAS(i)))
#define PWM_LED(i, _) IF_ENABLED(PWM_LED_IS_OKAY(i), (PWM_DT_SPEC_GET(PWM_LED_ALIAS(i)),))

#define MAX_LEDS 10
static const struct pwm_dt_spec pwm_leds[] = {LISTIFY(MAX_LEDS, PWM_LED, ())};