Skip to content

Commit 2cc8b49

Browse files
authored
Merge pull request #179 from kaysievers/tinyusb-midi-jacks
tinyusb: MIDI - split descriptor initializer into individual sections
2 parents 918379d + e5af75a commit 2cc8b49

File tree

1 file changed

+49
-26
lines changed
  • cores/arduino/Adafruit_TinyUSB_Core/tinyusb/src/device

1 file changed

+49
-26
lines changed

cores/arduino/Adafruit_TinyUSB_Core/tinyusb/src/device/usbd.h

Lines changed: 49 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,15 @@ TU_ATTR_WEAK bool tud_vendor_control_complete_cb(uint8_t rhport, tusb_control_re
169169
/* CDC Header */\
170170
5, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_HEADER, U16_TO_U8S_LE(0x0120),\
171171
/* CDC Call */\
172-
5, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_CALL_MANAGEMENT, 0, static_cast<uint8_t>((_itfnum) + 1),\
172+
5, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_CALL_MANAGEMENT, 0, (uint8_t)((_itfnum) + 1),\
173173
/* CDC ACM: support line request */\
174174
4, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_ABSTRACT_CONTROL_MANAGEMENT, 2,\
175175
/* CDC Union */\
176-
5, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_UNION, _itfnum, static_cast<uint8_t>((_itfnum) + 1),\
176+
5, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_UNION, _itfnum, (uint8_t)((_itfnum) + 1),\
177177
/* Endpoint Notification */\
178178
7, TUSB_DESC_ENDPOINT, _ep_notif, TUSB_XFER_INTERRUPT, U16_TO_U8S_LE(_ep_notif_size), 16,\
179179
/* CDC Data Interface */\
180-
9, TUSB_DESC_INTERFACE, static_cast<uint8_t>((_itfnum) + 1), 0, 2, TUSB_CLASS_CDC_DATA, 0, 0, 0,\
180+
9, TUSB_DESC_INTERFACE, (uint8_t)((_itfnum) + 1), 0, 2, TUSB_CLASS_CDC_DATA, 0, 0, 0,\
181181
/* Endpoint Out */\
182182
7, TUSB_DESC_ENDPOINT, _epout, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0,\
183183
/* Endpoint In */\
@@ -206,7 +206,7 @@ TU_ATTR_WEAK bool tud_vendor_control_complete_cb(uint8_t rhport, tusb_control_re
206206
// Interface number, string index, protocol, report descriptor len, EP In address, size & polling interval
207207
#define TUD_HID_DESCRIPTOR(_itfnum, _stridx, _boot_protocol, _report_desc_len, _epin, _epsize, _ep_interval) \
208208
/* Interface */\
209-
9, TUSB_DESC_INTERFACE, _itfnum, 0, 1, TUSB_CLASS_HID, static_cast<uint8_t>((_boot_protocol) ? HID_SUBCLASS_BOOT : 0), _boot_protocol, _stridx,\
209+
9, TUSB_DESC_INTERFACE, _itfnum, 0, 1, TUSB_CLASS_HID, (uint8_t)((_boot_protocol) ? HID_SUBCLASS_BOOT : 0), _boot_protocol, _stridx,\
210210
/* HID descriptor */\
211211
9, HID_DESC_TYPE_HID, U16_TO_U8S_LE(0x0111), 0, 1, HID_DESC_TYPE_REPORT, U16_TO_U8S_LE(_report_desc_len),\
212212
/* Endpoint In */\
@@ -219,7 +219,7 @@ TU_ATTR_WEAK bool tud_vendor_control_complete_cb(uint8_t rhport, tusb_control_re
219219
// Interface number, string index, protocol, report descriptor len, EP OUT & IN address, size & polling interval
220220
#define TUD_HID_INOUT_DESCRIPTOR(_itfnum, _stridx, _boot_protocol, _report_desc_len, _epout, _epin, _epsize, _ep_interval) \
221221
/* Interface */\
222-
9, TUSB_DESC_INTERFACE, _itfnum, 0, 2, TUSB_CLASS_HID, static_cast<uint8_t>((_boot_protocol) ? HID_SUBCLASS_BOOT : 0), _boot_protocol, _stridx,\
222+
9, TUSB_DESC_INTERFACE, _itfnum, 0, 2, TUSB_CLASS_HID, (uint8_t)((_boot_protocol) ? HID_SUBCLASS_BOOT : 0), _boot_protocol, _stridx,\
223223
/* HID descriptor */\
224224
9, HID_DESC_TYPE_HID, U16_TO_U8S_LE(0x0111), 0, 1, HID_DESC_TYPE_REPORT, U16_TO_U8S_LE(_report_desc_len),\
225225
/* Endpoint Out */\
@@ -229,37 +229,60 @@ TU_ATTR_WEAK bool tud_vendor_control_complete_cb(uint8_t rhport, tusb_control_re
229229

230230
//------------- MIDI -------------//
231231

232-
// Length of template descriptor (96 bytes)
233-
#define TUD_MIDI_DESC_LEN (9 + 9 + 9 + 7 + 6 + 6 + 9 + 9 + 7 + 5 + 7 + 5)
234-
235-
// MIDI simple descriptor
236-
// - 1 Embedded Jack In connected to 1 External Jack Out
237-
// - 1 Embedded Jack out connected to 1 External Jack In
238-
#define TUD_MIDI_DESCRIPTOR(_itfnum, _stridx, _epout, _epin, _epsize) \
232+
#define TUD_MIDI_DESC_HEAD_LEN (9 + 9 + 9 + 7)
233+
#define TUD_MIDI_DESC_HEAD(_itfnum, _stridx, _numcables) \
239234
/* Audio Control (AC) Interface */\
240235
9, TUSB_DESC_INTERFACE, _itfnum, 0, 0, TUSB_CLASS_AUDIO, AUDIO_SUBCLASS_CONTROL, AUDIO_PROTOCOL_V1, _stridx,\
241236
/* AC Header */\
242-
9, TUSB_DESC_CS_INTERFACE, AUDIO_CS_INTERFACE_HEADER, U16_TO_U8S_LE(0x0100), U16_TO_U8S_LE(0x0009), 1, static_cast<uint8_t>((_itfnum) + 1),\
237+
9, TUSB_DESC_CS_INTERFACE, AUDIO_CS_INTERFACE_HEADER, U16_TO_U8S_LE(0x0100), U16_TO_U8S_LE(0x0009), 1, (uint8_t)((_itfnum) + 1),\
243238
/* MIDI Streaming (MS) Interface */\
244-
9, TUSB_DESC_INTERFACE, static_cast<uint8_t>((_itfnum) + 1), 0, 2, TUSB_CLASS_AUDIO, AUDIO_SUBCLASS_MIDI_STREAMING, AUDIO_PROTOCOL_V1, 0,\
239+
9, TUSB_DESC_INTERFACE, (uint8_t)((_itfnum) + 1), 0, 2, TUSB_CLASS_AUDIO, AUDIO_SUBCLASS_MIDI_STREAMING, AUDIO_PROTOCOL_V1, 0,\
245240
/* MS Header */\
246-
7, TUSB_DESC_CS_INTERFACE, MIDI_CS_INTERFACE_HEADER, U16_TO_U8S_LE(0x0100), U16_TO_U8S_LE(0x0025),\
241+
7, TUSB_DESC_CS_INTERFACE, MIDI_CS_INTERFACE_HEADER, U16_TO_U8S_LE(0x0100), U16_TO_U8S_LE(7 + (_numcables) * TUD_MIDI_DESC_JACK_LEN)
242+
243+
#define TUD_MIDI_JACKID_IN_EMB(_cablenum) \
244+
(uint8_t)(((_cablenum) - 1) * 4 + 1)
245+
246+
#define TUD_MIDI_JACKID_IN_EXT(_cablenum) \
247+
(uint8_t)(((_cablenum) - 1) * 4 + 2)
248+
249+
#define TUD_MIDI_JACKID_OUT_EMB(_cablenum) \
250+
(uint8_t)(((_cablenum) - 1) * 4 + 3)
251+
252+
#define TUD_MIDI_JACKID_OUT_EXT(_cablenum) \
253+
(uint8_t)(((_cablenum) - 1) * 4 + 4)
254+
255+
#define TUD_MIDI_DESC_JACK_LEN (6 + 6 + 9 + 9)
256+
#define TUD_MIDI_DESC_JACK(_cablenum) \
247257
/* MS In Jack (Embedded) */\
248-
6, TUSB_DESC_CS_INTERFACE, MIDI_CS_INTERFACE_IN_JACK, MIDI_JACK_EMBEDDED, 1, 0,\
258+
6, TUSB_DESC_CS_INTERFACE, MIDI_CS_INTERFACE_IN_JACK, MIDI_JACK_EMBEDDED, TUD_MIDI_JACKID_IN_EMB(_cablenum), 0,\
249259
/* MS In Jack (External) */\
250-
6, TUSB_DESC_CS_INTERFACE, MIDI_CS_INTERFACE_IN_JACK, MIDI_JACK_EXTERNAL, 2, 0,\
260+
6, TUSB_DESC_CS_INTERFACE, MIDI_CS_INTERFACE_IN_JACK, MIDI_JACK_EXTERNAL, TUD_MIDI_JACKID_IN_EXT(_cablenum), 0,\
251261
/* MS Out Jack (Embedded), connected to In Jack External */\
252-
9, TUSB_DESC_CS_INTERFACE, MIDI_CS_INTERFACE_OUT_JACK, MIDI_JACK_EMBEDDED, 3, 1, 2, 1, 0,\
262+
9, TUSB_DESC_CS_INTERFACE, MIDI_CS_INTERFACE_OUT_JACK, MIDI_JACK_EMBEDDED, TUD_MIDI_JACKID_OUT_EMB(_cablenum), 1, TUD_MIDI_JACKID_IN_EXT(_cablenum), 1, 0,\
253263
/* MS Out Jack (External), connected to In Jack Embedded */\
254-
9, TUSB_DESC_CS_INTERFACE, MIDI_CS_INTERFACE_OUT_JACK, MIDI_JACK_EXTERNAL, 4, 1, 1, 1, 0,\
255-
/* Endpoint Out */\
264+
9, TUSB_DESC_CS_INTERFACE, MIDI_CS_INTERFACE_OUT_JACK, MIDI_JACK_EXTERNAL, TUD_MIDI_JACKID_OUT_EXT(_cablenum), 1, TUD_MIDI_JACKID_IN_EMB(_cablenum), 1, 0
265+
266+
#define TUD_MIDI_DESC_EP_LEN(_numcables) (7 + 4 + (_numcables))
267+
#define TUD_MIDI_DESC_EP(_epout, _epsize, _numcables) \
268+
/* Endpoint */\
256269
7, TUSB_DESC_ENDPOINT, _epout, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0,\
257-
/* MS Endpoint (connected to embedded jack in) */\
258-
5, TUSB_DESC_CS_ENDPOINT, MIDI_CS_ENDPOINT_GENERAL, 1, 1,\
259-
/* Endpoint In */\
260-
7, TUSB_DESC_ENDPOINT, _epin, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0,\
261-
/* MS Endpoint (connected to embedded jack out) */\
262-
5, TUSB_DESC_CS_ENDPOINT, MIDI_CS_ENDPOINT_GENERAL, 1, 3
270+
/* MS Endpoint (connected to embedded jack) */\
271+
(uint8_t)(4 + (_numcables)), TUSB_DESC_CS_ENDPOINT, MIDI_CS_ENDPOINT_GENERAL, _numcables
272+
273+
// Length of template descriptor (88 bytes)
274+
#define TUD_MIDI_DESC_LEN (TUD_MIDI_DESC_HEAD_LEN + TUD_MIDI_DESC_JACK_LEN + TUD_MIDI_DESC_EP_LEN(1) * 2)
275+
276+
// MIDI simple descriptor
277+
// - 1 Embedded Jack In connected to 1 External Jack Out
278+
// - 1 Embedded Jack out connected to 1 External Jack In
279+
#define TUD_MIDI_DESCRIPTOR(_itfnum, _stridx, _epout, _epin, _epsize) \
280+
TUD_MIDI_DESC_HEAD(_itfnum, _stridx, 1),\
281+
TUD_MIDI_DESC_JACK(1),\
282+
TUD_MIDI_DESC_EP(_epout, _epsize, 1),\
283+
TUD_MIDI_JACKID_IN_EMB(1),\
284+
TUD_MIDI_DESC_EP(_epin, _epsize, 1),\
285+
TUD_MIDI_JACKID_OUT_EMB(1)
263286

264287
//------------- Vendor -------------//
265288
#define TUD_VENDOR_DESC_LEN (9+7+7)

0 commit comments

Comments
 (0)