Skip to content

Commit

Permalink
Force Adafruit TinyUSB re-enumeration
Browse files Browse the repository at this point in the history
  • Loading branch information
tttapa committed Nov 3, 2024
1 parent 5f492cf commit 10f63eb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
1 change: 0 additions & 1 deletion doxygen/pages/MIDI-over-USB.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 12 additions & 4 deletions src/MIDI_Interfaces/USBMIDI/USBMIDI_Adafruit_TinyUSB.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,21 @@ BEGIN_CS_NAMESPACE
struct Adafruit_TinyUSB_USBDeviceMIDIBackend {
using MIDIUSBPacket_t = AH::Array<uint8_t, 4>;
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);
Expand Down

0 comments on commit 10f63eb

Please sign in to comment.