Skip to content

feat(usb): allow the MIDI constructor to define a device name #11720

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ void loop() {}

#include "USB.h"
#include "USBMIDI.h"
USBMIDI MIDI;
// Creates the MIDI device with specific descriptor
USBMIDI MIDI("ESP MIDI Device");

#define MIDI_NOTE_C4 60

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ void loop() {}

#include "USB.h"
#include "USBMIDI.h"
USBMIDI MIDI;
// Creates the MIDI device with specific descriptor
USBMIDI MIDI("ESP MIDI Device");


#define MIDI_RX 39
#define MIDI_TX 40
Expand Down
7 changes: 4 additions & 3 deletions libraries/USB/src/USBMIDI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

static bool tinyusb_midi_descriptor_loaded = false;
static bool tinyusb_midi_interface_enabled = false;
static String deviceDescriptor("");

extern "C" uint16_t tusb_midi_load_descriptor(uint8_t *dst, uint8_t *itf) {
if (tinyusb_midi_descriptor_loaded) {
return 0;
}
tinyusb_midi_descriptor_loaded = true;

uint8_t str_index = tinyusb_add_string_descriptor("TinyUSB MIDI");
uint8_t str_index = tinyusb_add_string_descriptor(deviceDescriptor.c_str());
uint8_t ep_in = tinyusb_get_free_in_endpoint();
TU_VERIFY(ep_in != 0);
uint8_t ep_out = tinyusb_get_free_out_endpoint();
Expand All @@ -32,9 +32,10 @@ extern "C" uint16_t tusb_midi_load_descriptor(uint8_t *dst, uint8_t *itf) {
return TUD_MIDI_DESC_LEN;
}

USBMIDI::USBMIDI() {
USBMIDI::USBMIDI(String devDescName) {
if (!tinyusb_midi_interface_enabled) {
tinyusb_midi_interface_enabled = true;
deviceDescriptor = devDescName;
tinyusb_enable_interface(USB_INTERFACE_MIDI, TUD_MIDI_DESC_LEN, tusb_midi_load_descriptor);
} else {
log_e("USBMIDI: Multiple instances of USBMIDI not supported!");
Expand Down
2 changes: 1 addition & 1 deletion libraries/USB/src/USBMIDI.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ typedef struct {

class USBMIDI {
public:
USBMIDI(void);
USBMIDI(String devDescName = "TinyUSB MIDI");
void begin(void);
void end(void);

Expand Down
Loading