From e40dd5330003079386a71862bee5fe6fc0e6e0da Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 3 Apr 2024 16:07:16 +1100 Subject: [PATCH] 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 --- micropython/usb/usb-device/usb/device/impl.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/micropython/usb/usb-device/usb/device/impl.py b/micropython/usb/usb-device/usb/device/impl.py index 90606082..b8b1786d 100644 --- a/micropython/usb/usb-device/usb/device/impl.py +++ b/micropython/usb/usb-device/usb/device/impl.py @@ -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( "