|
18 | 18 |
|
19 | 19 | #include "USBAPI.h" |
20 | 20 | #include "PluggableUSB.h" |
| 21 | +#include <stdlib.h> |
21 | 22 |
|
22 | 23 | #if defined(USBCON) |
23 | 24 |
|
@@ -69,10 +70,10 @@ const u8 STRING_MANUFACTURER[] PROGMEM = USB_MANUFACTURER; |
69 | 70 |
|
70 | 71 | // DEVICE DESCRIPTOR |
71 | 72 | const DeviceDescriptor USB_DeviceDescriptor = |
72 | | - D_DEVICE(0x00,0x00,0x00,64,USB_VID,USB_PID,0x100,IMANUFACTURER,IPRODUCT,0,1); |
| 73 | + D_DEVICE(0x00,0x00,0x00,64,USB_VID,USB_PID,0x100,IMANUFACTURER,IPRODUCT,ISERIAL,1); |
73 | 74 |
|
74 | 75 | const DeviceDescriptor USB_DeviceDescriptorB = |
75 | | - D_DEVICE(0xEF,0x02,0x01,64,USB_VID,USB_PID,0x100,IMANUFACTURER,IPRODUCT,0,1); |
| 76 | + D_DEVICE(0xEF,0x02,0x01,64,USB_VID,USB_PID,0x100,IMANUFACTURER,IPRODUCT,ISERIAL,1); |
76 | 77 |
|
77 | 78 | //================================================================== |
78 | 79 | //================================================================== |
@@ -409,11 +410,12 @@ int USB_SendControl(u8 flags, const void* d, int len) |
409 | 410 | // Send a USB descriptor string. The string is stored in PROGMEM as a |
410 | 411 | // plain ASCII string but is sent out as UTF-16 with the correct 2-byte |
411 | 412 | // prefix |
412 | | -static bool USB_SendStringDescriptor(const u8*string_P, u8 string_len) { |
| 413 | +static bool USB_SendStringDescriptor(const u8*string_P, u8 string_len, uint8_t flags) { |
413 | 414 | SendControl(2 + string_len * 2); |
414 | 415 | SendControl(3); |
| 416 | + bool pgm = flags & TRANSFER_PGM; |
415 | 417 | for(u8 i = 0; i < string_len; i++) { |
416 | | - bool r = SendControl(pgm_read_byte(&string_P[i])); |
| 418 | + bool r = SendControl(pgm ? pgm_read_byte(&string_P[i]) : string_P[i]); |
417 | 419 | r &= SendControl(0); // high byte |
418 | 420 | if(!r) { |
419 | 421 | return false; |
@@ -495,10 +497,17 @@ bool SendDescriptor(USBSetup& setup) |
495 | 497 | desc_addr = (const u8*)&STRING_LANGUAGE; |
496 | 498 | } |
497 | 499 | else if (setup.wValueL == IPRODUCT) { |
498 | | - return USB_SendStringDescriptor(STRING_PRODUCT, strlen(USB_PRODUCT)); |
| 500 | + return USB_SendStringDescriptor(STRING_PRODUCT, strlen(USB_PRODUCT), TRANSFER_PGM); |
499 | 501 | } |
500 | 502 | else if (setup.wValueL == IMANUFACTURER) { |
501 | | - return USB_SendStringDescriptor(STRING_MANUFACTURER, strlen(USB_MANUFACTURER)); |
| 503 | + return USB_SendStringDescriptor(STRING_MANUFACTURER, strlen(USB_MANUFACTURER), TRANSFER_PGM); |
| 504 | + } |
| 505 | + else if (setup.wValueL == ISERIAL) { |
| 506 | +#ifdef PLUGGABLE_USB_ENABLED |
| 507 | + char name[ISERIAL_MAX_LEN]; |
| 508 | + PluggableUSB().getShortName(name); |
| 509 | + return USB_SendStringDescriptor((uint8_t*)name, strlen(name), 0); |
| 510 | +#endif |
502 | 511 | } |
503 | 512 | else |
504 | 513 | return false; |
|
0 commit comments