summaryrefslogtreecommitdiff
path: root/src/class
diff options
context:
space:
mode:
authorHa Thach <[email protected]>2025-08-02 20:34:25 +0700
committerGitHub <[email protected]>2025-08-02 20:34:25 +0700
commit8f46021eba3a93dd95e8272ab0ac223fdfe6c881 (patch)
treefb87cfd20a01184b19ce6f586e4729123ded27b5 /src/class
parent60f075db6516f7d2481dd77c86237b22c50d3c3f (diff)
parent12a1d0e7ede97c793a5e11b3cce7284cdbe994c8 (diff)
Merge pull request #3183 from rppicomidi/fix_3159
Fix #3159: Handle MIDI interface after audio streaming interface
Diffstat (limited to 'src/class')
-rw-r--r--src/class/midi/midi_host.c23
-rw-r--r--src/class/vendor/vendor_device.c2
2 files changed, 21 insertions, 4 deletions
diff --git a/src/class/midi/midi_host.c b/src/class/midi/midi_host.c
index cd6e115ee..50bda1e36 100644
--- a/src/class/midi/midi_host.c
+++ b/src/class/midi/midi_host.c
@@ -211,7 +211,14 @@ bool midih_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *d
desc_cb.jack_num = 0;
// There can be just a MIDI or an Audio + MIDI interface
- // If there is Audio Control Interface + Audio Header descriptor, skip it
+ // - If there is Audio Control Interface + Audio Header descriptor, then skip it.
+ // - If there is an Audio Control Interface + Audio Streaming Interface, then ignore the Audio Streaming Interface.
+ // Future:
+ // Note that if this driver is used with an USB Audio Streaming host driver,
+ // then call that driver first. If the MIDI interface comes before the
+ // audio streaming interface, then the audio driver will have to call this
+ // driver after parsing the audio control interface and then resume parsing
+ // the streaming audio interface.
if (AUDIO_SUBCLASS_CONTROL == desc_itf->bInterfaceSubClass) {
TU_VERIFY(max_len > 2*sizeof(tusb_desc_interface_t) + sizeof(audio_desc_cs_ac_interface_t));
@@ -222,8 +229,18 @@ bool midih_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *d
p_desc = tu_desc_next(p_desc);
desc_itf = (const tusb_desc_interface_t *)p_desc;
- TU_VERIFY(TUSB_CLASS_AUDIO == desc_itf->bInterfaceClass);
p_midi->itf_count = 1;
+ // skip non-interface and non-midi streaming descriptors
+ while (tu_desc_in_bounds(p_desc, p_end) &&
+ (desc_itf->bDescriptorType != TUSB_DESC_INTERFACE || (desc_itf->bInterfaceClass == TUSB_CLASS_AUDIO && desc_itf->bInterfaceSubClass != AUDIO_SUBCLASS_MIDI_STREAMING))) {
+ if (desc_itf->bDescriptorType == TUSB_DESC_INTERFACE && desc_itf->bAlternateSetting == 0) {
+ p_midi->itf_count++;
+ }
+ p_desc = tu_desc_next(p_desc);
+ desc_itf = (tusb_desc_interface_t const *)p_desc;
+ }
+ TU_VERIFY(p_desc < p_end); // TODO: If MIDI interface comes after Audio Streaming, then max_len did not include the MIDI interface descriptor
+ TU_VERIFY(TUSB_CLASS_AUDIO == desc_itf->bInterfaceClass);
}
TU_VERIFY(AUDIO_SUBCLASS_MIDI_STREAMING == desc_itf->bInterfaceSubClass);
@@ -236,7 +253,7 @@ bool midih_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *d
p_desc = tu_desc_next(p_desc); // next to CS Header
bool found_new_interface = false;
- while ((p_desc < p_end) && (tu_desc_next(p_desc) <= p_end) && !found_new_interface) {
+ while (tu_desc_in_bounds(p_desc, p_end) && !found_new_interface) {
switch (tu_desc_type(p_desc)) {
case TUSB_DESC_INTERFACE:
found_new_interface = true;
diff --git a/src/class/vendor/vendor_device.c b/src/class/vendor/vendor_device.c
index 6f109c321..b0332b0fe 100644
--- a/src/class/vendor/vendor_device.c
+++ b/src/class/vendor/vendor_device.c
@@ -211,7 +211,7 @@ uint16_t vendord_open(uint8_t rhport, const tusb_desc_interface_t* desc_itf, uin
TU_VERIFY(p_vendor, 0);
p_vendor->itf_num = desc_itf->bInterfaceNumber;
- while (tu_desc_is_valid(p_desc, desc_end)) {
+ while (tu_desc_in_bounds(p_desc, desc_end)) {
const uint8_t desc_type = tu_desc_type(p_desc);
if (desc_type == TUSB_DESC_INTERFACE || desc_type == TUSB_DESC_INTERFACE_ASSOCIATION) {
break; // end of this interface