usb-device: Fix max_power_ma value if not using built-in driver.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
Angus Gratton 2024-04-04 15:41:06 +11:00
rodzic d90e654384
commit 163f8ea953
1 zmienionych plików z 9 dodań i 5 usunięć

Wyświetl plik

@ -198,12 +198,16 @@ 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
if max_power_ma is not None:
# Convert from mA to the units used in the descriptor
max_power_ma //= 2
else:
try:
# Default to whatever value the builtin driver reports
max_power_ma = _usbd.BUILTIN_DEFAULT.desc_cfg[8]
except IndexError:
# If no built-in driver, default to 250mA
max_power_ma = 125
desc.pack_into(
"<BBHBBBBB",