Skip to content

Commit

Permalink
Add hub characteristics to BOS descriptor
Browse files Browse the repository at this point in the history
Adds the following hub charcteristics to a new platform capability
in the BOS Descriptor:

 * Software version
 * Protocol version
 * Hub feature flags
 * Max program size

We reuse {A5C44A4C-53D4-4389-9821-AE95051908A1}, the value of the
DeviceInterfaceGUID, as the platform capability UUID.
  • Loading branch information
nkarstens committed Nov 8, 2023
1 parent 77ebf82 commit 8486b47
Showing 1 changed file with 49 additions and 3 deletions.
52 changes: 49 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,13 @@
#include "usbd_conf.h"
#include "usbd_pybricks.h"

#include "pbio/protocol.h"
#include "pbio/version.h"
#include "pbsys/app.h"
#include "pbsys/program_load.h"
#include "pbdrvconfig.h"
#include "sys/config.h"

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
#define USBD_VID 0x0483
Expand All @@ -62,7 +69,7 @@
#define DEVICE_ID3 (0x1FFF7A18)

#define USB_SIZ_STRING_SERIAL 0x1A
#define USB_SIZ_BOS_DESC 33
#define USB_SIZ_BOS_DESC (5 + 28 + 34)

/* USB Standard Device Descriptor */
__ALIGN_BEGIN uint8_t USBD_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = {
Expand Down Expand Up @@ -98,12 +105,14 @@ __ALIGN_BEGIN uint8_t USBD_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = {
#endif /* defined ( __ICCARM__ ) */
__ALIGN_BEGIN uint8_t USBD_BOSDesc[USB_SIZ_BOS_DESC] __ALIGN_END =
{
/* --- BOS Decriptor --- */
5, /* bLength */
USB_DESC_TYPE_BOS, /* bDescriptorType = BOS */
LOBYTE(USB_SIZ_BOS_DESC), /* wTotalLength */
HIBYTE(USB_SIZ_BOS_DESC), /* wTotalLength */
0x01, /* bNumDeviceCaps = 1 */
0x02, /* bNumDeviceCaps = 2 */

/* --- Platform Capability --- */
28, /* bLength */
USB_DEVICE_CAPABITY_TYPE, /* bDescriptorType = Device Capability */
0x05, /* bDevCapabilityType = Platform */
Expand All @@ -124,7 +133,44 @@ __ALIGN_BEGIN uint8_t USBD_BOSDesc[USB_SIZ_BOS_DESC] __ALIGN_END =
LOBYTE(USB_SIZ_MS_OS_DSCRPTR_SET), /* wMSOSDescriptorSetTotalLength */
HIBYTE(USB_SIZ_MS_OS_DSCRPTR_SET), /* wMSOSDescriptorSetTotalLength */
USB_MS_VENDOR_CODE, /* bMS_VendorCode */
0x00 /* bAltEnumCode = Does not support alternate enumeration */
0x00, /* bAltEnumCode = Does not support alternate enumeration */

/* --- Platform Capability --- */
34, /* bLength */
USB_DEVICE_CAPABITY_TYPE, /* bDescriptorType = Device Capability */
0x05, /* bDevCapabilityType = Platform */
0x00, /* bReserved */

/*
* PlatformCapabilityUUID
* Pybricks
* A5C44A4C-53D4-4389-9821-AE95051908A1
*/
0x4C, 0x4A, 0xC4, 0xA5,
0xD4, 0x53,
0x89, 0x43,
0x98, 0x21,
0xAE, 0x95, 0x05, 0x19, 0x08, 0xA1,

PBIO_VERSION_MAJOR, /* Firmware version (major) */
PBIO_VERSION_MINOR, /* Firmware version (minor) */
PBIO_VERSION_MICRO, /* Firmware version (micro) */

PBIO_PROTOCOL_VERSION_MAJOR, /* Protocol version (major) */
PBIO_PROTOCOL_VERSION_MINOR, /* Protocol version (minor) */
PBIO_PROTOCOL_VERSION_PATCH, /* Protocol version (patch) */

/* Hub feature flags */
(PBSYS_APP_HUB_FEATURE_FLAGS) & 0xFF,
(PBSYS_APP_HUB_FEATURE_FLAGS >> 8) & 0xFF,
(PBSYS_APP_HUB_FEATURE_FLAGS >> 16) & 0xFF,
(PBSYS_APP_HUB_FEATURE_FLAGS >> 24) & 0xFF,

/* Program size */
(PBSYS_PROGRAM_LOAD_MAX_PROGRAM_SIZE) & 0xFF,
(PBSYS_PROGRAM_LOAD_MAX_PROGRAM_SIZE >> 8) & 0xFF,
(PBSYS_PROGRAM_LOAD_MAX_PROGRAM_SIZE >> 16) & 0xFF,
(PBSYS_PROGRAM_LOAD_MAX_PROGRAM_SIZE >> 24) & 0xFF,
};
#endif /* (USBD_LPM_ENABLED == 1) || (USBD_CLASS_BOS_ENABLED == 1) */

Expand Down

0 comments on commit 8486b47

Please sign in to comment.