Skip to content

Commit

Permalink
esp32/usb: Wake main thread when usb receives data.
Browse files Browse the repository at this point in the history
This improves latency on stdin.

Signed-off-by: Andrew Leech <[email protected]>
  • Loading branch information
Andrew Leech committed Nov 1, 2023
1 parent 76bab8a commit 84a5d9a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ports/esp32/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@

static uint8_t usb_rx_buf[CONFIG_TINYUSB_CDC_RX_BUFSIZE];

// This is called from FreeRTOS task "tusb_tsk" in espressif__esp_tinyusb (not ISR).
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?
// espressif__esp_tinyusb places tinyusb rx data onto freertos ringbuffer which
// this function forwards onto the micropython stdin_ringbuf.
for (;;) {
size_t len = 0;
esp_err_t ret = tinyusb_cdcacm_read(itf, usb_rx_buf, sizeof(usb_rx_buf), &len);
Expand All @@ -58,6 +60,7 @@ static void usb_callback_rx(int itf, cdcacm_event_t *event) {
ringbuf_put(&stdin_ringbuf, usb_rx_buf[i]);
}
}
mp_hal_wake_main_task();
}
}

Expand Down

0 comments on commit 84a5d9a

Please sign in to comment.