77#include <tusb.h>
88#include <bsp/board_api.h>
99
10+ #include "pico/usb_reset_interface.h"
11+
1012// set some example Vendor and Product ID
1113// the board will use to identify at the host
1214#define _PID_MAP (itf , n ) ( (CFG_TUD_##itf) << (n) )
1315#define CDC_EXAMPLE_VID 0xCafe
1416// use _PID_MAP to generate unique PID for each interface
1517#define CDC_EXAMPLE_PID (0x4000 | _PID_MAP(CDC, 0))
1618// set USB 2.0
17- #define CDC_EXAMPLE_BCD 0x0200
19+ #define CDC_EXAMPLE_BCD 0x0210
20+
21+ // String descriptors referenced with .i... in the descriptor tables
22+
23+ enum {
24+ STRID_LANGID = 0 , // 0: supported language ID
25+ STRID_MANUFACTURER , // 1: Manufacturer
26+ STRID_PRODUCT , // 2: Product
27+ STRID_SERIAL , // 3: Serials
28+ STRID_CDC_0 , // 4: CDC Interface 0
29+ STRID_CDC_1 , // 5: CDC Interface 1
30+ STRID_RPI_RESET , // 6: Reset Interface
31+ };
32+
33+ // array of pointer to string descriptors
34+ char const * string_desc_arr [] = {
35+ // switched because board is little endian
36+ (const char []) { 0x09 , 0x04 }, // 0: supported language is English (0x0409)
37+ "Raspberry Pi" , // 1: Manufacturer
38+ "Pico (2)" , // 2: Product
39+ NULL , // 3: Serials (null so it uses unique ID if available)
40+ "Pico SDK stdio" , // 4: CDC Interface 0
41+ "Custom CDC" , // 5: CDC Interface 1,
42+ "Reset" // 6: Reset Interface
43+ };
1844
1945// defines a descriptor that will be communicated to the host
2046tusb_desc_device_t const desc_device = {
@@ -32,9 +58,9 @@ tusb_desc_device_t const desc_device = {
3258 .idProduct = CDC_EXAMPLE_PID ,
3359 .bcdDevice = 0x0100 , // Device release number
3460
35- .iManufacturer = 0x01 , // Index of manufacturer string
36- .iProduct = 0x02 , // Index of product string
37- .iSerialNumber = 0x03 , // Index of serial number string
61+ .iManufacturer = STRID_MANUFACTURER , // Index of manufacturer string
62+ .iProduct = STRID_PRODUCT , // Index of product string
63+ .iSerialNumber = STRID_SERIAL , // Index of serial number string
3864
3965 .bNumConfigurations = 0x01 // 1 configuration
4066};
@@ -47,11 +73,14 @@ enum {
4773 ITF_NUM_CDC_0_DATA ,
4874 ITF_NUM_CDC_1 ,
4975 ITF_NUM_CDC_1_DATA ,
76+ ITF_NUM_RPI_RESET ,
5077 ITF_NUM_TOTAL
5178};
5279
80+ static_assert (ITF_NUM_RPI_RESET == PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF , "ITF_NUM_RPI_RESET must be equal to the PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF set in CMakeLists.txt" );
81+
5382// total length of configuration descriptor
54- #define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + CFG_TUD_CDC * TUD_CDC_DESC_LEN)
83+ #define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + CFG_TUD_CDC * TUD_CDC_DESC_LEN + TUD_RPI_RESET_DESC_LEN )
5584
5685// define endpoint numbers
5786#define EPNUM_CDC_0_NOTIF 0x81 // notification endpoint for CDC 0
@@ -68,14 +97,17 @@ uint8_t const desc_configuration[] = {
6897 TUD_CONFIG_DESCRIPTOR (1 , ITF_NUM_TOTAL , 0 , CONFIG_TOTAL_LEN , 0x80 , 100 ),
6998
7099 // CDC 0: Communication Interface - TODO: get 64 from tusb_config.h
71- TUD_CDC_DESCRIPTOR (ITF_NUM_CDC_0 , 4 , EPNUM_CDC_0_NOTIF , 8 , EPNUM_CDC_0_OUT , EPNUM_CDC_0_IN , 64 ),
100+ TUD_CDC_DESCRIPTOR (ITF_NUM_CDC_0 , STRID_CDC_0 , EPNUM_CDC_0_NOTIF , 8 , EPNUM_CDC_0_OUT , EPNUM_CDC_0_IN , 64 ),
72101 // CDC 0: Data Interface
73102 //TUD_CDC_DESCRIPTOR(ITF_NUM_CDC_0_DATA, 4, 0x01, 0x02),
74103
75104 // CDC 1: Communication Interface - TODO: get 64 from tusb_config.h
76- TUD_CDC_DESCRIPTOR (ITF_NUM_CDC_1 , 4 , EPNUM_CDC_1_NOTIF , 8 , EPNUM_CDC_1_OUT , EPNUM_CDC_1_IN , 64 ),
105+ TUD_CDC_DESCRIPTOR (ITF_NUM_CDC_1 , STRID_CDC_1 , EPNUM_CDC_1_NOTIF , 8 , EPNUM_CDC_1_OUT , EPNUM_CDC_1_IN , 64 ),
77106 // CDC 1: Data Interface
78107 //TUD_CDC_DESCRIPTOR(ITF_NUM_CDC_1_DATA, 4, 0x03, 0x04),
108+
109+ // RPi Reset Interface
110+ TUD_RPI_RESET_DESCRIPTOR (ITF_NUM_RPI_RESET , STRID_RPI_RESET ),
79111};
80112
81113// called when host requests to get configuration descriptor
@@ -99,29 +131,6 @@ tusb_desc_device_qualifier_t const desc_device_qualifier = {
99131// called when host requests to get device qualifier descriptor
100132uint8_t const * tud_descriptor_device_qualifier_cb (void );
101133
102- // String descriptors referenced with .i... in the descriptor tables
103-
104- enum {
105- STRID_LANGID = 0 , // 0: supported language ID
106- STRID_MANUFACTURER , // 1: Manufacturer
107- STRID_PRODUCT , // 2: Product
108- STRID_SERIAL , // 3: Serials
109- STRID_CDC_0 , // 4: CDC Interface 0
110- STRID_CDC_1 , // 5: CDC Interface 1
111- };
112-
113- // array of pointer to string descriptors
114- char const * string_desc_arr [] = {
115- // switched because board is little endian
116- (const char []) { 0x09 , 0x04 }, // 0: supported language is English (0x0409)
117- "Raspberry Pi" , // 1: Manufacturer
118- "Pico (2)" , // 2: Product
119- NULL , // 3: Serials (null so it uses unique ID if available)
120- "Pico SDK stdio" // 4: CDC Interface 0
121- "Custom CDC" , // 5: CDC Interface 1,
122- "RPiReset" // 6: Reset Interface
123- };
124-
125134// buffer to hold the string descriptor during the request | plus 1 for the null terminator
126135static uint16_t _desc_str [32 + 1 ];
127136
0 commit comments