Skip to content

Commit 4a955b2

Browse files
authored
Correctly use earlephilhower.varant if variant not given, ensure USB power macro is always there (#444)
Fixes a crash of the builder script, `board.get("build.variant", None)` will throw an exception if the `build.variant` was not found (and not return `None` as the fallback value), but an empty string works, so check against that. USB power defines moved directly into the board files, but still ensure that the macro always exists (with a default fallback value) to not fail the build.
1 parent 4f27ec4 commit 4a955b2

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

tools/platformio-build.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,13 @@ def configure_usb_flags(cpp_defines):
148148
("USB_PID", usb_pid),
149149
("USB_MANUFACTURER", '\\"%s\\"' % usb_manufacturer),
150150
("USB_PRODUCT", '\\"%s\\"' % usb_product),
151-
("SERIALUSB_PID", usb_pid),
152-
("USBD_MAX_POWER_MA", 250)
151+
("SERIALUSB_PID", usb_pid)
153152
])
154153

154+
if "USBD_MAX_POWER_MA" not in env.Flatten(env.get("CPPDEFINES", [])):
155+
env.Append(CPPDEFINES=[("USBD_MAX_POWER_MA", 500)])
156+
print("Warning: Undefined USBD_MAX_OWER_MA, assuming 500mA")
157+
155158
# use vidtouse and pidtouse
156159
# for USB PID/VID autodetection
157160
hw_ids = board.get("build.hwids", [["0x2E8A", "0x00C0"]])
@@ -195,9 +198,9 @@ def configure_usb_flags(cpp_defines):
195198

196199
libs = []
197200

198-
variant = board.get("build.arduino.earlephilhower.variant", board.get("build.variant", None))
201+
variant = board.get("build.arduino.earlephilhower.variant", board.get("build.variant", ""))
199202

200-
if variant is not None:
203+
if variant != "":
201204
env.Append(CPPPATH=[
202205
os.path.join(FRAMEWORK_DIR, "variants", variant)
203206
])

0 commit comments

Comments
 (0)