3 Copyright (C) Dean Camera, 2012.
\r
5 dean [at] fourwalledcubicle [dot] com
\r
10 Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)
\r
12 Permission to use, copy, modify, distribute, and sell this
\r
13 software and its documentation for any purpose is hereby granted
\r
14 without fee, provided that the above copyright notice appear in
\r
15 all copies and that both that the copyright notice and this
\r
16 permission notice and warranty disclaimer appear in supporting
\r
17 documentation, and that the name of the author not be used in
\r
18 advertising or publicity pertaining to distribution of the
\r
19 software without specific, written prior permission.
\r
21 The author disclaim all warranties with regard to this
\r
22 software, including all implied warranties of merchantability
\r
23 and fitness. In no event shall the author be liable for any
\r
24 special, indirect or consequential damages or any damages
\r
25 whatsoever resulting from loss of use, data or profits, whether
\r
26 in an action of contract, negligence or other tortious action,
\r
27 arising out of or in connection with the use or performance of
\r
31 #define __INCLUDE_FROM_USB_DRIVER
\r
32 #include "../../Core/USBMode.h"
\r
34 #if defined(USB_CAN_BE_DEVICE)
\r
36 #define __INCLUDE_FROM_MIDI_DRIVER
\r
37 #define __INCLUDE_FROM_MIDI_DEVICE_C
\r
38 #include "MIDIClassDevice.h"
\r
40 bool MIDI_Device_ConfigureEndpoints(USB_ClassInfo_MIDI_Device_t* const MIDIInterfaceInfo)
\r
42 memset(&MIDIInterfaceInfo->State, 0x00, sizeof(MIDIInterfaceInfo->State));
\r
44 MIDIInterfaceInfo->Config.DataINEndpoint.Type = EP_TYPE_BULK;
\r
45 MIDIInterfaceInfo->Config.DataOUTEndpoint.Type = EP_TYPE_BULK;
\r
47 if (!(Endpoint_ConfigureEndpointTable(&MIDIInterfaceInfo->Config.DataINEndpoint, 1)))
\r
50 if (!(Endpoint_ConfigureEndpointTable(&MIDIInterfaceInfo->Config.DataOUTEndpoint, 1)))
\r
56 void MIDI_Device_USBTask(USB_ClassInfo_MIDI_Device_t* const MIDIInterfaceInfo)
\r
58 if (USB_DeviceState != DEVICE_STATE_Configured)
\r
61 #if !defined(NO_CLASS_DRIVER_AUTOFLUSH)
\r
62 MIDI_Device_Flush(MIDIInterfaceInfo);
\r
66 uint8_t MIDI_Device_SendEventPacket(USB_ClassInfo_MIDI_Device_t* const MIDIInterfaceInfo,
\r
67 const MIDI_EventPacket_t* const Event)
\r
69 if (USB_DeviceState != DEVICE_STATE_Configured)
\r
70 return ENDPOINT_RWSTREAM_DeviceDisconnected;
\r
74 Endpoint_SelectEndpoint(MIDIInterfaceInfo->Config.DataINEndpoint.Address);
\r
76 if ((ErrorCode = Endpoint_Write_Stream_LE(Event, sizeof(MIDI_EventPacket_t), NULL)) != ENDPOINT_RWSTREAM_NoError)
\r
79 if (!(Endpoint_IsReadWriteAllowed()))
\r
82 return ENDPOINT_RWSTREAM_NoError;
\r
85 uint8_t MIDI_Device_Flush(USB_ClassInfo_MIDI_Device_t* const MIDIInterfaceInfo)
\r
87 if (USB_DeviceState != DEVICE_STATE_Configured)
\r
88 return ENDPOINT_RWSTREAM_DeviceDisconnected;
\r
92 Endpoint_SelectEndpoint(MIDIInterfaceInfo->Config.DataINEndpoint.Address);
\r
94 if (Endpoint_BytesInEndpoint())
\r
98 if ((ErrorCode = Endpoint_WaitUntilReady()) != ENDPOINT_READYWAIT_NoError)
\r
102 return ENDPOINT_READYWAIT_NoError;
\r
105 bool MIDI_Device_ReceiveEventPacket(USB_ClassInfo_MIDI_Device_t* const MIDIInterfaceInfo,
\r
106 MIDI_EventPacket_t* const Event)
\r
108 if (USB_DeviceState != DEVICE_STATE_Configured)
\r
111 Endpoint_SelectEndpoint(MIDIInterfaceInfo->Config.DataOUTEndpoint.Address);
\r
113 if (!(Endpoint_IsReadWriteAllowed()))
\r
116 Endpoint_Read_Stream_LE(Event, sizeof(MIDI_EventPacket_t), NULL);
\r
118 if (!(Endpoint_IsReadWriteAllowed()))
\r
119 Endpoint_ClearOUT();
\r