From e42d7d6221e175e087196f946ae139ca236f4e46 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 30 Sep 2015 19:30:23 +0200 Subject: [PUSB] Fixed check for available endpoints The check for available slot in PluggableUSB is done on the endpoint and not on the number of plugged modules. The modulesCount field is no longer useful and it has been removed. --- cores/arduino/PluggableUSB.cpp | 45 ++++++++++++++++++++---------------------- cores/arduino/PluggableUSB.h | 1 - 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/cores/arduino/PluggableUSB.cpp b/cores/arduino/PluggableUSB.cpp index a8c69d4..5a53eb1 100644 --- a/cores/arduino/PluggableUSB.cpp +++ b/cores/arduino/PluggableUSB.cpp @@ -23,58 +23,56 @@ #if defined(USBCON) #ifdef PLUGGABLE_USB_ENABLED -#define MAX_MODULES 6 +// TODO: set correct value for different CPUs +#define MAX_EP 6 extern uint8_t _initEndpoints[]; -//PUSBCallbacks cbs[MAX_MODULES]; - PluggableUSB_ PluggableUSB; int PluggableUSB_::getInterface(uint8_t* interfaceNum) { int ret = 0; - PUSBListNode* node = rootNode; - for (uint8_t i=0; inext) { ret = node->getInterface(interfaceNum); - node = node->next; } return ret; } int PluggableUSB_::getDescriptor(int8_t t) { - int ret = 0; - PUSBListNode* node = rootNode; - for (uint8_t i=0; igetDescriptor(t); - node = node->next; + PUSBListNode* node; + for (node = rootNode; node; node = node->next) { + int ret = node->getDescriptor(t); + if (ret) + return ret; } - return ret; + return 0; } bool PluggableUSB_::setup(USBSetup& setup, uint8_t j) { - bool ret = false; - PUSBListNode* node = rootNode; - for (uint8_t i=0; isetup(setup, j); - node = node->next; + PUSBListNode* node; + for (node = rootNode; node; node = node->next) { + if (node->setup(setup, j)) { + return true; + } } - return ret; + return false; } bool PluggableUSB_::plug(PUSBListNode *node) { - if (modulesCount >= MAX_MODULES) { + if ((lastEp + node->numEndpoints) >= MAX_EP) { return false; } - if (modulesCount == 0) { + if (!rootNode) { rootNode = node; } else { PUSBListNode *current = rootNode; - while(current->next != NULL) { + while (current->next) { current = current->next; } current->next = node; @@ -83,18 +81,17 @@ bool PluggableUSB_::plug(PUSBListNode *node) node->pluggedInterface = lastIf; node->pluggedEndpoint = lastEp; lastIf += node->numInterfaces; - for (uint8_t i=0; inumEndpoints; i++) { + for (uint8_t i = 0; i < node->numEndpoints; i++) { _initEndpoints[lastEp] = node->endpointType[i]; lastEp++; } - modulesCount++; return true; // restart USB layer??? } PluggableUSB_::PluggableUSB_() : lastIf(CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT), lastEp(CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT), - modulesCount(0), rootNode(NULL) + rootNode(NULL) { // Empty } diff --git a/cores/arduino/PluggableUSB.h b/cores/arduino/PluggableUSB.h index 93ee15c..824440a 100644 --- a/cores/arduino/PluggableUSB.h +++ b/cores/arduino/PluggableUSB.h @@ -63,7 +63,6 @@ public: private: uint8_t lastIf; uint8_t lastEp; - uint8_t modulesCount; PUSBListNode* rootNode; }; -- cgit v1.2.3-18-g5258