LPCOpen Platform
LPCOpen Platform for NXP LPC Microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
MIDIClassDevice.c
Go to the documentation of this file.
1 /*
2  * @brief Device mode driver for the library USB MIDI Class driver
3  *
4  * @note
5  * Copyright(C) NXP Semiconductors, 2012
6  * Copyright(C) Dean Camera, 2011, 2012
7  * All rights reserved.
8  *
9  * @par
10  * Software that is described herein is for illustrative purposes only
11  * which provides customers with programming information regarding the
12  * LPC products. This software is supplied "AS IS" without any warranties of
13  * any kind, and NXP Semiconductors and its licensor disclaim any and
14  * all warranties, express or implied, including all implied warranties of
15  * merchantability, fitness for a particular purpose and non-infringement of
16  * intellectual property rights. NXP Semiconductors assumes no responsibility
17  * or liability for the use of the software, conveys no license or rights under any
18  * patent, copyright, mask work right, or any other intellectual property rights in
19  * or to any products. NXP Semiconductors reserves the right to make changes
20  * in the software without notification. NXP Semiconductors also makes no
21  * representation or warranty that such application will be suitable for the
22  * specified use without further testing or modification.
23  *
24  * @par
25  * Permission to use, copy, modify, and distribute this software and its
26  * documentation is hereby granted, under NXP Semiconductors' and its
27  * licensor's relevant copyrights in the software, without fee, provided that it
28  * is used in conjunction with NXP Semiconductors microcontrollers. This
29  * copyright, permission, and disclaimer notice must appear in all copies of
30  * this code.
31  */
32 
33 
34 #define __INCLUDE_FROM_USB_DRIVER
35 #include "../../Core/USBMode.h"
36 
37 #if defined(USB_CAN_BE_DEVICE)
38 
39 #define __INCLUDE_FROM_MIDI_DRIVER
40 #define __INCLUDE_FROM_MIDI_DEVICE_C
41 #include "MIDIClassDevice.h"
42 
44 {
45  // memset(&MIDIInterfaceInfo->State, 0x00, sizeof(MIDIInterfaceInfo->State));
46 
47  for (uint8_t EndpointNum = 1; EndpointNum < ENDPOINT_TOTAL_ENDPOINTS; EndpointNum++)
48  {
49  uint16_t Size;
50  uint8_t Type;
51  uint8_t Direction;
52  bool DoubleBanked;
53 
54  if (EndpointNum == MIDIInterfaceInfo->Config.DataINEndpointNumber)
55  {
56  Size = MIDIInterfaceInfo->Config.DataINEndpointSize;
57  Direction = ENDPOINT_DIR_IN;
58  Type = EP_TYPE_BULK;
59  DoubleBanked = MIDIInterfaceInfo->Config.DataINEndpointDoubleBank;
60  }
61  else if (EndpointNum == MIDIInterfaceInfo->Config.DataOUTEndpointNumber)
62  {
63  Size = MIDIInterfaceInfo->Config.DataOUTEndpointSize;
64  Direction = ENDPOINT_DIR_OUT;
65  Type = EP_TYPE_BULK;
66  DoubleBanked = MIDIInterfaceInfo->Config.DataOUTEndpointDoubleBank;
67  }
68  else
69  {
70  continue;
71  }
72 
73  if (!(Endpoint_ConfigureEndpoint(EndpointNum, Type, Direction, Size,
74  DoubleBanked ? ENDPOINT_BANK_DOUBLE : ENDPOINT_BANK_SINGLE)))
75  {
76  return false;
77  }
78  }
79 
80  return true;
81 }
82 
83 void MIDI_Device_USBTask(USB_ClassInfo_MIDI_Device_t* const MIDIInterfaceInfo)
84 {
86  return;
87 
88  #if !defined(NO_CLASS_DRIVER_AUTOFLUSH)
89  MIDI_Device_Flush(MIDIInterfaceInfo);
90  #endif
91 }
92 
94  const MIDI_EventPacket_t* const Event)
95 {
98 
99  uint8_t ErrorCode;
100 
102 
103  if ((ErrorCode = Endpoint_Write_Stream_LE(Event, sizeof(MIDI_EventPacket_t), NULL)) != ENDPOINT_RWSTREAM_NoError)
104  return ErrorCode;
105 
108 
110 }
111 
112 uint8_t MIDI_Device_Flush(USB_ClassInfo_MIDI_Device_t* const MIDIInterfaceInfo)
113 {
116 
117  uint8_t ErrorCode;
118 
120 
122  {
124 
126  return ErrorCode;
127  }
128 
130 }
131 
133  MIDI_EventPacket_t* const Event)
134 {
136  return false;
137 
139 
141  return false;
142 
144 
147 
148  return true;
149 }
150 
151 #endif
152