From e7fd416f9f90e4776bb2a7ee6c6c353072b0acf6 Mon Sep 17 00:00:00 2001 From: dongjiuzhu1 Date: Sun, 21 Apr 2024 15:28:20 +0800 Subject: [PATCH] drivers/usbdev: support config pid/vid by soft interface Signed-off-by: dongjiuzhu1 --- boards/Kconfig | 6 ++++++ drivers/usbdev/composite.c | 14 ++++++++++++++ include/nuttx/board.h | 17 +++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/boards/Kconfig b/boards/Kconfig index 18680b3345..02da2d0e2a 100644 --- a/boards/Kconfig +++ b/boards/Kconfig @@ -4736,6 +4736,12 @@ config BOARD_USBDEV_SERIALSTR ---help--- Use board unique serial number to iSerialNumber in the device descriptor. +config BOARD_USBDEV_PIDVID + bool "Board-specific usbdev pid/vid" + default n + ---help--- + Use board unique pid/vid. + config BOARD_MEMORY_RANGE string "Board memory range" default "" diff --git a/drivers/usbdev/composite.c b/drivers/usbdev/composite.c index 5d3ca13a33..479c138774 100644 --- a/drivers/usbdev/composite.c +++ b/drivers/usbdev/composite.c @@ -644,6 +644,20 @@ static int composite_setup(FAR struct usbdevclass_driver_s *driver, { ret = USB_SIZEOF_DEVDESC; memcpy(ctrlreq->buf, priv->descs->devdesc, ret); +#ifdef CONFIG_BOARD_USBDEV_PIDVID + { + uint16_t pid = board_usbdev_pid(); + uint16_t vid = board_usbdev_vid(); + FAR struct usb_devdesc_s *p_desc = + (FAR struct usb_devdesc_s *)ctrlreq->buf; + + p_desc->vendor[0] = LSBYTE(vid); + p_desc->vendor[1] = MSBYTE(vid); + + p_desc->product[0] = LSBYTE(pid); + p_desc->product[1] = MSBYTE(pid); + } +#endif } break; diff --git a/include/nuttx/board.h b/include/nuttx/board.h index 55dcd633c9..a937bc437b 100644 --- a/include/nuttx/board.h +++ b/include/nuttx/board.h @@ -450,6 +450,23 @@ FAR void *board_composite_connect(int port, int configid); FAR const char *board_usbdev_serialstr(void); #endif +/**************************************************************************** + * Name: board_usbdev_pid,board_usbdev_vid + * + * Description: + * Use board unique pid/vid in the device descriptor. This is for that + * usb can be dynamically configured while the board is running + * + * Returned Value: + * The board unique pid/vid. + * + ****************************************************************************/ + +#if defined(CONFIG_BOARD_USBDEV_PIDVID) +uint16_t board_usbdev_pid(void); +uint16_t board_usbdev_vid(void); +#endif + /**************************************************************************** * Name: board_graphics_setup *