Skip to content

Commit

Permalink
Merge branch 'feature/usbd_msc_mount_callback' into 'master'
Browse files Browse the repository at this point in the history
USBD: update example of usb device msc by adding usage of new API.

Closes IDF-7369

See merge request espressif/esp-idf!23761
  • Loading branch information
tore-espressif committed May 23, 2023
2 parents 86b2ca3 + 6f7a6b1 commit f4dfc8f
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions examples/peripherals/usb/device/tusb_msc/main/tusb_msc_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,19 @@ static int console_status(int argc, char **argv)
// exit from application
static int console_exit(int argc, char **argv)
{
tinyusb_msc_unregister_callback(TINYUSB_MSC_EVENT_MOUNT_CHANGED);
tinyusb_msc_storage_deinit();
printf("Application Exiting\n");
exit(0);
return 0;
}

// callback that is delivered when storage is mounted/unmounted by application.
static void storage_mount_changed_cb(tinyusb_msc_event_t *event)
{
ESP_LOGI(TAG, "Storage mounted to application: %s", event->mount_changed_data.is_mounted ? "Yes" : "No");
}

#ifdef CONFIG_EXAMPLE_STORAGE_MEDIA_SPIFLASH
static esp_err_t storage_init_spiflash(wl_handle_t *wl_handle)
{
Expand Down Expand Up @@ -339,17 +346,21 @@ void app_main(void)
ESP_ERROR_CHECK(storage_init_spiflash(&wl_handle));

const tinyusb_msc_spiflash_config_t config_spi = {
.wl_handle = wl_handle
.wl_handle = wl_handle,
.callback_mount_changed = storage_mount_changed_cb /* First way to register the callback. This is while initializing the storage. */
};
ESP_ERROR_CHECK(tinyusb_msc_storage_init_spiflash(&config_spi));
ESP_ERROR_CHECK(tinyusb_msc_register_callback(TINYUSB_MSC_EVENT_MOUNT_CHANGED, storage_mount_changed_cb)); /* Other way to register the callback i.e. registering using separate API. If the callback had been already registered, it will be overwritten. */
#else // CONFIG_EXAMPLE_STORAGE_MEDIA_SPIFLASH
static sdmmc_card_t *card = NULL;
ESP_ERROR_CHECK(storage_init_sdmmc(&card));

const tinyusb_msc_sdmmc_config_t config_sdmmc = {
.card = card
.card = card,
.callback_mount_changed = storage_mount_changed_cb /* First way to register the callback. This is while initializing the storage. */
};
ESP_ERROR_CHECK(tinyusb_msc_storage_init_sdmmc(&config_sdmmc));
ESP_ERROR_CHECK(tinyusb_msc_register_callback(TINYUSB_MSC_EVENT_MOUNT_CHANGED, storage_mount_changed_cb)); /* Other way to register the callback i.e. registering using separate API. If the callback had been already registered, it will be overwritten. */
#endif // CONFIG_EXAMPLE_STORAGE_MEDIA_SPIFLASH

//mounted in the app by default
Expand Down

0 comments on commit f4dfc8f

Please sign in to comment.