From c7d02856718992dec19de22b5b0f54dd8b2b3692 Mon Sep 17 00:00:00 2001 From: chrysn Date: Sun, 25 Aug 2024 12:49:00 +0200 Subject: [PATCH] drivers/leds: Make initialization conditional on presence, not pin The LEDx_PIN may still be defined (eg. on the particle-mesh family because it is used to configure the PWM pins); the IS_PRESENT macro performs the stricter check ov testing for an _ON function. --- drivers/periph_common/init_leds.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/drivers/periph_common/init_leds.c b/drivers/periph_common/init_leds.c index 88688e54db401..56e3bf0c2f4aa 100644 --- a/drivers/periph_common/init_leds.c +++ b/drivers/periph_common/init_leds.c @@ -17,7 +17,7 @@ * @} */ -#include "board.h" +#include "led.h" #include "periph/gpio.h" #include "kernel_defines.h" @@ -35,28 +35,32 @@ void led_init(void) return; } -#ifdef LED0_PIN + /* The condition is dual: We don't init if the LED is absent (eg. when a + * LEDn_PIN is defined, but there is a higher level driver such as SAUL PWM that makes the + * direct use impossible), but we also don't init if there is no pin (eg. + * on native where there is a different mechanism for LEDs). */ +#if defined(LED0_IS_PRESENT) && defined(LED0_PIN) LED_INIT(0); #endif -#ifdef LED1_PIN +#if defined(LED1_IS_PRESENT) && defined(LED1_PIN) LED_INIT(1); #endif -#ifdef LED2_PIN +#if defined(LED2_IS_PRESENT) && defined(LED2_PIN) LED_INIT(2); #endif -#ifdef LED3_PIN +#if defined(LED3_IS_PRESENT) && defined(LED3_PIN) LED_INIT(3); #endif -#ifdef LED4_PIN +#if defined(LED4_IS_PRESENT) && defined(LED4_PIN) LED_INIT(4); #endif -#ifdef LED5_PIN +#if defined(LED5_IS_PRESENT) && defined(LED5_PIN) LED_INIT(5); #endif -#ifdef LED6_PIN +#if defined(LED6_IS_PRESENT) && defined(LED6_PIN) LED_INIT(6); #endif -#ifdef LED7_PIN +#if defined(LED7_IS_PRESENT) && defined(LED7_PIN) LED_INIT(7); #endif }