28
28
29
29
#include " Adafruit_USBD_HID.h"
30
30
31
- #define EPOUT 0x00
32
- #define EPIN 0x80
33
-
34
31
uint8_t const _ascii2keycode[128 ][2 ] = {HID_ASCII_TO_KEYCODE};
35
32
static Adafruit_USBD_HID *_hid_instances[CFG_TUD_HID] = {0 };
36
33
@@ -94,7 +91,7 @@ Adafruit_USBD_HID::Adafruit_USBD_HID(uint8_t const *desc_report, uint16_t len,
94
91
_instance = _instance_count++;
95
92
_hid_instances[_instance] = this ;
96
93
97
- uint16_t const desc_len = getInterfaceDescriptor ( 0 , NULL , 0 );
94
+ uint16_t const desc_len = getInterfaceDescriptorLen ( );
98
95
tinyusb_enable_interface (USB_INTERFACE_HID, desc_len, hid_load_descriptor);
99
96
#endif
100
97
}
@@ -132,11 +129,11 @@ uint16_t Adafruit_USBD_HID::makeItfDesc(uint8_t itfnum, uint8_t *buf,
132
129
return 0 ;
133
130
}
134
131
135
- uint8_t const desc_inout[] = {
136
- TUD_HID_INOUT_DESCRIPTOR ( itfnum, 0 , _protocol, _desc_report_len, ep_in,
137
- ep_out, CFG_TUD_HID_EP_BUFSIZE, _interval_ms)};
132
+ uint8_t const desc_inout[] = {TUD_HID_INOUT_DESCRIPTOR (
133
+ itfnum, _strid , _protocol, _desc_report_len, ep_in, ep_out ,
134
+ CFG_TUD_HID_EP_BUFSIZE, _interval_ms)};
138
135
uint8_t const desc_in_only[] = {
139
- TUD_HID_DESCRIPTOR (itfnum, 0 , _protocol, _desc_report_len, ep_in,
136
+ TUD_HID_DESCRIPTOR (itfnum, _strid , _protocol, _desc_report_len, ep_in,
140
137
CFG_TUD_HID_EP_BUFSIZE, _interval_ms)};
141
138
142
139
uint8_t const *desc;
@@ -155,17 +152,30 @@ uint16_t Adafruit_USBD_HID::makeItfDesc(uint8_t itfnum, uint8_t *buf,
155
152
if (bufsize < len) {
156
153
return 0 ;
157
154
}
158
-
159
155
memcpy (buf, desc, len);
160
156
}
161
157
162
158
return len;
163
159
}
164
160
165
- uint16_t Adafruit_USBD_HID::getInterfaceDescriptor (uint8_t itfnum, uint8_t *buf,
161
+ uint16_t Adafruit_USBD_HID::getInterfaceDescriptor (uint8_t itfnum_deprecated,
162
+ uint8_t *buf,
166
163
uint16_t bufsize) {
167
- // usb core will automatically update endpoint number
168
- return makeItfDesc (itfnum, buf, bufsize, EPIN, EPOUT);
164
+ uint8_t itfnum = 0 ;
165
+ uint8_t ep_in = 0 ;
166
+ uint8_t ep_out = 0 ;
167
+
168
+ // null buffer is used to get the length of descriptor only
169
+ if (buf) {
170
+ itfnum = TinyUSBDevice.allocInterface (1 );
171
+ ep_in = TinyUSBDevice.allocEndpoint (TUSB_DIR_IN);
172
+
173
+ if (_out_endpoint) {
174
+ TinyUSBDevice.allocEndpoint (TUSB_DIR_OUT);
175
+ }
176
+ }
177
+
178
+ return makeItfDesc (itfnum, buf, bufsize, ep_in, ep_out);
169
179
}
170
180
171
181
bool Adafruit_USBD_HID::begin (void ) {
0 commit comments