Skip to content

Commit 14b5080

Browse files
committed
shared/tinyusb: Add optional port-specific hook on USBD init.
This allows a port to do hardware initialization just before the TinyUSB stack is brought up. That means the hardware is only turned on when it's needed. Signed-off-by: Damien George <damien@micropython.org>
1 parent 9b73e34 commit 14b5080

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

shared/tinyusb/mp_usbd.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@
4545
#define MICROPY_WRAP_TUD_EVENT_HOOK_CB(name) name
4646
#endif
4747

48+
#ifndef MICROPY_HW_TINYUSB_LL_INIT
49+
#define MICROPY_HW_TINYUSB_LL_INIT()
50+
#endif
51+
4852
#if MICROPY_HW_ENABLE_USBDEV
4953

5054
#include "py/obj.h"
@@ -102,6 +106,7 @@ void mp_usbd_task_callback(mp_sched_node_t *node);
102106
static inline void mp_usbd_init(void) {
103107
// Without runtime USB support, this can be a thin wrapper wrapper around tusb_init()
104108
// which is called in the below helper function.
109+
MICROPY_HW_TINYUSB_LL_INIT();
105110
mp_usbd_init_tud();
106111
}
107112

shared/tinyusb/mp_usbd_runtime.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,8 @@ void mp_usbd_init(void) {
430430
}
431431

432432
if (need_usb) {
433+
// Call any port-specific initialization code.
434+
MICROPY_HW_TINYUSB_LL_INIT();
433435
// The following will call tusb_init(), which is safe to call redundantly.
434436
mp_usbd_init_tud();
435437
// Reconnect if mp_usbd_deinit() has disconnected.

0 commit comments

Comments
 (0)