2010-05-08 05:12:14 +02:00
|
|
|
/*
|
|
|
|
LUFA Library
|
2011-01-01 14:00:56 +01:00
|
|
|
Copyright (C) Dean Camera, 2011.
|
2010-10-13 16:05:35 +02:00
|
|
|
|
2010-05-08 05:12:14 +02:00
|
|
|
dean [at] fourwalledcubicle [dot] com
|
2010-10-28 08:08:58 +02:00
|
|
|
www.lufa-lib.org
|
2010-05-08 05:12:14 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2011-01-01 14:00:56 +01:00
|
|
|
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
|
2010-05-08 05:12:14 +02:00
|
|
|
|
2010-10-13 16:05:35 +02:00
|
|
|
Permission to use, copy, modify, distribute, and sell this
|
2010-05-08 05:12:14 +02:00
|
|
|
software and its documentation for any purpose is hereby granted
|
2010-10-13 16:05:35 +02:00
|
|
|
without fee, provided that the above copyright notice appear in
|
2010-05-08 05:12:14 +02:00
|
|
|
all copies and that both that the copyright notice and this
|
2010-10-13 16:05:35 +02:00
|
|
|
permission notice and warranty disclaimer appear in supporting
|
|
|
|
documentation, and that the name of the author not be used in
|
|
|
|
advertising or publicity pertaining to distribution of the
|
2010-05-08 05:12:14 +02:00
|
|
|
software without specific, written prior permission.
|
|
|
|
|
|
|
|
The author disclaim all warranties with regard to this
|
|
|
|
software, including all implied warranties of merchantability
|
|
|
|
and fitness. In no event shall the author be liable for any
|
|
|
|
special, indirect or consequential damages or any damages
|
|
|
|
whatsoever resulting from loss of use, data or profits, whether
|
|
|
|
in an action of contract, negligence or other tortious action,
|
|
|
|
arising out of or in connection with the use or performance of
|
|
|
|
this software.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define __INCLUDE_FROM_USB_DRIVER
|
2011-02-19 23:59:27 +01:00
|
|
|
#include "../../Core/USBMode.h"
|
|
|
|
|
2010-05-08 05:12:14 +02:00
|
|
|
#if defined(USB_CAN_BE_DEVICE)
|
|
|
|
|
|
|
|
#define __INCLUDE_FROM_MIDI_DRIVER
|
2010-10-25 00:53:57 +02:00
|
|
|
#define __INCLUDE_FROM_MIDI_DEVICE_C
|
2010-05-08 05:12:14 +02:00
|
|
|
#include "MIDI.h"
|
|
|
|
|
|
|
|
bool MIDI_Device_ConfigureEndpoints(USB_ClassInfo_MIDI_Device_t* const MIDIInterfaceInfo)
|
|
|
|
{
|
|
|
|
memset(&MIDIInterfaceInfo->State, 0x00, sizeof(MIDIInterfaceInfo->State));
|
|
|
|
|
2010-09-30 08:23:38 +02:00
|
|
|
for (uint8_t EndpointNum = 1; EndpointNum < ENDPOINT_TOTAL_ENDPOINTS; EndpointNum++)
|
2010-05-08 05:12:14 +02:00
|
|
|
{
|
2010-09-30 08:23:38 +02:00
|
|
|
uint16_t Size;
|
|
|
|
uint8_t Type;
|
|
|
|
uint8_t Direction;
|
|
|
|
bool DoubleBanked;
|
|
|
|
|
|
|
|
if (EndpointNum == MIDIInterfaceInfo->Config.DataINEndpointNumber)
|
2010-05-08 05:12:14 +02:00
|
|
|
{
|
2010-09-30 08:23:38 +02:00
|
|
|
Size = MIDIInterfaceInfo->Config.DataINEndpointSize;
|
|
|
|
Direction = ENDPOINT_DIR_IN;
|
|
|
|
Type = EP_TYPE_BULK;
|
|
|
|
DoubleBanked = MIDIInterfaceInfo->Config.DataINEndpointDoubleBank;
|
2010-05-08 05:12:14 +02:00
|
|
|
}
|
2010-09-30 08:23:38 +02:00
|
|
|
else if (EndpointNum == MIDIInterfaceInfo->Config.DataOUTEndpointNumber)
|
|
|
|
{
|
|
|
|
Size = MIDIInterfaceInfo->Config.DataOUTEndpointSize;
|
|
|
|
Direction = ENDPOINT_DIR_OUT;
|
|
|
|
Type = EP_TYPE_BULK;
|
|
|
|
DoubleBanked = MIDIInterfaceInfo->Config.DataOUTEndpointDoubleBank;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2010-10-13 16:05:35 +02:00
|
|
|
|
2010-09-30 08:23:38 +02:00
|
|
|
if (!(Endpoint_ConfigureEndpoint(EndpointNum, Type, Direction, Size,
|
2010-12-02 02:56:06 +01:00
|
|
|
DoubleBanked ? ENDPOINT_BANK_DOUBLE : ENDPOINT_BANK_SINGLE)))
|
2010-05-08 05:12:14 +02:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2010-10-13 16:05:35 +02:00
|
|
|
|
2010-05-08 05:12:14 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-10-27 09:23:51 +02:00
|
|
|
void MIDI_Device_USBTask(USB_ClassInfo_MIDI_Device_t* const MIDIInterfaceInfo)
|
|
|
|
{
|
|
|
|
if (USB_DeviceState != DEVICE_STATE_Configured)
|
|
|
|
return;
|
|
|
|
|
|
|
|
#if !defined(NO_CLASS_DRIVER_AUTOFLUSH)
|
|
|
|
MIDI_Device_Flush(MIDIInterfaceInfo);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-07-21 16:00:51 +02:00
|
|
|
uint8_t MIDI_Device_SendEventPacket(USB_ClassInfo_MIDI_Device_t* const MIDIInterfaceInfo,
|
|
|
|
const MIDI_EventPacket_t* const Event)
|
2010-05-08 05:12:14 +02:00
|
|
|
{
|
|
|
|
if (USB_DeviceState != DEVICE_STATE_Configured)
|
|
|
|
return ENDPOINT_RWSTREAM_DeviceDisconnected;
|
2010-10-13 16:05:35 +02:00
|
|
|
|
2010-11-03 04:20:08 +01:00
|
|
|
uint8_t ErrorCode;
|
2010-05-08 05:12:14 +02:00
|
|
|
|
2010-11-03 04:20:08 +01:00
|
|
|
Endpoint_SelectEndpoint(MIDIInterfaceInfo->Config.DataINEndpointNumber);
|
2010-05-08 05:12:14 +02:00
|
|
|
|
2011-01-10 19:43:34 +01:00
|
|
|
if ((ErrorCode = Endpoint_Write_Stream_LE(Event, sizeof(MIDI_EventPacket_t), NULL)) != ENDPOINT_RWSTREAM_NoError)
|
2010-11-03 04:20:08 +01:00
|
|
|
return ErrorCode;
|
2010-05-08 05:12:14 +02:00
|
|
|
|
2010-11-03 04:20:08 +01:00
|
|
|
if (!(Endpoint_IsReadWriteAllowed()))
|
|
|
|
Endpoint_ClearIN();
|
2010-10-13 16:05:35 +02:00
|
|
|
|
2010-05-08 05:12:14 +02:00
|
|
|
return ENDPOINT_RWSTREAM_NoError;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t MIDI_Device_Flush(USB_ClassInfo_MIDI_Device_t* const MIDIInterfaceInfo)
|
|
|
|
{
|
|
|
|
if (USB_DeviceState != DEVICE_STATE_Configured)
|
|
|
|
return ENDPOINT_RWSTREAM_DeviceDisconnected;
|
2010-10-13 16:05:35 +02:00
|
|
|
|
2010-05-08 05:12:14 +02:00
|
|
|
uint8_t ErrorCode;
|
|
|
|
|
|
|
|
Endpoint_SelectEndpoint(MIDIInterfaceInfo->Config.DataINEndpointNumber);
|
|
|
|
|
|
|
|
if (Endpoint_BytesInEndpoint())
|
|
|
|
{
|
|
|
|
Endpoint_ClearIN();
|
|
|
|
|
|
|
|
if ((ErrorCode = Endpoint_WaitUntilReady()) != ENDPOINT_READYWAIT_NoError)
|
|
|
|
return ErrorCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ENDPOINT_READYWAIT_NoError;
|
|
|
|
}
|
|
|
|
|
2010-07-21 16:00:51 +02:00
|
|
|
bool MIDI_Device_ReceiveEventPacket(USB_ClassInfo_MIDI_Device_t* const MIDIInterfaceInfo,
|
|
|
|
MIDI_EventPacket_t* const Event)
|
2010-05-08 05:12:14 +02:00
|
|
|
{
|
|
|
|
if (USB_DeviceState != DEVICE_STATE_Configured)
|
|
|
|
return false;
|
2010-10-13 16:05:35 +02:00
|
|
|
|
2010-05-08 05:12:14 +02:00
|
|
|
Endpoint_SelectEndpoint(MIDIInterfaceInfo->Config.DataOUTEndpointNumber);
|
|
|
|
|
|
|
|
if (!(Endpoint_IsReadWriteAllowed()))
|
|
|
|
return false;
|
|
|
|
|
2011-01-10 19:43:34 +01:00
|
|
|
Endpoint_Read_Stream_LE(Event, sizeof(MIDI_EventPacket_t), NULL);
|
2010-10-13 16:05:35 +02:00
|
|
|
|
2010-05-08 05:12:14 +02:00
|
|
|
if (!(Endpoint_IsReadWriteAllowed()))
|
|
|
|
Endpoint_ClearOUT();
|
2010-10-13 16:05:35 +02:00
|
|
|
|
2010-05-08 05:12:14 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2010-10-13 16:05:35 +02:00
|
|
|
|