|
1 | 1 | /* |
2 | | - * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD |
| 2 | + * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD |
3 | 3 | * |
4 | 4 | * SPDX-License-Identifier: Apache-2.0 |
5 | 5 | */ |
@@ -375,23 +375,57 @@ static msc_device_t *find_msc_device(usb_device_handle_t device_handle) |
375 | 375 |
|
376 | 376 | static void client_event_cb(const usb_host_client_event_msg_t *event, void *arg) |
377 | 377 | { |
378 | | - if (event->event == USB_HOST_CLIENT_EVENT_NEW_DEV) { |
| 378 | + switch (event->event) { |
| 379 | + case USB_HOST_CLIENT_EVENT_NEW_DEV: |
| 380 | + ESP_LOGD(TAG, "New device connected"); |
379 | 381 | if (is_mass_storage_device(event->new_dev.address)) { |
380 | 382 | const msc_host_event_t msc_event = { |
381 | 383 | .event = MSC_DEVICE_CONNECTED, |
382 | 384 | .device.address = event->new_dev.address, |
383 | 385 | }; |
384 | 386 | s_msc_driver->user_cb(&msc_event, s_msc_driver->user_arg); |
385 | 387 | } |
386 | | - } else if (event->event == USB_HOST_CLIENT_EVENT_DEV_GONE) { |
387 | | - msc_device_t *msc_device = find_msc_device(event->dev_gone.dev_hdl); |
388 | | - if (msc_device) { |
| 388 | + break; |
| 389 | + case USB_HOST_CLIENT_EVENT_DEV_GONE: |
| 390 | + ESP_LOGD(TAG, "Device suddenly disconnected"); |
| 391 | + msc_device_t *msc_device_gone = find_msc_device(event->dev_gone.dev_hdl); |
| 392 | + if (msc_device_gone) { |
389 | 393 | const msc_host_event_t msc_event = { |
390 | 394 | .event = MSC_DEVICE_DISCONNECTED, |
391 | | - .device.handle = msc_device, |
| 395 | + .device.handle = msc_device_gone, |
| 396 | + }; |
| 397 | + s_msc_driver->user_cb(&msc_event, s_msc_driver->user_arg); |
| 398 | + } |
| 399 | + break; |
| 400 | + |
| 401 | +#ifdef MSC_HOST_SUSPEND_RESUME_API_SUPPORTED |
| 402 | + case USB_HOST_CLIENT_EVENT_DEV_SUSPENDED: |
| 403 | + ESP_LOGD(TAG, "Device suspended"); |
| 404 | + msc_device_t *msc_device_susp = find_msc_device(event->dev_gone.dev_hdl); |
| 405 | + if (msc_device_susp) { |
| 406 | + const msc_host_event_t msc_event = { |
| 407 | + .event = MSC_DEVICE_SUSPENDED, |
| 408 | + .device.handle = msc_device_susp, |
| 409 | + }; |
| 410 | + s_msc_driver->user_cb(&msc_event, s_msc_driver->user_arg); |
| 411 | + } |
| 412 | + break; |
| 413 | + case USB_HOST_CLIENT_EVENT_DEV_RESUMED: |
| 414 | + ESP_LOGD(TAG, "Device resumed"); |
| 415 | + msc_device_t *msc_device_res = find_msc_device(event->dev_gone.dev_hdl); |
| 416 | + if (msc_device_res) { |
| 417 | + const msc_host_event_t msc_event = { |
| 418 | + .event = MSC_DEVICE_RESUMED, |
| 419 | + .device.handle = msc_device_res, |
392 | 420 | }; |
393 | 421 | s_msc_driver->user_cb(&msc_event, s_msc_driver->user_arg); |
394 | 422 | } |
| 423 | + break; |
| 424 | +#endif // MSC_HOST_SUSPEND_RESUME_API_SUPPORTED |
| 425 | + |
| 426 | + default: |
| 427 | + ESP_LOGW(TAG, "Unrecognized USB Host client event"); |
| 428 | + break; |
395 | 429 | } |
396 | 430 | } |
397 | 431 |
|
|
0 commit comments