diff options
| author | Dario Nieuwenhuis <[email protected]> | 2023-02-07 20:49:10 +0100 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2023-02-08 00:16:04 +0100 |
| commit | 1d841cc8ac74feacc4d231958ce2c46419ae3bda (patch) | |
| tree | 44dbe827369eceb661c287d2c47ea17f00878c11 /embassy-usb/gen_config.py | |
| parent | 4a224efe75c7986f5b3d8c5d6083fa17cb774f12 (diff) | |
usb: make max interface count configurable at compile time.
Diffstat (limited to 'embassy-usb/gen_config.py')
| -rw-r--r-- | embassy-usb/gen_config.py | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/embassy-usb/gen_config.py b/embassy-usb/gen_config.py new file mode 100644 index 000000000..55a7fa3c0 --- /dev/null +++ b/embassy-usb/gen_config.py | |||
| @@ -0,0 +1,73 @@ | |||
| 1 | import os | ||
| 2 | |||
| 3 | abspath = os.path.abspath(__file__) | ||
| 4 | dname = os.path.dirname(abspath) | ||
| 5 | os.chdir(dname) | ||
| 6 | |||
| 7 | features = [] | ||
| 8 | |||
| 9 | |||
| 10 | def feature(name, default, min, max, pow2=None): | ||
| 11 | vals = set() | ||
| 12 | val = min | ||
| 13 | while val <= max: | ||
| 14 | vals.add(val) | ||
| 15 | if pow2 == True or (isinstance(pow2, int) and val >= pow2): | ||
| 16 | val *= 2 | ||
| 17 | else: | ||
| 18 | val += 1 | ||
| 19 | vals.add(default) | ||
| 20 | |||
| 21 | features.append( | ||
| 22 | { | ||
| 23 | "name": name, | ||
| 24 | "default": default, | ||
| 25 | "vals": sorted(list(vals)), | ||
| 26 | } | ||
| 27 | ) | ||
| 28 | |||
| 29 | |||
| 30 | feature("max_interface_count", default=4, min=1, max=8) | ||
| 31 | |||
| 32 | # ========= Update Cargo.toml | ||
| 33 | |||
| 34 | things = "" | ||
| 35 | for f in features: | ||
| 36 | name = f["name"].replace("_", "-") | ||
| 37 | for val in f["vals"]: | ||
| 38 | things += f"{name}-{val} = []" | ||
| 39 | if val == f["default"]: | ||
| 40 | things += " # Default" | ||
| 41 | things += "\n" | ||
| 42 | things += "\n" | ||
| 43 | |||
| 44 | SEPARATOR_START = "# BEGIN AUTOGENERATED CONFIG FEATURES\n" | ||
| 45 | SEPARATOR_END = "# END AUTOGENERATED CONFIG FEATURES\n" | ||
| 46 | HELP = "# Generated by gen_config.py. DO NOT EDIT.\n" | ||
| 47 | with open("Cargo.toml", "r") as f: | ||
| 48 | data = f.read() | ||
| 49 | before, data = data.split(SEPARATOR_START, maxsplit=1) | ||
| 50 | _, after = data.split(SEPARATOR_END, maxsplit=1) | ||
| 51 | data = before + SEPARATOR_START + HELP + things + SEPARATOR_END + after | ||
| 52 | with open("Cargo.toml", "w") as f: | ||
| 53 | f.write(data) | ||
| 54 | |||
| 55 | |||
| 56 | # ========= Update build.rs | ||
| 57 | |||
| 58 | things = "" | ||
| 59 | for f in features: | ||
| 60 | name = f["name"].upper() | ||
| 61 | things += f' ("{name}", {f["default"]}),\n' | ||
| 62 | |||
| 63 | SEPARATOR_START = "// BEGIN AUTOGENERATED CONFIG FEATURES\n" | ||
| 64 | SEPARATOR_END = "// END AUTOGENERATED CONFIG FEATURES\n" | ||
| 65 | HELP = " // Generated by gen_config.py. DO NOT EDIT.\n" | ||
| 66 | with open("build.rs", "r") as f: | ||
| 67 | data = f.read() | ||
| 68 | before, data = data.split(SEPARATOR_START, maxsplit=1) | ||
| 69 | _, after = data.split(SEPARATOR_END, maxsplit=1) | ||
| 70 | data = before + SEPARATOR_START + HELP + \ | ||
| 71 | things + " " + SEPARATOR_END + after | ||
| 72 | with open("build.rs", "w") as f: | ||
| 73 | f.write(data) | ||
