Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4210c3d

Browse files
author
Martino Facchin
committed
rework PUSBCallbacks initialization
1 parent ebbd307 commit 4210c3d

File tree

4 files changed

+50
-41
lines changed

4 files changed

+50
-41
lines changed

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

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

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

3832
//PUSBCallbacks cbs[MAX_MODULES];
@@ -46,7 +40,7 @@ int8_t PUSB_GetInterface(u8* interfaceNum)
4640
int8_t ret = 0;
4741
PUSBListNode* node = rootNode;
4842
for (u8 i=0; i<modules_count; i++) {
49-
ret = node->cb.getInterface(interfaceNum);
43+
ret = node->cb->getInterface(interfaceNum);
5044
node = node->next;
5145
}
5246
return ret;
@@ -57,7 +51,7 @@ int8_t PUSB_GetDescriptor(int8_t t)
5751
int8_t ret = 0;
5852
PUSBListNode* node = rootNode;
5953
for (u8 i=0; i<modules_count && ret == 0; i++) {
60-
ret = node->cb.getDescriptor(t);
54+
ret = node->cb->getDescriptor(t);
6155
node = node->next;
6256
}
6357
return ret;
@@ -68,24 +62,18 @@ bool PUSB_Setup(Setup& setup, u8 j)
6862
bool ret = false;
6963
PUSBListNode* node = rootNode;
7064
for (u8 i=0; i<modules_count && ret == false; i++) {
71-
ret = node->cb.setup(setup, j);
65+
ret = node->cb->setup(setup, j);
7266
node = node->next;
7367
}
7468
return ret;
7569
}
7670

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

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

9684
*interface = lastIf;
97-
lastIf += cb->numInterfaces;
98-
for ( u8 i = 0; i< cb->numEndpoints; i++) {
99-
_initEndpoints[lastEp] = cb->endpointType[i];
85+
lastIf += node->cb->numInterfaces;
86+
for ( u8 i = 0; i< node->cb->numEndpoints; i++) {
87+
_initEndpoints[lastEp] = node->cb->endpointType[i];
10088
lastEp++;
10189
}
10290
modules_count++;
103-
return lastEp - cb->numEndpoints;
91+
return lastEp - node->cb->numEndpoints;
10492
// restart USB layer???
10593
}
10694

‎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-
u8endpointType[];
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

‎libraries/HID/HID.cpp‎

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,22 @@ bool WEAK HID_Setup(Setup& setup, u8 i)
114114
// to be called by begin(), will trigger USB disconnection and reconnection
115115
int8_t HID_Plug(void)
116116
{
117-
PUSBCallbacks cb;
118-
119-
cb.setup = &HID_Setup;
120-
cb.getInterface = &HID_GetInterface;
121-
cb.getDescriptor = &HID_GetDescriptor;
122-
cb.numEndpoints = 1;
123-
cb.numInterfaces = 1;
124-
cb.endpointType[0] = EP_TYPE_INTERRUPT_IN;
125-
HID_ENDPOINT_INT = PUSB_AddFunction(&cb, &HID_INTERFACE);
117+
static uint8_t endpointType[1];
118+
119+
endpointType[0] = EP_TYPE_INTERRUPT_IN;
120+
121+
static PUSBCallbacks cb = {
122+
.setup = &HID_Setup,
123+
.getInterface = &HID_GetInterface,
124+
.getDescriptor = &HID_GetDescriptor,
125+
.numEndpoints = 1,
126+
.numInterfaces = 1,
127+
.endpointType = endpointType,
128+
};
129+
130+
static PUSBListNode node(&cb);
131+
132+
HID_ENDPOINT_INT = PUSB_AddFunction(&node, &HID_INTERFACE);
126133

127134
_hidInterface =
128135
{

‎libraries/MIDIUSB/MIDIUSB.cpp‎

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "PluggableUSB.h"
1717
#include "MIDIUSB.h"
1818

19-
#define MIDI_BUFFER_SIZE 128
19+
#define MIDI_BUFFER_SIZE 16
2020

2121

2222
static u8 MIDI_AC_INTERFACE; // MIDI AC Interface
@@ -173,17 +173,24 @@ void MIDI_::sendMIDI(midiEventPacket_t event)
173173

174174
int8_t MIDI_plug(void)
175175
{
176-
PUSBCallbacks cb;
177176

178-
cb.setup = &MIDI_Setup;
179-
cb.getInterface = &MIDI_GetInterface;
180-
cb.getDescriptor = &MIDI_GetDescriptor;
181-
cb.numEndpoints = 2;
182-
cb.numInterfaces = 2;
183-
cb.endpointType[0] = EP_TYPE_BULK_OUT_MIDI; // MIDI_ENDPOINT_OUT
184-
cb.endpointType[1] = EP_TYPE_BULK_IN_MIDI; // MIDI_ENDPOINT_IN
177+
static uint8_t endpointType[2];
185178

186-
MIDI_ENDPOINT_OUT = PUSB_AddFunction(&cb, &MIDI_AC_INTERFACE);
179+
endpointType[0] = EP_TYPE_BULK_OUT_MIDI; // MIDI_ENDPOINT_OUT
180+
endpointType[1] = EP_TYPE_BULK_IN_MIDI; // MIDI_ENDPOINT_IN
181+
182+
static PUSBCallbacks cb = {
183+
.setup = &MIDI_Setup,
184+
.getInterface = &MIDI_GetInterface,
185+
.getDescriptor = &MIDI_GetDescriptor,
186+
.numEndpoints = 1,
187+
.numInterfaces = 2,
188+
.endpointType = endpointType,
189+
};
190+
191+
static PUSBListNode node(&cb);
192+
193+
MIDI_ENDPOINT_OUT = PUSB_AddFunction(&node, &MIDI_AC_INTERFACE);
187194
MIDI_ENDPOINT_IN = MIDI_ENDPOINT_OUT + 1;
188195
MIDI_INTERFACE = MIDI_AC_INTERFACE + 1;
189196

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /