diff --git a/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp b/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp index b5e94eeb6..15195b01a 100644 --- a/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp +++ b/hardware/arduino/avr/cores/arduino/PluggableUSB.cpp @@ -28,16 +28,27 @@ static u8 lastIf = CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT; static u8 lastEp = CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT; +class PUSBListNode { +public: + PUSBListNode *next = NULL; + PUSBCallbacks cb; +}; + extern u8 _initEndpoints[]; -PUSBCallbacks cbs[MAX_MODULES]; -u8 modules_count = 0; +//PUSBCallbacks cbs[MAX_MODULES]; +static u8 modules_count = 0; + +static PUSBListNode* rootNode = NULL; +static PUSBListNode* lastNode = NULL; int8_t PUSB_GetInterface(u8* interfaceNum) { int8_t ret = 0; + PUSBListNode* node = rootNode; for (u8 i=0; icb.getInterface(interfaceNum); + node = node->next; } return ret; } @@ -45,8 +56,10 @@ int8_t PUSB_GetInterface(u8* interfaceNum) int8_t PUSB_GetDescriptor(int8_t t) { int8_t ret = 0; + PUSBListNode* node = rootNode; for (u8 i=0; icb.getDescriptor(t); + node = node->next; } return ret; } @@ -54,8 +67,10 @@ int8_t PUSB_GetDescriptor(int8_t t) bool PUSB_Setup(Setup& setup, u8 j) { bool ret = false; + PUSBListNode* node = rootNode; for (u8 i=0; icb.setup(setup, j); + node = node->next; } return ret; } @@ -65,7 +80,19 @@ int8_t PUSB_AddFunction(PUSBCallbacks *cb, u8* interface) if (modules_count >= MAX_MODULES) { return 0; } - cbs[modules_count] = *cb; + + PUSBListNode *node = new PUSBListNode; + + node->cb.setup = cb->setup; + node->cb.getInterface = cb->getInterface; + node->cb.getDescriptor = cb->getDescriptor; + + if (modules_count == 0) { + rootNode = node; + lastNode = node; + } else { + lastNode->next = node; + } *interface = lastIf; lastIf++; diff --git a/hardware/arduino/avr/cores/arduino/PluggableUSB.h b/hardware/arduino/avr/cores/arduino/PluggableUSB.h index 877a9b00f..e066d3775 100644 --- a/hardware/arduino/avr/cores/arduino/PluggableUSB.h +++ b/hardware/arduino/avr/cores/arduino/PluggableUSB.h @@ -31,7 +31,7 @@ typedef struct int8_t (*getInterface)(u8* interfaceNum); int8_t (*getDescriptor)(int8_t t); int8_t numEndpoints; - u8 endpointType[6]; + u8 endpointType[]; } PUSBCallbacks; typedef struct