summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSaulo VerĂ­ssimo <[email protected]>2026-05-17 11:31:12 -0300
committerSaulo VerĂ­ssimo <[email protected]>2026-05-17 11:31:12 -0300
commit5ac6346dd4980af75973e53dd130e7ee2a9af32d (patch)
treeff7f9cadb429de8d0a5c7ce127974db5ea3e0328
parente00ac15b7f31be28ff888a5220cbde93a61c17f4 (diff)
midi2: peek 4 bytes for MT, restore 256 buffers
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.
-rw-r--r--src/class/midi/midi2_device.c15
-rw-r--r--src/class/midi/midi2_device.h4
2 files changed, 11 insertions, 8 deletions
diff --git a/src/class/midi/midi2_device.c b/src/class/midi/midi2_device.c
index 360d70967..48cb3d388 100644
--- a/src/class/midi/midi2_device.c
+++ b/src/class/midi/midi2_device.c
@@ -266,10 +266,12 @@ static void _nego_handle_stream_msg(midi2d_interface_t* p_midi, const uint32_t*
static void _nego_process_rx(midi2d_interface_t* p_midi) {
tu_edpt_stream_t* ep_rx = &p_midi->ep_stream.rx;
- uint8_t first_byte;
+ uint8_t word_bytes[4];
- while (tu_edpt_stream_peek(ep_rx, &first_byte)) {
- uint8_t mt = (first_byte >> 4) & 0x0F;
+ while (tu_fifo_peek_n(&ep_rx->ff, word_bytes, 4) == 4) {
+ // UMP words travel LSB-first on the wire and in LE memory, so MT is in
+ // the high nibble of byte 3, not byte 0.
+ uint8_t mt = (word_bytes[3] >> 4) & 0x0F;
uint8_t pkt_words = midi2_ump_word_count(mt);
uint32_t pkt_bytes = (uint32_t)pkt_words * 4;
@@ -310,10 +312,11 @@ uint32_t tud_midi2_n_ump_read(uint8_t itf, uint32_t* words, uint32_t max_words)
uint32_t total_read = 0;
while (total_read < max_words) {
- uint8_t first_byte;
- if (!tu_edpt_stream_peek(ep_rx, &first_byte)) break;
+ uint8_t word_bytes[4];
+ if (tu_fifo_peek_n(&ep_rx->ff, word_bytes, 4) < 4) break;
- uint8_t mt = (first_byte >> 4) & 0x0F;
+ // UMP words travel LSB-first; MT is the high nibble of byte 3, not byte 0.
+ uint8_t mt = (word_bytes[3] >> 4) & 0x0F;
uint8_t pkt_words = midi2_ump_word_count(mt);
if (total_read + pkt_words > max_words) break;
diff --git a/src/class/midi/midi2_device.h b/src/class/midi/midi2_device.h
index b7caf97a3..a1c51f047 100644
--- a/src/class/midi/midi2_device.h
+++ b/src/class/midi/midi2_device.h
@@ -49,11 +49,11 @@ extern "C" {
//--------------------------------------------------------------------+
#ifndef CFG_TUD_MIDI2_TX_BUFSIZE
- #define CFG_TUD_MIDI2_TX_BUFSIZE TUD_EPSIZE_BULK_MAX
+ #define CFG_TUD_MIDI2_TX_BUFSIZE 256
#endif
#ifndef CFG_TUD_MIDI2_RX_BUFSIZE
- #define CFG_TUD_MIDI2_RX_BUFSIZE TUD_EPSIZE_BULK_MAX
+ #define CFG_TUD_MIDI2_RX_BUFSIZE 256
#endif
#ifndef CFG_TUD_MIDI2_TX_EPSIZE