diff --git a/dist/tools/doccheck/exclude_patterns b/dist/tools/doccheck/exclude_patterns index bd2ff2310f..b8625f3b27 100644 --- a/dist/tools/doccheck/exclude_patterns +++ b/dist/tools/doccheck/exclude_patterns @@ -1327,7 +1327,7 @@ boards/common/nucleo144/include/arduino_pinmap\.h:[0-9]+: warning: Member ARDUIN boards/common/nucleo144/include/arduino_pinmap\.h:[0-9]+: warning: Member ARDUINO_PIN_A4 \(macro definition\) of file arduino_pinmap\.h is not documented\. boards/common/nucleo144/include/arduino_pinmap\.h:[0-9]+: warning: Member ARDUINO_PIN_A5 \(macro definition\) of file arduino_pinmap\.h is not documented\. boards/common/nucleo144/include/arduino_pinmap\.h:[0-9]+: warning: end of file with unbalanced grouping commands -boards/common/nucleo144/include/board\.h:[0-9]+: warning: Member AUTO_INIT_LED0 \(macro definition\) of group boards_common_nucleo144 is not documented\. +boards/common/nucleo144/include/board\.h:[0-9]+: warning: Member PERIPH_INIT_LED0 \(macro definition\) of group boards_common_nucleo144 is not documented\. boards/common/nucleo144/include/board\.h:[0-9]+: warning: Member BTN0_MODE \(macro definition\) of group boards_common_nucleo144 is not documented\. boards/common/nucleo144/include/board\.h:[0-9]+: warning: Member BTN0_PIN \(macro definition\) of group boards_common_nucleo144 is not documented\. boards/common/nucleo144/include/board\.h:[0-9]+: warning: Member LED0_MASK \(macro definition\) of group boards_common_nucleo144 is not documented\. diff --git a/drivers/periph_common/Kconfig b/drivers/periph_common/Kconfig index 903b93440e..2947f5c5b0 100644 --- a/drivers/periph_common/Kconfig +++ b/drivers/periph_common/Kconfig @@ -115,6 +115,7 @@ config MODULE_PERIPH_INIT_QDEC default y if MODULE_PERIPH_INIT depends on MODULE_PERIPH_QDEC +rsource "Kconfig.leds" rsource "Kconfig.rtc" config MODULE_PERIPH_RTT diff --git a/drivers/periph_common/Kconfig.leds b/drivers/periph_common/Kconfig.leds new file mode 100644 index 0000000000..d779573ef9 --- /dev/null +++ b/drivers/periph_common/Kconfig.leds @@ -0,0 +1,69 @@ +# Copyright (c) 2022 Inria +# +# This file is subject to the terms and conditions of the GNU Lesser +# General Public License v2.1. See the file LICENSE in the top level +# directory for more details. +# + +config MODULE_PERIPH_INIT_LEDS + bool + default y + depends on TEST_KCONFIG + help + Enable auto initialization of board leds + +config MODULE_PERIPH_INIT_LED0 + bool + default y + depends on MODULE_PERIPH_INIT_LEDS + help + Enable auto initialization of LED0 if present + +config MODULE_PERIPH_INIT_LED1 + bool + default y + depends on MODULE_PERIPH_INIT_LEDS + help + Enable auto initialization of LED1 if present + +config MODULE_PERIPH_INIT_LED2 + bool + default y + depends on MODULE_PERIPH_INIT_LEDS + help + Enable auto initialization of LED2 if present + +config MODULE_PERIPH_INIT_LED3 + bool + default y + depends on MODULE_PERIPH_INIT_LEDS + help + Enable auto initialization of LED3 if present + +config MODULE_PERIPH_INIT_LED4 + bool + default y + depends on MODULE_PERIPH_INIT_LEDS + help + Enable auto initialization of LED4 if present + +config MODULE_PERIPH_INIT_LED5 + bool + default y + depends on MODULE_PERIPH_INIT_LEDS + help + Enable auto initialization of LED5 if present + +config MODULE_PERIPH_INIT_LED6 + bool + default y + depends on MODULE_PERIPH_INIT_LEDS + help + Enable auto initialization of LED6 if present + +config MODULE_PERIPH_INIT_LED7 + bool + default y + depends on MODULE_PERIPH_INIT_LEDS + help + Enable auto initialization of LED7 if present diff --git a/drivers/periph_common/init.c b/drivers/periph_common/init.c index 5d328ab22e..8fbd394f30 100644 --- a/drivers/periph_common/init.c +++ b/drivers/periph_common/init.c @@ -22,6 +22,7 @@ #define USB_H_USER_IS_RIOT_INTERNAL +#include "kernel_defines.h" #include "periph_cpu.h" #ifdef MODULE_PERIPH_INIT @@ -54,6 +55,11 @@ void periph_init(void) { #ifdef MODULE_PERIPH_INIT + /* initialize leds */ + if (IS_USED(MODULE_PERIPH_INIT_LEDS)) { + extern void led_init(void); + led_init(); + } /* initialize configured I2C devices */ #ifdef MODULE_PERIPH_INIT_I2C for (unsigned i = 0; i < I2C_NUMOF; i++) { diff --git a/drivers/periph_common/init_leds.c b/drivers/periph_common/init_leds.c new file mode 100644 index 0000000000..88688e54db --- /dev/null +++ b/drivers/periph_common/init_leds.c @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2022 ML!PA Consulting GmbH + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup drivers_periph_init + * @{ + * + * @file + * @brief Init on board LEDs + * + * @author Benjamin Valentin + * @} + */ + +#include "board.h" +#include "periph/gpio.h" +#include "kernel_defines.h" + +#define LED_INIT(x) do { \ + if (IS_ACTIVE(MODULE_PERIPH_INIT_LED##x)) { \ + gpio_init(LED##x##_PIN, GPIO_OUT); \ + LED##x##_OFF; \ + } \ + } while (0) + +__attribute__ ((weak)) +void led_init(void) +{ + if (!IS_USED(MODULE_PERIPH_GPIO)) { + return; + } + +#ifdef LED0_PIN + LED_INIT(0); +#endif +#ifdef LED1_PIN + LED_INIT(1); +#endif +#ifdef LED2_PIN + LED_INIT(2); +#endif +#ifdef LED3_PIN + LED_INIT(3); +#endif +#ifdef LED4_PIN + LED_INIT(4); +#endif +#ifdef LED5_PIN + LED_INIT(5); +#endif +#ifdef LED6_PIN + LED_INIT(6); +#endif +#ifdef LED7_PIN + LED_INIT(7); +#endif +} diff --git a/sys/auto_init/leds/Makefile b/sys/auto_init/leds/Makefile new file mode 100644 index 0000000000..5d0aa8a123 --- /dev/null +++ b/sys/auto_init/leds/Makefile @@ -0,0 +1,3 @@ +MODULE = periph_init_leds + +include $(RIOTMAKE)/auto_init.inc.mk