The Audio_Device_IsSampleReceived() and Audio_Device_IsReadyForNextSample() functions...
[pub/USBasp.git] / LUFA / Drivers / USB / Class / Device / Audio.h
index 2d33f39..fd821e9 100644 (file)
                         */\r
                        void Audio_Device_ProcessControlRequest(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);\r
                        \r
+               /* Inline Functions: */         \r
+                       /** General management task for a given Audio 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] AudioInterfaceInfo  Pointer to a structure containing an Audio Class configuration and state\r
+                        */\r
+                       static inline void Audio_Device_USBTask(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo);\r
+                       static inline void Audio_Device_USBTask(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo)\r
+                       {\r
+                               (void)AudioInterfaceInfo;\r
+                       }\r
+\r
                        /** Determines if the given audio interface is ready for a sample to be read from it, and selects the streaming\r
                         *  OUT endpoint ready for reading.\r
                         *\r
                         *  \param[in,out] AudioInterfaceInfo  Pointer to a structure containing an Audio Class configuration and state\r
                         *\r
                         *  \return Boolean true if the given Audio interface has a sample to be read, false otherwise\r
-                        */\r
-                       bool Audio_Device_IsSampleReceived(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo);\r
+                        */             \r
+                       static inline bool Audio_Device_IsSampleReceived(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo)\r
+                       {\r
+                               if ((USB_DeviceState != DEVICE_STATE_Configured) || !(AudioInterfaceInfo->State.InterfaceEnabled))\r
+                                 return false;\r
+                               \r
+                               Endpoint_SelectEndpoint(AudioInterfaceInfo->Config.DataOUTEndpointNumber);      \r
+                               return Endpoint_IsOUTReceived();\r
+                       }\r
 \r
                        /** Determines if the given audio interface is ready to accept the next sample to be written to it, and selects\r
                         *  the streaming IN endpoint ready for writing.\r
                         *\r
                         *  \return Boolean true if the given Audio interface is ready to accept the next sample, false otherwise\r
                         */\r
-                       bool Audio_Device_IsReadyForNextSample(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo);\r
-\r
-               /* Inline Functions: */\r
-                       /** General management task for a given Audio 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] AudioInterfaceInfo  Pointer to a structure containing an Audio Class configuration and state\r
-                        */\r
-                       static inline void Audio_Device_USBTask(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo);\r
-                       static inline void Audio_Device_USBTask(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo)\r
+                       static inline bool Audio_Device_IsReadyForNextSample(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo)\r
                        {\r
-                               (void)AudioInterfaceInfo;\r
+                               if ((USB_DeviceState != DEVICE_STATE_Configured) || !(AudioInterfaceInfo->State.InterfaceEnabled))\r
+                                 return false;\r
+                               \r
+                               Endpoint_SelectEndpoint(AudioInterfaceInfo->Config.DataINEndpointNumber);\r
+                               return Endpoint_IsINReady();\r
                        }\r
 \r
                        /** Reads the next 8-bit audio sample from the current audio interface.\r