@@ -86,6 +86,88 @@ Adafruit_USBD_Device TinyUSBDevice;
86
86
87
87
Adafruit_USBD_Device::Adafruit_USBD_Device (void ) {}
88
88
89
+ void Adafruit_USBD_Device::setConfigurationBuffer (uint8_t *buf,
90
+ uint32_t buflen) {
91
+ if (buflen < _desc_cfg_maxlen) {
92
+ return ;
93
+ }
94
+
95
+ memcpy (buf, _desc_cfg, _desc_cfg_len);
96
+ _desc_cfg = buf;
97
+ _desc_cfg_maxlen = buflen;
98
+ }
99
+
100
+ void Adafruit_USBD_Device::setID (uint16_t vid, uint16_t pid) {
101
+ _desc_device.idVendor = vid;
102
+ _desc_device.idProduct = pid;
103
+ }
104
+
105
+ void Adafruit_USBD_Device::setVersion (uint16_t bcd) {
106
+ _desc_device.bcdUSB = bcd;
107
+ }
108
+
109
+ void Adafruit_USBD_Device::setDeviceVersion (uint16_t bcd) {
110
+ _desc_device.bcdDevice = bcd;
111
+ }
112
+
113
+ void Adafruit_USBD_Device::setLanguageDescriptor (uint16_t language_id) {
114
+ _desc_str_arr[STRID_LANGUAGE] = (const char *)((uint32_t )language_id);
115
+ }
116
+
117
+ void Adafruit_USBD_Device::setManufacturerDescriptor (const char *s) {
118
+ _desc_str_arr[STRID_MANUFACTURER] = s;
119
+ }
120
+
121
+ void Adafruit_USBD_Device::setProductDescriptor (const char *s) {
122
+ _desc_str_arr[STRID_PRODUCT] = s;
123
+ }
124
+
125
+ void Adafruit_USBD_Device::task (void ) { tud_task (); }
126
+
127
+ bool Adafruit_USBD_Device::mounted (void ) { return tud_mounted (); }
128
+
129
+ bool Adafruit_USBD_Device::suspended (void ) { return tud_suspended (); }
130
+
131
+ bool Adafruit_USBD_Device::ready (void ) { return tud_ready (); }
132
+
133
+ bool Adafruit_USBD_Device::remoteWakeup (void ) { return tud_remote_wakeup (); }
134
+
135
+ bool Adafruit_USBD_Device::detach (void ) { return tud_disconnect (); }
136
+
137
+ bool Adafruit_USBD_Device::attach (void ) { return tud_connect (); }
138
+
139
+ // EPS32 use built-in core descriptor builder.
140
+ // Therefore most of descriptors are stubs only
141
+ #ifdef ARDUINO_ARCH_ESP32
142
+
143
+ void Adafruit_USBD_Device::clearConfiguration (void ) {
144
+
145
+ }
146
+
147
+ bool Adafruit_USBD_Device::addInterface (Adafruit_USBD_Interface &itf) {
148
+ (void )itf;
149
+ return true ;
150
+ }
151
+
152
+ bool Adafruit_USBD_Device::begin (uint8_t rhport) {
153
+ (void ) rhport;
154
+ return true ;
155
+ }
156
+
157
+ uint8_t Adafruit_USBD_Device::getSerialDescriptor (uint16_t *serial_utf16) {
158
+ (void ) serial_utf16;
159
+ return 0 ;
160
+ }
161
+
162
+ uint16_t const *Adafruit_USBD_Device::descriptor_string_cb (uint8_t index,
163
+ uint16_t langid) {
164
+ (void )index;
165
+ (void )langid;
166
+ return NULL ;
167
+ }
168
+
169
+ #else
170
+
89
171
void Adafruit_USBD_Device::clearConfiguration (void ) {
90
172
tusb_desc_device_t const desc_dev = {.bLength = sizeof (tusb_desc_device_t ),
91
173
.bDescriptorType = TUSB_DESC_DEVICE,
@@ -186,59 +268,6 @@ bool Adafruit_USBD_Device::addInterface(Adafruit_USBD_Interface &itf) {
186
268
return true ;
187
269
}
188
270
189
- void Adafruit_USBD_Device::setConfigurationBuffer (uint8_t *buf,
190
- uint32_t buflen) {
191
- if (buflen < _desc_cfg_maxlen) {
192
- return ;
193
- }
194
-
195
- memcpy (buf, _desc_cfg, _desc_cfg_len);
196
- _desc_cfg = buf;
197
- _desc_cfg_maxlen = buflen;
198
- }
199
-
200
- void Adafruit_USBD_Device::setID (uint16_t vid, uint16_t pid) {
201
- _desc_device.idVendor = vid;
202
- _desc_device.idProduct = pid;
203
- }
204
-
205
- void Adafruit_USBD_Device::setVersion (uint16_t bcd) {
206
- _desc_device.bcdUSB = bcd;
207
- }
208
-
209
- void Adafruit_USBD_Device::setDeviceVersion (uint16_t bcd) {
210
- _desc_device.bcdDevice = bcd;
211
- }
212
-
213
- void Adafruit_USBD_Device::setLanguageDescriptor (uint16_t language_id) {
214
- _desc_str_arr[STRID_LANGUAGE] = (const char *)((uint32_t )language_id);
215
- }
216
-
217
- void Adafruit_USBD_Device::setManufacturerDescriptor (const char *s) {
218
- _desc_str_arr[STRID_MANUFACTURER] = s;
219
- }
220
-
221
- void Adafruit_USBD_Device::setProductDescriptor (const char *s) {
222
- _desc_str_arr[STRID_PRODUCT] = s;
223
- }
224
-
225
- uint8_t Adafruit_USBD_Device::getSerialDescriptor (uint16_t *serial_utf16) {
226
- uint8_t serial_id[16 ] __attribute__ ((aligned (4 )));
227
- uint8_t const serial_len = TinyUSB_Port_GetSerialNumber (serial_id);
228
-
229
- for (uint8_t i = 0 ; i < serial_len; i++) {
230
- for (uint8_t j = 0 ; j < 2 ; j++) {
231
- const char nibble_to_hex[16 ] = {' 0' , ' 1' , ' 2' , ' 3' , ' 4' , ' 5' , ' 6' , ' 7' ,
232
- ' 8' , ' 9' , ' A' , ' B' , ' C' , ' D' , ' E' , ' F' };
233
-
234
- uint8_t nibble = (serial_id[i] >> (j * 4 )) & 0xf ;
235
- serial_utf16[1 + i * 2 + (1 - j)] = nibble_to_hex[nibble]; // UTF-16-LE
236
- }
237
- }
238
-
239
- return 2 * serial_len;
240
- }
241
-
242
271
bool Adafruit_USBD_Device::begin (uint8_t rhport) {
243
272
clearConfiguration ();
244
273
@@ -250,43 +279,31 @@ bool Adafruit_USBD_Device::begin(uint8_t rhport) {
250
279
_desc_device.bDeviceSubClass = MISC_SUBCLASS_COMMON;
251
280
_desc_device.bDeviceProtocol = MISC_PROTOCOL_IAD;
252
281
253
- #ifndef ARDUINO_ARCH_ESP32
254
282
SerialTinyUSB.begin (115200 );
255
283
256
284
// Init device hardware and call tusb_init()
257
285
TinyUSB_Port_InitDevice (rhport);
258
- #endif
259
286
260
287
return true ;
261
288
}
262
289
263
- void Adafruit_USBD_Device::task (void ) { tud_task (); }
264
-
265
- bool Adafruit_USBD_Device::mounted (void ) { return tud_mounted (); }
266
-
267
- bool Adafruit_USBD_Device::suspended (void ) { return tud_suspended (); }
268
-
269
- bool Adafruit_USBD_Device::ready (void ) { return tud_ready (); }
270
-
271
- bool Adafruit_USBD_Device::remoteWakeup (void ) { return tud_remote_wakeup (); }
272
-
273
- bool Adafruit_USBD_Device::detach (void ) { return tud_disconnect (); }
274
-
275
- bool Adafruit_USBD_Device::attach (void ) { return tud_connect (); }
290
+ uint8_t Adafruit_USBD_Device::getSerialDescriptor (uint16_t *serial_utf16) {
291
+ uint8_t serial_id[16 ] __attribute__ ((aligned (4 )));
292
+ uint8_t const serial_len = TinyUSB_Port_GetSerialNumber (serial_id);
276
293
277
- #ifdef ARDUINO_ARCH_ESP32
294
+ for (uint8_t i = 0 ; i < serial_len; i++) {
295
+ for (uint8_t j = 0 ; j < 2 ; j++) {
296
+ const char nibble_to_hex[16 ] = {' 0' , ' 1' , ' 2' , ' 3' , ' 4' , ' 5' , ' 6' , ' 7' ,
297
+ ' 8' , ' 9' , ' A' , ' B' , ' C' , ' D' , ' E' , ' F' };
278
298
279
- // EPS32 use built-in core descriptor builder
280
- uint16_t const *Adafruit_USBD_Device::descriptor_string_cb (uint8_t index,
281
- uint16_t langid) {
282
- (void )index;
283
- (void )langid;
299
+ uint8_t nibble = (serial_id[i] >> (j * 4 )) & 0xf ;
300
+ serial_utf16[1 + i * 2 + (1 - j)] = nibble_to_hex[nibble]; // UTF-16-LE
301
+ }
302
+ }
284
303
285
- return NULL ;
304
+ return 2 * serial_len ;
286
305
}
287
306
288
- #else
289
-
290
307
static int strcpy_utf16 (const char *s, uint16_t *buf, int bufsize);
291
308
uint16_t const *Adafruit_USBD_Device::descriptor_string_cb (uint8_t index,
292
309
uint16_t langid) {
0 commit comments