kopia lustrzana https://github.com/micropython/micropython
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>pull/12845/head
rodzic
d8a263435f
commit
06a7bf967c
|
@ -40,8 +40,10 @@
|
||||||
|
|
||||||
static uint8_t usb_rx_buf[CONFIG_TINYUSB_CDC_RX_BUFSIZE];
|
static uint8_t usb_rx_buf[CONFIG_TINYUSB_CDC_RX_BUFSIZE];
|
||||||
|
|
||||||
|
// This is called from FreeRTOS task "tusb_tsk" in espressif__esp_tinyusb (not an ISR).
|
||||||
static void usb_callback_rx(int itf, cdcacm_event_t *event) {
|
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 our stdin_ringbuf.
|
||||||
for (;;) {
|
for (;;) {
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
esp_err_t ret = tinyusb_cdcacm_read(itf, usb_rx_buf, sizeof(usb_rx_buf), &len);
|
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) {
|
||||||
ringbuf_put(&stdin_ringbuf, usb_rx_buf[i]);
|
ringbuf_put(&stdin_ringbuf, usb_rx_buf[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
mp_hal_wake_main_task();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue