14
14
** SOFTWARE.
15
15
*/
16
16
17
- #include " PluggableUSB.h"
18
17
#include " MIDIUSB.h"
19
18
20
19
#define MIDI_BUFFER_SIZE 16
21
20
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
22
35
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;
28
43
29
44
#define MIDI_RX MIDI_ENDPOINT_OUT
30
45
#define MIDI_TX MIDI_ENDPOINT_IN
@@ -45,7 +60,8 @@ int MIDI_GetInterface(uint8_t* interfaceNum)
45
60
interfaceNum[0 ] += 2 ; // uses 2
46
61
return USB_SendControl (0 ,&_midiInterface,sizeof (_midiInterface));
47
62
}
48
- bool MIDI_Setup (USBSetup& setup, u8 i)
63
+
64
+ bool MIDI_Setup (USBSetup& setup, uint8_t i)
49
65
{
50
66
// Support requests here if needed. Typically these are optional
51
67
return false ;
@@ -58,16 +74,6 @@ int MIDI_GetDescriptor(int8_t t)
58
74
59
75
void MIDI_::accept (void )
60
76
{
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
-
71
77
ring_bufferMIDI *buffer = &midi_rx_buffer;
72
78
uint32_t i = (uint32_t )(buffer->head +1 ) % MIDI_BUFFER_SIZE;
73
79
@@ -79,8 +85,10 @@ void MIDI_::accept(void)
79
85
int c;
80
86
midiEventPacket_t event;
81
87
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;
84
92
}
85
93
c = USB_Recv (MIDI_RX, &event, sizeof (event) );
86
94
@@ -92,9 +100,6 @@ void MIDI_::accept(void)
92
100
93
101
i = (i + 1 ) % MIDI_BUFFER_SIZE;
94
102
}
95
-
96
- // release the guard
97
- mguard = 0 ;
98
103
}
99
104
100
105
uint32_t MIDI_::available (void )
@@ -170,7 +175,7 @@ void MIDI_::sendMIDI(midiEventPacket_t event)
170
175
171
176
MIDI_::MIDI_ (void )
172
177
{
173
- static uint8_t endpointType[2 ];
178
+ static EPTYPE_DESCRIPTOR_SIZE endpointType[2 ];
174
179
175
180
endpointType[0 ] = EP_TYPE_BULK_OUT_MIDI; // MIDI_ENDPOINT_OUT
176
181
endpointType[1 ] = EP_TYPE_BULK_IN_MIDI; // MIDI_ENDPOINT_IN
@@ -213,4 +218,4 @@ int8_t MIDI_::begin()
213
218
}
214
219
215
220
216
- MIDI_ MidiUSB;
221
+ MIDI_ MidiUSB;
0 commit comments