]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Demo/FreeRTOS_Plus_UDP_and_CLI_LPC1830_GCC/ThirdParty/LPCOpen/LPCUSBLib/Drivers/USB/Class/Device/MIDIClassDevice.h
Update LPC18xx FreeRTOS+UDP demo to use LPCOpen USB and Ethernet drivers.
[freertos] / FreeRTOS-Plus / Demo / FreeRTOS_Plus_UDP_and_CLI_LPC1830_GCC / ThirdParty / LPCOpen / LPCUSBLib / Drivers / USB / Class / Device / MIDIClassDevice.h
1 /*\r
2  * @brief Device mode driver for the library USB MIDI Class driver\r
3  *\r
4  * @note\r
5  * Copyright(C) NXP Semiconductors, 2012\r
6  * Copyright(C) Dean Camera, 2011, 2012\r
7  * All rights reserved.\r
8  *\r
9  * @par\r
10  * Software that is described herein is for illustrative purposes only\r
11  * which provides customers with programming information regarding the\r
12  * LPC products.  This software is supplied "AS IS" without any warranties of\r
13  * any kind, and NXP Semiconductors and its licensor disclaim any and\r
14  * all warranties, express or implied, including all implied warranties of\r
15  * merchantability, fitness for a particular purpose and non-infringement of\r
16  * intellectual property rights.  NXP Semiconductors assumes no responsibility\r
17  * or liability for the use of the software, conveys no license or rights under any\r
18  * patent, copyright, mask work right, or any other intellectual property rights in\r
19  * or to any products. NXP Semiconductors reserves the right to make changes\r
20  * in the software without notification. NXP Semiconductors also makes no\r
21  * representation or warranty that such application will be suitable for the\r
22  * specified use without further testing or modification.\r
23  *\r
24  * @par\r
25  * Permission to use, copy, modify, and distribute this software and its\r
26  * documentation is hereby granted, under NXP Semiconductors' and its\r
27  * licensor's relevant copyrights in the software, without fee, provided that it\r
28  * is used in conjunction with NXP Semiconductors microcontrollers.  This\r
29  * copyright, permission, and disclaimer notice must appear in all copies of\r
30  * this code.\r
31  */\r
32 \r
33 /** @ingroup Group_USBClassMIDI\r
34  *  @defgroup Group_USBClassMIDIDevice MIDI Class Device Mode Driver\r
35  *\r
36  *  @section Sec_Dependencies Module Source Dependencies\r
37  *  The following files must be built with any user project that uses this module:\r
38  *    - nxpUSBlib/Drivers/USB/Class/Device/MIDI.c <i>(Makefile source module name: NXPUSBLIB_SRC_USBCLASS)</i>\r
39  *\r
40  *  @section Sec_ModDescription Module Description\r
41  *  Device Mode USB Class driver framework interface, for the MIDI USB Class driver.\r
42  *\r
43  * @{\r
44  */\r
45 \r
46 #ifndef _MIDI_CLASS_DEVICE_H_\r
47 #define _MIDI_CLASS_DEVICE_H_\r
48 \r
49 /* Includes: */\r
50                 #include "../../USB.h"\r
51                 #include "../Common/MIDIClassCommon.h"\r
52 \r
53 /* Enable C linkage for C++ Compilers: */\r
54                 #if defined(__cplusplus)\r
55 extern "C" {\r
56                 #endif\r
57 \r
58 /* Preprocessor Checks: */\r
59                 #if !defined(__INCLUDE_FROM_MIDI_DRIVER)\r
60                         #error Do not include this file directly. Include LPCUSBlib/Drivers/USB.h instead.\r
61                 #endif\r
62 \r
63 /* Public Interface - May be used in end-application: */\r
64 /* Type Define: */\r
65 /**\r
66  * @brief MIDI Class Device Mode Configuration and State Structure.\r
67  *\r
68  *  Class state structure. An instance of this structure should be made for each MIDI interface\r
69  *  within the user application, and passed to each of the MIDI class driver functions as the\r
70  *  \c MIDIInterfaceInfo parameter. This stores each MIDI interface's configuration and state information.\r
71  */\r
72 typedef struct {\r
73         const struct {\r
74                 uint8_t  StreamingInterfaceNumber;                              /**< Index of the Audio Streaming interface within the device this structure controls. */\r
75 \r
76                 uint8_t  DataINEndpointNumber;                          /**< Endpoint number of the incoming MIDI IN data, if available (zero if unused). */\r
77                 uint16_t DataINEndpointSize;                    /**< Size in bytes of the incoming MIDI IN data endpoint, if available (zero if unused). */\r
78                 bool     DataINEndpointDoubleBank;                              /**< Indicates if the MIDI interface's IN data endpoint should use double banking. */\r
79 \r
80                 uint8_t  DataOUTEndpointNumber;                         /**< Endpoint number of the outgoing MIDI OUT data, if available (zero if unused). */\r
81                 uint16_t DataOUTEndpointSize;                           /**< Size in bytes of the outgoing MIDI OUT data endpoint, if available (zero if unused). */\r
82                 bool     DataOUTEndpointDoubleBank;                             /**< Indicates if the MIDI interface's OUT data endpoint should use double banking. */\r
83                 uint8_t  PortNumber;                            /**< Port number that this interface is running.*/\r
84         } Config;                               /**< Config data for the USB class interface within the device. All elements in this section\r
85                                                          *   <b>must</b> be set or the interface will fail to enumerate and operate correctly.\r
86                                                          */\r
87 \r
88 #if 0\r
89         struct {\r
90                 // No state information for this class\r
91         } State;                        /**< State data for the USB class interface within the device. All elements in this section\r
92                                                  *   are reset to their defaults when the interface is enumerated.\r
93                                                  */\r
94 \r
95 #endif\r
96 } USB_ClassInfo_MIDI_Device_t;\r
97 \r
98 /* Function Prototypes: */\r
99 /**\r
100  * @brief       Configures the endpoints of a given MIDI interface, ready for use. This should be linked to the library\r
101  *  @ref EVENT_USB_Device_ConfigurationChanged() event so that the endpoints are configured when the configuration\r
102  *  containing the given MIDI interface is selected.\r
103  *\r
104  * @param       MIDIInterfaceInfo       : Pointer to a structure containing a MIDI Class configuration and state.\r
105  *\r
106  * @return      Boolean \c true if the endpoints were successfully configured, \c false otherwise.\r
107  */\r
108 bool MIDI_Device_ConfigureEndpoints(USB_ClassInfo_MIDI_Device_t *const MIDIInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);\r
109 \r
110 /**\r
111  * @brief       General management task for a given MIDI class interface, required for the correct operation of the interface. This should\r
112  *  be called frequently in the main program loop, before the master USB management task @ref USB_USBTask().\r
113  *\r
114  * @param       MIDIInterfaceInfo       : Pointer to a structure containing a MIDI Class configuration and state.\r
115   * @return     Nothing\r
116  */\r
117 void MIDI_Device_USBTask(USB_ClassInfo_MIDI_Device_t *const MIDIInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);\r
118 \r
119 /**\r
120  * @brief       Sends a MIDI event packet to the host. If no host is connected, the event packet is discarded. Events are queued into the\r
121  *  endpoint bank until either the endpoint bank is full, or @ref MIDI_Device_Flush() is called. This allows for multiple\r
122  *  MIDI events to be packed into a single endpoint packet, increasing data throughput.\r
123  *\r
124  *  @pre This function must only be called when the Host state machine is in the @ref HOST_STATE_Configured state or the\r
125  *       call will fail.\r
126  *\r
127  * @param       MIDIInterfaceInfo       : Pointer to a structure containing a MIDI Class configuration and state.\r
128  * @param       Event   : Pointer to a populated @ref MIDI_EventPacket_t structure containing the MIDI event to send.\r
129  *\r
130  * @return      A value from the @ref Endpoint_Stream_RW_ErrorCodes_t enum.\r
131  */\r
132 uint8_t MIDI_Device_SendEventPacket(USB_ClassInfo_MIDI_Device_t *const MIDIInterfaceInfo,\r
133                                                                         const MIDI_EventPacket_t *const Event) ATTR_NON_NULL_PTR_ARG(1)\r
134 ATTR_NON_NULL_PTR_ARG(2);\r
135 \r
136 /**\r
137  * @brief       Flushes the MIDI send buffer, sending any queued MIDI events to the host. This should be called to override the\r
138  *  @ref MIDI_Device_SendEventPacket() function's packing behaviour, to flush queued events.\r
139  *\r
140  * @param       MIDIInterfaceInfo       : Pointer to a structure containing a MIDI Class configuration and state.\r
141  *\r
142  * @return      A value from the @ref Endpoint_WaitUntilReady_ErrorCodes_t enum.\r
143  */\r
144 uint8_t MIDI_Device_Flush(USB_ClassInfo_MIDI_Device_t *const MIDIInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);\r
145 \r
146 /**\r
147  * @brief       Receives a MIDI event packet from the host. Events are unpacked from the endpoint, thus if the endpoint bank contains\r
148  *  multiple MIDI events from the host in the one packet, multiple calls to this function will return each individual event.\r
149  *\r
150  *  @pre This function must only be called when the Host state machine is in the @ref HOST_STATE_Configured state or the\r
151  *       call will fail.\r
152  *\r
153  * @param       MIDIInterfaceInfo       : Pointer to a structure containing a MIDI Class configuration and state.\r
154  * @param       Event   : Pointer to a USB_MIDI_EventPacket_t structure where the received MIDI event is to be placed.\r
155  *\r
156  * @return      Boolean \c true if a MIDI event packet was received, \c false otherwise.\r
157  */\r
158 bool MIDI_Device_ReceiveEventPacket(USB_ClassInfo_MIDI_Device_t *const MIDIInterfaceInfo,\r
159                                                                         MIDI_EventPacket_t *const Event) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(2);\r
160 \r
161 /* Inline Functions: */\r
162 /**\r
163  * @brief       Processes incoming control requests from the host, that are directed to the given MIDI class interface. This should be\r
164  *  linked to the library @ref EVENT_USB_Device_ControlRequest() event.\r
165  *\r
166  * @param       MIDIInterfaceInfo       : Pointer to a structure containing a MIDI Class configuration and state.\r
167  */\r
168 static inline void MIDI_Device_ProcessControlRequest(USB_ClassInfo_MIDI_Device_t *const MIDIInterfaceInfo)\r
169 ATTR_NON_NULL_PTR_ARG(1);\r
170 \r
171 static inline void MIDI_Device_ProcessControlRequest(USB_ClassInfo_MIDI_Device_t *const MIDIInterfaceInfo)\r
172 {\r
173         (void) MIDIInterfaceInfo;\r
174 }\r
175 \r
176 /* Disable C linkage for C++ Compilers: */\r
177                 #if defined(__cplusplus)\r
178 }\r
179                 #endif\r
180 \r
181 #endif\r
182 \r
183 /** @} */\r
184 \r