Skip to content

Add tud_midi_n_tx_avaiable interface created for easier flow control#3659

Open
SukuWc wants to merge 2 commits into
hathach:masterfrom
intechstudio:grid-0.20.0
Open

Add tud_midi_n_tx_avaiable interface created for easier flow control#3659
SukuWc wants to merge 2 commits into
hathach:masterfrom
intechstudio:grid-0.20.0

Conversation

@SukuWc
Copy link
Copy Markdown

@SukuWc SukuWc commented Jun 1, 2026

Added publicly accessible Tx and Rx available functions to the MIDI class driver. this allow proper flow-control to prevent data loss when using non-peekable tx FIFOs in the application.

Files changed

  • src/class/midi/midi_device.h
  • src/class/midi/midi_device.c

New interfaces

uint32_t tud_midi_n_tx_available(uint8_t itf);
uint32_t tud_midi_n_rx_available(uint8_t itf);

New inline functions

TU_ATTR_ALWAYS_INLINE static inline uint32_t tud_midi_tx_available(void) {
  return tud_midi_n_tx_available(0);
}

TU_ATTR_ALWAYS_INLINE static inline uint32_t tud_midi_rx_available(void) {
  return tud_midi_n_rx_available(0);
}

@HiFiPhile HiFiPhile requested a review from Copilot June 5, 2026 20:42
@HiFiPhile HiFiPhile changed the title SUKU tud_midi_n_tx_avaiable interface created for easier flow control Add tud_midi_n_tx_avaiable interface created for easier flow control Jun 5, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds public “available” query APIs to the USB MIDI device class so applications can implement flow control (notably when using non-peekable FIFOs) by checking TX/RX capacity before writing/reading.

Changes:

  • Add new multi-interface APIs tud_midi_n_tx_available() and tud_midi_n_rx_available().
  • Add single-interface inline wrappers tud_midi_tx_available() / tud_midi_rx_available() for interface 0.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/class/midi/midi_device.h Declares new public availability APIs and adds single-interface inline wrappers.
src/class/midi/midi_device.c Implements new availability APIs using endpoint-stream availability helpers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +297 to +301
uint32_t tud_midi_n_tx_available(uint8_t itf) {
midid_interface_t *p_midi = &_midid_itf[itf];
tu_edpt_stream_t *ep_str = &p_midi->ep_stream.tx;
return tu_edpt_stream_write_available(p_midi->rhport, ep_str);
}
Comment on lines +303 to +307
uint32_t tud_midi_n_rx_available(uint8_t itf) {
midid_interface_t *p_midi = &_midid_itf[itf];
tu_edpt_stream_t *ep_str = &p_midi->ep_stream.rx;
return tu_edpt_stream_read_available(ep_str);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants