diff options
| author | Angus Gratton <angus@redyak.com.au> | 2025-11-19 10:15:08 +1100 |
|---|---|---|
| committer | Angus Gratton <angus@redyak.com.au> | 2025-11-19 10:16:48 +1100 |
| commit | 8d05a8fc8a78dc6592e87ed5e87616bc01dce37c (patch) | |
| tree | e9aa0e6be0fa2c2368524c32371ff72f4fd0f3ee | |
| parent | 4441fd655c514dd92363ad00aa2e832c9f103b2f (diff) | |
shared/tinyusb/mp_usbd: Reorder the mp_usbd_init/deinit functions.
Not a functional change, but makes it easier to see that mp_usbd_init() is
available regardless of whether MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE is
set.
Also adds a no-op inline mp_usbd_deinit() implementation, which means both
a port's calls to mp_usbd_init()/deinit() can both be guarded on the same
MICROPY_HW_ENABLE_USBDEV.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
| -rw-r--r-- | shared/tinyusb/mp_usbd.h | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/shared/tinyusb/mp_usbd.h b/shared/tinyusb/mp_usbd.h index 176b1ba50..b46555536 100644 --- a/shared/tinyusb/mp_usbd.h +++ b/shared/tinyusb/mp_usbd.h @@ -88,9 +88,22 @@ extern const uint8_t mp_usbd_builtin_desc_cfg[MP_USBD_BUILTIN_DESC_CFG_LEN]; void mp_usbd_task_callback(mp_sched_node_t *node); -#if MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE -void mp_usbd_deinit(void); +#if !MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE + +static inline void mp_usbd_init(void) { + // Without runtime USB support, this can be a thin wrapper wrapper around tusb_init() + // which is called in the below helper function. + mp_usbd_init_tud(); +} + +static inline void mp_usbd_deinit(void) { + // Called in soft reset path. No-op if no runtime USB devices require cleanup. +} + +#else +// Runtime USB Device support requires more complex init/deinit void mp_usbd_init(void); +void mp_usbd_deinit(void); const char *mp_usbd_runtime_string_cb(uint8_t index); @@ -142,15 +155,7 @@ static inline bool mp_usb_device_builtin_enabled(const mp_obj_usb_device_t *usbd return usbd->builtin_driver != MP_OBJ_FROM_PTR(&mp_type_usb_device_builtin_none); } -#else // Static USBD drivers only - -static inline void mp_usbd_init(void) { - // Without runtime USB support, this can be a thin wrapper wrapper around tusb_init() - // which is called in the below helper function. - mp_usbd_init_tud(); -} - -#endif +#endif // MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE #endif // MICROPY_HW_ENABLE_USBDEV |
