Skip to content

Commit

Permalink
drivers/leds: Make initialization conditional on presence, not pin
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
chrysn committed Aug 25, 2024
1 parent 1f40313 commit c7d0285
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions drivers/periph_common/init_leds.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* @}
*/

#include "board.h"
#include "led.h"
#include "periph/gpio.h"
#include "kernel_defines.h"

Expand All @@ -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
}

0 comments on commit c7d0285

Please sign in to comment.