@@ -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,24 @@ 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'
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"
6455#endif
65- };
6656
67- const u16 STRING_IMANUFACTURER[ 12 ] = {
68- ( 3 << 8 ) | ( 2 + 2 * 11 ),
57+ const u8 STRING_PRODUCT[] PROGMEM = USB_PRODUCT;
58+
6959#if USB_VID == 0x2341
70- ' A ' , ' r ' , ' d ' , ' u ' , ' i ' , ' n ' , ' o ' , ' ' , ' L ' , ' L ' , ' C '
60+ # define USB_MANUFACTURER " Arduino LLC "
7161#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"
7566#endif
76- };
67+
68+ const u8 STRING_MANUFACTURER[] PROGMEM = USB_MANUFACTURER;
69+
7770
7871#ifdef CDC_ENABLED
7972#define DEVICE_CLASS 0x02
@@ -416,6 +409,22 @@ int USB_SendControl(u8 flags, const void* d, int len)
416409 return sent;
417410}
418411
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+
419428// Does not timeout or cross fifo boundaries
420429// Will only work for transfers <= 64 bytes
421430// TODO
@@ -476,7 +485,6 @@ bool SendDescriptor(Setup& setup)
476485 return HID_GetDescriptor (t);
477486#endif
478487
479- u8 desc_length = 0 ;
480488 const u8 * desc_addr = 0 ;
481489 if (USB_DEVICE_DESCRIPTOR_TYPE == t)
482490 {
@@ -486,20 +494,22 @@ bool SendDescriptor(Setup& setup)
486494 }
487495 else if (USB_STRING_DESCRIPTOR_TYPE == t)
488496 {
489- if (setup.wValueL == 0 )
497+ if (setup.wValueL == 0 ) {
490498 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+ }
495506 else
496507 return false ;
497508 }
498509
499510 if (desc_addr == 0 )
500511 return false ;
501- if (desc_length == 0 )
502- desc_length = pgm_read_byte (desc_addr);
512+ u8 desc_length = pgm_read_byte (desc_addr);
503513
504514 USB_SendControl (TRANSFER_PGM,desc_addr,desc_length);
505515 return true ;
0 commit comments