Skip to content

Commit 9c03000

Browse files
committed
[PUSB] No more static fields in PluggableUSB class
1 parent aa80236 commit 9c03000

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

hardware/arduino/avr/cores/arduino/PluggableUSB.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,17 @@
2525

2626
#define MAX_MODULES 6
2727

28-
static uint8_t lastIf = CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT;
29-
static uint8_t lastEp = CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT;
30-
3128
extern uint8_t _initEndpoints[];
3229

3330
//PUSBCallbacks cbs[MAX_MODULES];
34-
static uint8_t modules_count = 0;
3531

36-
static PUSBListNode* rootNode = NULL;
32+
PluggableUSB_ PluggableUSB;
3733

3834
int PluggableUSB_::getInterface(uint8_t* interfaceNum)
3935
{
4036
int ret = 0;
4137
PUSBListNode* node = rootNode;
42-
for (uint8_t i=0; i<modules_count; i++) {
38+
for (uint8_t i=0; i<modulesCount; i++) {
4339
ret = node->getInterface(interfaceNum);
4440
node = node->next;
4541
}
@@ -50,7 +46,7 @@ int PluggableUSB_::getDescriptor(int8_t t)
5046
{
5147
int ret = 0;
5248
PUSBListNode* node = rootNode;
53-
for (uint8_t i=0; i<modules_count && ret == 0; i++) {
49+
for (uint8_t i=0; i<modulesCount && ret == 0; i++) {
5450
ret = node->getDescriptor(t);
5551
node = node->next;
5652
}
@@ -61,7 +57,7 @@ bool PluggableUSB_::setup(USBSetup& setup, uint8_t j)
6157
{
6258
bool ret = false;
6359
PUSBListNode* node = rootNode;
64-
for (uint8_t i=0; i<modules_count && ret == false; i++) {
60+
for (uint8_t i=0; i<modulesCount && ret == false; i++) {
6561
ret = node->setup(setup, j);
6662
node = node->next;
6763
}
@@ -70,11 +66,11 @@ bool PluggableUSB_::setup(USBSetup& setup, uint8_t j)
7066

7167
bool PluggableUSB_::plug(PUSBListNode *node)
7268
{
73-
if (modules_count >= MAX_MODULES) {
69+
if (modulesCount >= MAX_MODULES) {
7470
return false;
7571
}
7672

77-
if (modules_count == 0) {
73+
if (modulesCount == 0) {
7874
rootNode = node;
7975
} else {
8076
PUSBListNode *current = rootNode;
@@ -91,11 +87,18 @@ bool PluggableUSB_::plug(PUSBListNode *node)
9187
_initEndpoints[lastEp] = node->endpointType[i];
9288
lastEp++;
9389
}
94-
modules_count++;
90+
modulesCount++;
9591
return true;
9692
// restart USB layer???
9793
}
9894

95+
PluggableUSB_::PluggableUSB_() : lastIf(CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT),
96+
lastEp(CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT),
97+
modulesCount(0), rootNode(NULL)
98+
{
99+
// Empty
100+
}
101+
99102
#endif
100103

101104
#endif /* if defined(USBCON) */

hardware/arduino/avr/cores/arduino/PluggableUSB.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,17 @@ class PUSBListNode {
5454

5555
class PluggableUSB_ {
5656
public:
57-
static bool plug(PUSBListNode *node);
58-
static int getInterface(uint8_t* interfaceNum);
59-
static int getDescriptor(int8_t t);
60-
static bool setup(USBSetup& setup, uint8_t i);
57+
PluggableUSB_();
58+
bool plug(PUSBListNode *node);
59+
int getInterface(uint8_t* interfaceNum);
60+
int getDescriptor(int8_t t);
61+
bool setup(USBSetup& setup, uint8_t i);
62+
63+
private:
64+
uint8_t lastIf;
65+
uint8_t lastEp;
66+
uint8_t modulesCount;
67+
PUSBListNode* rootNode;
6168
};
6269

6370
extern PluggableUSB_ PluggableUSB;

0 commit comments

Comments
 (0)