Update copyright year to 2010.
[pub/USBasp.git] / LUFA / Drivers / USB / Class / Device / MIDI.c
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2010.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
7 */
8
9 /*
10 Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
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.
20
21 The author disclaim 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
28 this software.
29 */
30
31 #include "../../HighLevel/USBMode.h"
32 #if defined(USB_CAN_BE_DEVICE)
33
34 #include "MIDI.h"
35
36 void MIDI_Device_ProcessControlRequest(USB_ClassInfo_MIDI_Device_t* const MIDIInterfaceInfo)
37 {
38
39 }
40
41 bool MIDI_Device_ConfigureEndpoints(USB_ClassInfo_MIDI_Device_t* const MIDIInterfaceInfo)
42 {
43 memset(&MIDIInterfaceInfo->State, 0x00, sizeof(MIDIInterfaceInfo->State));
44
45 if (MIDIInterfaceInfo->Config.DataINEndpointNumber)
46 {
47 if (!(Endpoint_ConfigureEndpoint(MIDIInterfaceInfo->Config.DataINEndpointNumber, EP_TYPE_BULK,
48 ENDPOINT_DIR_IN, MIDIInterfaceInfo->Config.DataINEndpointSize,
49 MIDIInterfaceInfo->Config.DataINEndpointDoubleBank ? ENDPOINT_BANK_DOUBLE : ENDPOINT_BANK_SINGLE)))
50 {
51 return false;
52 }
53 }
54
55 if (MIDIInterfaceInfo->Config.DataOUTEndpointNumber)
56 {
57 if (!(Endpoint_ConfigureEndpoint(MIDIInterfaceInfo->Config.DataOUTEndpointNumber, EP_TYPE_BULK,
58 ENDPOINT_DIR_OUT, MIDIInterfaceInfo->Config.DataOUTEndpointSize,
59 MIDIInterfaceInfo->Config.DataOUTEndpointDoubleBank ? ENDPOINT_BANK_DOUBLE : ENDPOINT_BANK_SINGLE)))
60 {
61 return false;
62 }
63 }
64
65 return true;
66 }
67
68 void MIDI_Device_USBTask(USB_ClassInfo_MIDI_Device_t* const MIDIInterfaceInfo)
69 {
70 (void)MIDIInterfaceInfo;
71 }
72
73 uint8_t MIDI_Device_SendEventPacket(USB_ClassInfo_MIDI_Device_t* const MIDIInterfaceInfo, MIDI_EventPacket_t* const Event)
74 {
75 if (USB_DeviceState != DEVICE_STATE_Configured)
76 return ENDPOINT_RWSTREAM_DeviceDisconnected;
77
78 Endpoint_SelectEndpoint(MIDIInterfaceInfo->Config.DataINEndpointNumber);
79
80 if (Endpoint_IsReadWriteAllowed());
81 {
82 uint8_t ErrorCode;
83
84 if ((ErrorCode = Endpoint_Write_Stream_LE(Event, sizeof(MIDI_EventPacket_t), NO_STREAM_CALLBACK)) != ENDPOINT_RWSTREAM_NoError)
85 return ErrorCode;
86
87 Endpoint_ClearIN();
88 }
89
90 return ENDPOINT_RWSTREAM_NoError;
91 }
92
93 bool MIDI_Device_ReceiveEventPacket(USB_ClassInfo_MIDI_Device_t* const MIDIInterfaceInfo, MIDI_EventPacket_t* const Event)
94 {
95 if (USB_DeviceState != DEVICE_STATE_Configured)
96 return false;
97
98 Endpoint_SelectEndpoint(MIDIInterfaceInfo->Config.DataOUTEndpointNumber);
99
100 if (!(Endpoint_IsReadWriteAllowed()))
101 return false;
102
103 Endpoint_Read_Stream_LE(Event, sizeof(MIDI_EventPacket_t), NO_STREAM_CALLBACK);
104 Endpoint_ClearOUT();
105
106 return true;
107 }
108
109 #endif