Skip to content

Commit 163f8ea

Browse files
committed
usb-device: Fix max_power_ma value if not using built-in driver.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
1 parent d90e654 commit 163f8ea

File tree

1 file changed

+9
-5
lines changed
  • micropython/usb/usb-device/usb/device

1 file changed

+9
-5
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,16 @@ 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
201+
if max_power_ma is not None:
202+
# Convert from mA to the units used in the descriptor
206203
max_power_ma //= 2
204+
else:
205+
try:
206+
# Default to whatever value the builtin driver reports
207+
max_power_ma = _usbd.BUILTIN_DEFAULT.desc_cfg[8]
208+
except IndexError:
209+
# If no built-in driver, default to 250mA
210+
max_power_ma = 125
207211

208212
desc.pack_into(
209213
"<BBHBBBBB",

0 commit comments

Comments
 (0)