fix rp2040 with new shared irq usb handler

This commit is contained in:
hathach 2023-03-13 21:49:01 +07:00
parent daa927a114
commit b432cf6201
No known key found for this signature in database
GPG Key ID: F5D50C6D51D17CBA
2 changed files with 10 additions and 13 deletions

View File

@ -39,15 +39,8 @@ STATIC void _usb_irq_wrapper(void) {
} }
void post_usb_init(void) { void post_usb_init(void) {
irq_set_enabled(USBCTRL_IRQ, false); irq_add_shared_handler(USBCTRL_IRQ, _usb_irq_wrapper,
PICO_SHARED_IRQ_HANDLER_LOWEST_ORDER_PRIORITY);
irq_handler_t usb_handler = irq_get_exclusive_handler(USBCTRL_IRQ);
if (usb_handler) {
irq_remove_handler(USBCTRL_IRQ, usb_handler);
}
irq_set_exclusive_handler(USBCTRL_IRQ, _usb_irq_wrapper);
irq_set_enabled(USBCTRL_IRQ, true);
// There is a small window where the USB interrupt may be handled by the // There is a small window where the USB interrupt may be handled by the
// pico-sdk instead of CircuitPython. If that is the case, then we'll have // pico-sdk instead of CircuitPython. If that is the case, then we'll have

View File

@ -225,13 +225,17 @@ void usb_background_schedule(void) {
} }
void usb_irq_handler(int instance) { void usb_irq_handler(int instance) {
#if CFG_TUSB_MCU != OPT_MCU_RP2040
// For rp2040, IRQ handler is already installed and invoked automatically
if (instance == CIRCUITPY_USB_DEVICE_INSTANCE) { if (instance == CIRCUITPY_USB_DEVICE_INSTANCE) {
tud_int_handler(instance); tud_int_handler(instance);
} else if (instance == CIRCUITPY_USB_HOST_INSTANCE) {
#if CIRCUITPY_USB_HOST
tuh_int_handler(instance);
#endif
} }
#if CIRCUITPY_USB_HOST
else if (instance == CIRCUITPY_USB_HOST_INSTANCE) {
tuh_int_handler(instance);
}
#endif
#endif
usb_background_schedule(); usb_background_schedule();
} }