Skip to content

Commit fd7f6ae

Browse files
nkarstensdlech
authored andcommitted
pbdrv/usb: Add WebUSB platform descriptor.
Add a WebUSB platform descriptor to the BOS descriptor and a landing page pointing to https://code.pybricks.com. Signed-off-by: Nate Karstens <[email protected]>
1 parent 141952f commit fd7f6ae

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

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

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static const char software_version[] = PBIO_PROTOCOL_VERSION_STR;
7373
#define USB_DEV_CAP_TYPE_PLATFORM (5)
7474

7575
#define USB_SIZ_STRING_SERIAL 0x1A
76-
#define USB_SIZ_BOS_DESC_CONST (5 + 28)
76+
#define USB_SIZ_BOS_DESC_CONST (5 + 28 + 24)
7777
#define USB_SIZ_UUID (128 / 8)
7878
#define USB_SIZ_PLATFORM_HDR (4 + USB_SIZ_UUID)
7979
#define USB_SIZ_HUB_NAME_MAX (16)
@@ -117,7 +117,7 @@ __ALIGN_BEGIN static uint8_t USBD_BOSDesc[USB_SIZ_BOS_DESC] __ALIGN_END =
117117
USB_DESC_TYPE_BOS, /* bDescriptorType = BOS */
118118
LOBYTE(USB_SIZ_BOS_DESC), /* wTotalLength */
119119
HIBYTE(USB_SIZ_BOS_DESC), /* wTotalLength */
120-
1, /* bNumDeviceCaps */
120+
2, /* bNumDeviceCaps */
121121

122122
28, /* bLength */
123123
USB_DEVICE_CAPABITY_TYPE, /* bDescriptorType = Device Capability */
@@ -140,7 +140,29 @@ __ALIGN_BEGIN static uint8_t USBD_BOSDesc[USB_SIZ_BOS_DESC] __ALIGN_END =
140140
LOBYTE(USBD_SIZ_MS_OS_DSCRPTR_SET), /* wMSOSDescriptorSetTotalLength */
141141
HIBYTE(USBD_SIZ_MS_OS_DSCRPTR_SET), /* wMSOSDescriptorSetTotalLength */
142142
USBD_MS_VENDOR_CODE, /* bMS_VendorCode */
143-
0x00 /* bAltEnumCode = Does not support alternate enumeration */
143+
0x00, /* bAltEnumCode = Does not support alternate enumeration */
144+
145+
24, /* bLength */
146+
USB_DEVICE_CAPABITY_TYPE, /* bDescriptorType = Device Capability */
147+
USB_DEV_CAP_TYPE_PLATFORM, /* bDevCapabilityType */
148+
0x00, /* bReserved */
149+
150+
/*
151+
* PlatformCapabilityUUID
152+
* WebUSB Platform Capability descriptor
153+
* 3408B638-09A9-47A0-8BFD-A0768815B665
154+
* RFC 4122 explains the correct byte ordering
155+
*/
156+
0x38, 0xB6, 0x08, 0x34, /* 32-bit value */
157+
0xA9, 0x09, /* 16-bit value */
158+
0xA0, 0x47, /* 16-bit value */
159+
0x8B, 0xFD,
160+
0xA0, 0x76, 0x88, 0x15, 0xB6, 0x65,
161+
162+
LOBYTE(0x0100), /* bcdVersion */
163+
HIBYTE(0x0100), /* bcdVersion */
164+
USBD_WEBUSB_VENDOR_CODE, /* bVendorCode */
165+
USBD_WEBUSB_LANDING_PAGE_IDX /* iLandingPage */
144166
};
145167

146168
static uint16_t USBD_BOSDesc_Len;

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,18 @@ __ALIGN_BEGIN static uint8_t USBD_Pybricks_CfgDesc[USBD_PYBRICKS_CONFIG_DESC_SIZ
155155
0x00 /* bInterval */
156156
};
157157

158+
__ALIGN_BEGIN static const uint8_t WebUSB_DescSet[20] __ALIGN_END =
159+
{
160+
20, /* bLength */
161+
0x03, /* bDescriptorType = URL */
162+
0x01, /* bScheme = https:// */
163+
164+
/* URL */
165+
'c', 'o', 'd', 'e', '.',
166+
'p', 'y', 'b', 'r', 'i', 'c', 'k', 's', '.',
167+
'c', 'o', 'm'
168+
};
169+
158170
/**
159171
* @}
160172
*/
@@ -244,6 +256,14 @@ static USBD_StatusTypeDef USBD_Pybricks_Setup(USBD_HandleTypeDef *pdev,
244256
MIN(sizeof(USBD_OSDescSet), req->wLength));
245257
break;
246258

259+
case USBD_WEBUSB_VENDOR_CODE:
260+
if ((req->wValue == USBD_WEBUSB_LANDING_PAGE_IDX) && (req->wIndex == 0x02)) {
261+
(void)USBD_CtlSendData(pdev,
262+
(uint8_t *)WebUSB_DescSet,
263+
MIN(sizeof(WebUSB_DescSet), req->wLength));
264+
}
265+
break;
266+
247267
default:
248268
USBD_CtlError(pdev, req);
249269
ret = USBD_FAIL;

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,12 @@ extern "C" {
4141
* @{
4242
*/
4343
#define USBD_MS_VENDOR_CODE 0x01
44+
#define USBD_WEBUSB_VENDOR_CODE 0x02
45+
4446
#define USBD_SIZ_MS_OS_DSCRPTR_SET (10 + 20 + 132)
4547

48+
#define USBD_WEBUSB_LANDING_PAGE_IDX 1
49+
4650
#define USBD_PYBRICKS_CONFIG_DESC_SIZ (9 + 9 + 7 + 7)
4751

4852
#define USBD_PYBRICKS_IN_EP 0x81U /* EP1 for data IN */

0 commit comments

Comments
 (0)