Skip to content

Commit 06a7bf9

Browse files
pi-anldpgeorge
authored andcommitted
esp32/usb: Wake main thread when USB receives data.
This improves (decreases) the latency on stdin, on SoCs with built-in USB and using TinyUSB, like S2 and S3. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
1 parent d8a2634 commit 06a7bf9

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

ports/esp32/usb.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@
4040

4141
static uint8_t usb_rx_buf[CONFIG_TINYUSB_CDC_RX_BUFSIZE];
4242

43+
// This is called from FreeRTOS task "tusb_tsk" in espressif__esp_tinyusb (not an ISR).
4344
static void usb_callback_rx(int itf, cdcacm_event_t *event) {
44-
// TODO: what happens if more chars come in during this function, are they lost?
45+
// espressif__esp_tinyusb places tinyusb rx data onto freertos ringbuffer which
46+
// this function forwards onto our stdin_ringbuf.
4547
for (;;) {
4648
size_t len = 0;
4749
esp_err_t ret = tinyusb_cdcacm_read(itf, usb_rx_buf, sizeof(usb_rx_buf), &len);
@@ -58,6 +60,7 @@ static void usb_callback_rx(int itf, cdcacm_event_t *event) {
5860
ringbuf_put(&stdin_ringbuf, usb_rx_buf[i]);
5961
}
6062
}
63+
mp_hal_wake_main_task();
6164
}
6265
}
6366

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy