mirror of
https://github.com/micropython/micropython.git
synced 2025-12-16 09:50:15 +01:00
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>
This commit is contained in:
@@ -45,6 +45,10 @@
|
|||||||
#define MICROPY_WRAP_TUD_EVENT_HOOK_CB(name) name
|
#define MICROPY_WRAP_TUD_EVENT_HOOK_CB(name) name
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef MICROPY_HW_TINYUSB_LL_INIT
|
||||||
|
#define MICROPY_HW_TINYUSB_LL_INIT()
|
||||||
|
#endif
|
||||||
|
|
||||||
#if MICROPY_HW_ENABLE_USBDEV
|
#if MICROPY_HW_ENABLE_USBDEV
|
||||||
|
|
||||||
#include "py/obj.h"
|
#include "py/obj.h"
|
||||||
@@ -102,6 +106,7 @@ void mp_usbd_task_callback(mp_sched_node_t *node);
|
|||||||
static inline void mp_usbd_init(void) {
|
static inline void mp_usbd_init(void) {
|
||||||
// Without runtime USB support, this can be a thin wrapper wrapper around tusb_init()
|
// Without runtime USB support, this can be a thin wrapper wrapper around tusb_init()
|
||||||
// which is called in the below helper function.
|
// which is called in the below helper function.
|
||||||
|
MICROPY_HW_TINYUSB_LL_INIT();
|
||||||
mp_usbd_init_tud();
|
mp_usbd_init_tud();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -430,6 +430,8 @@ void mp_usbd_init(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (need_usb) {
|
if (need_usb) {
|
||||||
|
// Call any port-specific initialization code.
|
||||||
|
MICROPY_HW_TINYUSB_LL_INIT();
|
||||||
// The following will call tusb_init(), which is safe to call redundantly.
|
// The following will call tusb_init(), which is safe to call redundantly.
|
||||||
mp_usbd_init_tud();
|
mp_usbd_init_tud();
|
||||||
// Reconnect if mp_usbd_deinit() has disconnected.
|
// Reconnect if mp_usbd_deinit() has disconnected.
|
||||||
|
|||||||
Reference in New Issue
Block a user