diff options
| author | Damien George <damien.p.george@gmail.com> | 2019-01-27 14:02:10 +1100 |
|---|---|---|
| committer | Damien George <damien.p.george@gmail.com> | 2019-01-27 14:02:10 +1100 |
| commit | 4caf5b23588a82b2a952b0206fe87cd18a9a9050 (patch) | |
| tree | b1d19df9689be3cfdd4e92f77ec28c211e5e439e | |
| parent | 7d8db42d17958560ccf56bbbae83ad795329aa43 (diff) | |
stm32/usbdev: Add USB config option for max power drawn by the board.
The new compile-time option is MICROPY_HW_USB_MAX_POWER_MA. Set this in
the board configuration file to the maximum current in mA that the board
will draw over USB. The default is 500mA.
| -rw-r--r-- | ports/stm32/usbdev/class/src/usbd_cdc_msc_hid.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/ports/stm32/usbdev/class/src/usbd_cdc_msc_hid.c b/ports/stm32/usbdev/class/src/usbd_cdc_msc_hid.c index 688cdc28b..fee1b23ea 100644 --- a/ports/stm32/usbdev/class/src/usbd_cdc_msc_hid.c +++ b/ports/stm32/usbdev/class/src/usbd_cdc_msc_hid.c @@ -103,6 +103,13 @@ #define CONFIG_DESC_ATTRIBUTES (0x80) // bus powered #endif +// Value used in the configuration descriptor for the bMaxPower entry +#if defined(MICROPY_HW_USB_MAX_POWER_MA) +#define CONFIG_DESC_MAXPOWER (MICROPY_HW_USB_MAX_POWER_MA / 2) // in units of 2mA +#else +#define CONFIG_DESC_MAXPOWER (0xfa) // 500mA in units of 2mA +#endif + #if USBD_SUPPORT_HS_MODE // USB Standard Device Descriptor __ALIGN_BEGIN static uint8_t USBD_CDC_MSC_HID_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END = { @@ -131,7 +138,7 @@ static const uint8_t msc_template_config_desc[MSC_TEMPLATE_CONFIG_DESC_SIZE] = { 0x01, // bConfigurationValue: Configuration value 0x00, // iConfiguration: Index of string descriptor describing the configuration CONFIG_DESC_ATTRIBUTES, // bmAttributes - 0xfa, // bMaxPower: in units of 2mA + CONFIG_DESC_MAXPOWER, // bMaxPower //========================================================================== // MSC only has 1 interface so doesn't need an IAD @@ -179,7 +186,7 @@ static const uint8_t cdc_msc_template_config_desc[CDC_MSC_TEMPLATE_CONFIG_DESC_S 0x01, // bConfigurationValue: Configuration value 0x00, // iConfiguration: Index of string descriptor describing the configuration CONFIG_DESC_ATTRIBUTES, // bmAttributes - 0xfa, // bMaxPower: in units of 2mA + CONFIG_DESC_MAXPOWER, // bMaxPower //========================================================================== // MSC only has 1 interface so doesn't need an IAD @@ -316,7 +323,7 @@ static const uint8_t cdc_hid_template_config_desc[CDC_HID_TEMPLATE_CONFIG_DESC_S 0x01, // bConfigurationValue: Configuration value 0x00, // iConfiguration: Index of string descriptor describing the configuration CONFIG_DESC_ATTRIBUTES, // bmAttributes - 0xfa, // bMaxPower: in units of 2mA + CONFIG_DESC_MAXPOWER, // bMaxPower //========================================================================== // HID only has 1 interface so doesn't need an IAD @@ -463,7 +470,7 @@ static const uint8_t cdc_template_config_desc[CDC_TEMPLATE_CONFIG_DESC_SIZE] = { 0x01, // bConfigurationValue: Configuration value 0x00, // iConfiguration: Index of string descriptor describing the configuration CONFIG_DESC_ATTRIBUTES, // bmAttributes - 0xfa, // bMaxPower: in units of 2mA + CONFIG_DESC_MAXPOWER, // bMaxPower //-------------------------------------------------------------------------- // Interface Descriptor |
