6
6
#include " Arduino.h"
7
7
#include " esp32-hal-tinyusb.h"
8
8
9
+ // Initialize static members
10
+ const char * USBMIDI::deviceName = nullptr ;
11
+ char USBMIDI::nameBuffer[32 ] = {0 };
12
+
9
13
// Default Cable Number (for simplified APIs that do not expose this)
10
14
#define DEFAULT_CN 0
11
15
12
16
static bool tinyusb_midi_descriptor_loaded = false ;
13
17
static bool tinyusb_midi_interface_enabled = false ;
14
- static String deviceDescriptor (" " );
15
18
16
19
extern " C" uint16_t tusb_midi_load_descriptor (uint8_t *dst, uint8_t *itf) {
17
20
if (tinyusb_midi_descriptor_loaded) {
18
21
return 0 ;
19
22
}
20
23
tinyusb_midi_descriptor_loaded = true ;
21
- uint8_t str_index = tinyusb_add_string_descriptor (deviceDescriptor.c_str ());
24
+
25
+ uint8_t str_index = tinyusb_add_string_descriptor (USBMIDI::getCurrentDeviceName ());
22
26
uint8_t ep_in = tinyusb_get_free_in_endpoint ();
23
27
TU_VERIFY (ep_in != 0 );
24
28
uint8_t ep_out = tinyusb_get_free_out_endpoint ();
@@ -32,10 +36,21 @@ extern "C" uint16_t tusb_midi_load_descriptor(uint8_t *dst, uint8_t *itf) {
32
36
return TUD_MIDI_DESC_LEN;
33
37
}
34
38
35
- USBMIDI::USBMIDI (String devDescName) {
39
+ USBMIDI::USBMIDI () {
40
+ if (!tinyusb_midi_interface_enabled) {
41
+ tinyusb_midi_interface_enabled = true ;
42
+ tinyusb_enable_interface (USB_INTERFACE_MIDI, TUD_MIDI_DESC_LEN, tusb_midi_load_descriptor);
43
+ } else {
44
+ log_e (" USBMIDI: Multiple instances of USBMIDI not supported!" );
45
+ }
46
+ }
47
+
48
+ USBMIDI::USBMIDI (const char * name) {
36
49
if (!tinyusb_midi_interface_enabled) {
50
+ strncpy (nameBuffer, name, sizeof (nameBuffer) - 1 );
51
+ nameBuffer[sizeof (nameBuffer) - 1 ] = ' \0 ' ;
52
+ deviceName = nameBuffer;
37
53
tinyusb_midi_interface_enabled = true ;
38
- deviceDescriptor = devDescName;
39
54
tinyusb_enable_interface (USB_INTERFACE_MIDI, TUD_MIDI_DESC_LEN, tusb_midi_load_descriptor);
40
55
} else {
41
56
log_e (" USBMIDI: Multiple instances of USBMIDI not supported!" );
0 commit comments