Skip to content

Commit 38b38e2

Browse files
committed
shared/tinyusb,extmod: Improve code organization and header declarations.
Consolidated extern declarations from scattered source locations into mp_usbd.h header. Made descriptor buffer and function declarations conditional on MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE to match their definitions. Removed dead code in descriptor.c. No functional changes - build sizes unchanged at 514,396 bytes (runtime) and 512,020 bytes (static). Signed-off-by: Andrew Leech <[email protected]> Signed-off-by: Andrew Leech <[email protected]>
1 parent f3f9b46 commit 38b38e2

File tree

4 files changed

+9
-28
lines changed

4 files changed

+9
-28
lines changed

extmod/machine_usb_device.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ static mp_obj_t usb_device_make_new(const mp_obj_type_t *type, size_t n_args, si
8484
o->base.type = &machine_usb_device_type;
8585

8686
// Initialize fields common to both minimal and full modes
87-
extern mp_usbd_class_state_t mp_usbd_class_state;
8887
#if MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE
8988
// Runtime mode: read current class state to reflect default CDC configuration
9089
o->builtin_driver = mp_usbd_class_state.flags;
@@ -213,12 +212,10 @@ static mp_obj_t usb_device_active(size_t n_args, const mp_obj_t *args) {
213212
// Update class state based on current builtin_driver
214213
if (mp_obj_is_type(usbd->builtin_driver, &mp_type_usb_builtin)) {
215214
mp_obj_usb_builtin_t *builtin = MP_OBJ_TO_PTR(usbd->builtin_driver);
216-
extern mp_usbd_class_state_t mp_usbd_class_state;
217215
mp_usbd_class_state.flags = builtin->flags;
218216
}
219217
} else {
220218
// Disable all classes when deactivating
221-
extern mp_usbd_class_state_t mp_usbd_class_state;
222219
mp_usbd_class_state.flags = USB_BUILTIN_FLAG_NONE;
223220
}
224221
#endif
@@ -413,13 +410,10 @@ static uint8_t mp_usbd_get_str_max(uint8_t flags) {
413410
}
414411

415412
static const uint8_t *mp_usbd_get_builtin_desc_cfg(uint8_t flags) {
416-
extern uint8_t mp_usbd_desc_cfg_buffer[];
417-
extern const uint8_t *mp_usbd_generate_desc_cfg_unified(uint8_t flags, uint8_t *buffer);
418413
return mp_usbd_generate_desc_cfg_unified(flags, mp_usbd_desc_cfg_buffer);
419414
}
420415

421416
static size_t mp_usbd_get_desc_cfg_len(uint8_t flags) {
422-
extern size_t mp_usbd_get_descriptor_cfg_len_from_flags(uint8_t flags);
423417
return mp_usbd_get_descriptor_cfg_len_from_flags(flags);
424418
}
425419
#endif // MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE

shared/tinyusb/mp_usbd.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,16 @@ size_t mp_usbd_get_descriptor_cfg_len(void);
203203

204204
// Built-in USB device and configuration descriptor values
205205
extern const tusb_desc_device_t mp_usbd_builtin_desc_dev;
206+
207+
#if !MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE
208+
// Static mode: Use static descriptor array
206209
extern const uint8_t mp_usbd_builtin_desc_cfg[MP_USBD_BUILTIN_DESC_CFG_LEN];
210+
#else
211+
// Runtime mode: Use buffer and generation functions
212+
extern uint8_t mp_usbd_desc_cfg_buffer[MP_USBD_BUILTIN_DESC_CFG_LEN];
213+
const uint8_t *mp_usbd_get_default_desc(void);
214+
const uint8_t *mp_usbd_generate_desc_cfg_unified(uint8_t flags, uint8_t *buffer);
215+
#endif
207216

208217
void mp_usbd_task_callback(mp_sched_node_t *node);
209218

shared/tinyusb/mp_usbd_descriptor.c

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -182,23 +182,6 @@ size_t mp_usbd_get_descriptor_cfg_len(void) {
182182
}
183183

184184

185-
#if 0
186-
// Static descriptor for maximum possible configuration
187-
static const uint8_t mp_usbd_builtin_desc_cfg_max[MP_USBD_BUILTIN_DESC_CFG_LEN] = {
188-
TUD_CONFIG_DESCRIPTOR(1, USBD_ITF_BUILTIN_MAX, USBD_STR_0, MP_USBD_BUILTIN_DESC_CFG_LEN,
189-
0, USBD_MAX_POWER_MA),
190-
191-
#if CFG_TUD_CDC
192-
TUD_CDC_DESCRIPTOR(USBD_ITF_CDC, USBD_STR_CDC, USBD_CDC_EP_CMD,
193-
USBD_CDC_CMD_MAX_SIZE, USBD_CDC_EP_OUT, USBD_CDC_EP_IN, USBD_CDC_IN_OUT_MAX_SIZE),
194-
#endif
195-
#if CFG_TUD_MSC
196-
TUD_MSC_DESCRIPTOR(USBD_ITF_MSC, USBD_STR_MSC, USBD_MSC_EP_OUT, USBD_MSC_EP_IN, USBD_MSC_IN_OUT_MAX_SIZE),
197-
#endif
198-
};
199-
#endif
200-
201-
202185
// Dynamic descriptor buffer for runtime configuration
203186
static uint8_t mp_usbd_dynamic_desc_cfg[MP_USBD_BUILTIN_DESC_CFG_LEN];
204187

shared/tinyusb/mp_usbd_runtime.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,21 +123,16 @@ const uint8_t *tud_descriptor_configuration_cb(uint8_t index) {
123123

124124
// If no runtime descriptor but builtin_driver is set, generate from flags
125125
if (!result && usbd->builtin_driver != USB_BUILTIN_FLAG_NONE) {
126-
extern uint8_t mp_usbd_desc_cfg_buffer[];
127-
extern const uint8_t *mp_usbd_generate_desc_cfg_unified(uint8_t flags, uint8_t *buffer);
128-
extern mp_usbd_class_state_t mp_usbd_class_state;
129126
mp_usbd_class_state.flags = usbd->builtin_driver;
130127
result = mp_usbd_generate_desc_cfg_unified(usbd->builtin_driver, mp_usbd_desc_cfg_buffer);
131128
}
132129
}
133130
// Fallback to descriptor (needed for boot before Python initializes)
134131
#if MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE
135132
// Runtime mode: Generate default descriptor from templates
136-
extern const uint8_t *mp_usbd_get_default_desc(void);
137133
return result ? result : mp_usbd_get_default_desc();
138134
#else
139135
// Static mode: Use static descriptor
140-
extern const uint8_t mp_usbd_builtin_desc_cfg[];
141136
return result ? result : mp_usbd_builtin_desc_cfg;
142137
#endif
143138
}

0 commit comments

Comments
 (0)