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
5975void 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
100105uint32_t MIDI_::available (void )
@@ -170,7 +175,7 @@ void MIDI_::sendMIDI(midiEventPacket_t event)
170175
171176MIDI_::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;
0 commit comments