summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorJeff Epler <jepler@gmail.com>2021-02-21 21:24:49 -0600
committerJeff Epler <jepler@gmail.com>2021-02-21 21:24:49 -0600
commit144acfcb988479d6e5802bfa600a62be39d39be7 (patch)
tree2c6280c4777ae44aaac10ad29cc5ba1873be81eb /tools
parent2830984aef2208abe911e1a6143e084293e3fc9c (diff)
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.
Diffstat (limited to 'tools')
-rw-r--r--tools/gen_usb_descriptor.py42
1 files changed, 22 insertions, 20 deletions
diff --git a/tools/gen_usb_descriptor.py b/tools/gen_usb_descriptor.py
index 089d00ff2..b21cfd920 100644
--- a/tools/gen_usb_descriptor.py
+++ b/tools/gen_usb_descriptor.py
@@ -778,30 +778,32 @@ 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 = ""
- c_file.write(
- """\
-{const}uint16_t {NAME}[] = {{
-""".format(
- const=const, NAME=variable_name
+ 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=const, NAME=variable_name
+ )
)
- )
- pointers_to_strings.append("{name}".format(name=variable_name))
- n = 0
- while i < len(b):
- length = b[i]
- for j in range(length // 2):
- c_file.write("0x{:04x}, ".format(b[i + 2 * j + 1] << 8 | b[i + 2 * j]))
- n += 1
- c_file.write("\n")
- i += length
- c_file.write(
- """\
-};
-"""
+ n = 0
+ while i < len(b):
+ length = b[i]
+ for j in range(length // 2):
+ c_file.write("0x{:04x}, ".format(b[i + 2 * j + 1] << 8 | b[i + 2 * j]))
+ n += 1
+ c_file.write("\n")
+ i += length
+ c_file.write(
+ """\
+ };
+ """
)
c_file.write(