diff --git a/main/SdCard.cpp b/main/SdCard.cpp index 7e1ebf2..6aa2675 100644 --- a/main/SdCard.cpp +++ b/main/SdCard.cpp @@ -4,7 +4,7 @@ #include "sdmmc_cmd.h" #include "driver/sdmmc_host.h" #include "sd_pwr_ctrl_by_on_chip_ldo.h" -#include "tinyusb.h" +#include "tinyusb_default_config.h" #include "tinyusb_msc.h" #include @@ -66,11 +66,9 @@ bool SdCard::init() { slot_config.flags |= SDMMC_SLOT_FLAG_INTERNAL_PULLUP; // Mount FAT filesystem - esp_vfs_fat_sdmmc_mount_config_t mount_config = { - .format_if_mount_failed = false, - .max_files = 5, - .allocation_unit_size = 16 * 1024 - }; + esp_vfs_fat_sdmmc_mount_config_t mount_config = VFS_FAT_MOUNT_DEFAULT_CONFIG(); + mount_config.max_files = 5; + mount_config.allocation_unit_size = 16 * 1024; ESP_LOGI(TAG, "Mounting SD card..."); ret = esp_vfs_fat_sdmmc_mount(MOUNT_POINT, &host, &slot_config, &mount_config, &s_card); @@ -139,10 +137,8 @@ bool SdCard::enableUsbMsc() { // Initialize TinyUSB ESP_LOGI(TAG, "Initializing TinyUSB..."); - const tinyusb_config_t cfg = { - .external_phy = false, - }; - esp_err_t ret = tinyusb_driver_install(&tusb_cfg); + const tinyusb_config_t cfg = TINYUSB_DEFAULT_CONFIG(); + esp_err_t ret = tinyusb_driver_install(&cfg); if (ret != ESP_OK) { ESP_LOGE(TAG, "Failed to install TinyUSB driver: %s", esp_err_to_name(ret)); return false; @@ -150,20 +146,24 @@ bool SdCard::enableUsbMsc() { // Initialize MSC storage with SD card ESP_LOGI(TAG, "Initializing USB MSC with SD card..."); - const tinyusb_msc_sdmmc_config_t msc_cfg = { - .card = s_card, - }; + tinyusb_msc_storage_config_t storage_cfg = {}; + storage_cfg.medium.card = s_card; + storage_cfg.mount_point = TINYUSB_MSC_STORAGE_MOUNT_USB; + storage_cfg.fat_fs.base_path = nullptr; + storage_cfg.fat_fs.config = VFS_FAT_MOUNT_DEFAULT_CONFIG(); + storage_cfg.fat_fs.config.max_files = 5; + storage_cfg.fat_fs.config.allocation_unit_size = 16 * 1024; + storage_cfg.fat_fs.do_not_format = true; + storage_cfg.fat_fs.format_flags = 0; - ret = tinyusb_msc_storage_init_sdmmc(&msc_cfg); + tinyusb_msc_storage_handle_t storage_hdl = nullptr; + ret = tinyusb_msc_new_storage_sdmmc(&storage_cfg, &storage_hdl); if (ret != ESP_OK) { ESP_LOGE(TAG, "Failed to initialize MSC storage: %s", esp_err_to_name(ret)); return false; } - - // Mount MSC storage - ret = tinyusb_msc_storage_mount(MOUNT_POINT); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "Failed to mount MSC storage: %s", esp_err_to_name(ret)); + if (storage_hdl == nullptr) { + ESP_LOGE(TAG, "MSC storage handle not initialized"); return false; }