mirror of
https://github.com/hathach/tinyusb.git
synced 2026-08-18 11:02:16 +00:00
midi2: drain pattern for RX FIFO
Default RX/TX buffers to EPSIZE for both device and host. Document drain-in-loop on ump_read; example device callback drains until empty.
This commit is contained in:
@ -529,7 +529,13 @@ void send_initial_setup(void);
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
void tud_midi2_rx_cb(uint8_t itf) {
|
||||
(void)itf;
|
||||
// Drain the RX FIFO in a loop until empty. Leaving words in the FIFO
|
||||
// across callbacks can prevent subsequent bulk OUT transfers from landing.
|
||||
uint32_t words[8];
|
||||
uint32_t n;
|
||||
while ((n = tud_midi2_n_ump_read(itf, words, TU_ARRAY_SIZE(words))) > 0) {
|
||||
(void) n;
|
||||
}
|
||||
}
|
||||
|
||||
// Reset playback state and re-send setup when host switches alt setting or
|
||||
|
||||
@ -57,11 +57,11 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef CFG_TUD_MIDI2_TX_BUFSIZE
|
||||
#define CFG_TUD_MIDI2_TX_BUFSIZE (4 * CFG_TUD_MIDI2_TX_EPSIZE)
|
||||
#define CFG_TUD_MIDI2_TX_BUFSIZE CFG_TUD_MIDI2_TX_EPSIZE
|
||||
#endif
|
||||
|
||||
#ifndef CFG_TUD_MIDI2_RX_BUFSIZE
|
||||
#define CFG_TUD_MIDI2_RX_BUFSIZE (4 * CFG_TUD_MIDI2_RX_EPSIZE)
|
||||
#define CFG_TUD_MIDI2_RX_BUFSIZE CFG_TUD_MIDI2_RX_EPSIZE
|
||||
#endif
|
||||
|
||||
#ifndef CFG_TUD_MIDI2_NUM_GROUPS
|
||||
@ -119,6 +119,14 @@ uint8_t tud_midi2_n_alt_setting(uint8_t itf);
|
||||
bool tud_midi2_n_negotiated(uint8_t itf);
|
||||
uint8_t tud_midi2_n_protocol(uint8_t itf);
|
||||
|
||||
// Read up to max_words UMP words from the RX FIFO. Returns the number of
|
||||
// words actually read (0 if FIFO is empty).
|
||||
//
|
||||
// NOTE: this function returns when max_words is reached or when the FIFO is
|
||||
// empty, whichever comes first. Applications should invoke it in a loop
|
||||
// until it returns 0 to guarantee the RX FIFO is fully drained per
|
||||
// tud_midi2_rx_cb callback. Leaving words in the FIFO across callbacks can
|
||||
// prevent subsequent bulk OUT transfers from landing.
|
||||
uint32_t tud_midi2_n_ump_read(uint8_t itf, uint32_t* words, uint32_t max_words);
|
||||
uint32_t tud_midi2_n_ump_write(uint8_t itf, const uint32_t* words, uint32_t count);
|
||||
|
||||
|
||||
@ -77,6 +77,14 @@ uint8_t tuh_midi2_get_cable_count(uint8_t idx);
|
||||
// Application API - I/O
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// Read up to max_words UMP words from the RX FIFO. Returns the number of
|
||||
// words actually read (0 if FIFO is empty).
|
||||
//
|
||||
// NOTE: this function returns when max_words is reached or when the FIFO is
|
||||
// empty, whichever comes first. Applications should invoke it in a loop
|
||||
// until it returns 0 to guarantee the RX FIFO is fully drained per
|
||||
// tuh_midi2_rx_cb callback. Leaving words in the FIFO across callbacks can
|
||||
// prevent subsequent bulk IN transfers from landing.
|
||||
uint32_t tuh_midi2_ump_read(uint8_t idx, uint32_t* words, uint32_t max_words);
|
||||
uint32_t tuh_midi2_ump_write(uint8_t idx, const uint32_t* words, uint32_t count);
|
||||
uint32_t tuh_midi2_write_flush(uint8_t idx);
|
||||
|
||||
@ -824,11 +824,11 @@
|
||||
#endif
|
||||
|
||||
#ifndef CFG_TUH_MIDI2_RX_BUFSIZE
|
||||
#define CFG_TUH_MIDI2_RX_BUFSIZE (4 * TUH_EPSIZE_BULK_MAX)
|
||||
#define CFG_TUH_MIDI2_RX_BUFSIZE TUH_EPSIZE_BULK_MAX
|
||||
#endif
|
||||
|
||||
#ifndef CFG_TUH_MIDI2_TX_BUFSIZE
|
||||
#define CFG_TUH_MIDI2_TX_BUFSIZE (4 * TUH_EPSIZE_BULK_MAX)
|
||||
#define CFG_TUH_MIDI2_TX_BUFSIZE TUH_EPSIZE_BULK_MAX
|
||||
#endif
|
||||
|
||||
#ifndef CFG_TUH_MIDI2_LOG_LEVEL
|
||||
|
||||
Reference in New Issue
Block a user