USB descriptors: Save flash storage for serial number
This saves about 60 bytes (Feather M4 went from 45040 -> 45100 bytes free) 66 bytes of data eliminated, but 6 bytes paid back to initialize the length field.
This commit is contained in:
parent
2830984aef
commit
144acfcb98
|
@ -62,6 +62,7 @@ void load_serial_number(void) {
|
|||
uint8_t raw_id[COMMON_HAL_MCU_PROCESSOR_UID_LENGTH];
|
||||
common_hal_mcu_processor_get_uid(raw_id);
|
||||
|
||||
usb_serial_number[0] = 0x300 | MP_ARRAY_SIZE(usb_serial_number);
|
||||
for (int i = 0; i < COMMON_HAL_MCU_PROCESSOR_UID_LENGTH; i++) {
|
||||
for (int j = 0; j < 2; j++) {
|
||||
uint8_t nibble = (raw_id[i] >> (j * 4)) & 0xf;
|
||||
|
|
|
@ -778,18 +778,20 @@ for idx, descriptor in enumerate(string_descriptors):
|
|||
variable_name = StringIndex.index_to_variable[idx]
|
||||
if not variable_name:
|
||||
variable_name = "string_descriptor{}".format(idx)
|
||||
pointers_to_strings.append("{name}".format(name=variable_name))
|
||||
|
||||
const = "const "
|
||||
if variable_name == "usb_serial_number":
|
||||
const = ""
|
||||
length = len(b)
|
||||
c_file.write(" uint16_t {NAME}[{length}];\n".format(NAME=variable_name, length=length//2))
|
||||
else:
|
||||
c_file.write(
|
||||
"""\
|
||||
{const}uint16_t {NAME}[] = {{
|
||||
""".format(
|
||||
const uint16_t {NAME}[] = {{
|
||||
""".format(
|
||||
const=const, NAME=variable_name
|
||||
)
|
||||
)
|
||||
pointers_to_strings.append("{name}".format(name=variable_name))
|
||||
n = 0
|
||||
while i < len(b):
|
||||
length = b[i]
|
||||
|
@ -800,8 +802,8 @@ for idx, descriptor in enumerate(string_descriptors):
|
|||
i += length
|
||||
c_file.write(
|
||||
"""\
|
||||
};
|
||||
"""
|
||||
};
|
||||
"""
|
||||
)
|
||||
|
||||
c_file.write(
|
||||
|
|
Loading…
Reference in New Issue