Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ea89608

Browse files
committed
add a way to get quite unique iSerial descriptor
1 parent 1942394 commit ea89608

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

‎hardware/arduino/avr/cores/arduino/USBCore.cpp‎

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "USBAPI.h"
2020
#include "PluggableUSB.h"
21+
#include <stdlib.h>
2122

2223
#if defined(USBCON)
2324

@@ -69,10 +70,10 @@ const u8 STRING_MANUFACTURER[] PROGMEM = USB_MANUFACTURER;
6970

7071
// DEVICE DESCRIPTOR
7172
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);
7374

7475
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);
7677

7778
//==================================================================
7879
//==================================================================
@@ -81,6 +82,8 @@ volatile u8 _usbConfiguration = 0;
8182
volatile u8 _usbCurrentStatus = 0; // meaning of bits see usb_20.pdf, Figure 9-4. Information Returned by a GetStatus() Request to a Device
8283
volatile u8 _usbSuspendState = 0; // copy of UDINT to check SUSPI and WAKEUPI bits
8384

85+
static int iSerial = 0;
86+
8487
static inline void WaitIN(void)
8588
{
8689
while (!(UEINTX & (1<<TXINI)))
@@ -427,6 +430,19 @@ static bool USB_SendStringDescriptor(const u8*string_P, u8 string_len) {
427430
return true;
428431
}
429432

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+
430446
// Does not timeout or cross fifo boundaries
431447
// Will only work for transfers <= 64 bytes
432448
// TODO
@@ -442,10 +458,10 @@ int SendInterfaces()
442458
{
443459
u8 interfaces = 0;
444460

445-
CDC_GetInterface(&interfaces);
461+
iSerial = CDC_GetInterface(&interfaces);
446462

447463
#ifdef PLUGGABLE_USB_ENABLED
448-
PUSB_GetInterface(&interfaces);
464+
iSerial += PUSB_GetInterface(&interfaces);
449465
#endif
450466

451467
return interfaces;
@@ -505,6 +521,11 @@ bool SendDescriptor(USBSetup& setup)
505521
else if (setup.wValueL == IMANUFACTURER) {
506522
return USB_SendStringDescriptor(STRING_MANUFACTURER, strlen(USB_MANUFACTURER));
507523
}
524+
else if (setup.wValueL == ISERIAL) {
525+
char StringNum[4];
526+
itoa(iSerial, StringNum, 10);
527+
return USB_SendStringDescriptorRAM((u8*)StringNum, strlen(StringNum));
528+
}
508529
else
509530
return false;
510531
}

‎hardware/arduino/avr/cores/arduino/USBDesc.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@
3636

3737
#define IMANUFACTURER 1
3838
#define IPRODUCT 2
39-
39+
#defineISERIAL 3

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /