mirror of
https://github.com/hathach/tinyusb.git
synced 2026-08-18 11:02:16 +00:00
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.
This commit is contained in:
@ -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
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user