Skip to content

Commit b73b30f

Browse files
committed
Switch to upstream TinyUSB
1 parent af8cc93 commit b73b30f

File tree

6 files changed

+27
-7
lines changed

6 files changed

+27
-7
lines changed

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
url = https://github.com/adafruit/nrfx.git
7676
[submodule "lib/tinyusb"]
7777
path = lib/tinyusb
78-
url = https://github.com/tannewt/tinyusb.git
78+
url = https://github.com/hathach/tinyusb.git
7979
branch = master
8080
fetchRecurseSubmodules = false
8181
[submodule "tools/huffman"]

lib/tinyusb

Submodule tinyusb updated 87 files

ports/raspberrypi/supervisor/usb.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,27 @@
2727
#include "lib/tinyusb/src/device/usbd.h"
2828
#include "supervisor/background_callback.h"
2929
#include "supervisor/usb.h"
30+
#include "src/rp2_common/hardware_irq/include/hardware/irq.h"
3031
#include "src/rp2_common/pico_platform/include/pico/platform.h"
3132
#include "src/rp2040/hardware_regs/include/hardware/regs/intctrl.h"
3233

34+
static background_callback_t usb_callback;
35+
static void usb_background_do(void* unused) {
36+
usb_background();
37+
}
38+
39+
static void queue_background(void) {
40+
background_callback_add(&usb_callback, usb_background_do, NULL);
41+
}
42+
3343
void init_usb_hardware(void) {
3444
}
3545

36-
void __isr __used isr_usbctrl(void) {
37-
usb_irq_handler();
46+
void post_usb_init(void) {
47+
irq_handler_t usb_handler = irq_get_exclusive_handler(USBCTRL_IRQ);
48+
if (usb_handler) {
49+
irq_remove_handler(USBCTRL_IRQ, usb_handler);
50+
irq_add_shared_handler(USBCTRL_IRQ, usb_handler, PICO_DEFAULT_IRQ_PRIORITY);
51+
}
52+
irq_add_shared_handler(USBCTRL_IRQ, queue_background, PICO_LOWEST_IRQ_PRIORITY);
3853
}

supervisor/shared/usb/usb.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,16 @@ bool usb_enabled(void) {
5959
return tusb_inited();
6060
}
6161

62+
MP_WEAK void post_usb_init(void) {}
63+
6264
void usb_init(void) {
6365
init_usb_hardware();
6466
load_serial_number();
6567

6668
tusb_init();
6769

70+
post_usb_init();
71+
6872
#if MICROPY_KBD_EXCEPTION
6973
// Set Ctrl+C as wanted char, tud_cdc_rx_wanted_cb() usb_callback will be invoked when Ctrl+C is received
7074
// This usb_callback always got invoked regardless of mp_interrupt_char value since we only set it once here

supervisor/shared/workflow.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ void supervisor_workflow_reset(void) {
3636
// Not that some chips don't notice when USB is unplugged after first being plugged in,
3737
// so this is not perfect, but tud_suspended() check helps.
3838
bool supervisor_workflow_connecting(void) {
39-
return true;
40-
// TODO: Use the below once we've updated TinyUSB for the RP2040.
41-
// return tud_connected() && !tud_suspended();
39+
return tud_connected() && !tud_suspended();
4240
}
4341

4442
// Return true if host has completed connection to us (such as USB enumeration).

supervisor/usb.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ void usb_irq_handler(void);
4242
// TinyUSB.
4343
void init_usb_hardware(void);
4444

45+
// Temporary hook for code after init. Only used for RP2040.
46+
void post_usb_init(void);
47+
4548
// Shared implementation.
4649
bool usb_enabled(void);
4750
void usb_init(void);

0 commit comments

Comments
 (0)