36
36
// TODO multiple instances
37
37
static Adafruit_USBD_MIDI *_midi_dev = NULL ;
38
38
39
- #ifdef ARDUINO_ARCH_ESP32
40
- static uint16_t midi_load_descriptor (uint8_t *dst, uint8_t *itf) {
41
- // uint8_t str_index = tinyusb_add_string_descriptor("TinyUSB HID");
42
-
43
- uint8_t ep_in = tinyusb_get_free_in_endpoint ();
44
- uint8_t ep_out = tinyusb_get_free_out_endpoint ();
45
- TU_VERIFY (ep_in && ep_out);
46
- ep_in |= 0x80 ;
47
-
48
- uint16_t desc_len = _midi_dev->getInterfaceDescriptorLen ();
49
- desc_len = _midi_dev->makeItfDesc (*itf, dst, desc_len, ep_in, ep_out);
50
-
51
- *itf += 2 ;
52
- return desc_len;
53
- }
54
- #endif
55
-
56
39
Adafruit_USBD_MIDI::Adafruit_USBD_MIDI (uint8_t n_cables) {
57
40
_n_cables = n_cables;
58
41
memset (_cable_name_strid, 0 , sizeof (_cable_name_strid));
59
-
60
- #ifdef ARDUINO_ARCH_ESP32
61
- // ESP32 requires setup configuration descriptor within constructor
62
- _midi_dev = this ;
63
- uint16_t const desc_len = getInterfaceDescriptorLen ();
64
- tinyusb_enable_interface (USB_INTERFACE_MIDI, desc_len, midi_load_descriptor);
65
- #endif
66
42
}
67
43
68
44
void Adafruit_USBD_MIDI::setCables (uint8_t n_cables) { _n_cables = n_cables; }
@@ -87,14 +63,16 @@ bool Adafruit_USBD_MIDI::begin(void) {
87
63
return true ;
88
64
}
89
65
90
- uint16_t Adafruit_USBD_MIDI::makeItfDesc (uint8_t itfnum, uint8_t *buf,
91
- uint16_t bufsize, uint8_t ep_in,
92
- uint8_t ep_out) {
66
+ uint16_t Adafruit_USBD_MIDI::getInterfaceDescriptor (uint8_t itfnum_deprecated,
67
+ uint8_t *buf,
68
+ uint16_t bufsize) {
69
+ (void )itfnum_deprecated;
70
+
93
71
uint16_t const desc_len = TUD_MIDI_DESC_HEAD_LEN +
94
72
TUD_MIDI_DESC_JACK_LEN * _n_cables +
95
73
2 * TUD_MIDI_DESC_EP_LEN (_n_cables);
96
74
97
- // null buf is for length only
75
+ // null buffer is used to get the length of descriptor only
98
76
if (!buf) {
99
77
return desc_len;
100
78
}
@@ -103,6 +81,10 @@ uint16_t Adafruit_USBD_MIDI::makeItfDesc(uint8_t itfnum, uint8_t *buf,
103
81
return 0 ;
104
82
}
105
83
84
+ uint8_t itfnum = TinyUSBDevice.allocInterface (2 );
85
+ uint8_t ep_in = TinyUSBDevice.allocEndpoint (TUSB_DIR_IN);
86
+ uint8_t ep_out = TinyUSBDevice.allocEndpoint (TUSB_DIR_OUT);
87
+
106
88
uint16_t len = 0 ;
107
89
108
90
// Header
@@ -153,25 +135,6 @@ uint16_t Adafruit_USBD_MIDI::makeItfDesc(uint8_t itfnum, uint8_t *buf,
153
135
return desc_len;
154
136
}
155
137
156
- uint16_t Adafruit_USBD_MIDI::getInterfaceDescriptor (uint8_t itfnum_deprecated,
157
- uint8_t *buf,
158
- uint16_t bufsize) {
159
- (void )itfnum_deprecated;
160
-
161
- uint8_t itfnum = 0 ;
162
- uint8_t ep_in = 0 ;
163
- uint8_t ep_out = 0 ;
164
-
165
- // null buffer is used to get the length of descriptor only
166
- if (buf) {
167
- itfnum = TinyUSBDevice.allocInterface (2 );
168
- ep_in = TinyUSBDevice.allocEndpoint (TUSB_DIR_IN);
169
- ep_out = TinyUSBDevice.allocEndpoint (TUSB_DIR_OUT);
170
- }
171
-
172
- return makeItfDesc (itfnum, buf, bufsize, ep_in, ep_out);
173
- }
174
-
175
138
int Adafruit_USBD_MIDI::read (void ) {
176
139
uint8_t ch;
177
140
return tud_midi_stream_read (&ch, 1 ) ? (int )ch : (-1 );
0 commit comments