16
16
17
17
#include " MIDIUSB.h"
18
18
19
- #define MIDI_BUFFER_SIZE 64
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 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;
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
54
24
55
25
#define MIDI_RX MIDI_ENDPOINT_OUT
56
26
#define MIDI_TX MIDI_ENDPOINT_IN
@@ -64,25 +34,47 @@ struct ring_bufferMIDI
64
34
65
35
ring_bufferMIDI midi_rx_buffer = {{0 ,0 ,0 ,0 }, 0 , 0 };
66
36
67
- static MIDIDescriptor _midiInterface ;
37
+ MIDI_ MidiUSB ;
68
38
69
- int MIDI_GetInterface (uint8_t * interfaceNum)
39
+ int MIDI_::getInterface (uint8_t * interfaceNum)
70
40
{
71
- interfaceNum[0 ] += 2 ; // uses 2
72
- return USB_SendControl (0 ,&_midiInterface,sizeof (_midiInterface));
41
+ interfaceNum[0 ] += 2 ; // uses 2 interfaces
42
+ MIDIDescriptor _midiInterface =
43
+ {
44
+ D_IAD (MIDI_AC_INTERFACE, 2 , MIDI_AUDIO, MIDI_AUDIO_CONTROL, 0 ),
45
+ D_INTERFACE (MIDI_AC_INTERFACE,0 ,MIDI_AUDIO,MIDI_AUDIO_CONTROL,0 ),
46
+ D_AC_INTERFACE (0x1 , MIDI_INTERFACE),
47
+ D_INTERFACE (MIDI_INTERFACE,2 , MIDI_AUDIO,MIDI_STREAMING,0 ),
48
+ D_AS_INTERFACE,
49
+ D_MIDI_INJACK (MIDI_JACK_EMD, 0x1 ),
50
+ D_MIDI_INJACK (MIDI_JACK_EXT, 0x2 ),
51
+ D_MIDI_OUTJACK (MIDI_JACK_EMD, 0x3 , 1 , 2 , 1 ),
52
+ D_MIDI_OUTJACK (MIDI_JACK_EXT, 0x4 , 1 , 1 , 1 ),
53
+ D_MIDI_JACK_EP (USB_ENDPOINT_OUT (MIDI_ENDPOINT_OUT),USB_ENDPOINT_TYPE_BULK,MIDI_BUFFER_SIZE),
54
+ D_MIDI_AC_JACK_EP (1 , 1 ),
55
+ D_MIDI_JACK_EP (USB_ENDPOINT_IN (MIDI_ENDPOINT_IN),USB_ENDPOINT_TYPE_BULK,MIDI_BUFFER_SIZE),
56
+ D_MIDI_AC_JACK_EP (1 , 3 )
57
+ };
58
+ return USB_SendControl (0 , &_midiInterface, sizeof (_midiInterface));
73
59
}
74
60
75
- bool MIDI_Setup (USBSetup& setup, uint8_t i )
61
+ bool MIDI_::setup (USBSetup& setup __attribute__ ((unused)) )
76
62
{
77
63
// Support requests here if needed. Typically these are optional
78
64
return false ;
79
65
}
80
66
81
- int MIDI_GetDescriptor ( int8_t t )
67
+ int MIDI_::getDescriptor (USBSetup& setup __attribute__ ((unused)) )
82
68
{
83
69
return 0 ;
84
70
}
85
71
72
+ uint8_t MIDI_::getShortName (char * name)
73
+ {
74
+ memcpy (name, " MIDI" , 4 );
75
+ return 4 ;
76
+ }
77
+
86
78
void MIDI_::accept (void )
87
79
{
88
80
ring_bufferMIDI *buffer = &midi_rx_buffer;
@@ -183,49 +175,9 @@ void MIDI_::sendMIDI(midiEventPacket_t event)
183
175
write (data, 4 );
184
176
}
185
177
186
- MIDI_::MIDI_ (void )
187
- {
188
- static EPTYPE_DESCRIPTOR_SIZE endpointType[2 ];
189
-
190
- endpointType[0 ] = EP_TYPE_BULK_OUT_MIDI; // MIDI_ENDPOINT_OUT
191
- endpointType[1 ] = EP_TYPE_BULK_IN_MIDI; // MIDI_ENDPOINT_IN
192
-
193
- static PUSBCallbacks cb = {
194
- .setup = &MIDI_Setup,
195
- .getInterface = &MIDI_GetInterface,
196
- .getDescriptor = &MIDI_GetDescriptor,
197
- .numEndpoints = 2 ,
198
- .numInterfaces = 2 ,
199
- .endpointType = endpointType,
200
- };
201
-
202
- static PUSBListNode node (&cb);
203
-
204
- MIDI_ENDPOINT_OUT = PUSB_AddFunction (&node, &MIDI_AC_INTERFACE);
205
- MIDI_ENDPOINT_IN = MIDI_ENDPOINT_OUT + 1 ;
206
- MIDI_INTERFACE = MIDI_AC_INTERFACE + 1 ;
207
-
208
- _midiInterface =
209
- {
210
- D_IAD (MIDI_AC_INTERFACE, 2 , MIDI_AUDIO, MIDI_AUDIO_CONTROL, 0 ),
211
- D_INTERFACE (MIDI_AC_INTERFACE,0 ,MIDI_AUDIO,MIDI_AUDIO_CONTROL,0 ),
212
- D_AC_INTERFACE (0x1 , MIDI_INTERFACE),
213
- D_INTERFACE (MIDI_INTERFACE,2 , MIDI_AUDIO,MIDI_STREAMING,0 ),
214
- D_AS_INTERFACE,
215
- D_MIDI_INJACK (MIDI_JACK_EMD, 0x1 ),
216
- D_MIDI_INJACK (MIDI_JACK_EXT, 0x2 ),
217
- D_MIDI_OUTJACK (MIDI_JACK_EMD, 0x3 , 1 , 2 , 1 ),
218
- D_MIDI_OUTJACK (MIDI_JACK_EXT, 0x4 , 1 , 1 , 1 ),
219
- D_MIDI_JACK_EP (USB_ENDPOINT_OUT (MIDI_ENDPOINT_OUT),USB_ENDPOINT_TYPE_BULK,512 ),
220
- D_MIDI_AC_JACK_EP (1 , 1 ),
221
- D_MIDI_JACK_EP (USB_ENDPOINT_IN (MIDI_ENDPOINT_IN),USB_ENDPOINT_TYPE_BULK,512 ),
222
- D_MIDI_AC_JACK_EP (1 , 3 )
223
- };
224
- }
225
-
226
- int8_t MIDI_::begin ()
178
+ MIDI_::MIDI_ (void ) : PluggableUSBModule(2 , 2 , epType)
227
179
{
228
- }
229
-
230
-
231
- MIDI_ MidiUSB;
180
+ epType[ 0 ] = EP_TYPE_BULK_OUT_MIDI; // MIDI_ENDPOINT_OUT
181
+ epType[ 1 ] = EP_TYPE_BULK_IN_MIDI; // MIDI_ENDPOINT_IN
182
+ PluggableUSB (). plug ( this );
183
+ }
0 commit comments