Commit Graph

3 Commits

Author SHA1 Message Date
4baf1883c1 midi2: convert to raw Tx FIFO for better segmentation handling, add count to packet api
Signed-off-by: HiFiPhile <admin@hifiphile.com>
2026-05-18 23:07:49 +02:00
fa9edeff9c fix: address PR review feedback for MIDI 2.0 drivers
Host driver (midi2_host.c):
- midih2_open() now returns actual parsed length instead of max_len,
  preventing composite device interface conflicts
- Parsers (alt0/alt1) refactored to return const uint8_t* end pointer
  following midi_host.c switch/case pattern
- Alt 1 CS Endpoint now parses MIDI 2.0 layout (bNumGrpTrmBlk at
  offset 3 with MIDI_CS_ENDPOINT_GENERAL_2_0 subtype check) instead
  of reusing MIDI 1.0 struct (bNumEmbMIDIJack)
- midih2_set_config() now issues SET_INTERFACE control request via
  tuh_interface_set() before completing configuration. Falls back to
  alt 0 if SET_INTERFACE fails
- Extracted midih2_set_config_complete() and midih2_set_interface_cb()
  for async SET_INTERFACE handling

Device driver (midi2_device.c):
- midi2d_open() skip loop now checks bInterfaceNumber, stopping at
  interfaces that belong to other functions in composite devices
- SET_INTERFACE handler now rejects alt > 1 (returns false/stall)
- Named constants for GTB descriptor types and MIDI protocol values

Descriptor macros (usbd.h):
- TUD_MIDI2_DESC_ALT1_HEAD: iInterface set to 0 (consistent with
  Alt 0), wTotalLength now uses TUD_MIDI2_DESC_ALT1_CS_LEN to cover
  all Alt 1 class-specific descriptors
- TUD_MIDI2_DESC_ALT1_EP: now accepts GTB ID list via variadic args,
  emitting complete CS endpoint descriptor

Host example:
- CMakeLists.txt restricted to rp2040 family (display.c requires
  Pico SDK headers)
- display.c: null terminator after strncpy in log scroll

Documentation:
- class_drivers.rst updated to reflect SET_INTERFACE behavior and
  auto-select with fallback

Addresses: Codex P1 (#1, #2, #3), Copilot (#4-#9)
2026-05-12 11:07:44 -03:00
77cef83304 test: add MIDI 2.0 Device and Host unit tests
Add unit tests for MIDI 2.0 drivers:
- Device: UMP word count (all 16 message types), descriptor macro
  validation (length, byte layout, alt settings, endpoints),
  CS endpoint subtypes, traversal integrity
- Host: UMP word count, callback struct validation, CS endpoint
  subtypes

Also add Sphinx documentation for MIDI 2.0 class drivers (Device
and Host API reference, lifecycle, configuration, examples).

Tests: 60/60 PASS (FIFO 26/26, USBD 5/5, MIDI2 Device 18/18,
MIDI2 Host 6/6, USBD internal 5/5)
2026-05-12 11:07:44 -03:00