Fix bugs in the Host mode Audio class driver.
authorDean Camera <dean@fourwalledcubicle.com>
Sun, 12 Jun 2011 13:59:03 +0000 (13:59 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Sun, 12 Jun 2011 13:59:03 +0000 (13:59 +0000)
Demos/Host/LowLevel/AudioInputHost/ConfigDescriptor.c
Demos/Host/LowLevel/AudioOutputHost/ConfigDescriptor.c
LUFA/Drivers/USB/Class/Host/Audio.c
LUFA/Drivers/USB/Class/Host/Audio.h

index 589012a..8f55114 100644 (file)
@@ -92,7 +92,7 @@ uint8_t ProcessConfigurationDescriptor(void)
                        {\r
                                /* Find a new Audio Control interface if the current one doesn't contain a compatible streaming interface */\r
                                if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,\r
-                                                                                         DComp_NextAudioControlInterface) != DESCRIPTOR_SEARCH_COMP_Found)\r
+                                                             DComp_NextAudioControlInterface) != DESCRIPTOR_SEARCH_COMP_Found)\r
                                {\r
                                        /* Descriptor not found, error out */\r
                                        return NoCompatibleInterfaceFound;\r
@@ -103,7 +103,7 @@ uint8_t ProcessConfigurationDescriptor(void)
 \r
                                /* Find the next Audio Streaming interface within that Audio Control interface */\r
                                if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,\r
-                                                                                 DComp_NextAudioStreamInterface) != DESCRIPTOR_SEARCH_COMP_Found)\r
+                                                             DComp_NextAudioStreamInterface) != DESCRIPTOR_SEARCH_COMP_Found)\r
                                {\r
                                        /* Descriptor not found, error out */\r
                                        return NoCompatibleInterfaceFound;\r
index 30b50c6..2171320 100644 (file)
@@ -88,11 +88,11 @@ uint8_t ProcessConfigurationDescriptor(void)
                        /* Check if we haven't found an Audio Control interface yet, or if we have run out of related Audio Streaming interfaces */\r
                        if (!(AudioControlInterface) ||\r
                            USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,\r
-                                                     DComp_NextAudioStreamInterface) != DESCRIPTOR_SEARCH_COMP_Found)\r
+                                                         DComp_NextAudioStreamInterface) != DESCRIPTOR_SEARCH_COMP_Found)\r
                        {\r
                                /* Find a new Audio Control interface if the current one doesn't contain a compatible streaming interface */\r
                                if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,\r
-                                                                                         DComp_NextAudioControlInterface) != DESCRIPTOR_SEARCH_COMP_Found)\r
+                                                             DComp_NextAudioControlInterface) != DESCRIPTOR_SEARCH_COMP_Found)\r
                                {\r
                                        /* Descriptor not found, error out */\r
                                        return NoCompatibleInterfaceFound;\r
@@ -103,7 +103,7 @@ uint8_t ProcessConfigurationDescriptor(void)
 \r
                                /* Find the next Audio Streaming interface within that Audio Control interface */\r
                                if (USB_GetNextDescriptorComp(&CurrConfigBytesRem, &CurrConfigLocation,\r
-                                                                                 DComp_NextAudioStreamInterface) != DESCRIPTOR_SEARCH_COMP_Found)\r
+                                                             DComp_NextAudioStreamInterface) != DESCRIPTOR_SEARCH_COMP_Found)\r
                                {\r
                                        /* Descriptor not found, error out */\r
                                        return NoCompatibleInterfaceFound;\r
index e02ce30..5760b6a 100644 (file)
@@ -62,7 +62,7 @@ uint8_t Audio_Host_ConfigurePipes(USB_ClassInfo_Audio_Host_t* const AudioInterfa
                                                      DComp_NextAudioStreamInterface) != DESCRIPTOR_SEARCH_COMP_Found)\r
                        {\r
                                if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,\r
-                                                                                         DComp_NextAudioControlInterface) != DESCRIPTOR_SEARCH_COMP_Found)\r
+                                                             DComp_NextAudioControlInterface) != DESCRIPTOR_SEARCH_COMP_Found)\r
                                {\r
                                        return AUDIO_ENUMERROR_NoCompatibleInterfaceFound;\r
                                }\r
@@ -70,7 +70,7 @@ uint8_t Audio_Host_ConfigurePipes(USB_ClassInfo_Audio_Host_t* const AudioInterfa
                                AudioControlInterface = DESCRIPTOR_PCAST(ConfigDescriptorData, USB_Descriptor_Interface_t);                     \r
 \r
                                if (USB_GetNextDescriptorComp(&ConfigDescriptorSize, &ConfigDescriptorData,\r
-                                                                                 DComp_NextAudioStreamInterface) != DESCRIPTOR_SEARCH_COMP_Found)\r
+                                                             DComp_NextAudioStreamInterface) != DESCRIPTOR_SEARCH_COMP_Found)\r
                                {\r
                                        return AUDIO_ENUMERROR_NoCompatibleInterfaceFound;\r
                                }\r
@@ -102,7 +102,7 @@ uint8_t Audio_Host_ConfigurePipes(USB_ClassInfo_Audio_Host_t* const AudioInterfa
                        Size            = DataINEndpoint->EndpointSize;\r
                        EndpointAddress = DataINEndpoint->EndpointAddress;\r
                        Token           = PIPE_TOKEN_IN;\r
-                       Type            = EP_TYPE_BULK;\r
+                       Type            = EP_TYPE_ISOCHRONOUS;\r
                        DoubleBanked    = true;\r
 \r
                        AudioInterfaceInfo->State.DataINPipeSize = DataINEndpoint->EndpointSize;\r
@@ -211,6 +211,9 @@ uint8_t Audio_GetSetEndpointProperty(USB_ClassInfo_Audio_Host_t* const AudioInte
                                                 uint16_t const DataLength,\r
                                                 void* const Data)\r
 {\r
+       if (!(AudioInterfaceInfo->State.IsActive))\r
+         return HOST_SENDCONTROL_DeviceDisconnected;\r
+\r
        uint8_t RequestType;\r
        uint8_t EndpointAddress;\r
 \r
index befcc2f..26d5376 100644 (file)
                        {\r
                                const struct\r
                                {\r
-                                       uint8_t  DataINPipeNumber; /**< Pipe number of the Audio interface's IN data pipe. */\r
-                                       uint8_t  DataOUTPipeNumber; /**< Pipe number of the Audio interface's OUT data pipe. */\r
+                                       uint8_t  DataINPipeNumber; /**< Pipe number of the Audio interface's IN data pipe. If this interface should not\r
+                                                                   *   bind to an IN endpoint, this may be set to 0 to disable audio input streaming for\r
+                                                                   *   this driver instance.\r
+                                                                   */\r
+                                       uint8_t  DataOUTPipeNumber; /**< Pipe number of the Audio interface's OUT data pipe. If this interface should not\r
+                                                                   *   bind to an OUT endpoint, this may be set to 0 to disable audio output streaming for\r
+                                                                   *   this driver instance.\r
+                                                                   */\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
                        {\r
                                Pipe_Write_8(Sample);\r
 \r
-                               if (Pipe_BytesInPipe() == AudioInterfaceInfo->State.DataOUTPipeSize)\r
+                               if (!(Pipe_IsReadWriteAllowed()))\r
                                {\r
                                        Pipe_Unfreeze();\r
                                        Pipe_ClearOUT();\r
+                                       Pipe_WaitUntilReady();\r
                                        Pipe_Freeze();\r
                                }\r
                        }\r
                        {\r
                                Pipe_Write_16_LE(Sample);\r
 \r
-                               if (Pipe_BytesInPipe() == AudioInterfaceInfo->State.DataOUTPipeSize)\r
+                               if (!(Pipe_IsReadWriteAllowed()))\r
                                {\r
                                        Pipe_Unfreeze();\r
                                        Pipe_ClearOUT();\r
+                                       Pipe_WaitUntilReady();\r
                                        Pipe_Freeze();\r
                                }\r
                        }\r
                                Pipe_Write_16_LE(Sample);\r
                                Pipe_Write_8(Sample >> 16);\r
 \r
-                               if (Pipe_BytesInPipe() == AudioInterfaceInfo->State.DataOUTPipeSize)\r
+                               if (!(Pipe_IsReadWriteAllowed()))\r
                                {\r
                                        Pipe_Unfreeze();\r
                                        Pipe_ClearOUT();\r
+                                       Pipe_WaitUntilReady();\r
                                        Pipe_Freeze();\r
                                }\r
                        }\r