Skip to content

Commit

Permalink
esp_peripherals: fix warnings with IDF >= 5.1
Browse files Browse the repository at this point in the history
Fix the following warnings when building with ESP-IDF >= 5.1.

Building C object esp-idf/esp_peripherals/CMakeFiles/__idf_esp_peripherals.dir/lib/sdcard/sdcard.c.obj/willow/deps/esp-adf/components/esp_peripherals/lib/sdcard/sdcard.c: In function 'sdcard_unmount':
/willow/deps/esp-adf/components/esp_peripherals/lib/sdcard/sdcard.c:168:5: warning: 'esp_vfs_fat_sdmmc_unmount' is deprecated: Please use esp_vfs_fat_sdcard_unmount instead [-Wdeprecated-declarations]
  168 |     esp_err_t ret = esp_vfs_fat_sdmmc_unmount();
      |     ^~~~~~~~~
In file included from /willow/deps/esp-adf/components/esp_peripherals/lib/sdcard/sdcard.c:32:
/opt/esp/idf/components/fatfs/vfs/esp_vfs_fat.h:197:11: note: declared here
  197 | esp_err_t esp_vfs_fat_sdmmc_unmount(void) __attribute__((deprecated("Please use esp_vfs_fat_sdcard_unmount instead")));
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~
  • Loading branch information
stintel committed Sep 27, 2023
1 parent d8bb73e commit e69f74d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
12 changes: 8 additions & 4 deletions components/esp_peripherals/lib/sdcard/sdcard.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@

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)
static void sdmmc_card_print_info(void)
{
ESP_LOGD(TAG, "Name: %s\n", card->cid.name);
ESP_LOGD(TAG, "Type: %s\n", (card->ocr & SD_OCR_SDHC_CAP) ? "SDHC/SDXC" : "SDSC");
Expand All @@ -64,7 +65,6 @@ 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 = {
Expand Down Expand Up @@ -142,7 +142,7 @@ esp_err_t sdcard_mount(const char *base_path, periph_sdcard_mode_t mode)
switch (ret) {
case ESP_OK:
// Card has been initialized, print its properties
sdmmc_card_print_info(card);
sdmmc_card_print_info();
ESP_LOGI(TAG, "CID name %s!\n", card->cid.name);
break;

Expand All @@ -163,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");
Expand Down
4 changes: 3 additions & 1 deletion components/esp_peripherals/lib/sdcard/sdcard.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions components/esp_peripherals/periph_sdcard.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit e69f74d

Please sign in to comment.