-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat(midi2): opt-in app responder for UMP Stream #3739
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -270,6 +270,7 @@ static uint32_t _tx_ump_write(midi2d_interface_t* p_midi, const uint32_t* words, | |
| //--------------------------------------------------------------------+ | ||
| // Protocol Negotiation | ||
| //--------------------------------------------------------------------+ | ||
| #if !CFG_TUD_MIDI2_USER_RESPONDER | ||
| static void _nego_send_ump(midi2d_interface_t* p_midi, const uint32_t* words, uint8_t count) { | ||
| if (!_tx_opened(p_midi)) return; | ||
| if (tu_fifo_remaining(&p_midi->ep_stream.tx.ff) < (uint32_t) count * 4) return; | ||
|
|
@@ -383,8 +384,16 @@ static void _nego_handle_stream_msg(midi2d_interface_t* p_midi, const uint32_t* | |
| break; | ||
| } | ||
| } | ||
| #endif // !CFG_TUD_MIDI2_USER_RESPONDER | ||
|
|
||
| static void _nego_process_rx(midi2d_interface_t* p_midi) { | ||
| #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. The app must drain | ||
| // them (e.g. in tud_midi2_rx_cb) to avoid RX FIFO backpressure. | ||
| (void)p_midi; | ||
| #else | ||
| tu_edpt_stream_t* ep_rx = &p_midi->ep_stream.rx; | ||
| uint8_t word_bytes[4]; | ||
|
|
||
|
|
@@ -402,6 +411,7 @@ static void _nego_process_rx(midi2d_interface_t* p_midi) { | |
| tu_edpt_stream_read(ep_rx, buf, pkt_bytes); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm thinking about adding a weak callback here, with the return value we can differentiate between Maybe the user only want to override a one specific response instead of implement full negotiation in app.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes exactely. |
||
| _nego_handle_stream_msg(p_midi, buf); | ||
| } | ||
| #endif | ||
| } | ||
|
|
||
| //--------------------------------------------------------------------+ | ||
|
|
@@ -510,6 +520,12 @@ uint8_t tud_midi2_n_protocol(uint8_t itf) { | |
| return _midi2d_itf[itf].protocol; | ||
| } | ||
|
|
||
| void tud_midi2_n_set_protocol(uint8_t itf, uint8_t protocol) { | ||
| TU_VERIFY(itf < CFG_TUD_MIDI2, ); | ||
| _midi2d_itf[itf].protocol = protocol; | ||
| _midi2d_itf[itf].negotiated = true; | ||
| } | ||
|
|
||
| //--------------------------------------------------------------------+ | ||
| // USBD Driver API | ||
| //--------------------------------------------------------------------+ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With
CFG_TUD_MIDI2_USER_RESPONDER=1, this branch returns before the only code path that handlesSTREAM_CONFIG_REQUEST; since there is also no public setter forp_midi->protocolorp_midi->negotiated, an application that accepts a host's MIDI 1.0 Config Request and sends its own Config Notify will still seetud_midi2_n_protocol()report the reset default MIDI2 andtud_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 👍 / 👎.