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 <angus@redyak.com.au>
Angus Gratton 2024-04-03 16:07:16 +11:00
rodzic 9cc9abed05
commit e40dd53300
1 zmienionych plików z 8 dodań i 1 usunięć

Wyświetl plik

@ -99,7 +99,7 @@ class _Device:
device_subclass=None,
device_protocol=None,
config_str=None,
max_power_ma=50,
max_power_ma=None,
):
# Configure the USB device with a set of interfaces, and optionally reconfiguring the
# device and configuration descriptor fields
@ -198,6 +198,13 @@ class _Device:
iConfiguration = len(strs)
strs.append(configuration_str)
if max_power_ma is None:
# Default to whatever value the builtin driver reports
max_power_ma = builtin.desc_cfg[8]
else:
# Otherwise, convert from mA to the units used in the descriptor
max_power_ma //= 2
desc.pack_into(
"<BBHBBBBB",
0,