From 4d7a3c1dbabca4ee89706ac39ceaaa28b1f06c95 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Mon, 18 Oct 2021 22:12:41 +0200 Subject: [PATCH] sys/board_common: add generic board_init() function --- Makefile.include | 3 ++ boards/Kconfig | 7 ++++ boards/common/init/Makefile | 2 ++ boards/common/init/board_common.c | 60 +++++++++++++++++++++++++++++++ makefiles/defaultmodules.inc.mk | 2 +- 5 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 boards/common/init/Makefile create mode 100644 boards/common/init/board_common.c diff --git a/Makefile.include b/Makefile.include index 4ce3bb43c4..462c3ab82e 100644 --- a/Makefile.include +++ b/Makefile.include @@ -584,6 +584,9 @@ USEMODULE_INCLUDES = include $(RIOTBASE)/sys/Makefile.include +# add default board_init() +DIRS += $(RIOTBASE)/boards/common/init + # include Makefile.includes of each driver modules if they exist -include $(USEMODULE:%=$(RIOTBASE)/drivers/%/Makefile.include) diff --git a/boards/Kconfig b/boards/Kconfig index 14933a9d99..d4c143b36d 100644 --- a/boards/Kconfig +++ b/boards/Kconfig @@ -15,3 +15,10 @@ config MODULE_BOARD depends on TEST_KCONFIG help Module which holds all board-specific files. + +config MODULE_BOARD_COMMON_INIT + bool + default y + depends on TEST_KCONFIG + help + Common board initialization module diff --git a/boards/common/init/Makefile b/boards/common/init/Makefile new file mode 100644 index 0000000000..ceda92ec0e --- /dev/null +++ b/boards/common/init/Makefile @@ -0,0 +1,2 @@ +MODULE = board_common_init +include $(RIOTBASE)/Makefile.base diff --git a/boards/common/init/board_common.c b/boards/common/init/board_common.c new file mode 100644 index 0000000000..11346d8504 --- /dev/null +++ b/boards/common/init/board_common.c @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2021 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 boards + * @{ + * + * @file + * @brief Generic board functions + * + * @author Benjamin Valentin + * @} + */ + +#include "board.h" +#include "periph/gpio.h" +#include "kernel_defines.h" + +#define LED_INIT(x) do { \ + gpio_init(LED##x##_PIN, GPIO_OUT); \ + LED##x##_OFF; \ + } while (0) + +__attribute__((__weak__)) +void board_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/makefiles/defaultmodules.inc.mk b/makefiles/defaultmodules.inc.mk index 65ab128606..74849bbbab 100644 --- a/makefiles/defaultmodules.inc.mk +++ b/makefiles/defaultmodules.inc.mk @@ -1,4 +1,4 @@ -DEFAULT_MODULE += board cpu core core_init core_msg core_panic sys +DEFAULT_MODULE += board board_common_init cpu core core_init core_msg core_panic sys # Include potentially added default modules by the board -include $(BOARDDIR)/Makefile.default