@@ -47,8 +47,8 @@ static char isEndpointHalt = 0;
47
47
// ==================================================================
48
48
49
49
extern const uint16_t STRING_LANGUAGE[];
50
- extern const uint16_t STRING_IPRODUCT [];
51
- extern const uint16_t STRING_IMANUFACTURER [];
50
+ extern const uint8_t STRING_PRODUCT [];
51
+ extern const uint8_t STRING_MANUFACTURER [];
52
52
extern const DeviceDescriptor USB_DeviceDescriptor;
53
53
extern const DeviceDescriptor USB_DeviceDescriptorA;
54
54
@@ -57,23 +57,25 @@ const uint16_t STRING_LANGUAGE[2] = {
57
57
0x0409 // English
58
58
};
59
59
60
- const uint16_t STRING_IPRODUCT[17 ] = {
61
- (3 <<8 ) | (2 +2 *16 ),
62
- #if USB_PID == USB_PID_LEONARDO
63
- ' A' ,' r' ,' d' ,' u' ,' i' ,' n' ,' o' ,' ' ,' L' ,' e' ,' o' ,' n' ,' a' ,' r' ,' d' ,' o'
64
- #elif USB_PID == USB_PID_MICRO
65
- ' A' ,' r' ,' d' ,' u' ,' i' ,' n' ,' o' ,' ' ,' M' ,' i' ,' c' ,' r' ,' o' ,' ' ,' ' ,' '
66
- #elif USB_PID == USB_PID_DUE
67
- ' A' ,' r' ,' d' ,' u' ,' i' ,' n' ,' o' ,' ' ,' D' ,' u' ,' e' ,' ' ,' ' ,' ' ,' ' ,' '
60
+ #ifndef USB_PRODUCT
61
+ // Use a hardcoded product name if none is provided
62
+ #if USB_PID == USB_PID_DUE
63
+ #define USB_PRODUCT " Arduino Due"
68
64
#else
69
- #error "Need an USB PID"
65
+ #define USB_PRODUCT " USB IO Board"
66
+ #endif
70
67
#endif
71
- };
72
68
73
- const uint16_t STRING_IMANUFACTURER[12 ] = {
74
- (3 <<8 ) | (2 +2 *11 ),
75
- ' A' ,' r' ,' d' ,' u' ,' i' ,' n' ,' o' ,' ' ,' L' ,' L' ,' C'
76
- };
69
+ const uint8_t STRING_PRODUCT[] = USB_PRODUCT;
70
+
71
+ #if USB_VID == 0x2341
72
+ #define USB_MANUFACTURER " Arduino LLC"
73
+ #elif !defined(USB_MANUFACTURER)
74
+ // Fall through to unknown if no manufacturer name was provided in a macro
75
+ #define USB_MANUFACTURER " Unknown"
76
+ #endif
77
+
78
+ const uint8_t STRING_MANUFACTURER[12 ] = USB_MANUFACTURER;
77
79
78
80
#ifdef CDC_ENABLED
79
81
#define DEVICE_CLASS 0x02
@@ -241,6 +243,21 @@ int USBD_SendControl(uint8_t flags, const void* d, uint32_t len)
241
243
return length;
242
244
}
243
245
246
+ // Send a USB descriptor string. The string is stored as a
247
+ // plain ASCII string but is sent out as UTF-16 with the
248
+ // correct 2-byte prefix
249
+ static bool USB_SendStringDescriptor (const uint8_t *string, int wLength) {
250
+ uint16_t buff[64 ];
251
+ int l = 1 ;
252
+ wLength-=2 ;
253
+ while (*string && wLength>0 ) {
254
+ buff[l++] = (uint8_t )(*string++);
255
+ wLength-=2 ;
256
+ }
257
+ buff[0 ] = (3 <<8 ) | (l*2 );
258
+ return USBD_SendControl (0 , (uint8_t *)buff, l*2 );
259
+ }
260
+
244
261
// Does not timeout or cross fifo boundaries
245
262
// Will only work for transfers <= 64 bytes
246
263
// TODO
@@ -400,19 +417,19 @@ static bool USBD_SendDescriptor(Setup& setup)
400
417
TRACE_CORE (puts (" => USBD_SendDescriptor : USB_STRING_DESCRIPTOR_TYPE\r\n " );)
401
418
if (setup.wValueL == 0 ) {
402
419
desc_addr = (const uint8_t *)&STRING_LANGUAGE;
403
- }
420
+ }
404
421
else if (setup.wValueL == IPRODUCT) {
405
- desc_addr = ( const uint8_t *)&STRING_IPRODUCT ;
406
- }
422
+ return USB_SendStringDescriptor (STRING_PRODUCT, setup. wLength ) ;
423
+ }
407
424
else if (setup.wValueL == IMANUFACTURER) {
408
- desc_addr = ( const uint8_t *)&STRING_IMANUFACTURER ;
409
- }
425
+ return USB_SendStringDescriptor (STRING_MANUFACTURER, setup. wLength ) ;
426
+ }
410
427
else {
411
428
return false ;
412
- }
413
- if ( *desc_addr > setup.wLength ) {
414
- desc_length = setup.wLength ;
415
- }
429
+ }
430
+ if ( *desc_addr > setup.wLength ) {
431
+ desc_length = setup.wLength ;
432
+ }
416
433
}
417
434
else if (USB_DEVICE_QUALIFIER == t)
418
435
{
0 commit comments