mirror of
https://github.com/arduino/Arduino.git
synced 2025-03-15 12:29:26 +01:00
rework PUSBCallbacks initialization
This commit is contained in:
parent
ada0e4c2f3
commit
89928b4e15
@ -28,12 +28,6 @@
|
||||
static u8 lastIf = CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT;
|
||||
static u8 lastEp = CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT;
|
||||
|
||||
class PUSBListNode {
|
||||
public:
|
||||
PUSBListNode *next = NULL;
|
||||
PUSBCallbacks cb;
|
||||
};
|
||||
|
||||
extern u8 _initEndpoints[];
|
||||
|
||||
//PUSBCallbacks cbs[MAX_MODULES];
|
||||
@ -47,7 +41,7 @@ int8_t PUSB_GetInterface(u8* interfaceNum)
|
||||
int8_t ret = 0;
|
||||
PUSBListNode* node = rootNode;
|
||||
for (u8 i=0; i<modules_count; i++) {
|
||||
ret = node->cb.getInterface(interfaceNum);
|
||||
ret = node->cb->getInterface(interfaceNum);
|
||||
node = node->next;
|
||||
}
|
||||
return ret;
|
||||
@ -58,7 +52,7 @@ int8_t PUSB_GetDescriptor(int8_t t)
|
||||
int8_t ret = 0;
|
||||
PUSBListNode* node = rootNode;
|
||||
for (u8 i=0; i<modules_count && ret == 0; i++) {
|
||||
ret = node->cb.getDescriptor(t);
|
||||
ret = node->cb->getDescriptor(t);
|
||||
node = node->next;
|
||||
}
|
||||
return ret;
|
||||
@ -69,24 +63,18 @@ bool PUSB_Setup(Setup& setup, u8 j)
|
||||
bool ret = false;
|
||||
PUSBListNode* node = rootNode;
|
||||
for (u8 i=0; i<modules_count && ret == false; i++) {
|
||||
ret = node->cb.setup(setup, j);
|
||||
ret = node->cb->setup(setup, j);
|
||||
node = node->next;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int8_t PUSB_AddFunction(PUSBCallbacks *cb, u8* interface)
|
||||
int8_t PUSB_AddFunction(PUSBListNode *node, u8* interface)
|
||||
{
|
||||
if (modules_count >= MAX_MODULES) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
PUSBListNode *node = new PUSBListNode;
|
||||
|
||||
node->cb.setup = cb->setup;
|
||||
node->cb.getInterface = cb->getInterface;
|
||||
node->cb.getDescriptor = cb->getDescriptor;
|
||||
|
||||
if (modules_count == 0) {
|
||||
rootNode = node;
|
||||
lastNode = node;
|
||||
@ -95,13 +83,13 @@ int8_t PUSB_AddFunction(PUSBCallbacks *cb, u8* interface)
|
||||
}
|
||||
|
||||
*interface = lastIf;
|
||||
lastIf += cb->numInterfaces;
|
||||
for ( u8 i = 0; i< cb->numEndpoints; i++) {
|
||||
_initEndpoints[lastEp] = cb->endpointType[i];
|
||||
lastIf += node->cb->numInterfaces;
|
||||
for ( u8 i = 0; i< node->cb->numEndpoints; i++) {
|
||||
_initEndpoints[lastEp] = node->cb->endpointType[i];
|
||||
lastEp++;
|
||||
}
|
||||
modules_count++;
|
||||
return lastEp - cb->numEndpoints;
|
||||
return lastEp - node->cb->numEndpoints;
|
||||
// restart USB layer???
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ typedef struct
|
||||
int8_t (*getDescriptor)(int8_t t);
|
||||
int8_t numEndpoints;
|
||||
int8_t numInterfaces;
|
||||
u8 endpointType[];
|
||||
uint8_t *endpointType;
|
||||
} PUSBCallbacks;
|
||||
|
||||
typedef struct
|
||||
@ -41,7 +41,14 @@ typedef struct
|
||||
u8 firstEndpoint;
|
||||
} PUSBReturn;
|
||||
|
||||
int8_t PUSB_AddFunction(PUSBCallbacks *cb, u8 *interface);
|
||||
class PUSBListNode {
|
||||
public:
|
||||
PUSBListNode *next = NULL;
|
||||
PUSBCallbacks *cb;
|
||||
PUSBListNode(PUSBCallbacks *ncb) {cb = ncb;}
|
||||
};
|
||||
|
||||
int8_t PUSB_AddFunction(PUSBListNode *node, u8 *interface);
|
||||
|
||||
int8_t PUSB_GetInterface(u8* interfaceNum);
|
||||
|
||||
|
@ -114,15 +114,22 @@ bool WEAK HID_Setup(Setup& setup, u8 i)
|
||||
// to be called by begin(), will trigger USB disconnection and reconnection
|
||||
int8_t HID_Plug(void)
|
||||
{
|
||||
PUSBCallbacks cb;
|
||||
static uint8_t endpointType[1];
|
||||
|
||||
cb.setup = &HID_Setup;
|
||||
cb.getInterface = &HID_GetInterface;
|
||||
cb.getDescriptor = &HID_GetDescriptor;
|
||||
cb.numEndpoints = 1;
|
||||
cb.numInterfaces = 1;
|
||||
cb.endpointType[0] = EP_TYPE_INTERRUPT_IN;
|
||||
HID_ENDPOINT_INT = PUSB_AddFunction(&cb, &HID_INTERFACE);
|
||||
endpointType[0] = EP_TYPE_INTERRUPT_IN;
|
||||
|
||||
static PUSBCallbacks cb = {
|
||||
.setup = &HID_Setup,
|
||||
.getInterface = &HID_GetInterface,
|
||||
.getDescriptor = &HID_GetDescriptor,
|
||||
.numEndpoints = 1,
|
||||
.numInterfaces = 1,
|
||||
.endpointType = endpointType,
|
||||
};
|
||||
|
||||
static PUSBListNode node(&cb);
|
||||
|
||||
HID_ENDPOINT_INT = PUSB_AddFunction(&node, &HID_INTERFACE);
|
||||
|
||||
_hidInterface =
|
||||
{
|
||||
|
@ -16,7 +16,7 @@
|
||||
#include "PluggableUSB.h"
|
||||
#include "MIDIUSB.h"
|
||||
|
||||
#define MIDI_BUFFER_SIZE 128
|
||||
#define MIDI_BUFFER_SIZE 16
|
||||
|
||||
|
||||
static u8 MIDI_AC_INTERFACE; // MIDI AC Interface
|
||||
@ -173,17 +173,24 @@ void MIDI_::sendMIDI(midiEventPacket_t event)
|
||||
|
||||
int8_t MIDI_plug(void)
|
||||
{
|
||||
PUSBCallbacks cb;
|
||||
|
||||
cb.setup = &MIDI_Setup;
|
||||
cb.getInterface = &MIDI_GetInterface;
|
||||
cb.getDescriptor = &MIDI_GetDescriptor;
|
||||
cb.numEndpoints = 2;
|
||||
cb.numInterfaces = 2;
|
||||
cb.endpointType[0] = EP_TYPE_BULK_OUT_MIDI; // MIDI_ENDPOINT_OUT
|
||||
cb.endpointType[1] = EP_TYPE_BULK_IN_MIDI; // MIDI_ENDPOINT_IN
|
||||
static uint8_t endpointType[2];
|
||||
|
||||
MIDI_ENDPOINT_OUT = PUSB_AddFunction(&cb, &MIDI_AC_INTERFACE);
|
||||
endpointType[0] = EP_TYPE_BULK_OUT_MIDI; // MIDI_ENDPOINT_OUT
|
||||
endpointType[1] = EP_TYPE_BULK_IN_MIDI; // MIDI_ENDPOINT_IN
|
||||
|
||||
static PUSBCallbacks cb = {
|
||||
.setup = &MIDI_Setup,
|
||||
.getInterface = &MIDI_GetInterface,
|
||||
.getDescriptor = &MIDI_GetDescriptor,
|
||||
.numEndpoints = 1,
|
||||
.numInterfaces = 2,
|
||||
.endpointType = endpointType,
|
||||
};
|
||||
|
||||
static PUSBListNode node(&cb);
|
||||
|
||||
MIDI_ENDPOINT_OUT = PUSB_AddFunction(&node, &MIDI_AC_INTERFACE);
|
||||
MIDI_ENDPOINT_IN = MIDI_ENDPOINT_OUT + 1;
|
||||
MIDI_INTERFACE = MIDI_AC_INTERFACE + 1;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user