Skip to content

Commit

Permalink
drv/usb/stm32_usbd: use Pybricks class/subclass/protocol
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dlech committed Dec 23, 2023
1 parent 92f2cac commit 2d783d3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/pbio/drv/usb/stm32_usbd/usbd_desc.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include <lego_usb.h>

#include <pbdrv/config.h>
#include <pbio/protocol.h>

#include "usbd_core.h"
#include "usbd_conf.h"
Expand All @@ -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 */
Expand Down
7 changes: 7 additions & 0 deletions lib/pbio/include/pbio/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_

/** @} */

0 comments on commit 2d783d3

Please sign in to comment.