@@ -46,21 +46,42 @@ Adafruit_USBD_CDC::Adafruit_USBD_CDC(void) { _instance = INVALID_INSTANCE; }
46
46
47
47
#if CFG_TUD_ENABLED
48
48
49
- #define EPOUT 0x00
50
- #define EPIN 0x80
51
-
52
- uint16_t Adafruit_USBD_CDC::getInterfaceDescriptor (uint8_t itfnum, uint8_t *buf,
49
+ uint16_t Adafruit_USBD_CDC::getInterfaceDescriptor (uint8_t itfnum_deprecated,
50
+ uint8_t *buf,
53
51
uint16_t bufsize) {
52
+ (void )itfnum_deprecated;
53
+
54
54
// CDC is mostly always existed for DFU
55
- // usb core will automatically update endpoint number
56
- uint8_t desc[] = {TUD_CDC_DESCRIPTOR (itfnum, 0 , EPIN, 8 , EPOUT, EPIN, 64 )};
55
+ uint8_t itfnum = 0 ;
56
+ uint8_t ep_notif = 0 ;
57
+ uint8_t ep_in = 0 ;
58
+ uint8_t ep_out = 0 ;
59
+
60
+ if (buf) {
61
+ itfnum = TinyUSBDevice.allocInterface (2 );
62
+ ep_notif = TinyUSBDevice.allocEndpoint (TUSB_DIR_IN);
63
+ ep_in = TinyUSBDevice.allocEndpoint (TUSB_DIR_IN);
64
+ ep_out = TinyUSBDevice.allocEndpoint (TUSB_DIR_OUT);
65
+ }
66
+
67
+ #if TINYUSB_API_VERSION < 20400
68
+ // backward compatible for core that include pre-2.4.0 TinyUSB
69
+ uint8_t _strid = 0 ;
70
+ #endif
71
+
72
+ uint8_t const desc[] = {
73
+ TUD_CDC_DESCRIPTOR (itfnum, _strid, ep_notif, 8 , ep_out, ep_in, 64 )};
74
+
57
75
uint16_t const len = sizeof (desc);
58
76
59
- if (bufsize < len) {
60
- return 0 ;
77
+ // null buffer is used to get the length of descriptor only
78
+ if (buf) {
79
+ if (bufsize < len) {
80
+ return 0 ;
81
+ }
82
+ memcpy (buf, desc, len);
61
83
}
62
84
63
- memcpy (buf, desc, len);
64
85
return len;
65
86
}
66
87
@@ -268,9 +289,10 @@ void tud_cdc_line_state_cb(uint8_t instance, bool dtr, bool rts) {
268
289
// Device stack is not enabled (probably in host mode)
269
290
#warning "TinyUSB Host selected. No output to Serial will occur!"
270
291
271
- uint16_t Adafruit_USBD_CDC::getInterfaceDescriptor (uint8_t itfnum, uint8_t *buf,
292
+ uint16_t Adafruit_USBD_CDC::getInterfaceDescriptor (uint8_t itfnum_deprecated,
293
+ uint8_t *buf,
272
294
uint16_t bufsize) {
273
- (void )itfnum ;
295
+ (void )itfnum_deprecated ;
274
296
(void )buf;
275
297
(void )bufsize;
276
298
0 commit comments