Skip to content

Commit e40dd53

Browse files
committed
usb-device: Keep the built-in driver's MaxPower value if not set.
Previously, if unset this value reverted to 100mA. Now also respects the units provided in the argument. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <[email protected]>
1 parent 9cc9abe commit e40dd53

File tree

1 file changed

+8
-1
lines changed
  • micropython/usb/usb-device/usb/device

1 file changed

+8
-1
lines changed

micropython/usb/usb-device/usb/device/impl.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def config( # noqa: PLR0913
9999
device_subclass=None,
100100
device_protocol=None,
101101
config_str=None,
102-
max_power_ma=50,
102+
max_power_ma=None,
103103
):
104104
# Configure the USB device with a set of interfaces, and optionally reconfiguring the
105105
# device and configuration descriptor fields
@@ -198,6 +198,13 @@ def maybe_set(value, idx):
198198
iConfiguration = len(strs)
199199
strs.append(configuration_str)
200200

201+
if max_power_ma is None:
202+
# Default to whatever value the builtin driver reports
203+
max_power_ma = builtin.desc_cfg[8]
204+
else:
205+
# Otherwise, convert from mA to the units used in the descriptor
206+
max_power_ma //= 2
207+
201208
desc.pack_into(
202209
"<BBHBBBBB",
203210
0,

0 commit comments

Comments
 (0)