Be doubly-certain that the incomming CDC class driver's endpoint/pipe is flushed...
[pub/USBasp.git] / LUFA / Drivers / USB / Class / Host / MIDI.h
index b86699e..7b1cba3 100644 (file)
@@ -1,21 +1,21 @@
 /*\r
              LUFA Library\r
 /*\r
              LUFA Library\r
-     Copyright (C) Dean Camera, 2009.\r
+     Copyright (C) Dean Camera, 2010.\r
               \r
   dean [at] fourwalledcubicle [dot] com\r
       www.fourwalledcubicle.com\r
 */\r
 \r
 /*\r
               \r
   dean [at] fourwalledcubicle [dot] com\r
       www.fourwalledcubicle.com\r
 */\r
 \r
 /*\r
-  Copyright 2009  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
+  Copyright 2010  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
 \r
 \r
-  Permission to use, copy, modify, and distribute this software\r
-  and its documentation for any purpose and without fee is hereby\r
-  granted, provided that the above copyright notice appear in all\r
-  copies and that both that the copyright notice and this\r
-  permission notice and warranty disclaimer appear in supporting\r
-  documentation, and that the name of the author not be used in\r
-  advertising or publicity pertaining to distribution of the\r
+  Permission to use, copy, modify, distribute, and sell this \r
+  software and its documentation for any purpose is hereby granted\r
+  without fee, provided that the above copyright notice appear in \r
+  all copies and that both that the copyright notice and this\r
+  permission notice and warranty disclaimer appear in supporting \r
+  documentation, and that the name of the author not be used in \r
+  advertising or publicity pertaining to distribution of the \r
   software without specific, written prior permission.\r
 \r
   The author disclaim all warranties with regard to this\r
   software without specific, written prior permission.\r
 \r
   The author disclaim all warranties with regard to this\r
                                const struct\r
                                {\r
                                        uint8_t  DataINPipeNumber; /**< Pipe number of the MIDI interface's streaming IN data pipe */\r
                                const struct\r
                                {\r
                                        uint8_t  DataINPipeNumber; /**< Pipe number of the MIDI interface's streaming IN data pipe */\r
+                                       bool     DataINPipeDoubleBank; /** Indicates if the MIDI interface's IN data pipe should use double banking */\r
+                                       \r
                                        uint8_t  DataOUTPipeNumber; /**< Pipe number of the MIDI interface's streaming OUT data pipe */\r
                                        uint8_t  DataOUTPipeNumber; /**< Pipe number of the MIDI interface's streaming OUT data pipe */\r
+                                       bool     DataOUTPipeDoubleBank; /** Indicates if the MIDI interface's OUT data pipe should use double banking */\r
                                } Config; /**< Config data for the USB class interface within the device. All elements in this section\r
                                           *   <b>must</b> be set or the interface will fail to enumerate and operate correctly.\r
                                           */\r
                                struct\r
                                {\r
                                        bool IsActive; /**< Indicates if the current interface instance is connected to an attached device, valid\r
                                } Config; /**< Config data for the USB class interface within the device. All elements in this section\r
                                           *   <b>must</b> be set or the interface will fail to enumerate and operate correctly.\r
                                           */\r
                                struct\r
                                {\r
                                        bool IsActive; /**< Indicates if the current interface instance is connected to an attached device, valid\r
-                                                       *   after \ref HID_Host_ConfigurePipes() is called and the Host state machine is in the\r
+                                                       *   after \ref MIDI_Host_ConfigurePipes() is called and the Host state machine is in the\r
                                                        *   Configured state\r
                                                        */\r
 \r
                                                        *   Configured state\r
                                                        */\r
 \r
                        };\r
        \r
                /* Function Prototypes: */\r
                        };\r
        \r
                /* Function Prototypes: */\r
-                       /** General management task for a given MIDI host class interface, required for the correct operation of the interface. This should\r
-                        *  be called frequently in the main program loop, before the master USB management task \ref USB_USBTask().\r
-                        *\r
-                        *  \param[in,out] MIDIInterfaceInfo  Pointer to a structure containing an MIDI Class host configuration and state\r
-                        */\r
-                       void MIDI_Host_USBTask(USB_ClassInfo_MIDI_Host_t* const MIDIInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);\r
-                       \r
                        /** Host interface configuration routine, to configure a given MIDI host interface instance using the Configuration\r
                         *  Descriptor read from an attached USB device. This function automatically updates the given MIDI Host instance's\r
                         *  state values and configures the pipes required to communicate with the interface if it is found within the device.\r
                        /** Host interface configuration routine, to configure a given MIDI host interface instance using the Configuration\r
                         *  Descriptor read from an attached USB device. This function automatically updates the given MIDI Host instance's\r
                         *  state values and configures the pipes required to communicate with the interface if it is found within the device.\r
                         *  \return A value from the \ref MIDIHost_EnumerationFailure_ErrorCodes_t enum\r
                         */\r
                        uint8_t MIDI_Host_ConfigurePipes(USB_ClassInfo_MIDI_Host_t* const MIDIInterfaceInfo, uint16_t ConfigDescriptorSize,\r
                         *  \return A value from the \ref MIDIHost_EnumerationFailure_ErrorCodes_t enum\r
                         */\r
                        uint8_t MIDI_Host_ConfigurePipes(USB_ClassInfo_MIDI_Host_t* const MIDIInterfaceInfo, uint16_t ConfigDescriptorSize,\r
-                                                        uint8_t* DeviceConfigDescriptor) ATTR_NON_NULL_PTR_ARG(1, 3);\r
+                                                        void* DeviceConfigDescriptor) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(3);\r
 \r
                        /** Sends a MIDI event packet to the device. If no device is connected, the event packet is discarded.\r
                         *\r
 \r
                        /** Sends a MIDI event packet to the device. If no device is connected, the event packet is discarded.\r
                         *\r
+                        *  \note This function must only be called when the Host state machine is in the HOST_STATE_Configured state or the\r
+                        *        call will fail.\r
+                        *\r
                         *  \param[in,out] MIDIInterfaceInfo  Pointer to a structure containing a MIDI Class configuration and state\r
                         *  \param[in] Event  Pointer to a populated USB_MIDI_EventPacket_t structure containing the MIDI event to send\r
                         *\r
                         *  \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum                       \r
                         */\r
                        uint8_t MIDI_Host_SendEventPacket(USB_ClassInfo_MIDI_Host_t* const MIDIInterfaceInfo,\r
                         *  \param[in,out] MIDIInterfaceInfo  Pointer to a structure containing a MIDI Class configuration and state\r
                         *  \param[in] Event  Pointer to a populated USB_MIDI_EventPacket_t structure containing the MIDI event to send\r
                         *\r
                         *  \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum                       \r
                         */\r
                        uint8_t MIDI_Host_SendEventPacket(USB_ClassInfo_MIDI_Host_t* const MIDIInterfaceInfo,\r
-                                                         MIDI_EventPacket_t* const Event) ATTR_NON_NULL_PTR_ARG(12);\r
+                                                         MIDI_EventPacket_t* const Event) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(2);\r
 \r
 \r
+                       /** Flushes the MIDI send buffer, sending any queued MIDI events to the device. This should be called to override the\r
+                        *  \ref MIDI_Host_SendEventPacket() function's packing behaviour, to flush queued events. Events are queued into the\r
+                        *  pipe bank until either the pipe bank is full, or \ref MIDI_Host_Flush() is called. This allows for multiple MIDI\r
+                        *  events to be packed into a single pipe packet, increasing data throughput.\r
+                        *\r
+                        *  \param[in,out] MIDIInterfaceInfo  Pointer to a structure containing a MIDI Class configuration and state\r
+                        *\r
+                        *  \return A value from the \ref Pipe_WaitUntilReady_ErrorCodes_t enum\r
+                        */\r
+                        uint8_t MIDI_Host_Flush(USB_ClassInfo_MIDI_Host_t* const MIDIInterfaceInfo);\r
+                        \r
                        /** Receives a MIDI event packet from the device.\r
                         *\r
                        /** Receives a MIDI event packet from the device.\r
                         *\r
+                        *  \note This function must only be called when the Host state machine is in the HOST_STATE_Configured state or the\r
+                        *        call will fail.\r
+                        *\r
                         *  \param[in,out] MIDIInterfaceInfo  Pointer to a structure containing a MIDI Class configuration and state\r
                         *  \param[out] Event  Pointer to a USB_MIDI_EventPacket_t structure where the received MIDI event is to be placed\r
                         *\r
                         *  \return Boolean true if a MIDI event packet was received, false otherwise\r
                         */\r
                        bool MIDI_Host_ReceiveEventPacket(USB_ClassInfo_MIDI_Host_t* const MIDIInterfaceInfo,\r
                         *  \param[in,out] MIDIInterfaceInfo  Pointer to a structure containing a MIDI Class configuration and state\r
                         *  \param[out] Event  Pointer to a USB_MIDI_EventPacket_t structure where the received MIDI event is to be placed\r
                         *\r
                         *  \return Boolean true if a MIDI event packet was received, false otherwise\r
                         */\r
                        bool MIDI_Host_ReceiveEventPacket(USB_ClassInfo_MIDI_Host_t* const MIDIInterfaceInfo,\r
-                                                         MIDI_EventPacket_t* const Event) ATTR_NON_NULL_PTR_ARG(1, 2);\r
-                                                                                               \r
+                                                         MIDI_EventPacket_t* const Event) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(2);\r
+\r
+               /* Inline Functions: */\r
+                       /** General management task for a given MIDI host class interface, required for the correct operation of the interface. This should\r
+                        *  be called frequently in the main program loop, before the master USB management task \ref USB_USBTask().\r
+                        *\r
+                        *  \param[in,out] MIDIInterfaceInfo  Pointer to a structure containing an MIDI Class host configuration and state\r
+                        */\r
+                       static inline void MIDI_Host_USBTask(USB_ClassInfo_MIDI_Host_t* const MIDIInterfaceInfo);\r
+                       static inline void MIDI_Host_USBTask(USB_ClassInfo_MIDI_Host_t* const MIDIInterfaceInfo)\r
+                       {\r
+                               (void)MIDIInterfaceInfo;\r
+                       }\r
+\r
        /* Private Interface - For use in library only: */\r
        #if !defined(__DOXYGEN__)\r
                /* Macros: */\r
        /* Private Interface - For use in library only: */\r
        #if !defined(__DOXYGEN__)\r
                /* Macros: */\r