]> git.donarmstrong.com Git - qmk_firmware.git/blob - protocol/lufa/LUFA-120730/LUFA/Drivers/USB/Class/Host/MIDIClassHost.h
Squashed 'tmk_core/' content from commit 05caacc
[qmk_firmware.git] / protocol / lufa / LUFA-120730 / LUFA / Drivers / USB / Class / Host / MIDIClassHost.h
1 /*\r
2              LUFA Library\r
3      Copyright (C) Dean Camera, 2012.\r
4 \r
5   dean [at] fourwalledcubicle [dot] com\r
6            www.lufa-lib.org\r
7 */\r
8 \r
9 /*\r
10   Copyright 2012  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
11 \r
12   Permission to use, copy, modify, distribute, and sell this\r
13   software and its documentation for any purpose is hereby granted\r
14   without fee, provided that the above copyright notice appear in\r
15   all copies and that both that the copyright notice and this\r
16   permission notice and warranty disclaimer appear in supporting\r
17   documentation, and that the name of the author not be used in\r
18   advertising or publicity pertaining to distribution of the\r
19   software without specific, written prior permission.\r
20 \r
21   The author disclaim all warranties with regard to this\r
22   software, including all implied warranties of merchantability\r
23   and fitness.  In no event shall the author be liable for any\r
24   special, indirect or consequential damages or any damages\r
25   whatsoever resulting from loss of use, data or profits, whether\r
26   in an action of contract, negligence or other tortious action,\r
27   arising out of or in connection with the use or performance of\r
28   this software.\r
29 */\r
30 \r
31 /** \file\r
32  *  \brief Host mode driver for the library USB MIDI Class driver.\r
33  *\r
34  *  Host mode driver for the library USB MIDI Class driver.\r
35  *\r
36  *  \note This file should not be included directly. It is automatically included as needed by the USB module driver\r
37  *        dispatch header located in LUFA/Drivers/USB.h.\r
38  */\r
39 \r
40 /** \ingroup Group_USBClassMIDI\r
41  *  \defgroup Group_USBClassMIDIHost MIDI Class Host Mode Driver\r
42  *\r
43  *  \section Sec_Dependencies Module Source Dependencies\r
44  *  The following files must be built with any user project that uses this module:\r
45  *    - LUFA/Drivers/USB/Class/Host/MIDIClassHost.c <i>(Makefile source module name: LUFA_SRC_USBCLASS)</i>\r
46  *\r
47  *  \section Sec_ModDescription Module Description\r
48  *  Host Mode USB Class driver framework interface, for the MIDI USB Class driver.\r
49  *\r
50  *  @{\r
51  */\r
52 \r
53 #ifndef __MIDI_CLASS_HOST_H__\r
54 #define __MIDI_CLASS_HOST_H__\r
55 \r
56         /* Includes: */\r
57                 #include "../../USB.h"\r
58                 #include "../Common/MIDIClassCommon.h"\r
59 \r
60         /* Enable C linkage for C++ Compilers: */\r
61                 #if defined(__cplusplus)\r
62                         extern "C" {\r
63                 #endif\r
64 \r
65         /* Preprocessor Checks: */\r
66                 #if !defined(__INCLUDE_FROM_MIDI_DRIVER)\r
67                         #error Do not include this file directly. Include LUFA/Drivers/USB.h instead.\r
68                 #endif\r
69 \r
70         /* Public Interface - May be used in end-application: */\r
71                 /* Type Defines: */\r
72                         /** \brief MIDI Class Host Mode Configuration and State Structure.\r
73                          *\r
74                          *  Class state structure. An instance of this structure should be made within the user application,\r
75                          *  and passed to each of the MIDI class driver functions as the \c MIDIInterfaceInfo parameter. This\r
76                          *  stores each MIDI interface's configuration and state information.\r
77                          */\r
78                         typedef struct\r
79                         {\r
80                                 struct\r
81                                 {\r
82                                         USB_Pipe_Table_t DataINPipe; /**< Data IN Pipe configuration table. */\r
83                                         USB_Pipe_Table_t DataOUTPipe; /**< Data OUT Pipe configuration table. */\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                                 struct\r
88                                 {\r
89                                         bool     IsActive; /**< Indicates if the current interface instance is connected to an attached device, valid\r
90                                                             *   after \ref MIDI_Host_ConfigurePipes() is called and the Host state machine is in the\r
91                                                             *   Configured state.\r
92                                                             */\r
93                                         uint8_t  InterfaceNumber; /**< Interface index of the MIDI interface within the attached device. */\r
94                                 } State; /**< State data for the USB class interface within the device. All elements in this section\r
95                                                   *   <b>may</b> be set to initial values, but may also be ignored to default to sane values when\r
96                                                   *   the interface is enumerated.\r
97                                                   */\r
98                         } USB_ClassInfo_MIDI_Host_t;\r
99 \r
100                 /* Enums: */\r
101                         /** Enum for the possible error codes returned by the \ref MIDI_Host_ConfigurePipes() function. */\r
102                         enum MIDI_Host_EnumerationFailure_ErrorCodes_t\r
103                         {\r
104                                 MIDI_ENUMERROR_NoError                    = 0, /**< Configuration Descriptor was processed successfully. */\r
105                                 MIDI_ENUMERROR_InvalidConfigDescriptor    = 1, /**< The device returned an invalid Configuration Descriptor. */\r
106                                 MIDI_ENUMERROR_NoCompatibleInterfaceFound = 2, /**< A compatible MIDI interface was not found in the device's Configuration Descriptor. */\r
107                                 MIDI_ENUMERROR_PipeConfigurationFailed    = 3, /**< One or more pipes for the specified interface could not be configured correctly. */\r
108                         };\r
109 \r
110                 /* Function Prototypes: */\r
111                         /** Host interface configuration routine, to configure a given MIDI host interface instance using the Configuration\r
112                          *  Descriptor read from an attached USB device. This function automatically updates the given MIDI Host instance's\r
113                          *  state values and configures the pipes required to communicate with the interface if it is found within the device.\r
114                          *  This should be called once after the stack has enumerated the attached device, while the host state machine is in\r
115                          *  the Addressed state.\r
116                          *\r
117                          *  \param[in,out] MIDIInterfaceInfo     Pointer to a structure containing an MIDI Class host configuration and state.\r
118                          *  \param[in]     ConfigDescriptorSize  Length of the attached device's Configuration Descriptor.\r
119                          *  \param[in]     ConfigDescriptorData  Pointer to a buffer containing the attached device's Configuration Descriptor.\r
120                          *\r
121                          *  \return A value from the \ref MIDI_Host_EnumerationFailure_ErrorCodes_t enum.\r
122                          */\r
123                         uint8_t MIDI_Host_ConfigurePipes(USB_ClassInfo_MIDI_Host_t* const MIDIInterfaceInfo,\r
124                                                          uint16_t ConfigDescriptorSize,\r
125                                                          void* ConfigDescriptorData) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(3);\r
126 \r
127                         /** General management task for a given MIDI host class interface, required for the correct operation of the interface. This should\r
128                          *  be called frequently in the main program loop, before the master USB management task \ref USB_USBTask().\r
129                          *\r
130                          *  \param[in,out] MIDIInterfaceInfo  Pointer to a structure containing an MIDI Class host configuration and state.\r
131                          */\r
132                         void MIDI_Host_USBTask(USB_ClassInfo_MIDI_Host_t* const MIDIInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);\r
133 \r
134                         /** Sends a MIDI event packet to the device. If no device is connected, the event packet is discarded.\r
135                          *\r
136                          *  \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the\r
137                          *       call will fail.\r
138                          *\r
139                          *  \param[in,out] MIDIInterfaceInfo  Pointer to a structure containing a MIDI Class configuration and state.\r
140                          *  \param[in]     Event              Pointer to a populated USB_MIDI_EventPacket_t structure containing the MIDI event to send.\r
141                          *\r
142                          *  \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum.\r
143                          */\r
144                         uint8_t MIDI_Host_SendEventPacket(USB_ClassInfo_MIDI_Host_t* const MIDIInterfaceInfo,\r
145                                                           MIDI_EventPacket_t* const Event) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(2);\r
146 \r
147                         /** Flushes the MIDI send buffer, sending any queued MIDI events to the device. This should be called to override the\r
148                          *  \ref MIDI_Host_SendEventPacket() function's packing behavior, to flush queued events. Events are queued into the\r
149                          *  pipe bank until either the pipe bank is full, or \ref MIDI_Host_Flush() is called. This allows for multiple MIDI\r
150                          *  events to be packed into a single pipe packet, increasing data throughput.\r
151                          *\r
152                          *  \param[in,out] MIDIInterfaceInfo  Pointer to a structure containing a MIDI Class configuration and state.\r
153                          *\r
154                          *  \return A value from the \ref Pipe_WaitUntilReady_ErrorCodes_t enum.\r
155                          */\r
156                          uint8_t MIDI_Host_Flush(USB_ClassInfo_MIDI_Host_t* const MIDIInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);\r
157 \r
158                         /** Receives a MIDI event packet from the device.\r
159                          *\r
160                          *  \pre This function must only be called when the Host state machine is in the \ref HOST_STATE_Configured state or the\r
161                          *       call will fail.\r
162                          *\r
163                          *  \param[in,out] MIDIInterfaceInfo  Pointer to a structure containing a MIDI Class configuration and state.\r
164                          *  \param[out]    Event              Pointer to a USB_MIDI_EventPacket_t structure where the received MIDI event is to be placed.\r
165                          *\r
166                          *  \return Boolean \c true if a MIDI event packet was received, \c false otherwise.\r
167                          */\r
168                         bool MIDI_Host_ReceiveEventPacket(USB_ClassInfo_MIDI_Host_t* const MIDIInterfaceInfo,\r
169                                                           MIDI_EventPacket_t* const Event) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(2);\r
170 \r
171         /* Private Interface - For use in library only: */\r
172         #if !defined(__DOXYGEN__)\r
173                 /* Function Prototypes: */\r
174                         #if defined(__INCLUDE_FROM_MIDI_HOST_C)\r
175                                 static uint8_t DCOMP_MIDI_Host_NextMIDIStreamingInterface(void* const CurrentDescriptor)\r
176                                                                                           ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(1);\r
177                                 static uint8_t DCOMP_MIDI_Host_NextMIDIStreamingDataEndpoint(void* const CurrentDescriptor)\r
178                                                                                              ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(1);\r
179                         #endif\r
180         #endif\r
181 \r
182         /* Disable C linkage for C++ Compilers: */\r
183                 #if defined(__cplusplus)\r
184                         }\r
185                 #endif\r
186 \r
187 #endif\r
188 \r
189 /** @} */\r
190 \r