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