@@ -39,8 +39,8 @@ volatile u8 RxLEDPulse; /**< Milliseconds remaining for data Rx LED pulse */
39
39
// ==================================================================
40
40
41
41
extern const u16 STRING_LANGUAGE[] PROGMEM;
42
- extern const u16 STRING_IPRODUCT [] PROGMEM;
43
- extern const u16 STRING_IMANUFACTURER [] PROGMEM;
42
+ extern const u8 STRING_PRODUCT [] PROGMEM;
43
+ extern const u8 STRING_MANUFACTURER [] PROGMEM;
44
44
extern const DeviceDescriptor USB_DeviceDescriptor PROGMEM;
45
45
extern const DeviceDescriptor USB_DeviceDescriptorA PROGMEM;
46
46
@@ -49,31 +49,34 @@ const u16 STRING_LANGUAGE[2] = {
49
49
0x0409 // English
50
50
};
51
51
52
- const u16 STRING_IPRODUCT[ 17 ] = {
53
- ( 3 << 8 ) | ( 2 + 2 * 16 ),
54
- #if USB_PID == 0x8036
55
- ' A ' , ' r ' , ' d ' , ' u ' , ' i ' , ' n ' , ' o ' , ' ' , ' L ' , ' e ' , ' o ' , ' n ' , ' a ' , ' r ' , ' d ' , ' o '
52
+ # ifndef USB_PRODUCT
53
+ // Use a hardcoded product name if none is provided
54
+ #if USB_PID == 0x8036
55
+ # define USB_PRODUCT " Arduino Leonardo "
56
56
#elif USB_PID == 0x8037
57
- ' A ' , ' r ' , ' d ' , ' u ' , ' i ' , ' n ' , ' o ' , ' ' , ' M ' , ' i ' , ' c ' , ' r ' , ' o ' , ' ' , ' ' , ' '
57
+ # define USB_PRODUCT " Arduino Micro "
58
58
#elif USB_PID == 0x803C
59
- ' A ' , ' r ' , ' d ' , ' u ' , ' i ' , ' n ' , ' o ' , ' ' , ' E ' , ' s ' , ' p ' , ' l ' , ' o ' , ' r ' , ' a ' , ' '
59
+ # define USB_PRODUCT " Arduino Esplora "
60
60
#elif USB_PID == 0x9208
61
- ' L ' , ' i ' , ' l ' , ' y ' , ' P ' , ' a ' , ' d ' , ' U ' , ' S ' , ' B ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' '
61
+ # define USB_PRODUCT " LilyPad USB "
62
62
#else
63
- ' U ' , ' S ' , ' B ' , ' ' , ' I ' , ' O ' , ' ' , ' B ' , ' o ' , ' a ' , ' r ' , ' d ' , ' ' , ' ' , ' ' , ' '
63
+ # define USB_PRODUCT " USB IO Board "
64
64
#endif
65
- };
65
+ #endif
66
+
67
+ const u8 STRING_PRODUCT[] PROGMEM = USB_PRODUCT;
66
68
67
- const u16 STRING_IMANUFACTURER[12 ] = {
68
- (3 <<8 ) | (2 +2 *11 ),
69
69
#if USB_VID == 0x2341
70
- ' A ' , ' r ' , ' d ' , ' u ' , ' i ' , ' n ' , ' o ' , ' ' , ' L ' , ' L ' , ' C '
70
+ # define USB_MANUFACTURER " Arduino LLC "
71
71
#elif USB_VID == 0x1b4f
72
- ' S' ,' p' ,' a' ,' r' ,' k' ,' F' ,' u' ,' n' ,' ' ,' ' ,' '
73
- #else
74
- ' U' ,' n' ,' k' ,' n' ,' o' ,' w' ,' n' ,' ' ,' ' ,' ' ,' '
72
+ #define USB_MANUFACTURER " SparkFun"
73
+ #elif !defined(USB_MANUFACTURER)
74
+ // Fall through to unknown if no manufacturer name was provided in a macro
75
+ #define USB_MANUFACTURER " Unknown"
75
76
#endif
76
- };
77
+
78
+ const u8 STRING_MANUFACTURER[] PROGMEM = USB_MANUFACTURER;
79
+
77
80
78
81
#ifdef CDC_ENABLED
79
82
#define DEVICE_CLASS 0x02
@@ -416,6 +419,22 @@ int USB_SendControl(u8 flags, const void* d, int len)
416
419
return sent;
417
420
}
418
421
422
+ // Send a USB descriptor string. The string is stored in PROGMEM as a
423
+ // plain ASCII string but is sent out as UTF-16 with the correct 2-byte
424
+ // prefix
425
+ static bool USB_SendStringDescriptor (const u8 *string_P, u8 string_len) {
426
+ SendControl (2 + string_len * 2 );
427
+ SendControl (3 );
428
+ for (u8 i = 0 ; i < string_len; i++) {
429
+ bool r = SendControl (pgm_read_byte (&string_P[i]));
430
+ r &= SendControl (0 ); // high byte
431
+ if (!r) {
432
+ return false ;
433
+ }
434
+ }
435
+ return true ;
436
+ }
437
+
419
438
// Does not timeout or cross fifo boundaries
420
439
// Will only work for transfers <= 64 bytes
421
440
// TODO
@@ -476,7 +495,6 @@ bool SendDescriptor(Setup& setup)
476
495
return HID_GetDescriptor (t);
477
496
#endif
478
497
479
- u8 desc_length = 0 ;
480
498
const u8 * desc_addr = 0 ;
481
499
if (USB_DEVICE_DESCRIPTOR_TYPE == t)
482
500
{
@@ -486,20 +504,22 @@ bool SendDescriptor(Setup& setup)
486
504
}
487
505
else if (USB_STRING_DESCRIPTOR_TYPE == t)
488
506
{
489
- if (setup.wValueL == 0 )
507
+ if (setup.wValueL == 0 ) {
490
508
desc_addr = (const u8 *)&STRING_LANGUAGE;
491
- else if (setup.wValueL == IPRODUCT)
492
- desc_addr = (const u8 *)&STRING_IPRODUCT;
493
- else if (setup.wValueL == IMANUFACTURER)
494
- desc_addr = (const u8 *)&STRING_IMANUFACTURER;
509
+ }
510
+ else if (setup.wValueL == IPRODUCT) {
511
+ return USB_SendStringDescriptor (STRING_PRODUCT, strlen (USB_PRODUCT));
512
+ }
513
+ else if (setup.wValueL == IMANUFACTURER) {
514
+ return USB_SendStringDescriptor (STRING_MANUFACTURER, strlen (USB_MANUFACTURER));
515
+ }
495
516
else
496
517
return false ;
497
518
}
498
519
499
520
if (desc_addr == 0 )
500
521
return false ;
501
- if (desc_length == 0 )
502
- desc_length = pgm_read_byte (desc_addr);
522
+ u8 desc_length = pgm_read_byte (desc_addr);
503
523
504
524
USB_SendControl (TRANSFER_PGM,desc_addr,desc_length);
505
525
return true ;
0 commit comments