forked from espressif/esp-idf
Merge branch 'feature/usbd_msc_mount_callback' into 'master'
USBD: update example of usb device msc by adding usage of new API. Closes IDF-7369 See merge request espressif/esp-idf!23761
This commit is contained in:
@@ -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)
|
||||
{
|
||||
@@ -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
|
||||
|
Reference in New Issue
Block a user