From 739cb53ca95cb5d169e016af32112ab23a66f9c1 Mon Sep 17 00:00:00 2001 From: Gunar Schorcht Date: Tue, 11 Apr 2023 18:47:59 +0200 Subject: [PATCH] drivers/mtd_default: use XFA with MTD pointers --- drivers/include/mtd_default.h | 74 +++++++---------------------------- 1 file changed, 14 insertions(+), 60 deletions(-) diff --git a/drivers/include/mtd_default.h b/drivers/include/mtd_default.h index 6ad168c8c6..671218635a 100644 --- a/drivers/include/mtd_default.h +++ b/drivers/include/mtd_default.h @@ -33,54 +33,28 @@ extern "C" { #include "mtd_emulated.h" #endif -#if !defined(MTD_NUMOF) && !DOXYGEN - -#if defined(MTD_3) -#define MTD_BOARD_NUMOF 4 -#elif defined(MTD_2) -#define MTD_BOARD_NUMOF 3 -#elif defined(MTD_1) -#define MTD_BOARD_NUMOF 2 -#elif defined(MTD_0) -#define MTD_BOARD_NUMOF 1 -#else -#define MTD_BOARD_NUMOF 0 -#endif - -#define MTD_SDCARD_NUMOF IS_USED(MODULE_MTD_SDCARD_DEFAULT) -#define MTD_EMULATED_NUMOF IS_USED(MODULE_MTD_EMULATED) - -/** - * @brief Number of MTD devices - */ -#define MTD_NUMOF (MTD_BOARD_NUMOF + MTD_SDCARD_NUMOF + MTD_EMULATED_NUMOF) - -#else -#define MTD_BOARD_NUMOF MTD_NUMOF -#endif /* !defined(MTD_NUMOF) && !DOXYGEN */ - #if !DOXYGEN /** - * @brief Declare `mtd*` according to the number of MTD devices + * @brief Declare `mtd*` according to the `MTD_*` symbols defined by the board */ -#if MTD_NUMOF > 0 -extern mtd_dev_t *mtd0; +#ifdef MTD_0 +extern mtd_dev_t *MTD_0; #endif -#if MTD_NUMOF > 1 -extern mtd_dev_t *mtd1; +#ifdef MTD_1 +extern mtd_dev_t *MTD_1; #endif -#if MTD_NUMOF > 2 -extern mtd_dev_t *mtd2; +#ifdef MTD_2 +extern mtd_dev_t *MTD_2; #endif -#if MTD_NUMOF > 3 -extern mtd_dev_t *mtd3; +#ifdef MTD_3 +extern mtd_dev_t *MTD_3; #endif -#if MTD_NUMOF > 4 -extern mtd_dev_t *mtd4; +#ifdef MTD_4 +extern mtd_dev_t *MTD_4; #endif -#if MTD_NUMOF > 5 -extern mtd_dev_t *mtd5; +#ifdef MTD_5 +extern mtd_dev_t *MTD_5; #endif #endif /* !DOXYGEN */ @@ -102,27 +76,7 @@ extern mtd_emulated_t mtd_emulated_dev0; */ static inline mtd_dev_t *mtd_default_get_dev(unsigned idx) { - switch (idx) { -#if MTD_BOARD_NUMOF > 0 - case 0: return MTD_0; -#endif -#if MTD_BOARD_NUMOF > 1 - case 1: return MTD_1; -#endif -#if MTD_BOARD_NUMOF > 2 - case 2: return MTD_2; -#endif -#if MTD_BOARD_NUMOF > 3 - case 3: return MTD_3; -#endif -#if MTD_SDCARD_NUMOF > 0 - case MTD_BOARD_NUMOF: return (mtd_dev_t *)&mtd_sdcard_dev0; -#endif -#if MTD_EMULATED_NUMOF > 0 - case MTD_BOARD_NUMOF + MTD_SDCARD_NUMOF: return (mtd_dev_t *)&mtd_emulated_dev0; -#endif - } - return NULL; + return ((MTD_NUMOF != 0) && (idx < MTD_NUMOF)) ? mtd_dev_xfa[idx] : NULL; } #ifdef __cplusplus