Skip to content

Commit 26c5450

Browse files
committed
update to stable PluggableUSB API
1 parent 28f871f commit 26c5450

File tree

2 files changed

+24
-25
lines changed

2 files changed

+24
-25
lines changed

src/MIDIUSB.cpp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@
1616

1717
#include "MIDIUSB.h"
1818

19-
#define MIDI_BUFFER_SIZE 64
20-
21-
#define MIDI_AC_INTERFACE interface() // MIDI AC Interface
22-
#define MIDI_INTERFACE interface()+1
23-
#define MIDI_FIRST_ENDPOINT endpoint()
24-
#define MIDI_ENDPOINT_OUT endpoint()
25-
#define MIDI_ENDPOINT_IN endpoint()+1
19+
#define MIDI_AC_INTERFACE pluggedInterface // MIDI AC Interface
20+
#define MIDI_INTERFACE pluggedInterface+1
21+
#define MIDI_FIRST_ENDPOINT pluggedEndpoint
22+
#define MIDI_ENDPOINT_OUT pluggedEndpoint
23+
#define MIDI_ENDPOINT_IN pluggedEndpoint+1
2624

2725
#define MIDI_RX MIDI_ENDPOINT_OUT
2826
#define MIDI_TX MIDI_ENDPOINT_IN
@@ -40,8 +38,8 @@ MIDI_ MidiUSB;
4038

4139
int MIDI_::getInterface(uint8_t* interfaceNum)
4240
{
43-
interfaceNum[0] += 2; // uses 2
44-
_midiInterface =
41+
interfaceNum[0] += 2; // uses 2 interfaces
42+
MIDIDescriptor _midiInterface =
4543
{
4644
D_IAD(MIDI_AC_INTERFACE, 2, MIDI_AUDIO, MIDI_AUDIO_CONTROL, 0),
4745
D_INTERFACE(MIDI_AC_INTERFACE,0,MIDI_AUDIO,MIDI_AUDIO_CONTROL,0),
@@ -52,28 +50,28 @@ int MIDI_::getInterface(uint8_t* interfaceNum)
5250
D_MIDI_INJACK(MIDI_JACK_EXT, 0x2),
5351
D_MIDI_OUTJACK(MIDI_JACK_EMD, 0x3, 1, 2, 1),
5452
D_MIDI_OUTJACK(MIDI_JACK_EXT, 0x4, 1, 1, 1),
55-
D_MIDI_JACK_EP(USB_ENDPOINT_OUT(MIDI_ENDPOINT_OUT),USB_ENDPOINT_TYPE_BULK,64),
53+
D_MIDI_JACK_EP(USB_ENDPOINT_OUT(MIDI_ENDPOINT_OUT),USB_ENDPOINT_TYPE_BULK,MIDI_BUFFER_SIZE),
5654
D_MIDI_AC_JACK_EP(1, 1),
57-
D_MIDI_JACK_EP(USB_ENDPOINT_IN(MIDI_ENDPOINT_IN),USB_ENDPOINT_TYPE_BULK,64),
55+
D_MIDI_JACK_EP(USB_ENDPOINT_IN(MIDI_ENDPOINT_IN),USB_ENDPOINT_TYPE_BULK,MIDI_BUFFER_SIZE),
5856
D_MIDI_AC_JACK_EP (1, 3)
5957
};
60-
return USB_SendControl(0,&_midiInterface,sizeof(_midiInterface));
58+
return USB_SendControl(0, &_midiInterface, sizeof(_midiInterface));
6159
}
6260

63-
bool MIDI_::setup(USBSetup& setup, uint8_t i)
61+
bool MIDI_::setup(USBSetup& setup __attribute__((unused)))
6462
{
6563
//Support requests here if needed. Typically these are optional
6664
return false;
6765
}
6866

69-
int MIDI_::getDescriptor(int8_t t)
67+
int MIDI_::getDescriptor(USBSetup& setup __attribute__((unused)))
7068
{
7169
return 0;
7270
}
7371

7472
char* MIDI_GetShortName()
7573
{
76-
static char* name = "MI";
74+
static char* name = "MIDI";
7775
return name;
7876
}
7977

@@ -177,7 +175,7 @@ void MIDI_::sendMIDI(midiEventPacket_t event)
177175
write(data, 4);
178176
}
179177

180-
MIDI_::MIDI_(void) : PUSBListNode(2, 2, epType)
178+
MIDI_::MIDI_(void) : PluggableUSBModule(2, 2, epType)
181179
{
182180
epType[0] = EP_TYPE_BULK_OUT_MIDI; // MIDI_ENDPOINT_OUT
183181
epType[1] = EP_TYPE_BULK_IN_MIDI; // MIDI_ENDPOINT_IN

src/MIDIUSB.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,16 @@ typedef struct
2121
#if defined(ARDUINO_ARCH_AVR)
2222

2323
#include "PluggableUSB.h"
24-
#define EPTYPE_DESCRIPTOR_SIZE uint8_t
24+
#define EPTYPE_DESCRIPTOR_SIZE uint8_t
2525
#define EP_TYPE_BULK_OUT_MIDI EP_TYPE_BULK_OUT
2626
#define EP_TYPE_BULK_IN_MIDI EP_TYPE_BULK_IN
27+
#define MIDI_BUFFER_SIZE 64
2728

2829
#else
2930

3031
#include "USB/PluggableUSB.h"
31-
#define EPTYPE_DESCRIPTOR_SIZE uint32_t
32+
#define EPTYPE_DESCRIPTOR_SIZE uint32_t
33+
#define MIDI_BUFFER_SIZE 512
3234

3335
#if defined(ARDUINO_ARCH_SAM)
3436
#define USB_SendControl USBD_SendControl
@@ -37,14 +39,14 @@ typedef struct
3739
#define USB_Send USBD_Send
3840
#define USB_Flush USBD_Flush
3941

40-
#define EP_TYPE_BULK_IN_MIDI (UOTGHS_DEVEPTCFG_EPSIZE_64_BYTE | \
42+
#define EP_TYPE_BULK_IN_MIDI (UOTGHS_DEVEPTCFG_EPSIZE_512_BYTE | \
4143
UOTGHS_DEVEPTCFG_EPDIR_IN | \
4244
UOTGHS_DEVEPTCFG_EPTYPE_BLK | \
4345
UOTGHS_DEVEPTCFG_EPBK_1_BANK | \
4446
UOTGHS_DEVEPTCFG_NBTRANS_1_TRANS | \
4547
UOTGHS_DEVEPTCFG_ALLOC)
4648

47-
#define EP_TYPE_BULK_OUT_MIDI (UOTGHS_DEVEPTCFG_EPSIZE_64_BYTE | \
49+
#define EP_TYPE_BULK_OUT_MIDI (UOTGHS_DEVEPTCFG_EPSIZE_512_BYTE | \
4850
UOTGHS_DEVEPTCFG_EPTYPE_BLK | \
4951
UOTGHS_DEVEPTCFG_EPBK_1_BANK | \
5052
UOTGHS_DEVEPTCFG_NBTRANS_1_TRANS | \
@@ -157,7 +159,7 @@ typedef struct
157159
} MIDIDescriptor;
158160

159161
#define D_AC_INTERFACE(_streamingInterfaces, _MIDIInterface) \
160-
{ 9, MIDI_CS_INTERFACE, 0x1, 0x0100, 0x0009, _streamingInterfaces, _MIDIInterface }
162+
{ 9, MIDI_CS_INTERFACE, 0x1, 0x0100, 0x0009, _streamingInterfaces, (uint8_t)(_MIDIInterface) }
161163

162164
#define D_AS_INTERFACE \
163165
{ 0x7, MIDI_CS_INTERFACE, 0x01,0x0100, 0x0041}
@@ -181,20 +183,19 @@ _Pragma("pack()")
181183

182184
#define WEAK __attribute__ ((weak))
183185

184-
class MIDI_ : public PUSBListNode
186+
class MIDI_ : public PluggableUSBModule
185187
{
186188
// private:
187189
// RingBuffer *_midi_rx_buffer;
188190
private:
189191
void accept(void);
190192
EPTYPE_DESCRIPTOR_SIZE epType[2];
191-
MIDIDescriptor _midiInterface;
192193

193194
protected:
194195
// Implementation of the PUSBListNode
195196
int getInterface(uint8_t* interfaceNum);
196-
int getDescriptor(int8_t t);
197-
bool setup(USBSetup& setup, uint8_t i);
197+
int getDescriptor(USBSetup& setup);
198+
bool setup(USBSetup& setup);
198199

199200
public:
200201
MIDI_(void);

0 commit comments

Comments
 (0)