Skip to content

Commit 10f63eb

Browse files
committed
Force Adafruit TinyUSB re-enumeration
Fixes adafruit/Adafruit_TinyUSB_Arduino#400 See also adafruit/Adafruit_TinyUSB_Arduino#454
1 parent 5f492cf commit 10f63eb

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

doxygen/pages/MIDI-over-USB.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ You can also use the [earlephilhower/arduino-pico](https://github.com/earlephilh
6161

6262
Known issues:
6363
- [ArduinoCore-mbed/issues#129](https://github.com/arduino/ArduinoCore-mbed/issues/129): Nano 33 BLE unreliable USB communication
64-
- [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
6564
- [adafruit/Adafruit_TinyUSB_Arduino#238](https://github.com/adafruit/Adafruit_TinyUSB_Arduino/issues/238): TinyUSB MIDI crashes when simultaneously receiving and sending messages
6665

6766
## Teensy

src/MIDI_Interfaces/USBMIDI/USBMIDI_Adafruit_TinyUSB.hpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,21 @@ BEGIN_CS_NAMESPACE
88
struct Adafruit_TinyUSB_USBDeviceMIDIBackend {
99
using MIDIUSBPacket_t = AH::Array<uint8_t, 4>;
1010
void begin() {
11-
#if defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_RP2040)
12-
// Manual begin() is required on core without built-in support for TinyUSB such as mbed rp2040
13-
TinyUSB_Device_Init(0);
14-
#endif
11+
// Manual begin() is required on core without built-in support e.g. mbed rp2040
12+
if (!TinyUSBDevice.isInitialized())
13+
TinyUSBDevice.begin(0);
1514
backend.begin();
15+
// If already enumerated, additional class driver begin() e.g msc, hid, midi won't take effect until re-enumeration
16+
if (TinyUSBDevice.mounted()) {
17+
TinyUSBDevice.detach();
18+
delay(10);
19+
TinyUSBDevice.attach();
20+
}
1621
}
1722
MIDIUSBPacket_t read() {
23+
#ifdef TINYUSB_NEED_POLLING_TASK
24+
TinyUSBDevice.task();
25+
#endif
1826
MIDIUSBPacket_t packet {};
1927
if (TinyUSBDevice.mounted())
2028
backend.readPacket(packet.data);

0 commit comments

Comments
 (0)