File tree Expand file tree Collapse file tree 9 files changed +31
-12
lines changed
Expand file tree Collapse file tree 9 files changed +31
-12
lines changed Original file line number Diff line number Diff line change @@ -85,7 +85,6 @@ void run_background_tasks(void) {
8585 network_module_background ();
8686 #endif
8787 filesystem_background ();
88- usb_background ();
8988 running_background_tasks = false;
9089 assert_heap_ok ();
9190
Original file line number Diff line number Diff line change 2929#include "hpl/gclk/hpl_gclk_base.h"
3030#include "hal_gpio.h"
3131#include "lib/tinyusb/src/device/usbd.h"
32+ #include "supervisor/background_callback.h"
33+ #include "supervisor/usb.h"
3234
3335void init_usb_hardware (void ) {
3436 #ifdef SAMD21
@@ -61,24 +63,24 @@ void init_usb_hardware(void) {
6163
6264#ifdef SAMD21
6365void USB_Handler (void ) {
64- tud_int_handler ( 0 );
66+ usb_irq_handler ( );
6567}
6668#endif
6769
6870#ifdef SAM_D5X_E5X
6971void USB_0_Handler (void ) {
70- tud_int_handler ( 0 );
72+ usb_irq_handler ( );
7173}
7274
7375void USB_1_Handler (void ) {
74- tud_int_handler ( 0 );
76+ usb_irq_handler ( );
7577}
7678
7779void USB_2_Handler (void ) {
78- tud_int_handler ( 0 );
80+ usb_irq_handler ( );
7981}
8082
8183void USB_3_Handler (void ) {
82- tud_int_handler ( 0 );
84+ usb_irq_handler ( );
8385}
8486#endif
Original file line number Diff line number Diff line change 3131#include "py/mphal.h"
3232#include "py/mpstate.h"
3333#include "py/gc.h"
34+ #include "supervisor/usb.h"
3435
3536#include "csr.h"
3637#include "generated/soc.h"
@@ -49,7 +50,7 @@ void isr(void) {
4950
5051#ifdef CFG_TUSB_MCU
5152 if (irqs & (1 << USB_INTERRUPT ))
52- tud_int_handler ( 0 );
53+ usb_irq_handler ( );
5354#endif
5455 if (irqs & (1 << TIMER0_INTERRUPT ))
5556 SysTick_Handler ();
Original file line number Diff line number Diff line change 2727
2828#include "fsl_clock.h"
2929#include "tusb.h"
30+ #include "supervisor/usb.h"
3031
3132void init_usb_hardware (void ) {
3233 CLOCK_EnableUsbhs0PhyPllClock (kCLOCK_Usbphy480M , 480000000U );
@@ -56,5 +57,5 @@ void init_usb_hardware(void) {
5657}
5758
5859void USB_OTG1_IRQHandler (void ) {
59- tud_int_handler ( 0 );
60+ usb_irq_handler ( );
6061}
Original file line number Diff line number Diff line change @@ -59,7 +59,6 @@ void run_background_tasks(void) {
5959 }
6060 running_background_tasks = true;
6161 filesystem_background ();
62- usb_background ();
6362#if CIRCUITPY_AUDIOPWMIO
6463 audiopwmout_background ();
6564#endif
Original file line number Diff line number Diff line change 3030#include "lib/utils/interrupt_char.h"
3131#include "lib/mp-readline/readline.h"
3232#include "lib/tinyusb/src/device/usbd.h"
33+ #include "supervisor/background_callback.h"
3334
3435#ifdef SOFTDEVICE_PRESENT
3536#include "nrf_sdm.h"
@@ -42,7 +43,9 @@ extern void tusb_hal_nrf_power_event(uint32_t event);
4243
4344void init_usb_hardware (void ) {
4445
45- // 2 is max priority (0, 1 are reserved for SD)
46+ // 2 is max priority (0, 1, and 4 are reserved for SD)
47+ // 5 is max priority that still allows calling SD functions such as
48+ // sd_softdevice_is_enabled
4649 NVIC_SetPriority (USBD_IRQn , 2 );
4750
4851 // USB power may already be ready at this time -> no event generated
@@ -89,5 +92,5 @@ void init_usb_hardware(void) {
8992}
9093
9194void USBD_IRQHandler (void ) {
92- tud_int_handler ( 0 );
95+ usb_irq_handler ( );
9396}
Original file line number Diff line number Diff line change @@ -130,5 +130,5 @@ void init_usb_hardware(void) {
130130}
131131
132132void OTG_FS_IRQHandler (void ) {
133- tud_int_handler ( 0 );
133+ usb_irq_handler ( );
134134}
Original file line number Diff line number Diff line change 2727#include "py/objstr.h"
2828#include "shared-bindings/microcontroller/Processor.h"
2929#include "shared-module/usb_midi/__init__.h"
30+ #include "supervisor/background_callback.h"
3031#include "supervisor/port.h"
3132#include "supervisor/usb.h"
3233#include "lib/utils/interrupt_char.h"
@@ -82,6 +83,16 @@ void usb_background(void) {
8283 }
8384}
8485
86+ static background_callback_t callback ;
87+ static void usb_background_do (void * unused ) {
88+ usb_background ();
89+ }
90+
91+ void usb_irq_handler (void ) {
92+ tud_int_handler (0 );
93+ background_callback_add (& callback , usb_background_do , NULL );
94+ }
95+
8596//--------------------------------------------------------------------+
8697// tinyusb callbacks
8798//--------------------------------------------------------------------+
Original file line number Diff line number Diff line change 3333// alive and responsive.
3434void usb_background (void );
3535
36+ // Ports must call this from their particular USB IRQ handler
37+ void usb_irq_handler (void );
38+
3639// Only inits the USB peripheral clocks and pins. The peripheral will be initialized by
3740// TinyUSB.
3841void init_usb_hardware (void );
You can’t perform that action at this time.
0 commit comments