1818
1919#define MIDI_BUFFER_SIZE 64
2020
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 EPTYPE_DESCRIPTOR_SIZE uint32_t
30-
31- #if defined(ARDUINO_ARCH_SAM)
32- #define USB_SendControl USBD_SendControl
33- #define USB_Available USBD_Available
34- #define USB_Recv USBD_Recv
35- #define USB_Send USBD_Send
36- #define USB_Flush USBD_Flush
37- #endif
38-
39- #if defined(__SAMD21G18A__)
40- #define USB_SendControl USBDevice.sendControl
41- #define USB_Available USBDevice.available
42- #define USB_Recv USBDevice.recv
43- #define USB_Send USBDevice.send
44- #define USB_Flush USBDevice.flush
45- #endif
46-
47- #endif
48-
49- static uint8_t MIDI_AC_INTERFACE; // MIDI AC Interface
50- static uint8_t MIDI_INTERFACE;
51- static uint8_t MIDI_FIRST_ENDPOINT;
52- static uint8_t MIDI_ENDPOINT_OUT;
53- static uint8_t MIDI_ENDPOINT_IN;
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
5426
5527#define MIDI_RX MIDI_ENDPOINT_OUT
5628#define MIDI_TX MIDI_ENDPOINT_IN
@@ -64,21 +36,37 @@ struct ring_bufferMIDI
6436
6537ring_bufferMIDI midi_rx_buffer = {{0 ,0 ,0 ,0 }, 0 , 0 };
6638
67- static MIDIDescriptor _midiInterface ;
39+ MIDI_ MidiUSB ;
6840
69- int MIDI_GetInterface (uint8_t * interfaceNum)
41+ int MIDI_::getInterface (uint8_t * interfaceNum)
7042{
7143 interfaceNum[0 ] += 2 ; // uses 2
44+ _midiInterface =
45+ {
46+ D_IAD (MIDI_AC_INTERFACE, 2 , MIDI_AUDIO, MIDI_AUDIO_CONTROL, 0 ),
47+ D_INTERFACE (MIDI_AC_INTERFACE,0 ,MIDI_AUDIO,MIDI_AUDIO_CONTROL,0 ),
48+ D_AC_INTERFACE (0x1 , MIDI_INTERFACE),
49+ D_INTERFACE (MIDI_INTERFACE,2 , MIDI_AUDIO,MIDI_STREAMING,0 ),
50+ D_AS_INTERFACE,
51+ D_MIDI_INJACK (MIDI_JACK_EMD, 0x1 ),
52+ D_MIDI_INJACK (MIDI_JACK_EXT, 0x2 ),
53+ D_MIDI_OUTJACK (MIDI_JACK_EMD, 0x3 , 1 , 2 , 1 ),
54+ 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 ),
56+ D_MIDI_AC_JACK_EP (1 , 1 ),
57+ D_MIDI_JACK_EP (USB_ENDPOINT_IN (MIDI_ENDPOINT_IN),USB_ENDPOINT_TYPE_BULK,64 ),
58+ D_MIDI_AC_JACK_EP (1 , 3 )
59+ };
7260 return USB_SendControl (0 ,&_midiInterface,sizeof (_midiInterface));
7361}
7462
75- bool MIDI_Setup (USBSetup& setup, uint8_t i)
63+ bool MIDI_::setup (USBSetup& setup, uint8_t i)
7664{
7765 // Support requests here if needed. Typically these are optional
7866 return false ;
7967}
8068
81- int MIDI_GetDescriptor (int8_t t)
69+ int MIDI_::getDescriptor (int8_t t)
8270{
8371 return 0 ;
8472}
@@ -189,50 +177,9 @@ void MIDI_::sendMIDI(midiEventPacket_t event)
189177 write (data, 4 );
190178}
191179
192- MIDI_::MIDI_ (void )
180+ MIDI_::MIDI_ (void ) : PUSBListNode( 2 , 2 , epType)
193181{
194- static EPTYPE_DESCRIPTOR_SIZE endpointType[2 ];
195-
196- endpointType[0 ] = EP_TYPE_BULK_OUT_MIDI; // MIDI_ENDPOINT_OUT
197- endpointType[1 ] = EP_TYPE_BULK_IN_MIDI; // MIDI_ENDPOINT_IN
198-
199- static PUSBCallbacks cb = {
200- .setup = &MIDI_Setup,
201- .getInterface = &MIDI_GetInterface,
202- .getDescriptor = &MIDI_GetDescriptor,
203- .getShortName = &MIDI_GetShortName,
204- .numEndpoints = 2 ,
205- .numInterfaces = 2 ,
206- .endpointType = endpointType,
207- };
208-
209- static PUSBListNode node (&cb);
210-
211- MIDI_ENDPOINT_OUT = PUSB_AddFunction (&node, &MIDI_AC_INTERFACE);
212- MIDI_ENDPOINT_IN = MIDI_ENDPOINT_OUT + 1 ;
213- MIDI_INTERFACE = MIDI_AC_INTERFACE + 1 ;
214-
215- _midiInterface =
216- {
217- D_IAD (MIDI_AC_INTERFACE, 2 , MIDI_AUDIO, MIDI_AUDIO_CONTROL, 0 ),
218- D_INTERFACE (MIDI_AC_INTERFACE,0 ,MIDI_AUDIO,MIDI_AUDIO_CONTROL,0 ),
219- D_AC_INTERFACE (0x1 , MIDI_INTERFACE),
220- D_INTERFACE (MIDI_INTERFACE,2 , MIDI_AUDIO,MIDI_STREAMING,0 ),
221- D_AS_INTERFACE,
222- D_MIDI_INJACK (MIDI_JACK_EMD, 0x1 ),
223- D_MIDI_INJACK (MIDI_JACK_EXT, 0x2 ),
224- D_MIDI_OUTJACK (MIDI_JACK_EMD, 0x3 , 1 , 2 , 1 ),
225- D_MIDI_OUTJACK (MIDI_JACK_EXT, 0x4 , 1 , 1 , 1 ),
226- D_MIDI_JACK_EP (USB_ENDPOINT_OUT (MIDI_ENDPOINT_OUT),USB_ENDPOINT_TYPE_BULK,512 ),
227- D_MIDI_AC_JACK_EP (1 , 1 ),
228- D_MIDI_JACK_EP (USB_ENDPOINT_IN (MIDI_ENDPOINT_IN),USB_ENDPOINT_TYPE_BULK,512 ),
229- D_MIDI_AC_JACK_EP (1 , 3 )
230- };
231- }
232-
233- int8_t MIDI_::begin ()
234- {
235- }
236-
237-
238- MIDI_ MidiUSB;
182+ epType[0 ] = EP_TYPE_BULK_OUT_MIDI; // MIDI_ENDPOINT_OUT
183+ epType[1 ] = EP_TYPE_BULK_IN_MIDI; // MIDI_ENDPOINT_IN
184+ PluggableUSB.plug (this );
185+ }
0 commit comments