23
23
#if defined(USBCON)
24
24
#ifdef PLUGGABLE_USB_ENABLED
25
25
26
- #define MAX_MODULES 6
26
+ // TODO: set correct value for different CPUs
27
+ #define MAX_EP 6
27
28
28
29
extern uint8_t _initEndpoints[];
29
30
30
- // PUSBCallbacks cbs[MAX_MODULES];
31
-
32
31
PluggableUSB_ PluggableUSB;
33
32
34
33
int PluggableUSB_::getInterface (uint8_t * interfaceNum)
35
34
{
36
35
int ret = 0 ;
37
- PUSBListNode* node = rootNode ;
38
- for (uint8_t i= 0 ; i<modulesCount; i++ ) {
36
+ PUSBListNode* node;
37
+ for (node = rootNode; node; node = node-> next ) {
39
38
ret = node->getInterface (interfaceNum);
40
- node = node->next ;
41
39
}
42
40
return ret;
43
41
}
44
42
45
43
int PluggableUSB_::getDescriptor (int8_t t)
46
44
{
47
- int ret = 0 ;
48
- PUSBListNode* node = rootNode;
49
- for ( uint8_t i= 0 ; i<modulesCount && ret == 0 ; i++) {
50
- ret = node-> getDescriptor (t);
51
- node = node-> next ;
45
+ PUSBListNode* node ;
46
+ for ( node = rootNode; node; node = node-> next ) {
47
+ int ret = node-> getDescriptor (t);
48
+ if (ret)
49
+ return ret ;
52
50
}
53
- return ret ;
51
+ return 0 ;
54
52
}
55
53
56
54
bool PluggableUSB_::setup (USBSetup& setup, uint8_t j)
57
55
{
58
- bool ret = false ;
59
- PUSBListNode* node = rootNode;
60
- for ( uint8_t i= 0 ; i<modulesCount && ret == false ; i++ ) {
61
- ret = node-> setup (setup, j) ;
62
- node = node-> next ;
56
+ PUSBListNode* node ;
57
+ for ( node = rootNode; node; node = node-> next ) {
58
+ if (node-> setup (setup, j) ) {
59
+ return true ;
60
+ }
63
61
}
64
- return ret ;
62
+ return false ;
65
63
}
66
64
67
65
bool PluggableUSB_::plug (PUSBListNode *node)
68
66
{
69
- if (modulesCount >= MAX_MODULES ) {
67
+ if ((lastEp + node-> numEndpoints ) >= MAX_EP ) {
70
68
return false ;
71
69
}
72
70
73
- if (modulesCount == 0 ) {
71
+ if (!rootNode ) {
74
72
rootNode = node;
75
73
} else {
76
74
PUSBListNode *current = rootNode;
77
- while (current->next != NULL ) {
75
+ while (current->next ) {
78
76
current = current->next ;
79
77
}
80
78
current->next = node;
@@ -83,18 +81,17 @@ bool PluggableUSB_::plug(PUSBListNode *node)
83
81
node->pluggedInterface = lastIf;
84
82
node->pluggedEndpoint = lastEp;
85
83
lastIf += node->numInterfaces ;
86
- for (uint8_t i= 0 ; i< node->numEndpoints ; i++) {
84
+ for (uint8_t i = 0 ; i < node->numEndpoints ; i++) {
87
85
_initEndpoints[lastEp] = node->endpointType [i];
88
86
lastEp++;
89
87
}
90
- modulesCount++;
91
88
return true ;
92
89
// restart USB layer???
93
90
}
94
91
95
92
PluggableUSB_::PluggableUSB_ () : lastIf(CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT),
96
93
lastEp(CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT),
97
- modulesCount( 0 ), rootNode(NULL )
94
+ rootNode(NULL )
98
95
{
99
96
// Empty
100
97
}
0 commit comments