From 9f7143af29814156482c5e80bab925687e37b16d Mon Sep 17 00:00:00 2001 From: Alexander Golovanov Date: Sat, 6 Feb 2021 00:01:46 +0300 Subject: [PATCH] CDC-like blocking behaviour for MIDI Also added a dummy readout for MIDI into examples --- examples/device/dynamic_configuration/src/main.c | 6 ++++++ examples/device/midi_test/src/main.c | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/examples/device/dynamic_configuration/src/main.c b/examples/device/dynamic_configuration/src/main.c index 3ad13aefa..45786e99a 100644 --- a/examples/device/dynamic_configuration/src/main.c +++ b/examples/device/dynamic_configuration/src/main.c @@ -165,6 +165,12 @@ void midi_task(void) { static uint32_t start_ms = 0; + // The MIDI interface always creates input and output port/jack descriptors + // regardless of these being used or not. Therefore incoming traffic should be read + // (possibly just discarded) to avoid the sender blocking in IO + uint8_t packet[4]; + while(tud_midi_available()) tud_midi_receive(packet); + // send note every 1000 ms if (board_millis() - start_ms < 286) return; // not enough time start_ms += 286; diff --git a/examples/device/midi_test/src/main.c b/examples/device/midi_test/src/main.c index 96292dd6b..d92621fc9 100644 --- a/examples/device/midi_test/src/main.c +++ b/examples/device/midi_test/src/main.c @@ -125,6 +125,12 @@ void midi_task(void) { static uint32_t start_ms = 0; + // The MIDI interface always creates input and output port/jack descriptors + // regardless of these being used or not. Therefore incoming traffic should be read + // (possibly just discarded) to avoid the sender blocking in IO + uint8_t packet[4]; + while(tud_midi_available()) tud_midi_receive(packet); + // send note every 1000 ms if (board_millis() - start_ms < 286) return; // not enough time start_ms += 286;