@@ -39,8 +39,8 @@ volatile u8 RxLEDPulse; /**< Milliseconds remaining for data Rx LED pulse */
3939// ==================================================================
4040
4141extern 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;
4444extern const DeviceDescriptor USB_DeviceDescriptor PROGMEM;
4545extern const DeviceDescriptor USB_DeviceDescriptorA PROGMEM;
4646
@@ -49,31 +49,34 @@ const u16 STRING_LANGUAGE[2] = {
4949 0x0409 // English
5050};
5151
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 "
5656#elif USB_PID == 0x8037
57- ' A ' , ' r ' , ' d ' , ' u ' , ' i ' , ' n ' , ' o ' , ' ' , ' M ' , ' i ' , ' c ' , ' r ' , ' o ' , ' ' , ' ' , ' '
57+ # define USB_PRODUCT " Arduino Micro "
5858#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 "
6060#elif USB_PID == 0x9208
61- ' L ' , ' i ' , ' l ' , ' y ' , ' P ' , ' a ' , ' d ' , ' U ' , ' S ' , ' B ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' '
61+ # define USB_PRODUCT " LilyPad USB "
6262#else
63- ' U ' , ' S ' , ' B ' , ' ' , ' I ' , ' O ' , ' ' , ' B ' , ' o ' , ' a ' , ' r ' , ' d ' , ' ' , ' ' , ' ' , ' '
63+ # define USB_PRODUCT " USB IO Board "
6464#endif
65- };
65+ #endif
66+
67+ const u8 STRING_PRODUCT[] PROGMEM = USB_PRODUCT;
6668
67- const u16 STRING_IMANUFACTURER[12 ] = {
68- (3 <<8 ) | (2 +2 *11 ),
6969#if USB_VID == 0x2341
70- ' A ' , ' r ' , ' d ' , ' u ' , ' i ' , ' n ' , ' o ' , ' ' , ' L ' , ' L ' , ' C '
70+ # define USB_MANUFACTURER " Arduino LLC "
7171#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"
7576#endif
76- };
77+
78+ const u8 STRING_MANUFACTURER[] PROGMEM = USB_MANUFACTURER;
79+
7780
7881#ifdef CDC_ENABLED
7982#define DEVICE_CLASS 0x02
@@ -416,6 +419,22 @@ int USB_SendControl(u8 flags, const void* d, int len)
416419 return sent;
417420}
418421
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+
419438// Does not timeout or cross fifo boundaries
420439// Will only work for transfers <= 64 bytes
421440// TODO
@@ -476,7 +495,6 @@ bool SendDescriptor(Setup& setup)
476495 return HID_GetDescriptor (t);
477496#endif
478497
479- u8 desc_length = 0 ;
480498 const u8 * desc_addr = 0 ;
481499 if (USB_DEVICE_DESCRIPTOR_TYPE == t)
482500 {
@@ -486,20 +504,22 @@ bool SendDescriptor(Setup& setup)
486504 }
487505 else if (USB_STRING_DESCRIPTOR_TYPE == t)
488506 {
489- if (setup.wValueL == 0 )
507+ if (setup.wValueL == 0 ) {
490508 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+ }
495516 else
496517 return false ;
497518 }
498519
499520 if (desc_addr == 0 )
500521 return false ;
501- if (desc_length == 0 )
502- desc_length = pgm_read_byte (desc_addr);
522+ u8 desc_length = pgm_read_byte (desc_addr);
503523
504524 USB_SendControl (TRANSFER_PGM,desc_addr,desc_length);
505525 return true ;
0 commit comments