Skip to content

Commit d98cbc5

Browse files
committed
implement PUSB modules as linked list
1 parent 454156e commit d98cbc5

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
@@ -27,34 +27,49 @@
2727
static u8 lastIf = CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT;
2828
static u8 lastEp = CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT;
2929

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

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

3544
int8_t PUSB_GetInterface(u8* interfaceNum)
3645
{
3746
int8_t ret = 0;
47+
PUSBListNode* node = rootNode;
3848
for (u8 i=0; i<modules_count; i++) {
39-
ret = cbs[i].getInterface(interfaceNum);
49+
ret = node->cb.getInterface(interfaceNum);
50+
node = node->next;
4051
}
4152
return ret;
4253
}
4354

4455
int8_t PUSB_GetDescriptor(int8_t t)
4556
{
4657
int8_t ret = 0;
58+
PUSBListNode* node = rootNode;
4759
for (u8 i=0; i<modules_count && ret == 0; i++) {
48-
ret = cbs[i].getDescriptor(t);
60+
ret = node->cb.getDescriptor(t);
61+
node = node->next;
4962
}
5063
return ret;
5164
}
5265

5366
bool PUSB_Setup(Setup& setup, u8 j)
5467
{
5568
bool ret = false;
69+
PUSBListNode* node = rootNode;
5670
for (u8 i=0; i<modules_count && ret == false; i++) {
57-
ret = cbs[i].setup(setup, j);
71+
ret = node->cb.setup(setup, j);
72+
node = node->next;
5873
}
5974
return ret;
6075
}
@@ -64,7 +79,19 @@ int8_t PUSB_AddFunction(PUSBCallbacks *cb, u8* interface)
6479
if (modules_count >= MAX_MODULES) {
6580
return 0;
6681
}
67-
cbs[modules_count] = *cb;
82+
83+
PUSBListNode *node = new PUSBListNode;
84+
85+
node->cb.setup = cb->setup;
86+
node->cb.getInterface = cb->getInterface;
87+
node->cb.getDescriptor = cb->getDescriptor;
88+
89+
if (modules_count == 0) {
90+
rootNode = node;
91+
lastNode = node;
92+
} else {
93+
lastNode->next = node;
94+
}
6895

6996
*interface = lastIf;
7097
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)