| Age | Commit message (Collapse) | Author |
|
feat(midi2): derive function blocks from the GTB descriptor
|
|
Signed-off-by: HiFiPhile <[email protected]>
|
|
* license: use SPDX identifiers for src/ headers
Replace the full ~20-line MIT license boilerplate on every src/ file with a
two-line SPDX tag (SPDX-FileCopyrightText + SPDX-License-Identifier), following
the REUSE convention used by CircuitPython and the Linux kernel. Removes ~3500
lines of duplicated boilerplate.
|
|
Function Block Info (direction, group span, name) is derived from the GTB
descriptor as the single source of truth, so a device can expose multiple
Group Terminal Blocks with independent directions. Adds Function Block Name
notifications (tud_midi2_fb_name_cb) and an opt-in callback to answer UMP
Stream messages from the application (tud_midi2_stream_msg_cb). Ref #3571
|
|
packet api
Signed-off-by: HiFiPhile <[email protected]>
|
|
|
|
Lets each instance return different NUM_GROUPS, NUM_FUNCTION_BLOCKS,
EP_NAME and PRODUCT_ID. Defaults fall back to the macros.
|
|
MT is in byte 3 of the UMP word in LE memory, not byte 0. Buffers
at mps blocked RX xfer re-arm on partial packets.
|
|
Signed-off-by: HiFiPhile <[email protected]>
|
|
The edpt_stream auto-flush is byte-oriented and could cut an UMP message
in half when the FIFO reached wMaxPacketSize, corrupting the peer's RX
context. Pre-flush whole packets before writing one that would cross the
boundary on both device (tud_midi2_n_ump_write) and host
(tuh_midi2_ump_write) paths. Host write also becomes packet-aware
instead of word-by-word.
Ref #3571
|
|
Alt 0 carries USB-MIDI 1.0 32-bit Event Packets, not UMP words; calling
the UMP API there would misinterpret the stream. Expose MIDI_PROTOCOL_MIDI1
and MIDI_PROTOCOL_MIDI2 in the public header so applications can branch on
the negotiated protocol.
Ref #3571
|
|
Brings the MIDI 2.0 device driver into full conformance with USB
Device Class Definition for MIDI Devices v2.0 (USB-IF, May 2020).
- Alt 1 MS Interface Header wTotalLength now reports 0x0007 per
Table 5-2 ("set to match bLength"), replacing the prior 0x0011
carried over from USB-MIDI 1.0 conventions.
- GET_DESCRIPTOR class request now validates bmRequestType direction,
type and recipient plus wIndex and wValue high byte per Section 6.
- iBlockItem in the default Group Terminal Block is driven by
CFG_TUD_MIDI2_BLOCK_STRIDX so applications can attach a UI string
descriptor to the block per Table 5-6.
- UMP word byte order assumption (little-endian host per Section
3.2.2) is documented inline so future big-endian ports know where
to wrap access with tu_htole32 / tu_le32toh.
Validated on RP2040 and ESP32-P4 under Linux kernel 6.17: lsusb -v
reports wTotalLength = 0x0007 on Alt 1 MS Header (raw bytes
07 24 01 00 02 07 00). amidi -l enumerates Group Terminals exposed
via the class-specific GET_DESCRIPTOR response.
|
|
Keep the MIDI 2.0 drivers fully self-contained, with no changes to
shared or generic stack code.
Allocate the per-endpoint buffer in both midi2_host and midi2_device,
following the convention used by cdc, midi, vendor, and printer.
The class buffer struct is declared unconditionally and passed to
tu_edpt_stream_init on every init, so the streaming helpers operate
on the same shape across all classes.
|
|
- Use UINT32_C(1) instead of 1u for bit shifts >= 16 in
midi2_device.c to avoid shift-count-overflow on 16-bit
platforms (MSP430)
- Add Makefiles for midi2_device and midi2_host examples with
family guard (skip if FAMILY != rp2040). These examples
require Pico SDK and board-specific hardware
- Restrict midi2_device CMakeLists.txt to rp2040 family
(matching midi2_host)
|
|
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)
|
|
Add native USB-MIDI 2.0 Device class driver to TinyUSB. Implements the
USB-MIDI 2.0 specification with both Alt Setting 0 (MIDI 1.0 fallback)
and Alt Setting 1 (UMP native) descriptor support.
Driver features:
- UMP (Universal MIDI Packet) read/write with atomic message framing
- Protocol negotiation: Endpoint Discovery, Config Request/Notify,
Function Block Discovery (embedded in driver)
- Group Terminal Block descriptor via GET_DESCRIPTOR
- Alt Setting switch handler with endpoint re-arm
- Static allocation, no dynamic memory, ISR-safe
Build system:
- Register midi2d_* in usbd.c driver table
- Add TUD_MIDI2_DESCRIPTOR macros to usbd.h
- Add config defaults (CFG_TUD_MIDI2_*) to tusb_option.h
- Add midi2_ump_word_count() to midi.h (shared by Device and Host)
- Add midi2_device.c/h to family.cmake and CMakeLists.txt
- Add midi2_device.h include to tusb.h
All changes guarded by #if CFG_TUD_MIDI2 (default 0). Zero impact on
existing drivers and examples.
Tested: Raspberry Pi Pico (RP2040), Linux ALSA, Windows MIDI Services
|