From 642affc7e336443f55dad7639a1087717efefee2 Mon Sep 17 00:00:00 2001 From: Andrew Leech <> Date: Wed, 1 Nov 2023 11:06:10 +1100 Subject: [PATCH] esp32/usb: Wake main thread when usb receives data. This improves latency on stdin. Signed-off-by: Andrew Leech --- ports/esp32/usb.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ports/esp32/usb.c b/ports/esp32/usb.c index 2e417755c9abf..15359d59f31f2 100644 --- a/ports/esp32/usb.c +++ b/ports/esp32/usb.c @@ -41,7 +41,8 @@ static uint8_t usb_rx_buf[CONFIG_TINYUSB_CDC_RX_BUFSIZE]; static void usb_callback_rx(int itf, cdcacm_event_t *event) { - // TODO: what happens if more chars come in during this function, are they lost? + // IDF places tinyusb rx data onto freertos ringbuffer which this function + // forwards onto the stdin_ringbuf for (;;) { size_t len = 0; esp_err_t ret = tinyusb_cdcacm_read(itf, usb_rx_buf, sizeof(usb_rx_buf), &len); @@ -58,6 +59,7 @@ static void usb_callback_rx(int itf, cdcacm_event_t *event) { ringbuf_put(&stdin_ringbuf, usb_rx_buf[i]); } } + xTaskNotifyGive(mp_main_task_handle); } }