feat(midi2): opt-in app responder for UMP Stream#3739
Conversation
There was a problem hiding this comment.
Pull request overview
Adds an opt-in build-time switch to the MIDI 2.0 device class that lets applications take over UMP Stream (MT=0xF) discovery/configuration handling, while preserving current driver behavior when the option is disabled.
Changes:
- Introduces
CFG_TUD_MIDI2_USER_RESPONDER(default0) configuration define. - When enabled, disables the built-in UMP Stream responder and leaves UMP Stream messages in the RX FIFO for the application to read/handle.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/class/midi/midi2_device.h | Adds the new opt-in configuration macro default. |
| src/class/midi/midi2_device.c | Gates the built-in UMP Stream negotiation responder and skips consuming stream messages when user-responder mode is enabled. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| #ifndef CFG_TUD_MIDI2_USER_RESPONDER | ||
| #define CFG_TUD_MIDI2_USER_RESPONDER 0 | ||
| #endif |
| #if CFG_TUD_MIDI2_USER_RESPONDER | ||
| // User responder owns UMP Stream discovery: MT 0xF messages stay in the | ||
| // RX FIFO and surface through tud_midi2_n_ump_read so the application can | ||
| // answer Endpoint / Function Block discovery itself. | ||
| (void)p_midi; | ||
| #else |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5f8a734576
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| #if CFG_TUD_MIDI2_USER_RESPONDER | ||
| // User responder owns UMP Stream discovery: MT 0xF messages stay in the | ||
| // RX FIFO and surface through tud_midi2_n_ump_read so the application can | ||
| // answer Endpoint / Function Block discovery itself. | ||
| (void)p_midi; |
There was a problem hiding this comment.
Preserve negotiation state in user responder mode
With CFG_TUD_MIDI2_USER_RESPONDER=1, this branch returns before the only code path that handles STREAM_CONFIG_REQUEST; since there is also no public setter for p_midi->protocol or p_midi->negotiated, an application that accepts a host's MIDI 1.0 Config Request and sends its own Config Notify will still see tud_midi2_n_protocol() report the reset default MIDI2 and tud_midi2_n_negotiated() stay false. Please either keep parsing config requests for state or provide a way for the user responder to update these getters.
Useful? React with 👍 / 👎.
CFG_TUD_MIDI2_USER_RESPONDER lets the application answer UMP Stream discovery (Endpoint, Function Block, Stream Config) instead of the built-in responder, for endpoints with dynamic topology. Ref hathach#3571
5f8a734 to
08d6bf8
Compare
|
Updated to address the automated review: added |
Hardware-in-the-loop (HIL) Test Reporthfp.json✅ 52 passed · ❌ 0 failed · ⚪ 0 skipped · blank not run
tinyusb.json✅ 200 passed · ❌ 138 failed · ⚪ 11 skipped · blank not run
|
|
| @@ -402,6 +411,7 @@ static void _nego_process_rx(midi2d_interface_t* p_midi) { | |||
| tu_edpt_stream_read(ep_rx, buf, pkt_bytes); | |||
There was a problem hiding this comment.
I'm thinking about adding a weak callback here, with the return value we can differentiate between Handled, Negotiated to V1 , Negotiated to V2 , etc.
Maybe the user only want to override a one specific response instead of implement full negotiation in app.
There was a problem hiding this comment.
Hi @HiFiPhile! Are you thinking of a per-message hook at the stream dispatch, where the return value decides fallthrough vs handled? So the app could intercept just FB Discovery, say, and let the built-in responder take the rest.
|
Closing this in favor of #3738. While I was working through the function block changes there, I ended up adding a per-message callback (tud_midi2_stream_msg_cb, returning PASS / HANDLED / NEGOTIATED_*) that does what the CFG_TUD_MIDI2_USER_RESPONDER flag here does, but per message and without a compile-time switch. That made this one redundant. |
Summary
Small, opt-in change, quick to review. Touches only the MIDI 2.0 device class
(legacy MIDI 1.0 driver untouched) and is byte-identical to current behavior
when the flag is off.
Adds CFG_TUD_MIDI2_USER_RESPONDER (default off). When set, the driver leaves
UMP Stream messages in the RX FIFO so the application can answer Endpoint /
Function Block discovery and Stream Configuration itself, for endpoints whose
topology is dynamic (e.g. a bridge whose function blocks track the devices
plugged into it). Built-in responder is unchanged when off.
Test plan
Ref #3571