misc: Fix TinyUSB polling.

This commit is contained in:
iabdalkader 2023-12-23 15:38:39 +01:00
parent 9dd6e47e06
commit ba754186f7

View File

@ -82,11 +82,15 @@ void tinyusb_debug_tx_strn(const char *str, mp_uint_t len) {
}
static void tinyusb_debug_task(void) {
tud_task();
tud_task_ext(0, false);
if (!tinyusb_debug_enabled() || !tud_cdc_connected() || tud_cdc_available() < 6) {
return;
}
uint8_t dbg_buf[DEBUG_MAX_PACKET];
if (tud_cdc_connected() && tud_cdc_available() >= 6) {
uint32_t count = tud_cdc_read(dbg_buf, 6);
if (count < 6 || dbg_buf[0] != 0x30) {
// Maybe we should try to recover from this state
// but for now, call __fatal_error which doesn't
@ -94,6 +98,7 @@ static void tinyusb_debug_task(void) {
__fatal_error();
return;
}
usbdbg_cmd_t *cmd = (usbdbg_cmd_t *) dbg_buf;
uint8_t request = cmd->request;
uint32_t xfer_length = cmd->xfer_length;
@ -102,7 +107,7 @@ static void tinyusb_debug_task(void) {
while (xfer_length) {
// && tud_cdc_connected())
if (tud_task_event_ready()) {
tud_task();
tud_task_ext(0, false);
}
if (request & 0x80) {
// Device-to-host data phase
@ -122,14 +127,13 @@ static void tinyusb_debug_task(void) {
}
}
}
}
// For the mimxrt, and nrf ports this replaces the weak USB IRQ handlers.
// For the RP2 port, this handler is installed in main.c
void OMV_USB1_IRQ_HANDLER(void) {
dcd_int_handler(0);
// If there are any event to process, schedule a call to cdc loop.
if (tinyusb_debug_enabled()) {
if (tud_task_event_ready()) {
pendsv_schedule_dispatch(PENDSV_DISPATCH_CDC, tinyusb_debug_task);
}
}
@ -138,7 +142,7 @@ void OMV_USB1_IRQ_HANDLER(void) {
void OMV_USB2_IRQ_HANDLER(void) {
dcd_int_handler(1);
// If there are any event to process, schedule a call to cdc loop.
if (tinyusb_debug_enabled()) {
if (tud_task_event_ready()) {
pendsv_schedule_dispatch(PENDSV_DISPATCH_CDC, tinyusb_debug_task);
}
}