Merge pull request #4243 from jepler/usb-serial-number-savings
USB descriptors: Save flash storage for serial number
This commit is contained in:
commit
b19e7c9148
@ -62,6 +62,7 @@ void load_serial_number(void) {
|
|||||||
uint8_t raw_id[COMMON_HAL_MCU_PROCESSOR_UID_LENGTH];
|
uint8_t raw_id[COMMON_HAL_MCU_PROCESSOR_UID_LENGTH];
|
||||||
common_hal_mcu_processor_get_uid(raw_id);
|
common_hal_mcu_processor_get_uid(raw_id);
|
||||||
|
|
||||||
|
usb_serial_number[0] = 0x300 | sizeof(usb_serial_number);
|
||||||
for (int i = 0; i < COMMON_HAL_MCU_PROCESSOR_UID_LENGTH; i++) {
|
for (int i = 0; i < COMMON_HAL_MCU_PROCESSOR_UID_LENGTH; i++) {
|
||||||
for (int j = 0; j < 2; j++) {
|
for (int j = 0; j < 2; j++) {
|
||||||
uint8_t nibble = (raw_id[i] >> (j * 4)) & 0xf;
|
uint8_t nibble = (raw_id[i] >> (j * 4)) & 0xf;
|
||||||
|
@ -778,30 +778,32 @@ for idx, descriptor in enumerate(string_descriptors):
|
|||||||
variable_name = StringIndex.index_to_variable[idx]
|
variable_name = StringIndex.index_to_variable[idx]
|
||||||
if not variable_name:
|
if not variable_name:
|
||||||
variable_name = "string_descriptor{}".format(idx)
|
variable_name = "string_descriptor{}".format(idx)
|
||||||
|
pointers_to_strings.append("{name}".format(name=variable_name))
|
||||||
|
|
||||||
const = "const "
|
const = "const "
|
||||||
if variable_name == "usb_serial_number":
|
if variable_name == "usb_serial_number":
|
||||||
const = ""
|
length = len(b)
|
||||||
c_file.write(
|
c_file.write(" uint16_t {NAME}[{length}];\n".format(NAME=variable_name, length=length//2))
|
||||||
"""\
|
else:
|
||||||
{const}uint16_t {NAME}[] = {{
|
c_file.write(
|
||||||
""".format(
|
"""\
|
||||||
const=const, NAME=variable_name
|
const uint16_t {NAME}[] = {{
|
||||||
|
""".format(
|
||||||
|
const=const, NAME=variable_name
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
n = 0
|
||||||
pointers_to_strings.append("{name}".format(name=variable_name))
|
while i < len(b):
|
||||||
n = 0
|
length = b[i]
|
||||||
while i < len(b):
|
for j in range(length // 2):
|
||||||
length = b[i]
|
c_file.write("0x{:04x}, ".format(b[i + 2 * j + 1] << 8 | b[i + 2 * j]))
|
||||||
for j in range(length // 2):
|
n += 1
|
||||||
c_file.write("0x{:04x}, ".format(b[i + 2 * j + 1] << 8 | b[i + 2 * j]))
|
c_file.write("\n")
|
||||||
n += 1
|
i += length
|
||||||
c_file.write("\n")
|
c_file.write(
|
||||||
i += length
|
"""\
|
||||||
c_file.write(
|
};
|
||||||
"""\
|
"""
|
||||||
};
|
|
||||||
"""
|
|
||||||
)
|
)
|
||||||
|
|
||||||
c_file.write(
|
c_file.write(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user