From b39e7db5fd6797b42acc6a85304e5c8e7947a6f0 Mon Sep 17 00:00:00 2001 From: maojianxin Date: Mon, 8 Apr 2024 10:47:18 +0800 Subject: [PATCH] esp_peripherals: fix warnings 'esp_vfs_fat_sdmmc_unmount' is deprecated --- components/esp_peripherals/lib/sdcard/sdcard.c | 9 ++++++--- components/esp_peripherals/lib/sdcard/sdcard.h | 4 +++- components/esp_peripherals/periph_sdcard.c | 4 ++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/components/esp_peripherals/lib/sdcard/sdcard.c b/components/esp_peripherals/lib/sdcard/sdcard.c index 052624941..899cedd83 100644 --- a/components/esp_peripherals/lib/sdcard/sdcard.c +++ b/components/esp_peripherals/lib/sdcard/sdcard.c @@ -44,6 +44,7 @@ static const char *TAG = "SDCARD"; static int g_gpio = -1; +static sdmmc_card_t *card = NULL; static void sdmmc_card_print_info(const sdmmc_card_t *card) { @@ -64,9 +65,7 @@ esp_err_t sdcard_mount(const char *base_path, periph_sdcard_mode_t mode) return ESP_FAIL; } - sdmmc_card_t *card = NULL; esp_err_t ret = ESP_FAIL; - esp_vfs_fat_sdmmc_mount_config_t mount_config = { .format_if_mount_failed = false, .max_files = get_sdcard_open_file_num_max(), @@ -164,9 +163,13 @@ esp_err_t sdcard_mount(const char *base_path, periph_sdcard_mode_t mode) } -esp_err_t sdcard_unmount(void) +esp_err_t sdcard_unmount(const char *base_path) { +#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 0)) + esp_err_t ret = esp_vfs_fat_sdcard_unmount(base_path, card); +#else esp_err_t ret = esp_vfs_fat_sdmmc_unmount(); +#endif if (ret == ESP_ERR_INVALID_STATE) { ESP_LOGE(TAG, "File system not mounted"); diff --git a/components/esp_peripherals/lib/sdcard/sdcard.h b/components/esp_peripherals/lib/sdcard/sdcard.h index 42bdc98a0..527df1344 100644 --- a/components/esp_peripherals/lib/sdcard/sdcard.h +++ b/components/esp_peripherals/lib/sdcard/sdcard.h @@ -60,11 +60,13 @@ esp_err_t sdcard_mount(const char* base_path, periph_sdcard_mode_t mode); /** * @brief Unmount FAT filesystem and release resources acquired using esp_vfs_fat_sdmmc_mount * + * @param base_path path where partition is mounted (e.g. "/sdcard") + * * @return * - ESP_OK on success * - ESP_ERR_INVALID_STATE if sd_card_mount hasn't been called */ -esp_err_t sdcard_unmount(void); +esp_err_t sdcard_unmount(const char *base_path); /** * @brief remove the sdcard device GPIO interruption in Audio board diff --git a/components/esp_peripherals/periph_sdcard.c b/components/esp_peripherals/periph_sdcard.c index c5471b4d5..ff05ed7fc 100644 --- a/components/esp_peripherals/periph_sdcard.c +++ b/components/esp_peripherals/periph_sdcard.c @@ -106,7 +106,7 @@ static esp_err_t _sdcard_destroy(esp_periph_handle_t self) esp_err_t ret = ESP_OK; periph_sdcard_t *sdcard = esp_periph_get_data(self); if (sdcard->is_mounted) { - ret |= sdcard_unmount(); + ret |= sdcard_unmount(sdcard->root); sdcard->is_mounted = false; } ret |= sdcard_destroy(); @@ -145,7 +145,7 @@ esp_err_t periph_sdcard_unmount(esp_periph_handle_t periph) { VALIDATE_SDCARD(periph, ESP_FAIL); periph_sdcard_t *sdcard = esp_periph_get_data(periph); - int ret = sdcard_unmount(); + int ret = sdcard_unmount(sdcard->root); if (ret == ESP_OK) { ESP_LOGD(TAG, "UnMount SDCARD success"); sdcard->is_mounted = false;