Skip to content

Commit 7b5c25f

Browse files
facchinmcmaglie
authored andcommitted
implement PUSB modules as linked list
1 parent f67318a commit 7b5c25f

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

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

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,34 +28,49 @@
2828
static u8 lastIf = CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT;
2929
static u8 lastEp = CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT;
3030

31+
class PUSBListNode {
32+
public:
33+
PUSBListNode *next = NULL;
34+
PUSBCallbacks cb;
35+
};
36+
3137
extern u8 _initEndpoints[];
3238

33-
PUSBCallbacks cbs[MAX_MODULES];
34-
u8 modules_count = 0;
39+
//PUSBCallbacks cbs[MAX_MODULES];
40+
static u8 modules_count = 0;
41+
42+
static PUSBListNode* rootNode = NULL;
43+
static PUSBListNode* lastNode = NULL;
3544

3645
int8_t PUSB_GetInterface(u8* interfaceNum)
3746
{
3847
int8_t ret = 0;
48+
PUSBListNode* node = rootNode;
3949
for (u8 i=0; i<modules_count; i++) {
40-
ret = cbs[i].getInterface(interfaceNum);
50+
ret = node->cb.getInterface(interfaceNum);
51+
node = node->next;
4152
}
4253
return ret;
4354
}
4455

4556
int8_t PUSB_GetDescriptor(int8_t t)
4657
{
4758
int8_t ret = 0;
59+
PUSBListNode* node = rootNode;
4860
for (u8 i=0; i<modules_count && ret == 0; i++) {
49-
ret = cbs[i].getDescriptor(t);
61+
ret = node->cb.getDescriptor(t);
62+
node = node->next;
5063
}
5164
return ret;
5265
}
5366

5467
bool PUSB_Setup(Setup& setup, u8 j)
5568
{
5669
bool ret = false;
70+
PUSBListNode* node = rootNode;
5771
for (u8 i=0; i<modules_count && ret == false; i++) {
58-
ret = cbs[i].setup(setup, j);
72+
ret = node->cb.setup(setup, j);
73+
node = node->next;
5974
}
6075
return ret;
6176
}
@@ -65,7 +80,19 @@ int8_t PUSB_AddFunction(PUSBCallbacks *cb, u8* interface)
6580
if (modules_count >= MAX_MODULES) {
6681
return 0;
6782
}
68-
cbs[modules_count] = *cb;
83+
84+
PUSBListNode *node = new PUSBListNode;
85+
86+
node->cb.setup = cb->setup;
87+
node->cb.getInterface = cb->getInterface;
88+
node->cb.getDescriptor = cb->getDescriptor;
89+
90+
if (modules_count == 0) {
91+
rootNode = node;
92+
lastNode = node;
93+
} else {
94+
lastNode->next = node;
95+
}
6996

7097
*interface = lastIf;
7198
lastIf++;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ typedef struct
3131
int8_t (*getInterface)(u8* interfaceNum);
3232
int8_t (*getDescriptor)(int8_t t);
3333
int8_t numEndpoints;
34-
u8 endpointType[6];
34+
u8 endpointType[];
3535
} PUSBCallbacks;
3636

3737
typedef struct

0 commit comments

Comments
 (0)