squeeze the usb identification code
This commit is contained in:
parent
c567b43441
commit
daf415d9c7
@ -122,7 +122,9 @@ void usb_set_defaults(void) {
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if CIRCUITPY_USB_IDENTIFICATION
|
||||||
supervisor_allocation *usb_identification_allocation;
|
supervisor_allocation *usb_identification_allocation;
|
||||||
|
#endif
|
||||||
|
|
||||||
// Some dynamic USB data must be saved after boot.py. How much is needed?
|
// Some dynamic USB data must be saved after boot.py. How much is needed?
|
||||||
size_t usb_boot_py_data_size(void) {
|
size_t usb_boot_py_data_size(void) {
|
||||||
@ -137,16 +139,21 @@ size_t usb_boot_py_data_size(void) {
|
|||||||
|
|
||||||
// Fill in the data to save.
|
// Fill in the data to save.
|
||||||
void usb_get_boot_py_data(uint8_t *temp_storage, size_t temp_storage_size) {
|
void usb_get_boot_py_data(uint8_t *temp_storage, size_t temp_storage_size) {
|
||||||
|
#if CIRCUITPY_USB_IDENTIFICATION
|
||||||
if (usb_identification_allocation) {
|
if (usb_identification_allocation) {
|
||||||
memcpy(temp_storage, usb_identification_allocation->ptr, sizeof(usb_identification_t));
|
memcpy(temp_storage, usb_identification_allocation->ptr, sizeof(usb_identification_t));
|
||||||
free_memory(usb_identification_allocation);
|
free_memory(usb_identification_allocation);
|
||||||
|
#else
|
||||||
|
if (false) {
|
||||||
|
// Nothing
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
usb_identification_t defaults = {
|
usb_identification_t defaults;
|
||||||
.vid = USB_VID,
|
// This compiles to less code than using a struct initializer.
|
||||||
.pid = USB_PID,
|
defaults.vid = USB_VID;
|
||||||
.manufacturer_name = USB_MANUFACTURER,
|
defaults.pid = USB_PID;
|
||||||
.product_name = USB_PRODUCT,
|
strcpy(defaults.manufacturer_name, USB_MANUFACTURER);
|
||||||
};
|
strcpy(defaults.product_name, USB_PRODUCT);
|
||||||
memcpy(temp_storage, &defaults, sizeof(defaults));
|
memcpy(temp_storage, &defaults, sizeof(defaults));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user