@@ -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,24 @@ 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'
56
- #elif USB_PID == 0x8037
57
- ' A' ,' r' ,' d' ,' u' ,' i' ,' n' ,' o' ,' ' ,' M' ,' i' ,' c' ,' r' ,' o' ,' ' ,' ' ,' '
58
- #elif USB_PID == 0x803C
59
- ' A' ,' r' ,' d' ,' u' ,' i' ,' n' ,' o' ,' ' ,' E' ,' s' ,' p' ,' l' ,' o' ,' r' ,' a' ,' '
60
- #elif USB_PID == 0x9208
61
- ' L' ,' i' ,' l' ,' y' ,' P' ,' a' ,' d' ,' U' ,' S' ,' B' ,' ' ,' ' ,' ' ,' ' ,' ' ,' '
62
- #else
63
- ' U' ,' S' ,' B' ,' ' ,' I' ,' O' ,' ' ,' B' ,' o' ,' a' ,' r' ,' d' ,' ' ,' ' ,' ' ,' '
52
+ #ifndef USB_PRODUCT
53
+ // If no product is provided, use USB IO Board
54
+ #define USB_PRODUCT " USB IO Board"
64
55
#endif
65
- };
66
56
67
- const u16 STRING_IMANUFACTURER[ 12 ] = {
68
- ( 3 << 8 ) | ( 2 + 2 * 11 ),
57
+ const u8 STRING_PRODUCT[] PROGMEM = USB_PRODUCT;
58
+
69
59
#if USB_VID == 0x2341
70
- ' A ' , ' r ' , ' d ' , ' u ' , ' i ' , ' n ' , ' o ' , ' ' , ' L ' , ' L ' , ' C '
60
+ # define USB_MANUFACTURER " Arduino LLC "
71
61
#elif USB_VID == 0x1b4f
72
- ' S' ,' p' ,' a' ,' r' ,' k' ,' F' ,' u' ,' n' ,' ' ,' ' ,' '
73
- #else
74
- ' U' ,' n' ,' k' ,' n' ,' o' ,' w' ,' n' ,' ' ,' ' ,' ' ,' '
62
+ #define USB_MANUFACTURER " SparkFun"
63
+ #elif !defined(USB_MANUFACTURER)
64
+ // Fall through to unknown if no manufacturer name was provided in a macro
65
+ #define USB_MANUFACTURER " Unknown"
75
66
#endif
76
- };
67
+
68
+ const u8 STRING_MANUFACTURER[] PROGMEM = USB_MANUFACTURER;
69
+
77
70
78
71
#ifdef CDC_ENABLED
79
72
#define DEVICE_CLASS 0x02
@@ -416,6 +409,22 @@ int USB_SendControl(u8 flags, const void* d, int len)
416
409
return sent;
417
410
}
418
411
412
+ // Send a USB descriptor string. The string is stored in PROGMEM as a
413
+ // plain ASCII string but is sent out as UTF-16 with the correct 2-byte
414
+ // prefix
415
+ static bool USB_SendStringDescriptor (const u8 *string_P, u8 string_len) {
416
+ SendControl (2 + string_len * 2 );
417
+ SendControl (3 );
418
+ for (u8 i = 0 ; i < string_len; i++) {
419
+ bool r = SendControl (pgm_read_byte (&string_P[i]));
420
+ r &= SendControl (0 ); // high byte
421
+ if (!r) {
422
+ return false ;
423
+ }
424
+ }
425
+ return true ;
426
+ }
427
+
419
428
// Does not timeout or cross fifo boundaries
420
429
// Will only work for transfers <= 64 bytes
421
430
// TODO
@@ -476,7 +485,6 @@ bool SendDescriptor(Setup& setup)
476
485
return HID_GetDescriptor (t);
477
486
#endif
478
487
479
- u8 desc_length = 0 ;
480
488
const u8 * desc_addr = 0 ;
481
489
if (USB_DEVICE_DESCRIPTOR_TYPE == t)
482
490
{
@@ -486,20 +494,22 @@ bool SendDescriptor(Setup& setup)
486
494
}
487
495
else if (USB_STRING_DESCRIPTOR_TYPE == t)
488
496
{
489
- if (setup.wValueL == 0 )
497
+ if (setup.wValueL == 0 ) {
490
498
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;
499
+ }
500
+ else if (setup.wValueL == IPRODUCT) {
501
+ return USB_SendStringDescriptor (STRING_PRODUCT, strlen (USB_PRODUCT));
502
+ }
503
+ else if (setup.wValueL == IMANUFACTURER) {
504
+ return USB_SendStringDescriptor (STRING_MANUFACTURER, strlen (USB_MANUFACTURER));
505
+ }
495
506
else
496
507
return false ;
497
508
}
498
509
499
510
if (desc_addr == 0 )
500
511
return false ;
501
- if (desc_length == 0 )
502
- desc_length = pgm_read_byte (desc_addr);
512
+ u8 desc_length = pgm_read_byte (desc_addr);
503
513
504
514
USB_SendControl (TRANSFER_PGM,desc_addr,desc_length);
505
515
return true ;
0 commit comments