summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2019-01-27 13:52:43 +1100
committerDamien George <damien.p.george@gmail.com>2019-01-27 13:52:43 +1100
commit7d8db42d17958560ccf56bbbae83ad795329aa43 (patch)
tree685771473eb0d1a194ca9ce484d009de45f76125
parentc2886868b9ccbe8580f57135bb29779a5d36c1e8 (diff)
stm32/usbdev: Add USB config option for board being self powered.
The new compile-time option is MICROPY_HW_USB_SELF_POWERED. Set this option to 1 in the board configuration file to indicate that the USB device is self powered. This option is disabled by default (previous behaviour).
-rw-r--r--ports/stm32/usbd_conf.h6
-rw-r--r--ports/stm32/usbdev/class/src/usbd_cdc_msc_hid.c15
2 files changed, 17 insertions, 4 deletions
diff --git a/ports/stm32/usbd_conf.h b/ports/stm32/usbd_conf.h
index 1f8e754a2..c5faf6c8c 100644
--- a/ports/stm32/usbd_conf.h
+++ b/ports/stm32/usbd_conf.h
@@ -37,10 +37,16 @@
#include <stdlib.h>
#include <string.h>
+#include "py/mpconfig.h"
+
#define USBD_MAX_NUM_INTERFACES 4
#define USBD_MAX_NUM_CONFIGURATION 1
#define USBD_MAX_STR_DESC_SIZ 0x100
+#if MICROPY_HW_USB_SELF_POWERED
+#define USBD_SELF_POWERED 1
+#else
#define USBD_SELF_POWERED 0
+#endif
#define USBD_DEBUG_LEVEL 0
#endif // MICROPY_INCLUDED_STM32_USBD_CONF_H
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 809e0d42f..688cdc28b 100644
--- a/ports/stm32/usbdev/class/src/usbd_cdc_msc_hid.c
+++ b/ports/stm32/usbdev/class/src/usbd_cdc_msc_hid.c
@@ -96,6 +96,13 @@
#define HID_REQ_SET_IDLE (0x0a)
#define HID_REQ_GET_IDLE (0x02)
+// Value used in the configuration descriptor for the bmAttributes entry
+#if MICROPY_HW_USB_SELF_POWERED
+#define CONFIG_DESC_ATTRIBUTES (0xc0) // self powered
+#else
+#define CONFIG_DESC_ATTRIBUTES (0x80) // bus powered
+#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 = {
@@ -123,7 +130,7 @@ static const uint8_t msc_template_config_desc[MSC_TEMPLATE_CONFIG_DESC_SIZE] = {
0x01, // bNumInterfaces: 1 interfaces
0x01, // bConfigurationValue: Configuration value
0x00, // iConfiguration: Index of string descriptor describing the configuration
- 0x80, // bmAttributes: bus powered; 0xc0 for self powered
+ CONFIG_DESC_ATTRIBUTES, // bmAttributes
0xfa, // bMaxPower: in units of 2mA
//==========================================================================
@@ -171,7 +178,7 @@ static const uint8_t cdc_msc_template_config_desc[CDC_MSC_TEMPLATE_CONFIG_DESC_S
0x03, // bNumInterfaces: 3 interfaces
0x01, // bConfigurationValue: Configuration value
0x00, // iConfiguration: Index of string descriptor describing the configuration
- 0x80, // bmAttributes: bus powered; 0xc0 for self powered
+ CONFIG_DESC_ATTRIBUTES, // bmAttributes
0xfa, // bMaxPower: in units of 2mA
//==========================================================================
@@ -308,7 +315,7 @@ static const uint8_t cdc_hid_template_config_desc[CDC_HID_TEMPLATE_CONFIG_DESC_S
0x03, // bNumInterfaces: 3 interfaces
0x01, // bConfigurationValue: Configuration value
0x00, // iConfiguration: Index of string descriptor describing the configuration
- 0x80, // bmAttributes: bus powered; 0xc0 for self powered
+ CONFIG_DESC_ATTRIBUTES, // bmAttributes
0xfa, // bMaxPower: in units of 2mA
//==========================================================================
@@ -455,7 +462,7 @@ static const uint8_t cdc_template_config_desc[CDC_TEMPLATE_CONFIG_DESC_SIZE] = {
0x02, // bNumInterfaces: 2 interface
0x01, // bConfigurationValue: Configuration value
0x00, // iConfiguration: Index of string descriptor describing the configuration
- 0x80, // bmAttributes: bus powered; 0xc0 for self powered
+ CONFIG_DESC_ATTRIBUTES, // bmAttributes
0xfa, // bMaxPower: in units of 2mA
//--------------------------------------------------------------------------