Skip to content

Commit 9e73ffe

Browse files
committed
make library compatible with Due
1 parent 8adec1c commit 9e73ffe

File tree

2 files changed

+51
-24
lines changed

2 files changed

+51
-24
lines changed

src/MIDIUSB.cpp

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,32 @@
1414
** SOFTWARE.
1515
*/
1616

17-
#include "PluggableUSB.h"
1817
#include "MIDIUSB.h"
1918

2019
#define MIDI_BUFFER_SIZE 16
2120

21+
#if defined(ARDUINO_ARCH_AVR)
22+
23+
#include "PluggableUSB.h"
24+
#define EPTYPE_DESCRIPTOR_SIZE uint8_t
25+
26+
#else
27+
28+
#include "USB/PluggableUSB.h"
29+
#define USB_SendControl USBD_SendControl
30+
#define USB_Available USBD_Available
31+
#define USB_Recv USBD_Recv
32+
#define USB_Send USBD_Send
33+
#define USB_Flush USBD_Flush
34+
#define EPTYPE_DESCRIPTOR_SIZE uint32_t
2235

23-
static u8 MIDI_AC_INTERFACE; // MIDI AC Interface
24-
static u8 MIDI_INTERFACE;
25-
static u8 MIDI_FIRST_ENDPOINT;
26-
static u8 MIDI_ENDPOINT_OUT;
27-
static u8 MIDI_ENDPOINT_IN;
36+
#endif
37+
38+
static uint8_t MIDI_AC_INTERFACE; // MIDI AC Interface
39+
static uint8_t MIDI_INTERFACE;
40+
static uint8_t MIDI_FIRST_ENDPOINT;
41+
static uint8_t MIDI_ENDPOINT_OUT;
42+
static uint8_t MIDI_ENDPOINT_IN;
2843

2944
#define MIDI_RX MIDI_ENDPOINT_OUT
3045
#define MIDI_TX MIDI_ENDPOINT_IN
@@ -45,7 +60,8 @@ int MIDI_GetInterface(uint8_t* interfaceNum)
4560
interfaceNum[0] += 2; // uses 2
4661
return USB_SendControl(0,&_midiInterface,sizeof(_midiInterface));
4762
}
48-
bool MIDI_Setup(USBSetup& setup, u8 i)
63+
64+
bool MIDI_Setup(USBSetup& setup, uint8_t i)
4965
{
5066
//Support requests here if needed. Typically these are optional
5167
return false;
@@ -58,16 +74,6 @@ int MIDI_GetDescriptor(int8_t t)
5874

5975
void MIDI_::accept(void)
6076
{
61-
static uint32_t mguard = 0;
62-
63-
// // synchronized access to guard
64-
// do {
65-
// if (__LDREXW(&mguard) != 0) {
66-
// __CLREX();
67-
// return; // busy
68-
// }
69-
// } while (__STREXW(1, &mguard) != 0); // retry until write succeed
70-
7177
ring_bufferMIDI *buffer = &midi_rx_buffer;
7278
uint32_t i = (uint32_t)(buffer->head+1) % MIDI_BUFFER_SIZE;
7379

@@ -79,8 +85,10 @@ void MIDI_::accept(void)
7985
int c;
8086
midiEventPacket_t event;
8187
if (!USB_Available(MIDI_RX)) {
82-
//udd_ack_fifocon(MIDI_RX);
83-
break;
88+
#if defined(ARDUINO_ARCH_SAM)
89+
udd_ack_fifocon(MIDI_RX);
90+
#endif
91+
//break;
8492
}
8593
c = USB_Recv(MIDI_RX, &event, sizeof(event) );
8694

@@ -92,9 +100,6 @@ void MIDI_::accept(void)
92100

93101
i = (i + 1) % MIDI_BUFFER_SIZE;
94102
}
95-
96-
// release the guard
97-
mguard = 0;
98103
}
99104

100105
uint32_t MIDI_::available(void)
@@ -170,7 +175,7 @@ void MIDI_::sendMIDI(midiEventPacket_t event)
170175

171176
MIDI_::MIDI_(void)
172177
{
173-
static uint8_t endpointType[2];
178+
static EPTYPE_DESCRIPTOR_SIZE endpointType[2];
174179

175180
endpointType[0] = EP_TYPE_BULK_OUT_MIDI; // MIDI_ENDPOINT_OUT
176181
endpointType[1] = EP_TYPE_BULK_IN_MIDI; // MIDI_ENDPOINT_IN
@@ -213,4 +218,4 @@ int8_t MIDI_::begin()
213218
}
214219

215220

216-
MIDI_ MidiUSB;
221+
MIDI_ MidiUSB;

src/MIDIUSB.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,27 @@ typedef struct
1818
uint8_t byte3;
1919
}midiEventPacket_t;
2020

21+
#if !defined(ARDUINO_ARCH_SAM)
22+
2123
#define EP_TYPE_BULK_OUT_MIDI EP_TYPE_BULK_OUT
2224
#define EP_TYPE_BULK_IN_MIDI EP_TYPE_BULK_IN
2325

26+
#else
27+
28+
#define EP_TYPE_BULK_IN_MIDI (UOTGHS_DEVEPTCFG_EPSIZE_64_BYTE | \
29+
UOTGHS_DEVEPTCFG_EPDIR_IN | \
30+
UOTGHS_DEVEPTCFG_EPTYPE_BLK | \
31+
UOTGHS_DEVEPTCFG_EPBK_1_BANK | \
32+
UOTGHS_DEVEPTCFG_NBTRANS_1_TRANS | \
33+
UOTGHS_DEVEPTCFG_ALLOC)
34+
35+
#define EP_TYPE_BULK_OUT_MIDI (UOTGHS_DEVEPTCFG_EPSIZE_64_BYTE | \
36+
UOTGHS_DEVEPTCFG_EPTYPE_BLK | \
37+
UOTGHS_DEVEPTCFG_EPBK_1_BANK | \
38+
UOTGHS_DEVEPTCFG_NBTRANS_1_TRANS | \
39+
UOTGHS_DEVEPTCFG_ALLOC)
40+
#endif
41+
2442
class MIDI_
2543
{
2644
// private:
@@ -48,6 +66,8 @@ extern MIDI_ MidiUSB;
4866
#define MIDI_JACK_EMD 0x01
4967
#define MIDI_JACK_EXT 0X02
5068

69+
#pragma pack(1)
70+
5171
typedef struct
5272
{
5373
uint8_t len; // 9
@@ -151,6 +171,8 @@ typedef struct
151171
#define D_CDCCS(_subtype,_d0,_d1) { 5, 0x24, _subtype, _d0, _d1 }
152172
#define D_CDCCS4(_subtype,_d0) { 4, 0x24, _subtype, _d0 }
153173

174+
#pragma pack()
175+
154176
#define WEAK __attribute__ ((weak))
155177

156178
#endif

0 commit comments

Comments
 (0)