From 2d783d362dc5fdf1a5d4364b92748813451cb98e Mon Sep 17 00:00:00 2001 From: David Lechner Date: Sun, 26 Nov 2023 18:32:46 -0600 Subject: [PATCH] drv/usb/stm32_usbd: use Pybricks class/subclass/protocol This adds new defines for the Pybricks USB device class, subclass and protocol. The class (0xff) is defined by the USB-IF and is the vendor- specific class. The subclass and protocol are vendor-specific and come from the first two bytes of the the Pybricks Bluetooth UUIDs. This allows us to identify hubs running Pybricks when enumerating USB devices. --- lib/pbio/drv/usb/stm32_usbd/usbd_desc.c | 7 ++++--- lib/pbio/include/pbio/protocol.h | 7 +++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/pbio/drv/usb/stm32_usbd/usbd_desc.c b/lib/pbio/drv/usb/stm32_usbd/usbd_desc.c index 0a4b04276..2519506dd 100644 --- a/lib/pbio/drv/usb/stm32_usbd/usbd_desc.c +++ b/lib/pbio/drv/usb/stm32_usbd/usbd_desc.c @@ -47,6 +47,7 @@ #include #include +#include #include "usbd_core.h" #include "usbd_conf.h" @@ -73,9 +74,9 @@ uint8_t USBD_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = { USB_DESC_TYPE_DEVICE, /* bDescriptorType */ 0x00, /* bcdUSB */ 0x02, - 0x02, /* bDeviceClass */ - 0x02, /* bDeviceSubClass */ - 0x00, /* bDeviceProtocol */ + PBIO_PYBRICKS_USB_DEVICE_CLASS, /* bDeviceClass */ + PBIO_PYBRICKS_USB_DEVICE_SUBCLASS, /* bDeviceSubClass */ + PBIO_PYBRICKS_USB_DEVICE_PROTOCOL, /* bDeviceProtocol */ USB_MAX_EP0_SIZE, /* bMaxPacketSize */ LOBYTE(PBDRV_CONFIG_USB_VID), /* idVendor */ HIBYTE(PBDRV_CONFIG_USB_VID), /* idVendor */ diff --git a/lib/pbio/include/pbio/protocol.h b/lib/pbio/include/pbio/protocol.h index 48e65685f..4fa00bca2 100644 --- a/lib/pbio/include/pbio/protocol.h +++ b/lib/pbio/include/pbio/protocol.h @@ -311,6 +311,13 @@ extern const uint8_t pbio_nus_service_uuid[]; extern const uint8_t pbio_nus_rx_char_uuid[]; extern const uint8_t pbio_nus_tx_char_uuid[]; +/** USB bDeviceClass for Pybricks hubs */ +#define PBIO_PYBRICKS_USB_DEVICE_CLASS 0xFF +/** USB bDeviceSubClass for Pybricks hubs */ +#define PBIO_PYBRICKS_USB_DEVICE_SUBCLASS 0xC5 +/** USB bDeviceProtocol for Pybricks hubs */ +#define PBIO_PYBRICKS_USB_DEVICE_PROTOCOL 0xF5 + #endif // _PBIO_PROTOCOL_H_ /** @} */