|
25 | 25 |
|
26 | 26 | extern uint8_t _initEndpoints[];
|
27 | 27 |
|
| 28 | +PUSBListNode *PluggableUSB_::rootNode = NULL; |
| 29 | + |
| 30 | +void PluggableUSB_::plug(PUSBListNode *node) |
| 31 | +{ |
| 32 | + if (!rootNode) { |
| 33 | + rootNode = node; |
| 34 | + } else { |
| 35 | + PUSBListNode *current = rootNode; |
| 36 | + while (current->next) { |
| 37 | + current = current->next; |
| 38 | + } |
| 39 | + current->next = node; |
| 40 | + } |
| 41 | +} |
| 42 | + |
28 | 43 | PluggableUSB_ PluggableUSB;
|
29 | 44 |
|
30 | 45 | int PluggableUSB_::getInterface(uint8_t* interfaceNum)
|
@@ -63,36 +78,29 @@ bool PluggableUSB_::setup(USBSetup& setup, uint8_t j)
|
63 | 78 | return false;
|
64 | 79 | }
|
65 | 80 |
|
66 |
| -bool PluggableUSB_::plug(PUSBListNode *node) |
| 81 | +bool PluggableUSB_::init() |
67 | 82 | {
|
68 |
| - if ((lastEp + node->numEndpoints) > USB_ENDPOINTS) { |
69 |
| - return false; |
70 |
| - } |
71 |
| - |
72 |
| - if (!rootNode) { |
73 |
| - rootNode = node; |
74 |
| - } else { |
75 |
| - PUSBListNode *current = rootNode; |
76 |
| - while (current->next) { |
77 |
| - current = current->next; |
| 83 | + PUSBListNode* node; |
| 84 | + for (node = rootNode; node; node = node->next) { |
| 85 | + if ((lastEp + node->numEndpoints) > USB_ENDPOINTS) { |
| 86 | + return false; |
78 | 87 | }
|
79 |
| - current->next = node; |
80 |
| - } |
81 | 88 |
|
82 |
| - node->pluggedInterface = lastIf; |
83 |
| - node->pluggedEndpoint = lastEp; |
84 |
| - lastIf += node->numInterfaces; |
85 |
| - for (uint8_t i = 0; i < node->numEndpoints; i++) { |
86 |
| - _initEndpoints[lastEp] = node->endpointType[i]; |
87 |
| - lastEp++; |
| 89 | + node->pluggedInterface = lastIf; |
| 90 | + node->pluggedEndpoint = lastEp; |
| 91 | + lastIf += node->numInterfaces; |
| 92 | + for (uint8_t i = 0; i < node->numEndpoints; i++) { |
| 93 | + _initEndpoints[lastEp] = node->endpointType[i]; |
| 94 | + lastEp++; |
| 95 | + } |
| 96 | + node->init(); |
88 | 97 | }
|
89 | 98 | return true;
|
90 | 99 | // restart USB layer???
|
91 | 100 | }
|
92 | 101 |
|
93 | 102 | PluggableUSB_::PluggableUSB_() : lastIf(CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT),
|
94 |
| - lastEp(CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT), |
95 |
| - rootNode(NULL) |
| 103 | + lastEp(CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT) |
96 | 104 | {
|
97 | 105 | // Empty
|
98 | 106 | }
|
|
0 commit comments