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