diff --git a/doxygen/pages/MIDI-over-USB.md b/doxygen/pages/MIDI-over-USB.md index debb5278de..e0aa72afbd 100644 --- a/doxygen/pages/MIDI-over-USB.md +++ b/doxygen/pages/MIDI-over-USB.md @@ -61,7 +61,6 @@ You can also use the [earlephilhower/arduino-pico](https://github.com/earlephilh Known issues: - [ArduinoCore-mbed/issues#129](https://github.com/arduino/ArduinoCore-mbed/issues/129): Nano 33 BLE unreliable USB communication - - [adafruit/Adafruit_TinyUSB_Arduino#400](https://github.com/adafruit/Adafruit_TinyUSB_Arduino/issues/400): USB descriptors not correctly updated if Bluetooth stack is initialized before Adafruit_TinyUSB - [adafruit/Adafruit_TinyUSB_Arduino#238](https://github.com/adafruit/Adafruit_TinyUSB_Arduino/issues/238): TinyUSB MIDI crashes when simultaneously receiving and sending messages ## Teensy diff --git a/src/MIDI_Interfaces/USBMIDI/USBMIDI_Adafruit_TinyUSB.hpp b/src/MIDI_Interfaces/USBMIDI/USBMIDI_Adafruit_TinyUSB.hpp index 48b7a857f2..390befe924 100644 --- a/src/MIDI_Interfaces/USBMIDI/USBMIDI_Adafruit_TinyUSB.hpp +++ b/src/MIDI_Interfaces/USBMIDI/USBMIDI_Adafruit_TinyUSB.hpp @@ -8,13 +8,21 @@ BEGIN_CS_NAMESPACE struct Adafruit_TinyUSB_USBDeviceMIDIBackend { using MIDIUSBPacket_t = AH::Array; void begin() { -#if defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_RP2040) - // Manual begin() is required on core without built-in support for TinyUSB such as mbed rp2040 - TinyUSB_Device_Init(0); -#endif + // Manual begin() is required on core without built-in support e.g. mbed rp2040 + if (!TinyUSBDevice.isInitialized()) + TinyUSBDevice.begin(0); backend.begin(); + // If already enumerated, additional class driver begin() e.g msc, hid, midi won't take effect until re-enumeration + if (TinyUSBDevice.mounted()) { + TinyUSBDevice.detach(); + delay(10); + TinyUSBDevice.attach(); + } } MIDIUSBPacket_t read() { +#ifdef TINYUSB_NEED_POLLING_TASK + TinyUSBDevice.task(); +#endif MIDIUSBPacket_t packet {}; if (TinyUSBDevice.mounted()) backend.readPacket(packet.data);