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 4a550a3

Browse files
committed
use plugged modules name to create iSerial field
To solve the re-enumeration problem on Win, two different approaches where tested: - creating a S/N based on the descriptor length (collisions still possible, less overhead) - craft a S/N string from the pluggable modules properties (no collision, no difference between different HID submodules) A call has been added getShortName and it MUST be implemented by any library based on PluggableUSB. No effect on PluggableHID-based libraries.
1 parent ea89608 commit 4a550a3

File tree

9 files changed

+66
-12
lines changed

9 files changed

+66
-12
lines changed

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#if defined(USBCON)
2424
#ifdef PLUGGABLE_USB_ENABLED
2525

26-
#define MAX_MODULES 6
26+
#define MAX_MODULES 3
2727

2828
static u8 lastIf = CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT;
2929
static u8 lastEp = CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT;
@@ -35,12 +35,14 @@ static u8 modules_count = 0;
3535

3636
static PUSBListNode* rootNode = NULL;
3737

38+
char _iSerialNum[2*MAX_MODULES] = {0};
39+
3840
int PUSB_GetInterface(u8* interfaceNum)
3941
{
4042
int ret = 0;
4143
PUSBListNode* node = rootNode;
4244
for (u8 i=0; i<modules_count; i++) {
43-
ret = node->cb->getInterface(interfaceNum);
45+
ret += node->cb->getInterface(interfaceNum);
4446
node = node->next;
4547
}
4648
return ret;
@@ -57,6 +59,18 @@ int PUSB_GetDescriptor(int8_t t)
5759
return ret;
5860
}
5961

62+
char* PUSB_GetShortName()
63+
{
64+
char* ret = 0;
65+
PUSBListNode* node = rootNode;
66+
for (u8 i=0; i<modules_count; i++) {
67+
ret = node->cb->getShortName();
68+
memcpy(&_iSerialNum[i*2], ret, 2);
69+
node = node->next;
70+
}
71+
return _iSerialNum;
72+
}
73+
6074
bool PUSB_Setup(USBSetup& setup, u8 j)
6175
{
6276
bool ret = false;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ typedef struct __attribute__((packed))
3030
bool (*setup)(USBSetup& setup, u8 i);
3131
int (*getInterface)(u8* interfaceNum);
3232
int (*getDescriptor)(int8_t t);
33+
char* (*getShortName)();
3334
int8_t numEndpoints;
3435
int8_t numInterfaces;
3536
uint8_t *endpointType;
@@ -54,6 +55,8 @@ int PUSB_GetInterface(u8* interfaceNum);
5455

5556
int PUSB_GetDescriptor(int8_t t);
5657

58+
char* PUSB_GetShortName();
59+
5760
bool PUSB_Setup(USBSetup& setup, u8 i);
5861

5962
void PUSB_Begin();

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ volatile u8 _usbConfiguration = 0;
8282
volatile u8 _usbCurrentStatus = 0; // meaning of bits see usb_20.pdf, Figure 9-4. Information Returned by a GetStatus() Request to a Device
8383
volatile u8 _usbSuspendState = 0; // copy of UDINT to check SUSPI and WAKEUPI bits
8484

85-
static int iSerial = 0;
86-
8785
static inline void WaitIN(void)
8886
{
8987
while (!(UEINTX & (1<<TXINI)))
@@ -458,10 +456,10 @@ int SendInterfaces()
458456
{
459457
u8 interfaces = 0;
460458

461-
iSerial = CDC_GetInterface(&interfaces);
459+
CDC_GetInterface(&interfaces);
462460

463461
#ifdef PLUGGABLE_USB_ENABLED
464-
iSerial += PUSB_GetInterface(&interfaces);
462+
PUSB_GetInterface(&interfaces);
465463
#endif
466464

467465
return interfaces;
@@ -522,9 +520,10 @@ bool SendDescriptor(USBSetup& setup)
522520
return USB_SendStringDescriptor(STRING_MANUFACTURER, strlen(USB_MANUFACTURER));
523521
}
524522
else if (setup.wValueL == ISERIAL) {
525-
char StringNum[4];
526-
itoa(iSerial, StringNum, 10);
527-
return USB_SendStringDescriptorRAM((u8*)StringNum, strlen(StringNum));
523+
#ifdef PLUGGABLE_USB_ENABLED
524+
char* name = PUSB_GetShortName();
525+
return USB_SendStringDescriptorRAM((uint8_t*)name, strlen(name));
526+
#endif
528527
}
529528
else
530529
return false;

‎hardware/arduino/avr/libraries/HID/HID.cpp‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ int HID_GetDescriptor(int8_t t)
7979
}
8080
}
8181

82+
char* HID_GetShortName()
83+
{
84+
static char* name = "HI";
85+
return name;
86+
}
87+
8288
void HID_::AppendDescriptor(HIDDescriptorListNode *node)
8389
{
8490
if (modules_count == 0) {
@@ -149,6 +155,7 @@ HID_::HID_(void)
149155
.setup = &HID_Setup,
150156
.getInterface = &HID_GetInterface,
151157
.getDescriptor = &HID_GetDescriptor,
158+
.getShortName = &HID_GetShortName,
152159
.numEndpoints = 1,
153160
.numInterfaces = 1,
154161
.endpointType = endpointType,

‎hardware/arduino/sam/cores/arduino/USB/PluggableUSB.cpp‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ static uint8_t modules_count = 0;
3535

3636
static PUSBListNode* rootNode = NULL;
3737

38+
char _iSerialNum[2*MAX_MODULES] = {0};
39+
3840
int PUSB_GetInterface(uint8_t* interfaceNum)
3941
{
4042
int ret = 0;
4143
PUSBListNode* node = rootNode;
4244
for (uint8_t i=0; i<modules_count; i++) {
43-
ret = node->cb->getInterface(interfaceNum);
45+
ret += node->cb->getInterface(interfaceNum);
4446
node = node->next;
4547
}
4648
return ret;
@@ -68,6 +70,18 @@ bool PUSB_Setup(USBSetup& setup, uint8_t j)
6870
return ret;
6971
}
7072

73+
char* PUSB_GetShortName()
74+
{
75+
char* ret = 0;
76+
PUSBListNode* node = rootNode;
77+
for (uint8_t i=0; i<modules_count; i++) {
78+
ret = node->cb->getShortName();
79+
memcpy(&_iSerialNum[i*2], ret, 2);
80+
node = node->next;
81+
}
82+
return _iSerialNum;
83+
}
84+
7185
int8_t PUSB_AddFunction(PUSBListNode *node, uint8_t* interface)
7286
{
7387
if (modules_count >= MAX_MODULES) {

‎hardware/arduino/sam/cores/arduino/USB/PluggableUSB.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ typedef struct __attribute__((packed))
3030
bool (*setup)(USBSetup& setup, uint8_t i);
3131
int (*getInterface)(uint8_t* interfaceNum);
3232
int (*getDescriptor)(int8_t t);
33+
char* (*getShortName)();
3334
int8_t numEndpoints;
3435
int8_t numInterfaces;
3536
uint32_t *endpointType;
@@ -56,6 +57,8 @@ int PUSB_GetDescriptor(int8_t t);
5657

5758
bool PUSB_Setup(USBSetup& setup, uint8_t i);
5859

60+
char* PUSB_GetShortName();
61+
5962
void PUSB_Begin();
6063

6164
#endif

‎hardware/arduino/sam/cores/arduino/USB/USBCore.cpp‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ const uint8_t STRING_MANUFACTURER[12] = USB_MANUFACTURER;
9696

9797
// DEVICE DESCRIPTOR
9898
const DeviceDescriptor USB_DeviceDescriptor =
99-
D_DEVICE(0x00,0x00,0x00,64,USB_VID,USB_PID,0x100,IMANUFACTURER,IPRODUCT,0,1);
99+
D_DEVICE(0x00,0x00,0x00,64,USB_VID,USB_PID,0x100,IMANUFACTURER,IPRODUCT,ISERIAL,1);
100100

101101
const DeviceDescriptor USB_DeviceDescriptorA =
102-
D_DEVICE(0xEF,0x02,0x01,64,USB_VID,USB_PID,0x100,IMANUFACTURER,IPRODUCT,0,1);
102+
D_DEVICE(0xEF,0x02,0x01,64,USB_VID,USB_PID,0x100,IMANUFACTURER,IPRODUCT,ISERIAL,1);
103103

104104
const DeviceDescriptor USB_DeviceQualifier =
105105
D_QUALIFIER(0x00,0x00,0x00,64,1);
@@ -429,6 +429,12 @@ static bool USBD_SendDescriptor(USBSetup& setup)
429429
else if (setup.wValueL == IMANUFACTURER) {
430430
return USB_SendStringDescriptor(STRING_MANUFACTURER, setup.wLength);
431431
}
432+
else if (setup.wValueL == ISERIAL) {
433+
#ifdef PLUGGABLE_USB_ENABLED
434+
char* name = PUSB_GetShortName();
435+
return USB_SendStringDescriptor((uint8_t*)name, setup.wLength);
436+
#endif
437+
}
432438
else {
433439
return false;
434440
}

‎hardware/arduino/sam/cores/arduino/USB/USBDesc.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,6 @@
4444

4545
#define IMANUFACTURER 1
4646
#define IPRODUCT 2
47+
#define ISERIAL 3
4748

4849
#endif /* __USBDESC_H__ */

‎hardware/arduino/sam/libraries/HID/HID.cpp‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ int HID_GetDescriptor(int8_t t)
7777
}
7878
}
7979

80+
char* HID_GetShortName()
81+
{
82+
static char* name = "HI";
83+
return name;
84+
}
85+
8086
void HID_::AppendDescriptor(HIDDescriptorListNode *node)
8187
{
8288
if (modules_count == 0) {
@@ -152,6 +158,7 @@ HID_::HID_(void)
152158
.setup = &HID_Setup,
153159
.getInterface = &HID_GetInterface,
154160
.getDescriptor = &HID_GetDescriptor,
161+
.getShortName = &HID_GetShortName,
155162
.numEndpoints = 1,
156163
.numInterfaces = 1,
157164
.endpointType = endpointType,

0 commit comments

Comments
(0)

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