From 396d3bbe2b4b61733d56b36c4e3d72d71d425f67 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Fri, 10 Nov 2023 19:20:16 +0100 Subject: [PATCH] drivers/mtd: introduce mtd_dev_get() --- drivers/include/mtd.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/include/mtd.h b/drivers/include/mtd.h index 6a638be274..eda7ded808 100644 --- a/drivers/include/mtd.h +++ b/drivers/include/mtd.h @@ -73,6 +73,7 @@ #ifndef MTD_H #define MTD_H +#include #include #include "xfa.h" @@ -517,6 +518,19 @@ int mtd_erase_sector(mtd_dev_t *mtd, uint32_t sector, uint32_t num); */ int mtd_power(mtd_dev_t *mtd, enum mtd_power_state power); +/** + * @brief Get an MTD device by index + * + * @param[in] idx Index of the MTD device + * + * @return MTD_0 for @p idx 0 and so on + * NULL if no MTD device exists for the given index + */ +static inline mtd_dev_t *mtd_dev_get(unsigned idx) +{ + return ((MTD_NUMOF != 0) && (idx < MTD_NUMOF)) ? mtd_dev_xfa[idx] : NULL; +} + #ifdef __cplusplus } #endif