esp32-usb-host-demos icon indicating copy to clipboard operation
esp32-usb-host-demos copied to clipboard

Don't work when MIDI Device re-plug

Open oujianshen opened this issue 10 months ago • 4 comments

This is a great project, I can run it and all the functions are normal

When the MIDI Device is reinserted, it cannot be automatically recognized and needs to be restarted to function properly again I see that the new device is defined in the function in usbhelp.hpp as void _cliend_event_callback (const usbhost_cliend_event_msg_t * event_msg, void * arg) I guess this function was not called during the second insertion But my ability is limited and I can't change this code well Who can help fix this issue of reinsertion and rediscovery? Thank you very much

oujianshen avatar Apr 13 '24 15:04 oujianshen

I made a hackjob fix here

The original does not do any cleanup when the device is unplugged - either in the sketch or the ESP USB Host library. I added a callback so usbhelp.hpp can call a function in the main sketch when the device is "gone".

I'm sure it is pretty janky, would love to hear some improvements. I know next to nothing about USB. Cheers.

fastfourier666 avatar Apr 20 '24 22:04 fastfourier666

~~ I spent a whole day looking for this problem and finally found the reason.

use usb_host_interface_release,usb_host_device_close can fix it example code usbhhelp.hpp

case USB_HOST_CLIENT_EVENT_DEV_GONE:
    ESP_LOGI("", "Device Gone handle: %x", event_msg->dev_gone.dev_hdl);
    err = usb_host_interface_release(Client_Handle, event_msg->dev_gone.dev_hdl, 0);
    if (err != ESP_OK)
      ESP_LOGI("", "usb_host_interface_release: %x", err);
    err = usb_host_device_close(Client_Handle, event_msg->dev_gone.dev_hdl);
    if (err != ESP_OK)
      ESP_LOGI("", "usb_host_device_close: %x", err);
    break;

qa2080639 avatar Jul 25 '24 09:07 qa2080639

case USB_HOST_CLIENT_EVENT_DEV_GONE: ESP_LOGI("", "Device Gone handle: %x", event_msg->dev_gone.dev_hdl); err = usb_host_interface_release(Client_Handle, event_msg->dev_gone.dev_hdl, 0); if (err != ESP_OK) ESP_LOGI("", "usb_host_interface_release: %x", err); err = usb_host_device_close(Client_Handle, event_msg->dev_gone.dev_hdl); if (err != ESP_OK) ESP_LOGI("", "usb_host_device_close: %x", err); break;

Can explain how? I tried it and I know of a skilled embedded engineer that also tried it.

When I flashed an ESP32-S3 dev kit clone with that in verbose mode, it simply flashes it and the transmit LED turns on, but no serial monitor messages sadly.

Recommended solutions? Thanks in advance!

01GOD avatar Aug 20 '24 12:08 01GOD

@fastfourier666 You did a great job thank you for sharing !

EParisot avatar Sep 13 '24 21:09 EParisot