@@ -47,8 +47,8 @@ static char isEndpointHalt = 0;
4747// ==================================================================
4848
4949extern 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 [];
5252extern const DeviceDescriptor USB_DeviceDescriptor;
5353extern const DeviceDescriptor USB_DeviceDescriptorA;
5454
@@ -57,23 +57,25 @@ const uint16_t STRING_LANGUAGE[2] = {
5757 0x0409 // English
5858};
5959
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"
6864#else
69- #error "Need an USB PID"
65+ #define USB_PRODUCT " USB IO Board"
66+ #endif
7067#endif
71- };
7268
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;
7779
7880#ifdef CDC_ENABLED
7981#define DEVICE_CLASS 0x02
@@ -241,6 +243,21 @@ int USBD_SendControl(uint8_t flags, const void* d, uint32_t len)
241243 return length;
242244}
243245
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+
244261// Does not timeout or cross fifo boundaries
245262// Will only work for transfers <= 64 bytes
246263// TODO
@@ -400,19 +417,19 @@ static bool USBD_SendDescriptor(Setup& setup)
400417 TRACE_CORE (puts (" => USBD_SendDescriptor : USB_STRING_DESCRIPTOR_TYPE\r\n " );)
401418 if (setup.wValueL == 0 ) {
402419 desc_addr = (const uint8_t *)&STRING_LANGUAGE;
403- }
420+ }
404421 else if (setup.wValueL == IPRODUCT) {
405- desc_addr = ( const uint8_t *)&STRING_IPRODUCT ;
406- }
422+ return USB_SendStringDescriptor (STRING_PRODUCT, setup. wLength ) ;
423+ }
407424 else if (setup.wValueL == IMANUFACTURER) {
408- desc_addr = ( const uint8_t *)&STRING_IMANUFACTURER ;
409- }
425+ return USB_SendStringDescriptor (STRING_MANUFACTURER, setup. wLength ) ;
426+ }
410427 else {
411428 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+ }
416433 }
417434 else if (USB_DEVICE_QUALIFIER == t)
418435 {
0 commit comments