Skip to content

Commit 87819f6

Browse files
authored
feat(usb): allow the MIDI constructor to define a device name
This PR will allow the user to modify the MIDI USB Device Name (device descriptor). Fomer API continues to be valid and the default device name is "TinyUSB MIDI". The user can change the device name by passing a string to the constructor, declaring it like this `USBMIDI myMIDI("MyDeviceName");
1 parent f6b1910 commit 87819f6

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

libraries/USB/src/USBMIDI.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111

1212
static bool tinyusb_midi_descriptor_loaded = false;
1313
static bool tinyusb_midi_interface_enabled = false;
14+
static String deviceDescriptor("");
1415

1516
extern "C" uint16_t tusb_midi_load_descriptor(uint8_t *dst, uint8_t *itf) {
1617
if (tinyusb_midi_descriptor_loaded) {
1718
return 0;
1819
}
1920
tinyusb_midi_descriptor_loaded = true;
20-
21-
uint8_t str_index = tinyusb_add_string_descriptor("TinyUSB MIDI");
21+
uint8_t str_index = tinyusb_add_string_descriptor(deviceDescriptor.c_str());
2222
uint8_t ep_in = tinyusb_get_free_in_endpoint();
2323
TU_VERIFY(ep_in != 0);
2424
uint8_t ep_out = tinyusb_get_free_out_endpoint();
@@ -32,9 +32,10 @@ extern "C" uint16_t tusb_midi_load_descriptor(uint8_t *dst, uint8_t *itf) {
3232
return TUD_MIDI_DESC_LEN;
3333
}
3434

35-
USBMIDI::USBMIDI() {
35+
USBMIDI::USBMIDI(String devDescName = "TinyUSB MIDI") {
3636
if (!tinyusb_midi_interface_enabled) {
3737
tinyusb_midi_interface_enabled = true;
38+
deviceDescriptor = devDescName;
3839
tinyusb_enable_interface(USB_INTERFACE_MIDI, TUD_MIDI_DESC_LEN, tusb_midi_load_descriptor);
3940
} else {
4041
log_e("USBMIDI: Multiple instances of USBMIDI not supported!");

0 commit comments

Comments
 (0)