Skip to content

Commit 53ffb34

Browse files
facchinmcmaglie
authored andcommitted
rework PUSBCallbacks initialization
1 parent fd11fe5 commit 53ffb34

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

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

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@
2828
static u8 lastIf = CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT;
2929
static u8 lastEp = CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT;
3030

31-
class PUSBListNode {
32-
public:
33-
PUSBListNode *next = NULL;
34-
PUSBCallbacks cb;
35-
};
36-
3731
extern u8 _initEndpoints[];
3832

3933
//PUSBCallbacks cbs[MAX_MODULES];
@@ -47,7 +41,7 @@ int8_t PUSB_GetInterface(u8* interfaceNum)
4741
int8_t ret = 0;
4842
PUSBListNode* node = rootNode;
4943
for (u8 i=0; i<modules_count; i++) {
50-
ret = node->cb.getInterface(interfaceNum);
44+
ret = node->cb->getInterface(interfaceNum);
5145
node = node->next;
5246
}
5347
return ret;
@@ -58,7 +52,7 @@ int8_t PUSB_GetDescriptor(int8_t t)
5852
int8_t ret = 0;
5953
PUSBListNode* node = rootNode;
6054
for (u8 i=0; i<modules_count && ret == 0; i++) {
61-
ret = node->cb.getDescriptor(t);
55+
ret = node->cb->getDescriptor(t);
6256
node = node->next;
6357
}
6458
return ret;
@@ -69,24 +63,18 @@ bool PUSB_Setup(Setup& setup, u8 j)
6963
bool ret = false;
7064
PUSBListNode* node = rootNode;
7165
for (u8 i=0; i<modules_count && ret == false; i++) {
72-
ret = node->cb.setup(setup, j);
66+
ret = node->cb->setup(setup, j);
7367
node = node->next;
7468
}
7569
return ret;
7670
}
7771

78-
int8_t PUSB_AddFunction(PUSBCallbacks *cb, u8* interface)
72+
int8_t PUSB_AddFunction(PUSBListNode *node, u8* interface)
7973
{
8074
if (modules_count >= MAX_MODULES) {
8175
return 0;
8276
}
8377

84-
PUSBListNode *node = new PUSBListNode;
85-
86-
node->cb.setup = cb->setup;
87-
node->cb.getInterface = cb->getInterface;
88-
node->cb.getDescriptor = cb->getDescriptor;
89-
9078
if (modules_count == 0) {
9179
rootNode = node;
9280
lastNode = node;
@@ -95,13 +83,13 @@ int8_t PUSB_AddFunction(PUSBCallbacks *cb, u8* interface)
9583
}
9684

9785
*interface = lastIf;
98-
lastIf += cb->numInterfaces;
99-
for ( u8 i = 0; i< cb->numEndpoints; i++) {
100-
_initEndpoints[lastEp] = cb->endpointType[i];
86+
lastIf += node->cb->numInterfaces;
87+
for ( u8 i = 0; i< node->cb->numEndpoints; i++) {
88+
_initEndpoints[lastEp] = node->cb->endpointType[i];
10189
lastEp++;
10290
}
10391
modules_count++;
104-
return lastEp - cb->numEndpoints;
92+
return lastEp - node->cb->numEndpoints;
10593
// restart USB layer???
10694
}
10795

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ typedef struct
3232
int8_t (*getDescriptor)(int8_t t);
3333
int8_t numEndpoints;
3434
int8_t numInterfaces;
35-
u8 endpointType[];
35+
uint8_t *endpointType;
3636
} PUSBCallbacks;
3737

3838
typedef struct
@@ -41,7 +41,14 @@ typedef struct
4141
u8 firstEndpoint;
4242
} PUSBReturn;
4343

44-
int8_t PUSB_AddFunction(PUSBCallbacks *cb, u8 *interface);
44+
class PUSBListNode {
45+
public:
46+
PUSBListNode *next = NULL;
47+
PUSBCallbacks *cb;
48+
PUSBListNode(PUSBCallbacks *ncb) {cb = ncb;}
49+
};
50+
51+
int8_t PUSB_AddFunction(PUSBListNode *node, u8 *interface);
4552

4653
int8_t PUSB_GetInterface(u8* interfaceNum);
4754

0 commit comments

Comments
 (0)