Skip to content

Commit 52cca37

Browse files
projectgusiabdalkader
authored andcommitted
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>
1 parent 8d25702 commit 52cca37

1 file changed

Lines changed: 16 additions & 11 deletions

File tree

shared/tinyusb/mp_usbd.h

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,22 @@ extern const uint8_t mp_usbd_builtin_desc_cfg[MP_USBD_BUILTIN_DESC_CFG_LEN];
9090

9191
void mp_usbd_task_callback(mp_sched_node_t *node);
9292

93-
#if MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE
94-
void mp_usbd_deinit(void);
93+
#if !MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE
94+
95+
static inline void mp_usbd_init(void) {
96+
// Without runtime USB support, this can be a thin wrapper wrapper around tusb_init()
97+
// which is called in the below helper function.
98+
mp_usbd_init_tud();
99+
}
100+
101+
static inline void mp_usbd_deinit(void) {
102+
// Called in soft reset path. No-op if no runtime USB devices require cleanup.
103+
}
104+
105+
#else
106+
// Runtime USB Device support requires more complex init/deinit
95107
void mp_usbd_init(void);
108+
void mp_usbd_deinit(void);
96109

97110
const char *mp_usbd_runtime_string_cb(uint8_t index);
98111

@@ -144,15 +157,7 @@ inline static bool mp_usb_device_builtin_enabled(const mp_obj_usb_device_t *usbd
144157
return usbd->builtin_driver != MP_OBJ_FROM_PTR(&mp_type_usb_device_builtin_none);
145158
}
146159

147-
#else // Static USBD drivers only
148-
149-
static inline void mp_usbd_init(void) {
150-
// Without runtime USB support, this can be a thin wrapper wrapper around tusb_init()
151-
// which is called in the below helper function.
152-
mp_usbd_init_tud();
153-
}
154-
155-
#endif
160+
#endif // MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE
156161

157162
#endif // MICROPY_HW_ENABLE_USBDEV
158163

0 commit comments

Comments
 (0)