From b38d7f07f0ee8e5e9bdc912966dcee4ae3a8b3e7 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Mon, 8 Jun 2015 12:31:24 +0200 Subject: implement PUSB modules as linked list --- cores/arduino/PluggableUSB.cpp | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) (limited to 'cores/arduino/PluggableUSB.cpp') diff --git a/cores/arduino/PluggableUSB.cpp b/cores/arduino/PluggableUSB.cpp index b5e94ee..15195b0 100644 --- a/cores/arduino/PluggableUSB.cpp +++ b/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++; -- cgit v1.2.3-18-g5258