diff --git a/drivers/periph_common/Kconfig b/drivers/periph_common/Kconfig index 14219ec373..4add675808 100644 --- a/drivers/periph_common/Kconfig +++ b/drivers/periph_common/Kconfig @@ -28,6 +28,12 @@ config MODULE_PERIPH_INIT_ADC default y if MODULE_PERIPH_INIT depends on MODULE_PERIPH_ADC +config MODULE_PERIPH_INIT_BUTTONS + bool + depends on TEST_KCONFIG + help + Enable auto initialization of on-board buttons + config MODULE_PERIPH_CPUID bool "CPU unique ID" depends on HAS_PERIPH_CPUID diff --git a/drivers/periph_common/init.c b/drivers/periph_common/init.c index 9d88170b72..f547852cf5 100644 --- a/drivers/periph_common/init.c +++ b/drivers/periph_common/init.c @@ -63,6 +63,11 @@ void periph_init(void) extern void led_init(void); led_init(); } + /* initialize buttonss */ + if (IS_USED(MODULE_PERIPH_INIT_BUTTONS)) { + extern void button_init(void); + button_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_buttons.c b/drivers/periph_common/init_buttons.c new file mode 100644 index 0000000000..1a2b85cfe5 --- /dev/null +++ b/drivers/periph_common/init_buttons.c @@ -0,0 +1,55 @@ +/* + * 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 Buttons as input + * + * @author Benjamin Valentin + * @} + */ + +#include "board.h" +#include "periph/gpio.h" +#include "kernel_defines.h" + +__attribute__ ((weak)) +void button_init(void) +{ + if (!IS_USED(MODULE_PERIPH_GPIO)) { + return; + } + +#ifdef BTN0_PIN + gpio_init(BTN0_PIN, BTN0_MODE); +#endif +#ifdef BTN1_PIN + gpio_init(BTN1_PIN, BTN1_MODE); +#endif +#ifdef BTN2_PIN + gpio_init(BTN2_PIN, BTN2_MODE); +#endif +#ifdef BTN3_PIN + gpio_init(BTN3_PIN, BTN3_MODE); +#endif +#ifdef BTN4_PIN + gpio_init(BTN4_PIN, BTN4_MODE); +#endif +#ifdef BTN5_PIN + gpio_init(BTN5_PIN, BTN5_MODE); +#endif +#ifdef BTN6_PIN + gpio_init(BTN6_PIN, BTN6_MODE); +#endif +#ifdef BTN7_PIN + gpio_init(BTN7_PIN, BTN7_MODE); +#endif +}