@@ -46,21 +46,42 @@ Adafruit_USBD_CDC::Adafruit_USBD_CDC(void) { _instance = INVALID_INSTANCE; }
4646
4747#if CFG_TUD_ENABLED
4848
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,
5351 uint16_t bufsize) {
52+ (void )itfnum_deprecated;
53+
5454 // 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+
5775 uint16_t const len = sizeof (desc);
5876
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);
6183 }
6284
63- memcpy (buf, desc, len);
6485 return len;
6586}
6687
@@ -268,9 +289,10 @@ void tud_cdc_line_state_cb(uint8_t instance, bool dtr, bool rts) {
268289// Device stack is not enabled (probably in host mode)
269290#warning "TinyUSB Host selected. No output to Serial will occur!"
270291
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,
272294 uint16_t bufsize) {
273- (void )itfnum ;
295+ (void )itfnum_deprecated ;
274296 (void )buf;
275297 (void )bufsize;
276298
0 commit comments