summaryrefslogtreecommitdiff
path: root/src/device
diff options
context:
space:
mode:
authorZixun LI <[email protected]>2026-05-19 22:12:28 +0200
committerGitHub <[email protected]>2026-05-19 22:12:28 +0200
commit4c87db341e4af7d53ce9cbbdf693593a520dc538 (patch)
treed5c6be4b83d44b42b8c9512e1cdc36261f945c31 /src/device
parent90c0884c71a8a4efbdaf8b1e44fa260f6881231e (diff)
parentdad8c0ae51d68fd5355a8a0de4e478e4149ec05e (diff)
Merge pull request #3571 from sauloverissimo/feat/midi2-device-host-driver
feat: Add USB-MIDI 2.0 Device and Host class drivers
Diffstat (limited to 'src/device')
-rw-r--r--src/device/usbd.c14
-rw-r--r--src/device/usbd.h37
2 files changed, 51 insertions, 0 deletions
diff --git a/src/device/usbd.c b/src/device/usbd.c
index 0e58f70bf..55ad330c1 100644
--- a/src/device/usbd.c
+++ b/src/device/usbd.c
@@ -254,6 +254,20 @@ static const usbd_class_driver_t _usbd_driver[] = {
},
#endif
+ #if CFG_TUD_MIDI2
+ {
+ .name = DRIVER_NAME("MIDI2"),
+ .init = midi2d_init,
+ .deinit = midi2d_deinit,
+ .open = midi2d_open,
+ .reset = midi2d_reset,
+ .control_xfer_cb = midi2d_control_xfer_cb,
+ .xfer_cb = midi2d_xfer_cb,
+ .xfer_isr = NULL,
+ .sof = NULL
+ },
+ #endif
+
#if CFG_TUD_VENDOR
{
.name = DRIVER_NAME("VENDOR"),
diff --git a/src/device/usbd.h b/src/device/usbd.h
index 473e697ac..abce5a887 100644
--- a/src/device/usbd.h
+++ b/src/device/usbd.h
@@ -425,6 +425,43 @@ bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_requ
TUD_MIDI_JACKID_OUT_EMB(1)
//--------------------------------------------------------------------+
+// MIDI 2.0 Descriptor Templates (USB-MIDI 2.0)
+//--------------------------------------------------------------------+
+
+// Alt Setting 1: MS Interface + MS Header (bcdMSC=0x0200)
+// Per USB-MIDI 2.0 Table 5-2: wTotalLength in the MS Header is not used in 2.0
+// and shall be set to match bLength (= 0x0007) for conformity with USB-MIDI 1.0.
+#define TUD_MIDI2_DESC_ALT1_HEAD_LEN (9 + 7)
+#define TUD_MIDI2_DESC_ALT1_HEAD(_itfnum, _stridx) \
+ /* MIDI Streaming Interface, Alt Setting 1 */\
+ 9, TUSB_DESC_INTERFACE, (uint8_t)((_itfnum) + 1), 1, 2, TUSB_CLASS_AUDIO, AUDIO_SUBCLASS_MIDI_STREAMING, AUDIO_FUNC_PROTOCOL_CODE_UNDEF, 0,\
+ /* MS Header (MIDI 2.0): wTotalLength = bLength per spec */\
+ 7, TUSB_DESC_CS_INTERFACE, MIDI_CS_INTERFACE_HEADER, U16_TO_U8S_LE(0x0200), U16_TO_U8S_LE(0x0007)
+
+// Alt Setting 1: Standard USB Endpoint (7 bytes) + CS Endpoint General 2.0
+#define TUD_MIDI2_DESC_ALT1_EP_LEN(_numgtbs) (7 + 4 + (_numgtbs))
+#define TUD_MIDI2_DESC_ALT1_EP(_ep, _epsize, _numgtbs, ...) \
+ 7, TUSB_DESC_ENDPOINT, _ep, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0, \
+ (uint8_t)(4 + (_numgtbs)), TUSB_DESC_CS_ENDPOINT, MIDI_CS_ENDPOINT_GENERAL_2_0, _numgtbs, ## __VA_ARGS__
+
+// Total length: Alt 0 (MIDI 1.0) + Alt 1 (UMP)
+#define TUD_MIDI2_DESC_LEN (TUD_MIDI_DESC_LEN + TUD_MIDI2_DESC_ALT1_HEAD_LEN + TUD_MIDI2_DESC_ALT1_EP_LEN(1) * 2)
+
+// Complete MIDI 2.0 descriptor with both alternate settings (single cable/GTB)
+#define TUD_MIDI2_DESCRIPTOR(_itfnum, _stridx, _epout, _epin, _epsize) \
+ /* Alt Setting 0 (MIDI 1.0) */\
+ TUD_MIDI_DESC_HEAD(_itfnum, _stridx, 1),\
+ TUD_MIDI_DESC_JACK_DESC(1, 0),\
+ TUD_MIDI_DESC_EP(_epout, _epsize, 1),\
+ TUD_MIDI_JACKID_IN_EMB(1),\
+ TUD_MIDI_DESC_EP(_epin, _epsize, 1),\
+ TUD_MIDI_JACKID_OUT_EMB(1),\
+ /* Alt Setting 1 (UMP) */\
+ TUD_MIDI2_DESC_ALT1_HEAD(_itfnum, _stridx),\
+ TUD_MIDI2_DESC_ALT1_EP(_epout, _epsize, 1, 1 /* bAssoGrpTrmBlkID */),\
+ TUD_MIDI2_DESC_ALT1_EP(_epin, _epsize, 1, 1 /* bAssoGrpTrmBlkID */)
+
+//--------------------------------------------------------------------+
// Audio Descriptor Templates
//--------------------------------------------------------------------+