Skip to content

Commit 6a9478b

Browse files
committed
Add reset interface to dev_multi_cdc example
1 parent 4c3a3dc commit 6a9478b

File tree

3 files changed

+50
-30
lines changed

3 files changed

+50
-30
lines changed

usb/device/dev_multi_cdc/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ target_sources(dev_multi_cdc PUBLIC
1111
target_include_directories(dev_multi_cdc PUBLIC
1212
${CMAKE_CURRENT_LIST_DIR})
1313

14+
target_compile_definitions(dev_multi_cdc PUBLIC
15+
PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE=1
16+
PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_MS_OS_20_DESCRIPTOR=1
17+
PICO_STDIO_USB_RESET_INTERFACE_MS_OS_20_DESCRIPTOR_ITF=4
18+
)
19+
1420
# In addition to pico_stdlib required for common PicoSDK functionality, add dependency on tinyusb_device
1521
# for TinyUSB device support and tinyusb_board for the additional board support library used by the example
1622
target_link_libraries(dev_multi_cdc PUBLIC pico_stdlib pico_unique_id tinyusb_device tinyusb_board)

usb/device/dev_multi_cdc/tusb_config.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
#define CFG_TUD_CDC_TX_BUFSIZE (64)
3232
#define CFG_TUD_CDC_EP_BUFSIZE (64)
3333

34+
// Vendor driver used for Microsoft OS 2.0 descriptor
35+
#define CFG_TUD_VENDOR (1)
36+
#define CFG_TUD_VENDOR_RX_BUFSIZE (256)
37+
#define CFG_TUD_VENDOR_TX_BUFSIZE (256)
38+
3439
#ifndef CFG_TUD_ENDPOINT0_SIZE
3540
#define CFG_TUD_ENDPOINT0_SIZE (64)
3641
#endif

usb/device/dev_multi_cdc/usb_descriptors.c

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,40 @@
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
2046
tusb_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
100132
uint8_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
126135
static uint16_t _desc_str[32 + 1];
127136

0 commit comments

Comments
 (0)