Skip to content

Commit 77ebf82

Browse files
committed
Add new Pybricks device class
Adds a new Pybricks device class and provides the correct descriptors so that Windows will use the WinUSB driver.
1 parent 2c5d111 commit 77ebf82

File tree

6 files changed

+989
-2
lines changed

6 files changed

+989
-2
lines changed

bricks/_common/arm_none_eabi.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ endif
373373
SRC_STM32_USB_DEV += $(addprefix lib/pbio/drv/usb/stm32_usbd/,\
374374
usbd_conf.c \
375375
usbd_desc.c \
376+
usbd_pybricks.c \
376377
)
377378

378379
NXOS_SRC_C = $(addprefix lib/pbio/platform/nxt/nxos/,\

lib/pbio/drv/usb/stm32_usbd/usbd_conf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
#define USBD_MAX_NUM_CONFIGURATION 1
1111
#define USBD_MAX_STR_DESC_SIZ 0x100
1212
#define USBD_SELF_POWERED 1
13+
#define USBD_CLASS_BOS_ENABLED 1
1314

1415
#endif /* _USBD_CONF_H_ */

lib/pbio/drv/usb/stm32_usbd/usbd_desc.c

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
/* Includes ------------------------------------------------------------------*/
4646
#include "usbd_core.h"
4747
#include "usbd_conf.h"
48+
#include "usbd_pybricks.h"
4849

4950
/* Private typedef -----------------------------------------------------------*/
5051
/* Private define ------------------------------------------------------------*/
@@ -61,12 +62,18 @@
6162
#define DEVICE_ID3 (0x1FFF7A18)
6263

6364
#define USB_SIZ_STRING_SERIAL 0x1A
65+
#define USB_SIZ_BOS_DESC 33
6466

6567
/* USB Standard Device Descriptor */
6668
__ALIGN_BEGIN uint8_t USBD_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = {
6769
0x12, /* bLength */
6870
USB_DESC_TYPE_DEVICE, /* bDescriptorType */
71+
#if ((USBD_LPM_ENABLED == 1) || (USBD_CLASS_BOS_ENABLED == 1))
72+
0x01, /* bcdUSB */ /* changed to USB version 2.01
73+
in order to support BOS Desc */
74+
#else
6975
0x00, /* bcdUSB */
76+
#endif /* (USBD_LPM_ENABLED == 1) || (USBD_CLASS_BOS_ENABLED == 1) */
7077
0x02,
7178
0x02, /* bDeviceClass */
7279
0x02, /* bDeviceSubClass */
@@ -84,6 +91,135 @@ __ALIGN_BEGIN uint8_t USBD_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = {
8491
USBD_MAX_NUM_CONFIGURATION /* bNumConfigurations */
8592
}; /* USB_DeviceDescriptor */
8693

94+
/** BOS descriptor. */
95+
#if ((USBD_LPM_ENABLED == 1) || (USBD_CLASS_BOS_ENABLED == 1))
96+
#if defined ( __ICCARM__ ) /* IAR Compiler */
97+
#pragma data_alignment=4
98+
#endif /* defined ( __ICCARM__ ) */
99+
__ALIGN_BEGIN uint8_t USBD_BOSDesc[USB_SIZ_BOS_DESC] __ALIGN_END =
100+
{
101+
5, /* bLength */
102+
USB_DESC_TYPE_BOS, /* bDescriptorType = BOS */
103+
LOBYTE(USB_SIZ_BOS_DESC), /* wTotalLength */
104+
HIBYTE(USB_SIZ_BOS_DESC), /* wTotalLength */
105+
0x01, /* bNumDeviceCaps = 1 */
106+
107+
28, /* bLength */
108+
USB_DEVICE_CAPABITY_TYPE, /* bDescriptorType = Device Capability */
109+
0x05, /* bDevCapabilityType = Platform */
110+
0x00, /* bReserved */
111+
112+
/*
113+
* PlatformCapabilityUUID
114+
* Microsoft OS 2.0 descriptor platform capability ID
115+
* D8DD60DF-4589-4CC7-9CD2-659D9E648A9F
116+
*/
117+
0xDF, 0x60, 0xDD, 0xD8,
118+
0x89, 0x45,
119+
0xC7, 0x4C,
120+
0x9C, 0xD2,
121+
0x65, 0x9D, 0x9E, 0x64, 0x8A, 0x9F,
122+
123+
0x00, 0x00, 0x03, 0x06, /* dwWindowsVersion = 0x06030000 for Windows 8.1 Build */
124+
LOBYTE(USB_SIZ_MS_OS_DSCRPTR_SET), /* wMSOSDescriptorSetTotalLength */
125+
HIBYTE(USB_SIZ_MS_OS_DSCRPTR_SET), /* wMSOSDescriptorSetTotalLength */
126+
USB_MS_VENDOR_CODE, /* bMS_VendorCode */
127+
0x00 /* bAltEnumCode = Does not support alternate enumeration */
128+
};
129+
#endif /* (USBD_LPM_ENABLED == 1) || (USBD_CLASS_BOS_ENABLED == 1) */
130+
131+
#if ((USBD_LPM_ENABLED == 1) || (USBD_CLASS_BOS_ENABLED == 1))
132+
#if defined ( __ICCARM__ ) /* IAR Compiler */
133+
#pragma data_alignment=4
134+
#endif /* defined ( __ICCARM__ ) */
135+
__ALIGN_BEGIN uint8_t USBD_OSDescSet[USB_SIZ_MS_OS_DSCRPTR_SET] __ALIGN_END =
136+
{
137+
0x0A, 0x00, /* wLength = 10 */
138+
0x00, 0x00, /* wDescriptorType = MS_OS_20_SET_HEADER_DESCRIPTOR */
139+
0x00, 0x00, 0x03, 0x06, /* dwWindowsVersion = 0x06030000 for Windows 8.1 Build */
140+
LOBYTE(USB_SIZ_MS_OS_DSCRPTR_SET), /* wTotalLength */
141+
HIBYTE(USB_SIZ_MS_OS_DSCRPTR_SET), /* wTotalLength (cont.) */
142+
143+
0x14, 0x00, /* wLength = 20 */
144+
0x03, 0x00, /* wDescriptorType = MS_OS_20_FEATURE_COMPATBLE_ID */
145+
'W', 'I', 'N', 'U', 'S', 'B', /* CompatibleID */
146+
0x00, 0x00, /* CompatibleID (cont.) */
147+
0x00, 0x00, 0x00, 0x00, /* SubCompatibleID */
148+
0x00, 0x00, 0x00, 0x00, /* SubCompatibleID (cont.) */
149+
150+
0x82, 0x00, /* wLength = 130 */
151+
0x04, 0x00, /* wDescriptorType = MS_OS_20_FEATURE_REG_PROPERTY */
152+
0x07, 0x00, /* wStringType = REG_MULTI_SZ */
153+
/* wPropertyNameLength = 42 */
154+
0x2A, 0x00,
155+
/* PropertyName = DeviceInterfaceGUIDs */
156+
'D', '\0',
157+
'e', '\0',
158+
'v', '\0',
159+
'i', '\0',
160+
'c', '\0',
161+
'e', '\0',
162+
'I', '\0',
163+
'n', '\0',
164+
't', '\0',
165+
'e', '\0',
166+
'r', '\0',
167+
'f', '\0',
168+
'a', '\0',
169+
'c', '\0',
170+
'e', '\0',
171+
'G', '\0',
172+
'U', '\0',
173+
'I', '\0',
174+
'D', '\0',
175+
's', '\0',
176+
'\0', '\0',
177+
178+
/* wPropertyDataLength = 78 */
179+
0x4E, 0x00,
180+
/* PropertyData = {A5C44A4C-53D4-4389-9821-AE95051908A1} */
181+
'{', '\0',
182+
'A', '\0',
183+
'5', '\0',
184+
'C', '\0',
185+
'4', '\0',
186+
'4', '\0',
187+
'A', '\0',
188+
'4', '\0',
189+
'C', '\0',
190+
'-', '\0',
191+
'5', '\0',
192+
'3', '\0',
193+
'D', '\0',
194+
'4', '\0',
195+
'-', '\0',
196+
'4', '\0',
197+
'3', '\0',
198+
'8', '\0',
199+
'9', '\0',
200+
'-', '\0',
201+
'9', '\0',
202+
'8', '\0',
203+
'2', '\0',
204+
'1', '\0',
205+
'-', '\0',
206+
'A', '\0',
207+
'E', '\0',
208+
'9', '\0',
209+
'5', '\0',
210+
'0', '\0',
211+
'5', '\0',
212+
'1', '\0',
213+
'9', '\0',
214+
'0', '\0',
215+
'8', '\0',
216+
'A', '\0',
217+
'1', '\0',
218+
'}', '\0',
219+
'\0', '\0'
220+
};
221+
#endif /* (USBD_LPM_ENABLED == 1) || (USBD_CLASS_BOS_ENABLED == 1) */
222+
87223
/* USB Standard Device Descriptor */
88224
__ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END = {
89225
USB_LEN_LANGID_STR_DESC,
@@ -236,6 +372,16 @@ static uint8_t *USBD_Pybricks_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, ui
236372
return USBD_StrDesc;
237373
}
238374

375+
#if ((USBD_LPM_ENABLED == 1) || (USBD_CLASS_BOS_ENABLED == 1))
376+
static uint8_t *USBD_Pybricks_BOSDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) {
377+
/* Prevent unused argument(s) compilation warning */
378+
UNUSED(speed);
379+
380+
*length = sizeof(USBD_BOSDesc);
381+
return (uint8_t *)USBD_BOSDesc;
382+
}
383+
#endif /* (USBD_LPM_ENABLED == 1) || (USBD_CLASS_BOS_ENABLED == 1) */
384+
239385
USBD_DescriptorsTypeDef Pybricks_Desc = {
240386
.GetDeviceDescriptor = USBD_Pybricks_DeviceDescriptor,
241387
.GetLangIDStrDescriptor = USBD_Pybricks_LangIDStrDescriptor,
@@ -244,4 +390,7 @@ USBD_DescriptorsTypeDef Pybricks_Desc = {
244390
.GetSerialStrDescriptor = USBD_Pybricks_SerialStrDescriptor,
245391
.GetConfigurationStrDescriptor = USBD_Pybricks_ConfigStrDescriptor,
246392
.GetInterfaceStrDescriptor = USBD_Pybricks_InterfaceStrDescriptor,
393+
#if ((USBD_LPM_ENABLED == 1) || (USBD_CLASS_BOS_ENABLED == 1))
394+
.GetBOSDescriptor = USBD_Pybricks_BOSDescriptor,
395+
#endif
247396
};

0 commit comments

Comments
 (0)