Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb.h b/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb.h
- index 8ac8244..2975447 100644
- --- a/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb.h
- +++ b/src/rp2_common/pico_stdio_usb/include/pico/stdio_usb.h
- @@ -120,6 +120,40 @@ bool stdio_usb_init(void);
- * \return true if stdio is connected over CDC
- */
- bool stdio_usb_connected(void);
- +
- +#if !defined(LIB_TINYUSB_DEVICE)
- +/*! \brief Holds information for custom CDC descriptors used by \ref stdio_usb_set_custom_descriptors
- + *
- + * This struct is passed to \ref stdio_usb_set_custom_descriptors to apply custom VendorID, ProductID,
- + * Manufacturer String, Product String, and Serial Number to the built-in tinyUSB CDC.
- + *
- + * \note The struct does not need to remain valid after calling \ref stdio_usb_set_custom_descriptors
- + * but the string data pointed to by the the member fields must remain valid until the host has received
- + * all descriptors.
- + */
- +typedef struct {
- + uint16_t idVendor;
- + uint16_t idProduct;
- + char* str_manufacturer;
- + char* str_product;
- + char* str_serial;
- +} stdio_custom_CDC_config_t;
- +/*! \brief Set custom CDC descriptors for the built-in tinyUSB CDC
- + * \ingroup pico_stdio_usb
- + *
- + * Set custom USB CDC descriptors (idVendor, idProduct, ...) for use with the default tinyUSB CDC. The parameters
- + * are wrapped inside a \ref stdio_custom_CDC_config_t struct.
- + *
- + * \par These settings should not be changed arbitrarily! For commercial products, a USB Vendor ID must be acquired
- + * from the [USB-IF](https://www.usb.org/) if you want to change it from the default (0x2E8A) to your own!
- + *
- + * \note This function must be called prior to \ref pico_stdio_usb to have any effect. This function is not
- + * available if tinyUSB is explicitly linked; in that case the device should be configured using the tinyUSB API.
- + *
- + * \param *CDC_config
- + */
- +void stdio_usb_set_custom_descriptors(stdio_custom_CDC_config_t* CDC_config);
- +#endif
- #ifdef __cplusplus
- }
- #endif
- diff --git a/src/rp2_common/pico_stdio_usb/stdio_usb.c b/src/rp2_common/pico_stdio_usb/stdio_usb.c
- index cd2e2c9..4165304 100644
- --- a/src/rp2_common/pico_stdio_usb/stdio_usb.c
- +++ b/src/rp2_common/pico_stdio_usb/stdio_usb.c
- @@ -168,16 +168,59 @@ bool stdio_usb_init(void) {
- bool stdio_usb_connected(void) {
- return tud_cdc_connected();
- }
- +
- +#if !defined(LIB_TINYUSB_DEVICE) // only provide the custom override if the user did not explicitly pull in tinyUSB
- +/* forward declarations of the customizing functions inside our stdio_usb_descriptors.c */
- +tusb_desc_device_t *tud_descriptor_device_ptr();
- +void tud_descriptor_override_manufacturer(const char *new_value);
- +void tud_descriptor_override_product(const char *new_value);
- +void tud_descriptor_override_serial(const char *new_value);
- +void stdio_usb_set_custom_descriptors(stdio_custom_CDC_config_t* CDC_config) {
- + tusb_desc_device_t* tusb_device = tud_descriptor_device_ptr();
- + if (CDC_config == 0 || tusb_device == 0 || stdio_usb_connected()) {
- + return;
- + }
- + if (CDC_config->str_manufacturer != 0) {
- + tud_descriptor_override_manufacturer(CDC_config->str_manufacturer);
- + }
- + if (CDC_config->str_product != 0) {
- + tud_descriptor_override_product(CDC_config->str_product);
- + }
- + if (CDC_config->str_serial != 0) {
- + tud_descriptor_override_serial(CDC_config->str_serial);
- + }
- + if (CDC_config->idVendor != 0) {
- + tusb_device->idVendor = CDC_config->idVendor;
- + }
- + if (CDC_config->idProduct != 0) {
- + tusb_device->idProduct = CDC_config->idProduct;
- + }
- +}
- +#else /* !defined(LIB_TINYUSB_DEVICE) */
- +void stdio_usb_set_custom_descriptors(stdio_custom_CDC_config_t* CDC_config)
- +{
- + (void)CDC_config;
- +}
- +#endif /* !defined(LIB_TINYUSB_DEVICE) */
- +
- #else
- #warning stdio USB was configured along with user use of TinyUSB device mode, but CDC is not enabled
- bool stdio_usb_init(void) {
- return false;
- }
- +void stdio_usb_set_custom_descriptors(stdio_custom_CDC_config_t* CDC_config)
- +{
- + (void)CDC_config;
- +}
- #endif // CFG_TUD_ENABLED && CFG_TUD_CDC
- #else
- #warning stdio USB was configured, but is being disabled as TinyUSB host is explicitly linked
- bool stdio_usb_init(void) {
- return false;
- }
- +void stdio_usb_set_custom_descriptors(stdio_custom_CDC_config_t* CDC_config)
- +{
- + (void)CDC_config;
- +}
- #endif // !LIB_TINYUSB_HOST
- diff --git a/src/rp2_common/pico_stdio_usb/stdio_usb_descriptors.c b/src/rp2_common/pico_stdio_usb/stdio_usb_descriptors.c
- index b3cfed0..cee1141 100644
- --- a/src/rp2_common/pico_stdio_usb/stdio_usb_descriptors.c
- +++ b/src/rp2_common/pico_stdio_usb/stdio_usb_descriptors.c
- @@ -66,7 +66,7 @@
- // Note: descriptors returned from callbacks must exist long enough for transfer to complete
- -static const tusb_desc_device_t usbd_desc_device = {
- +static tusb_desc_device_t usbd_desc_device = {
- .bLength = sizeof(tusb_desc_device_t),
- .bDescriptorType = TUSB_DESC_DEVICE,
- .bcdUSB = 0x0200,
- @@ -101,7 +101,7 @@ static const uint8_t usbd_desc_cfg[USBD_DESC_LEN] = {
- static char usbd_serial_str[PICO_UNIQUE_BOARD_ID_SIZE_BYTES * 2 + 1];
- -static const char *const usbd_desc_str[] = {
- +static const char *usbd_desc_str[] = {
- [USBD_STR_MANUF] = "Raspberry Pi",
- [USBD_STR_PRODUCT] = "Pico",
- [USBD_STR_SERIAL] = usbd_serial_str,
- @@ -148,4 +148,20 @@ const uint16_t *tud_descriptor_string_cb(uint8_t index, __unused uint16_t langid
- return desc_str;
- }
- +tusb_desc_device_t *tud_descriptor_device_ptr() {
- + return &usbd_desc_device;
- +}
- +
- +void tud_descriptor_override_manufacturer(const char *new_value) {
- + usbd_desc_str[USBD_STR_MANUF] = new_value;
- +}
- +
- +void tud_descriptor_override_product(const char *new_value) {
- + usbd_desc_str[USBD_STR_PRODUCT] = new_value;
- +}
- +
- +void tud_descriptor_override_serial(const char *new_value) {
- + usbd_desc_str[USBD_STR_SERIAL] = new_value;
- +}
- +
- #endif
Advertisement
Add Comment
Please, Sign In to add comment