Skip to content

Commit 187a8ad

Browse files
pillo79kartben
authored andcommitted
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 a5fd92b ("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: Luca Burelli <l.burelli@arduino.cc>
1 parent ac01879 commit 187a8ad

File tree

1 file changed

+2
-2
lines changed
  • samples/basic/fade_led/src

1 file changed

+2
-2
lines changed

samples/basic/fade_led/src/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
#include <zephyr/drivers/pwm.h>
1616

1717
#define PWM_LED_ALIAS(i) DT_ALIAS(_CONCAT(pwm_led, i))
18-
#define PWM_LED(i, _) \
19-
IF_ENABLED(DT_NODE_EXISTS(PWM_LED_ALIAS(i)), (PWM_DT_SPEC_GET(PWM_LED_ALIAS(i)),))
18+
#define PWM_LED_IS_OKAY(i) DT_NODE_HAS_STATUS_OKAY(DT_PARENT(PWM_LED_ALIAS(i)))
19+
#define PWM_LED(i, _) IF_ENABLED(PWM_LED_IS_OKAY(i), (PWM_DT_SPEC_GET(PWM_LED_ALIAS(i)),))
2020

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

0 commit comments

Comments
 (0)