summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSaulo VerĂ­ssimo <[email protected]>2026-06-28 16:28:29 -0300
committerSaulo VerĂ­ssimo <[email protected]>2026-06-28 16:34:35 -0300
commit516fb063d88ca02c3d4e6ff7523407f774bfde67 (patch)
treebd6bbcff60d15a9c9062ab82ba7627e3b1509c8c
parent9e7dc67b62ab097b5ed66c74302206b20b5b2e65 (diff)
example(midi2): update example to demonstrate multiple fb
Adds two Group Terminal Blocks (output and input) with names and per-direction endpoint association, plus an explicit endpoint name.
-rw-r--r--examples/device/midi2_device/src/main.c19
-rw-r--r--examples/device/midi2_device/src/tusb_config.h4
-rw-r--r--examples/device/midi2_device/src/usb_descriptors.c18
3 files changed, 38 insertions, 3 deletions
diff --git a/examples/device/midi2_device/src/main.c b/examples/device/midi2_device/src/main.c
index ce052a20b..2c77652dc 100644
--- a/examples/device/midi2_device/src/main.c
+++ b/examples/device/midi2_device/src/main.c
@@ -546,6 +546,25 @@ void tud_midi2_set_itf_cb(uint8_t itf, uint8_t alt) {
printf("[ALT] Host selected alt=%u\r\n", (unsigned)alt);
}
+// PROTOTYPE: two Function Blocks with independent directions.
+// FB0: output only, group 0 FB1: input only, group 1
+static const uint8_t gtb_two_blocks[] = {
+ TUD_MIDI2_GTB_HEADER(2),
+ TUD_MIDI2_GTB_BLOCK(1, MIDI2_GTB_OUTPUT_ONLY, 0, 1, 0), // block 1: group 0
+ TUD_MIDI2_GTB_BLOCK(2, MIDI2_GTB_INPUT_ONLY, 1, 1, 0), // block 2: group 1
+};
+
+const uint8_t* tud_midi2_gtb_desc_cb(uint8_t itf, uint16_t* len) {
+ (void)itf;
+ *len = sizeof(gtb_two_blocks);
+ return gtb_two_blocks;
+}
+
+const char* tud_midi2_fb_name_cb(uint8_t itf, uint8_t fb_idx) {
+ (void)itf;
+ return (fb_idx == 0) ? "Synth Out" : "Keys In";
+}
+
//--------------------------------------------------------------------+
// Initial Setup - Program Change, CC, Per-Note Management
//--------------------------------------------------------------------+
diff --git a/examples/device/midi2_device/src/tusb_config.h b/examples/device/midi2_device/src/tusb_config.h
index 1ada0015f..e829c91c4 100644
--- a/examples/device/midi2_device/src/tusb_config.h
+++ b/examples/device/midi2_device/src/tusb_config.h
@@ -81,6 +81,10 @@ extern "C" {
//------------- CLASS -------------//
#define CFG_TUD_MIDI2 1
+// UMP Endpoint name shown by the host. Set to your device name; keep the USB
+// iProduct string (usb_descriptors.c) in sync.
+#define CFG_TUD_MIDI2_EP_NAME "TinyUSB MIDI 2.0"
+
#ifdef __cplusplus
}
#endif
diff --git a/examples/device/midi2_device/src/usb_descriptors.c b/examples/device/midi2_device/src/usb_descriptors.c
index f035f9c48..2cd6bf0f6 100644
--- a/examples/device/midi2_device/src/usb_descriptors.c
+++ b/examples/device/midi2_device/src/usb_descriptors.c
@@ -62,7 +62,7 @@ uint8_t const * tud_descriptor_device_cb(void) {
enum {
ITF_NUM_MIDI2 = 0, // Audio Control interface
- ITF_NUM_MIDI2_STREAMING, // MIDI Streaming interface (auto-created by TUD_MIDI2_DESCRIPTOR)
+ ITF_NUM_MIDI2_STREAMING, // MIDI Streaming interface
ITF_NUM_TOTAL
};
@@ -80,8 +80,20 @@ static uint8_t const desc_fs_configuration[] = {
// Config number, interface count, string index, total length, attribute, power in mA
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
- // MIDI 2.0 Interface
- TUD_MIDI2_DESCRIPTOR(ITF_NUM_MIDI2, 0, EPNUM_MIDI2_OUT, EPNUM_MIDI2_IN, 64)
+ // MIDI 2.0 Interface, two Group Terminal Blocks associated per direction:
+ // bulk OUT (host to device) carries the input block (ID 2)
+ // bulk IN (device to host) carries the output block (ID 1)
+ // Alt Setting 0 (MIDI 1.0)
+ TUD_MIDI_DESC_HEAD(ITF_NUM_MIDI2, 0, 1),
+ TUD_MIDI_DESC_JACK_DESC(1, 0),
+ TUD_MIDI_DESC_EP(EPNUM_MIDI2_OUT, 64, 1),
+ TUD_MIDI_JACKID_IN_EMB(1),
+ TUD_MIDI_DESC_EP(EPNUM_MIDI2_IN, 64, 1),
+ TUD_MIDI_JACKID_OUT_EMB(1),
+ // Alt Setting 1 (UMP)
+ TUD_MIDI2_DESC_ALT1_HEAD(ITF_NUM_MIDI2, 0),
+ TUD_MIDI2_DESC_ALT1_EP(EPNUM_MIDI2_OUT, 64, 1, 2),
+ TUD_MIDI2_DESC_ALT1_EP(EPNUM_MIDI2_IN, 64, 1, 1)
};
uint8_t const * tud_descriptor_configuration_cb(uint8_t index) {