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).
This commit is contained in:
Damien George 2019-01-27 13:52:43 +11:00
parent c2886868b9
commit 7d8db42d17
2 changed files with 17 additions and 4 deletions

View File

@ -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

View File

@ -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
//--------------------------------------------------------------------------