Skip to content

Commit 9a065b7

Browse files
dpgeorgeiabdalkader
authored andcommitted
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 <[email protected]>
1 parent f186a58 commit 9a065b7

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"
@@ -95,6 +99,7 @@ void mp_usbd_task_callback(mp_sched_node_t *node);
9599
static inline void mp_usbd_init(void) {
96100
// Without runtime USB support, this can be a thin wrapper wrapper around tusb_init()
97101
// which is called in the below helper function.
102+
MICROPY_HW_TINYUSB_LL_INIT();
98103
mp_usbd_init_tud();
99104
}
100105

shared/tinyusb/mp_usbd_runtime.c

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

430430
if (need_usb) {
431+
// Call any port-specific initialization code.
432+
MICROPY_HW_TINYUSB_LL_INIT();
431433
// The following will call tusb_init(), which is safe to call redundantly.
432434
mp_usbd_init_tud();
433435
// Reconnect if mp_usbd_deinit() has disconnected.

0 commit comments

Comments
 (0)