27
27
static u8 lastIf = CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT;
28
28
static u8 lastEp = CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT;
29
29
30
+ class PUSBListNode {
31
+ public:
32
+ PUSBListNode *next = NULL ;
33
+ PUSBCallbacks cb;
34
+ };
35
+
30
36
extern u8 _initEndpoints[];
31
37
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 ;
34
43
35
44
int8_t PUSB_GetInterface (u8 * interfaceNum)
36
45
{
37
46
int8_t ret = 0 ;
47
+ PUSBListNode* node = rootNode;
38
48
for (u8 i=0 ; i<modules_count; i++) {
39
- ret = cbs[i].getInterface (interfaceNum);
49
+ ret = node->cb .getInterface (interfaceNum);
50
+ node = node->next ;
40
51
}
41
52
return ret;
42
53
}
43
54
44
55
int8_t PUSB_GetDescriptor (int8_t t)
45
56
{
46
57
int8_t ret = 0 ;
58
+ PUSBListNode* node = rootNode;
47
59
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 ;
49
62
}
50
63
return ret;
51
64
}
52
65
53
66
bool PUSB_Setup (Setup& setup, u8 j)
54
67
{
55
68
bool ret = false ;
69
+ PUSBListNode* node = rootNode;
56
70
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 ;
58
73
}
59
74
return ret;
60
75
}
@@ -64,7 +79,19 @@ int8_t PUSB_AddFunction(PUSBCallbacks *cb, u8* interface)
64
79
if (modules_count >= MAX_MODULES) {
65
80
return 0 ;
66
81
}
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
+ }
68
95
69
96
*interface = lastIf;
70
97
lastIf++;
0 commit comments