5151
5252#include "usbd_core.h"
5353#include "usbd_conf.h"
54+ #include "usbd_pybricks.h"
5455
5556/* Private typedef -----------------------------------------------------------*/
5657/* Private define ------------------------------------------------------------*/
6263#define DEVICE_ID2 (0x1FFF7A14)
6364#define DEVICE_ID3 (0x1FFF7A18)
6465
66+ #define USB_DEV_CAP_TYPE_PLATFORM (5)
67+
6568#define USB_SIZ_STRING_SERIAL 0x1A
69+ #define USB_SIZ_BOS_DESC 33
6670
6771/* USB Standard Device Descriptor */
6872__ALIGN_BEGIN static
7276uint8_t USBD_DeviceDesc [USB_LEN_DEV_DESC ] __ALIGN_END = {
7377 0x12 , /* bLength */
7478 USB_DESC_TYPE_DEVICE , /* bDescriptorType */
75- 0x00 , /* bcdUSB */
79+ 0x01 , /* bcdUSB */ /* changed to USB version 2.01
80+ in order to support BOS Desc */
7681 0x02 ,
7782 PBIO_PYBRICKS_USB_DEVICE_CLASS , /* bDeviceClass */
7883 PBIO_PYBRICKS_USB_DEVICE_SUBCLASS , /* bDeviceSubClass */
@@ -90,6 +95,127 @@ uint8_t USBD_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = {
9095 USBD_MAX_NUM_CONFIGURATION /* bNumConfigurations */
9196}; /* USB_DeviceDescriptor */
9297
98+ /** BOS descriptor. */
99+ __ALIGN_BEGIN static 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+ 1 , /* bNumDeviceCaps */
106+
107+ 28 , /* bLength */
108+ USB_DEVICE_CAPABITY_TYPE , /* bDescriptorType = Device Capability */
109+ USB_DEV_CAP_TYPE_PLATFORM , /* bDevCapabilityType */
110+ 0x00 , /* bReserved */
111+
112+ /*
113+ * PlatformCapabilityUUID
114+ * Microsoft OS 2.0 descriptor platform capability ID
115+ * D8DD60DF-4589-4CC7-9CD2-659D9E648A9F
116+ * RFC 4122 explains the correct byte ordering
117+ */
118+ 0xDF , 0x60 , 0xDD , 0xD8 , /* 32-bit value */
119+ 0x89 , 0x45 , /* 16-bit value */
120+ 0xC7 , 0x4C , /* 16-bit value */
121+ 0x9C , 0xD2 ,
122+ 0x65 , 0x9D , 0x9E , 0x64 , 0x8A , 0x9F ,
123+
124+ 0x00 , 0x00 , 0x03 , 0x06 , /* dwWindowsVersion = 0x06030000 for Windows 8.1 Build */
125+ LOBYTE (USBD_SIZ_MS_OS_DSCRPTR_SET ), /* wMSOSDescriptorSetTotalLength */
126+ HIBYTE (USBD_SIZ_MS_OS_DSCRPTR_SET ), /* wMSOSDescriptorSetTotalLength */
127+ USBD_MS_VENDOR_CODE , /* bMS_VendorCode */
128+ 0x00 /* bAltEnumCode = Does not support alternate enumeration */
129+ };
130+
131+ __ALIGN_BEGIN const uint8_t USBD_OSDescSet [USBD_SIZ_MS_OS_DSCRPTR_SET ] __ALIGN_END =
132+ {
133+ 0x0A , 0x00 , /* wLength = 10 */
134+ 0x00 , 0x00 , /* wDescriptorType = MS_OS_20_SET_HEADER_DESCRIPTOR */
135+ 0x00 , 0x00 , 0x03 , 0x06 , /* dwWindowsVersion = 0x06030000 for Windows 8.1 Build */
136+ LOBYTE (USBD_SIZ_MS_OS_DSCRPTR_SET ), /* wTotalLength */
137+ HIBYTE (USBD_SIZ_MS_OS_DSCRPTR_SET ), /* wTotalLength (cont.) */
138+
139+ 0x14 , 0x00 , /* wLength = 20 */
140+ 0x03 , 0x00 , /* wDescriptorType = MS_OS_20_FEATURE_COMPATBLE_ID */
141+ 'W' , 'I' , 'N' , 'U' , 'S' , 'B' , /* CompatibleID */
142+ 0x00 , 0x00 , /* CompatibleID (cont.) */
143+ 0x00 , 0x00 , 0x00 , 0x00 , /* SubCompatibleID */
144+ 0x00 , 0x00 , 0x00 , 0x00 , /* SubCompatibleID (cont.) */
145+
146+ 0x84 , 0x00 , /* wLength = 132 */
147+ 0x04 , 0x00 , /* wDescriptorType = MS_OS_20_FEATURE_REG_PROPERTY */
148+ 0x07 , 0x00 , /* wStringType = REG_MULTI_SZ */
149+ /* wPropertyNameLength = 42 */
150+ 0x2A , 0x00 ,
151+ /* PropertyName = DeviceInterfaceGUIDs */
152+ 'D' , '\0' ,
153+ 'e' , '\0' ,
154+ 'v' , '\0' ,
155+ 'i' , '\0' ,
156+ 'c' , '\0' ,
157+ 'e' , '\0' ,
158+ 'I' , '\0' ,
159+ 'n' , '\0' ,
160+ 't' , '\0' ,
161+ 'e' , '\0' ,
162+ 'r' , '\0' ,
163+ 'f' , '\0' ,
164+ 'a' , '\0' ,
165+ 'c' , '\0' ,
166+ 'e' , '\0' ,
167+ 'G' , '\0' ,
168+ 'U' , '\0' ,
169+ 'I' , '\0' ,
170+ 'D' , '\0' ,
171+ 's' , '\0' ,
172+ '\0' , '\0' ,
173+
174+ /* wPropertyDataLength = 80 */
175+ 0x50 , 0x00 ,
176+ /* PropertyData = {A5C44A4C-53D4-4389-9821-AE95051908A1} */
177+ '{' , '\0' ,
178+ 'A' , '\0' ,
179+ '5' , '\0' ,
180+ 'C' , '\0' ,
181+ '4' , '\0' ,
182+ '4' , '\0' ,
183+ 'A' , '\0' ,
184+ '4' , '\0' ,
185+ 'C' , '\0' ,
186+ '-' , '\0' ,
187+ '5' , '\0' ,
188+ '3' , '\0' ,
189+ 'D' , '\0' ,
190+ '4' , '\0' ,
191+ '-' , '\0' ,
192+ '4' , '\0' ,
193+ '3' , '\0' ,
194+ '8' , '\0' ,
195+ '9' , '\0' ,
196+ '-' , '\0' ,
197+ '9' , '\0' ,
198+ '8' , '\0' ,
199+ '2' , '\0' ,
200+ '1' , '\0' ,
201+ '-' , '\0' ,
202+ 'A' , '\0' ,
203+ 'E' , '\0' ,
204+ '9' , '\0' ,
205+ '5' , '\0' ,
206+ '0' , '\0' ,
207+ '5' , '\0' ,
208+ '1' , '\0' ,
209+ '9' , '\0' ,
210+ '0' , '\0' ,
211+ '8' , '\0' ,
212+ 'A' , '\0' ,
213+ '1' , '\0' ,
214+ '}' , '\0' ,
215+ '\0' , '\0' ,
216+ '\0' , '\0'
217+ };
218+
93219/* USB Standard Device Descriptor */
94220__ALIGN_BEGIN static const uint8_t USBD_LangIDDesc [USB_LEN_LANGID_STR_DESC ] __ALIGN_END = {
95221 USB_LEN_LANGID_STR_DESC ,
@@ -242,6 +368,14 @@ static uint8_t *USBD_Pybricks_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, ui
242368 return USBD_StrDesc ;
243369}
244370
371+ static uint8_t * USBD_Pybricks_BOSDescriptor (USBD_SpeedTypeDef speed , uint16_t * length ) {
372+ /* Prevent unused argument(s) compilation warning */
373+ UNUSED (speed );
374+
375+ * length = sizeof (USBD_BOSDesc );
376+ return (uint8_t * )USBD_BOSDesc ;
377+ }
378+
245379USBD_DescriptorsTypeDef USBD_Pybricks_Desc = {
246380 .GetDeviceDescriptor = USBD_Pybricks_DeviceDescriptor ,
247381 .GetLangIDStrDescriptor = USBD_Pybricks_LangIDStrDescriptor ,
@@ -250,6 +384,7 @@ USBD_DescriptorsTypeDef USBD_Pybricks_Desc = {
250384 .GetSerialStrDescriptor = USBD_Pybricks_SerialStrDescriptor ,
251385 .GetConfigurationStrDescriptor = USBD_Pybricks_ConfigStrDescriptor ,
252386 .GetInterfaceStrDescriptor = USBD_Pybricks_InterfaceStrDescriptor ,
387+ .GetBOSDescriptor = USBD_Pybricks_BOSDescriptor ,
253388};
254389
255390void USBD_Pybricks_Desc_Init (void ) {
0 commit comments