LPCOpen Platform
LPCOpen Platform for NXP LPC Microcontrollers
Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
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
43
bool
MIDI_Device_ConfigureEndpoints
(
USB_ClassInfo_MIDI_Device_t
*
const
MIDIInterfaceInfo)
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
{
85
if
(
USB_DeviceState
!=
DEVICE_STATE_Configured
)
86
return
;
87
88
#if !defined(NO_CLASS_DRIVER_AUTOFLUSH)
89
MIDI_Device_Flush
(MIDIInterfaceInfo);
90
#endif
91
}
92
93
uint8_t
MIDI_Device_SendEventPacket
(
USB_ClassInfo_MIDI_Device_t
*
const
MIDIInterfaceInfo,
94
const
MIDI_EventPacket_t
*
const
Event)
95
{
96
if
(
USB_DeviceState
!=
DEVICE_STATE_Configured
)
97
return
ENDPOINT_RWSTREAM_DeviceDisconnected
;
98
99
uint8_t ErrorCode;
100
101
Endpoint_SelectEndpoint
(MIDIInterfaceInfo->
Config
.
DataINEndpointNumber
);
102
103
if
((ErrorCode =
Endpoint_Write_Stream_LE
(Event,
sizeof
(
MIDI_EventPacket_t
),
NULL
)) !=
ENDPOINT_RWSTREAM_NoError
)
104
return
ErrorCode;
105
106
if
(!(
Endpoint_IsReadWriteAllowed
()))
107
Endpoint_ClearIN
();
108
109
return
ENDPOINT_RWSTREAM_NoError
;
110
}
111
112
uint8_t
MIDI_Device_Flush
(
USB_ClassInfo_MIDI_Device_t
*
const
MIDIInterfaceInfo)
113
{
114
if
(
USB_DeviceState
!=
DEVICE_STATE_Configured
)
115
return
ENDPOINT_RWSTREAM_DeviceDisconnected
;
116
117
uint8_t ErrorCode;
118
119
Endpoint_SelectEndpoint
(MIDIInterfaceInfo->
Config
.
DataINEndpointNumber
);
120
121
if
(
Endpoint_BytesInEndpoint
())
122
{
123
Endpoint_ClearIN
();
124
125
if
((ErrorCode =
Endpoint_WaitUntilReady
()) !=
ENDPOINT_READYWAIT_NoError
)
126
return
ErrorCode;
127
}
128
129
return
ENDPOINT_READYWAIT_NoError
;
130
}
131
132
bool
MIDI_Device_ReceiveEventPacket
(
USB_ClassInfo_MIDI_Device_t
*
const
MIDIInterfaceInfo,
133
MIDI_EventPacket_t
*
const
Event)
134
{
135
if
(
USB_DeviceState
!=
DEVICE_STATE_Configured
)
136
return
false
;
137
138
Endpoint_SelectEndpoint
(MIDIInterfaceInfo->
Config
.
DataOUTEndpointNumber
);
139
140
if
(!(
Endpoint_IsReadWriteAllowed
()))
141
return
false
;
142
143
Endpoint_Read_Stream_LE
(Event,
sizeof
(
MIDI_EventPacket_t
),
NULL
);
144
145
if
(!(
Endpoint_IsReadWriteAllowed
()))
146
Endpoint_ClearOUT
();
147
148
return
true
;
149
}
150
151
#endif
152
software
LPCUSBLib
Drivers
USB
Class
Device
MIDIClassDevice.c
Generated on Fri Nov 16 2012 13:36:45 for LPCOpen Platform by
1.8.2