34
34
// USB Information can be defined in variant file e.g pins_arduino.h
35
35
#include " Arduino.h"
36
36
37
- // - USB_VID, USB_PID, USB_MANUFACTURER, USB_PRODUCT are defined on most
38
- // core that has built-in support for TinyUSB. Otherwise
39
- // - BOARD_VENDORID, BOARD_PRODUCTID, BOARD_MANUFACTURER, BOARD_NAME are use
40
- // if defined, mostly on mbed core
37
+ /* VID, PID, Manufacturer and Product name:
38
+ * - For most ports: USB_VID, USB_PID, USB_MANUFACTURER, USB_PRODUCT are
39
+ * defined.
40
+ * - For ESP32: Default USB_MANUFACTURER is Espressif (instead of Adafruit),
41
+ * ARDUINO_BOARD as USB_PRODUCT
42
+ * - For mbed core: BOARD_VENDORID, BOARD_PRODUCTID, BOARD_MANUFACTURER,
43
+ * BOARD_NAME are defined
44
+ */
41
45
42
46
#ifndef USB_VID
43
47
#ifdef BOARD_VENDORID
56
60
#endif
57
61
58
62
#ifndef USB_MANUFACTURER
59
-
60
63
#ifdef BOARD_MANUFACTURER
61
64
#define USB_MANUFACTURER BOARD_MANUFACTURER
65
+ #elif defined(ARDUINO_ARCH_ESP32)
66
+ #define USB_MANUFACTURER " Espressif Systems"
62
67
#else
63
68
#define USB_MANUFACTURER " Adafruit"
64
69
#endif
65
70
#endif
66
71
67
72
#ifndef USB_PRODUCT
68
- #ifdef BOARD_NAME
73
+ #if defined(ARDUINO_BOARD)
74
+ #define USB_PRODUCT ARDUINO_BOARD
75
+ #elif defined(BOARD_NAME)
69
76
#define USB_PRODUCT BOARD_NAME
70
77
#else
71
78
#define USB_PRODUCT " Unknown"
@@ -84,7 +91,12 @@ enum { STRID_LANGUAGE = 0, STRID_MANUFACTURER, STRID_PRODUCT, STRID_SERIAL };
84
91
85
92
Adafruit_USBD_Device TinyUSBDevice;
86
93
87
- Adafruit_USBD_Device::Adafruit_USBD_Device (void ) {}
94
+ Adafruit_USBD_Device::Adafruit_USBD_Device (void ) {
95
+ #if defined(ARDUINO_ARCH_ESP32) && ARDUINO_USB_CDC_ON_BOOT && !ARDUINO_USB_MODE
96
+ // auto begin for ESP32 USB OTG Mode with CDC on boot
97
+ begin (0 );
98
+ #endif
99
+ }
88
100
89
101
void Adafruit_USBD_Device::setConfigurationBuffer (uint8_t *buf,
90
102
uint32_t buflen) {
@@ -152,36 +164,6 @@ bool Adafruit_USBD_Device::detach(void) { return tud_disconnect(); }
152
164
153
165
bool Adafruit_USBD_Device::attach (void ) { return tud_connect (); }
154
166
155
- // EPS32 use built-in core descriptor builder.
156
- // Therefore most of descriptors are stubs only
157
- #ifdef ARDUINO_ARCH_ESP32
158
-
159
- void Adafruit_USBD_Device::clearConfiguration (void ) {}
160
-
161
- bool Adafruit_USBD_Device::addInterface (Adafruit_USBD_Interface &itf) {
162
- (void )itf;
163
- return true ;
164
- }
165
-
166
- bool Adafruit_USBD_Device::begin (uint8_t rhport) {
167
- (void )rhport;
168
- return true ;
169
- }
170
-
171
- uint8_t Adafruit_USBD_Device::getSerialDescriptor (uint16_t *serial_utf16) {
172
- (void )serial_utf16;
173
- return 0 ;
174
- }
175
-
176
- uint16_t const *Adafruit_USBD_Device::descriptor_string_cb (uint8_t index,
177
- uint16_t langid) {
178
- (void )index;
179
- (void )langid;
180
- return NULL ;
181
- }
182
-
183
- #else
184
-
185
167
void Adafruit_USBD_Device::clearConfiguration (void ) {
186
168
tusb_desc_device_t const desc_dev = {.bLength = sizeof (tusb_desc_device_t ),
187
169
.bDescriptorType = TUSB_DESC_DEVICE,
@@ -261,10 +243,28 @@ bool Adafruit_USBD_Device::begin(uint8_t rhport) {
261
243
_desc_device.bDeviceSubClass = MISC_SUBCLASS_COMMON;
262
244
_desc_device.bDeviceProtocol = MISC_PROTOCOL_IAD;
263
245
246
+ #if defined(ARDUINO_ARCH_ESP32)
247
+ #if ARDUINO_USB_CDC_ON_BOOT && !ARDUINO_USB_MODE
248
+ // follow USBCDC cdc descriptor
249
+ uint8_t itfnum = allocInterface (2 );
250
+ uint8_t strid = addStringDescriptor (" TinyUSB Serial" );
251
+ uint8_t const desc_cdc[TUD_CDC_DESC_LEN] = {
252
+ TUD_CDC_DESCRIPTOR (itfnum, strid, 0x85 , 64 , 0x03 , 0x84 , 64 )};
253
+
254
+ memcpy (_desc_cfg + _desc_cfg_len, desc_cdc, sizeof (desc_cdc));
255
+ _desc_cfg_len += sizeof (desc_cdc);
256
+
257
+ // Update configuration descriptor
258
+ tusb_desc_configuration_t *config = (tusb_desc_configuration_t *)_desc_cfg;
259
+ config->wTotalLength = _desc_cfg_len;
260
+ config->bNumInterfaces = _itf_count;
261
+ #endif
262
+ #else
264
263
SerialTinyUSB.begin (115200 );
265
264
266
265
// Init device hardware and call tusb_init()
267
266
TinyUSB_Port_InitDevice (rhport);
267
+ #endif
268
268
269
269
return true ;
270
270
}
@@ -520,6 +520,4 @@ void tud_dfu_runtime_reboot_to_dfu_cb(void) {
520
520
}
521
521
#endif
522
522
523
- #endif // ESP32
524
-
525
523
#endif // CFG_TUD_ENABLED
0 commit comments