From c0f9296ae5bae083bcc793de1ddd7c7c79ad4236 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 30 Sep 2015 19:04:01 +0200 Subject: [PUSB] No more static fields in PluggableUSB class --- cores/arduino/PluggableUSB.cpp | 25 ++++++++++++++----------- cores/arduino/PluggableUSB.h | 15 +++++++++++---- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/cores/arduino/PluggableUSB.cpp b/cores/arduino/PluggableUSB.cpp index 2c7221d..a8c69d4 100644 --- a/cores/arduino/PluggableUSB.cpp +++ b/cores/arduino/PluggableUSB.cpp @@ -25,21 +25,17 @@ #define MAX_MODULES 6 -static uint8_t lastIf = CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT; -static uint8_t lastEp = CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT; - extern uint8_t _initEndpoints[]; //PUSBCallbacks cbs[MAX_MODULES]; -static uint8_t modules_count = 0; -static PUSBListNode* rootNode = NULL; +PluggableUSB_ PluggableUSB; int PluggableUSB_::getInterface(uint8_t* interfaceNum) { int ret = 0; PUSBListNode* node = rootNode; - for (uint8_t i=0; igetInterface(interfaceNum); node = node->next; } @@ -50,7 +46,7 @@ int PluggableUSB_::getDescriptor(int8_t t) { int ret = 0; PUSBListNode* node = rootNode; - for (uint8_t i=0; igetDescriptor(t); node = node->next; } @@ -61,7 +57,7 @@ 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; } @@ -70,11 +66,11 @@ bool PluggableUSB_::setup(USBSetup& setup, uint8_t j) bool PluggableUSB_::plug(PUSBListNode *node) { - if (modules_count >= MAX_MODULES) { + if (modulesCount >= MAX_MODULES) { return false; } - if (modules_count == 0) { + if (modulesCount == 0) { rootNode = node; } else { PUSBListNode *current = rootNode; @@ -91,11 +87,18 @@ bool PluggableUSB_::plug(PUSBListNode *node) _initEndpoints[lastEp] = node->endpointType[i]; lastEp++; } - modules_count++; + 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) +{ + // Empty +} + #endif #endif /* if defined(USBCON) */ diff --git a/cores/arduino/PluggableUSB.h b/cores/arduino/PluggableUSB.h index 0f776c0..93ee15c 100644 --- a/cores/arduino/PluggableUSB.h +++ b/cores/arduino/PluggableUSB.h @@ -54,10 +54,17 @@ public: class PluggableUSB_ { public: - static bool plug(PUSBListNode *node); - static int getInterface(uint8_t* interfaceNum); - static int getDescriptor(int8_t t); - static bool setup(USBSetup& setup, uint8_t i); + PluggableUSB_(); + bool plug(PUSBListNode *node); + int getInterface(uint8_t* interfaceNum); + int getDescriptor(int8_t t); + bool setup(USBSetup& setup, uint8_t i); + +private: + uint8_t lastIf; + uint8_t lastEp; + uint8_t modulesCount; + PUSBListNode* rootNode; }; extern PluggableUSB_ PluggableUSB; -- cgit v1.2.3-18-g5258