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
// ==================================================================
@@ -81,6 +82,8 @@ volatile u8 _usbConfiguration = 0;
81
82
volatile u8 _usbCurrentStatus = 0 ; // meaning of bits see usb_20.pdf, Figure 9-4. Information Returned by a GetStatus() Request to a Device
82
83
volatile u8 _usbSuspendState = 0 ; // copy of UDINT to check SUSPI and WAKEUPI bits
83
84
85
+ static int iSerial = 0 ;
86
+
84
87
static inline void WaitIN (void )
85
88
{
86
89
while (!(UEINTX & (1 <<TXINI)))
@@ -427,6 +430,19 @@ static bool USB_SendStringDescriptor(const u8*string_P, u8 string_len) {
427
430
return true ;
428
431
}
429
432
433
+ static bool USB_SendStringDescriptorRAM (u8* string_P, u8 string_len) {
434
+ SendControl (2 + string_len * 2 );
435
+ SendControl (3 );
436
+ for (u8 i = 0 ; i < string_len; i++) {
437
+ bool r = SendControl (string_P[i]);
438
+ r &= SendControl (0 ); // high byte
439
+ if (!r) {
440
+ return false ;
441
+ }
442
+ }
443
+ return true ;
444
+ }
445
+
430
446
// Does not timeout or cross fifo boundaries
431
447
// Will only work for transfers <= 64 bytes
432
448
// TODO
@@ -442,10 +458,10 @@ int SendInterfaces()
442
458
{
443
459
u8 interfaces = 0 ;
444
460
445
- CDC_GetInterface (&interfaces);
461
+ iSerial = CDC_GetInterface (&interfaces);
446
462
447
463
#ifdef PLUGGABLE_USB_ENABLED
448
- PUSB_GetInterface (&interfaces);
464
+ iSerial += PUSB_GetInterface (&interfaces);
449
465
#endif
450
466
451
467
return interfaces;
@@ -505,6 +521,11 @@ bool SendDescriptor(USBSetup& setup)
505
521
else if (setup.wValueL == IMANUFACTURER) {
506
522
return USB_SendStringDescriptor (STRING_MANUFACTURER, strlen (USB_MANUFACTURER));
507
523
}
524
+ else if (setup.wValueL == ISERIAL) {
525
+ char StringNum[4 ];
526
+ itoa (iSerial, StringNum, 10 );
527
+ return USB_SendStringDescriptorRAM ((u8*)StringNum, strlen (StringNum));
528
+ }
508
529
else
509
530
return false ;
510
531
}
0 commit comments