Skip to content

Commit daf415d

Browse files
committed
squeeze the usb identification code
1 parent c567b43 commit daf415d

File tree

1 file changed

+13
-6
lines changed
  • supervisor/shared/usb

1 file changed

+13
-6
lines changed

supervisor/shared/usb/usb.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ void usb_set_defaults(void) {
122122
#endif
123123
};
124124

125+
#if CIRCUITPY_USB_IDENTIFICATION
125126
supervisor_allocation *usb_identification_allocation;
127+
#endif
126128

127129
// Some dynamic USB data must be saved after boot.py. How much is needed?
128130
size_t usb_boot_py_data_size(void) {
@@ -137,16 +139,21 @@ size_t usb_boot_py_data_size(void) {
137139

138140
// Fill in the data to save.
139141
void usb_get_boot_py_data(uint8_t *temp_storage, size_t temp_storage_size) {
142+
#if CIRCUITPY_USB_IDENTIFICATION
140143
if (usb_identification_allocation) {
141144
memcpy(temp_storage, usb_identification_allocation->ptr, sizeof(usb_identification_t));
142145
free_memory(usb_identification_allocation);
146+
#else
147+
if (false) {
148+
// Nothing
149+
#endif
143150
} else {
144-
usb_identification_t defaults = {
145-
.vid = USB_VID,
146-
.pid = USB_PID,
147-
.manufacturer_name = USB_MANUFACTURER,
148-
.product_name = USB_PRODUCT,
149-
};
151+
usb_identification_t defaults;
152+
// This compiles to less code than using a struct initializer.
153+
defaults.vid = USB_VID;
154+
defaults.pid = USB_PID;
155+
strcpy(defaults.manufacturer_name, USB_MANUFACTURER);
156+
strcpy(defaults.product_name, USB_PRODUCT);
150157
memcpy(temp_storage, &defaults, sizeof(defaults));
151158
}
152159

0 commit comments

Comments
 (0)