Fix errors in the Audio device demos and class driver regarding multiple sample frequency support.

pull/1469/head
Dean Camera 13 years ago
parent 2d778a3ff5
commit 567f7ecce0

@ -190,13 +190,13 @@ void EVENT_USB_Device_ControlRequest(void)
*/ */
bool CALLBACK_Audio_GetSetEndpointProperty(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo, bool CALLBACK_Audio_GetSetEndpointProperty(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo,
const uint8_t EndpointProperty, const uint8_t EndpointProperty,
const uint8_t EndpointIndex, const uint8_t EndpointAddress,
const uint8_t EndpointControl, const uint8_t EndpointControl,
uint16_t* const DataLength, uint16_t* const DataLength,
uint8_t* Data) uint8_t* Data)
{ {
/* Check the requested endpoint to see if a supported endpoint is being manipulated */ /* Check the requested endpoint to see if a supported endpoint is being manipulated */
if (EndpointIndex == Microphone_Audio_Interface.Config.DataINEndpointNumber) if (EndpointAddress == (ENDPOINT_DESCRIPTOR_DIR_IN | Microphone_Audio_Interface.Config.DataINEndpointNumber))
{ {
/* Check the requested control to see if a supported control is being manipulated */ /* Check the requested control to see if a supported control is being manipulated */
if (EndpointControl == AUDIO_EPCONTROL_SamplingFreq) if (EndpointControl == AUDIO_EPCONTROL_SamplingFreq)

@ -226,13 +226,13 @@ void EVENT_USB_Device_ControlRequest(void)
*/ */
bool CALLBACK_Audio_GetSetEndpointProperty(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo, bool CALLBACK_Audio_GetSetEndpointProperty(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo,
const uint8_t EndpointProperty, const uint8_t EndpointProperty,
const uint8_t EndpointIndex, const uint8_t EndpointAddress,
const uint8_t EndpointControl, const uint8_t EndpointControl,
uint16_t* const DataLength, uint16_t* const DataLength,
uint8_t* Data) uint8_t* Data)
{ {
/* Check the requested endpoint to see if a supported endpoint is being manipulated */ /* Check the requested endpoint to see if a supported endpoint is being manipulated */
if (EndpointIndex == Speaker_Audio_Interface.Config.DataOUTEndpointNumber) if (EndpointAddress == (ENDPOINT_DESCRIPTOR_DIR_OUT | Speaker_Audio_Interface.Config.DataOUTEndpointNumber))
{ {
/* Check the requested control to see if a supported control is being manipulated */ /* Check the requested control to see if a supported control is being manipulated */
if (EndpointControl == AUDIO_EPCONTROL_SamplingFreq) if (EndpointControl == AUDIO_EPCONTROL_SamplingFreq)

@ -160,18 +160,18 @@ void EVENT_USB_Device_ControlRequest(void)
case AUDIO_REQ_SetCurrent: case AUDIO_REQ_SetCurrent:
if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_ENDPOINT)) if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_ENDPOINT))
{ {
/* Extract out the relevant request information to get the target Endpoint index and control being set */ /* Extract out the relevant request information to get the target Endpoint address and control being set */
uint8_t EndpointIndex = (uint8_t)USB_ControlRequest.wIndex; uint8_t EndpointAddress = (uint8_t)USB_ControlRequest.wIndex;
uint8_t EndpointControl = (USB_ControlRequest.wValue >> 8); uint8_t EndpointControl = (USB_ControlRequest.wValue >> 8);
/* Only handle SET CURRENT requests to the audio endpoint's sample frequency property */ /* Only handle SET CURRENT requests to the audio endpoint's sample frequency property */
if ((EndpointIndex == AUDIO_STREAM_EPNUM) && (EndpointControl == AUDIO_EPCONTROL_SamplingFreq)) if ((EndpointAddress == (ENDPOINT_DESCRIPTOR_DIR_IN | AUDIO_STREAM_EPNUM)) && (EndpointControl == AUDIO_EPCONTROL_SamplingFreq))
{ {
uint8_t SampleRate[3]; uint8_t SampleRate[3];
Endpoint_ClearSETUP(); Endpoint_ClearSETUP();
Endpoint_Read_Control_Stream_LE(SampleRate, sizeof(SampleRate)); Endpoint_Read_Control_Stream_LE(SampleRate, sizeof(SampleRate));
Endpoint_ClearOUT(); Endpoint_ClearIN();
/* Set the new sampling frequency to the value given by the host */ /* Set the new sampling frequency to the value given by the host */
CurrentAudioSampleFrequency = (((uint32_t)SampleRate[2] << 16) | ((uint32_t)SampleRate[1] << 8) | (uint32_t)SampleRate[0]); CurrentAudioSampleFrequency = (((uint32_t)SampleRate[2] << 16) | ((uint32_t)SampleRate[1] << 8) | (uint32_t)SampleRate[0]);
@ -183,14 +183,14 @@ void EVENT_USB_Device_ControlRequest(void)
break; break;
case AUDIO_REQ_GetCurrent: case AUDIO_REQ_GetCurrent:
if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_ENDPOINT)) if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_ENDPOINT))
{ {
/* Extract out the relevant request information to get the target Endpoint index and control being retrieved */ /* Extract out the relevant request information to get the target Endpoint address and control being retrieved */
uint8_t EndpointIndex = (uint8_t)USB_ControlRequest.wIndex; uint8_t EndpointAddress = (uint8_t)USB_ControlRequest.wIndex;
uint8_t EndpointControl = (USB_ControlRequest.wValue >> 8); uint8_t EndpointControl = (USB_ControlRequest.wValue >> 8);
/* Only handle GET CURRENT requests to the audio endpoint's sample frequency property */ /* Only handle GET CURRENT requests to the audio endpoint's sample frequency property */
if ((EndpointIndex == AUDIO_STREAM_EPNUM) && (EndpointControl == AUDIO_EPCONTROL_SamplingFreq)) if ((EndpointAddress == (ENDPOINT_DESCRIPTOR_DIR_IN | AUDIO_STREAM_EPNUM)) && (EndpointControl == AUDIO_EPCONTROL_SamplingFreq))
{ {
uint8_t SampleRate[3]; uint8_t SampleRate[3];

@ -235,7 +235,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
.Header = {.Size = sizeof(USB_Audio_Descriptor_StreamEndpoint_Spc_t), .Type = DTYPE_CSEndpoint}, .Header = {.Size = sizeof(USB_Audio_Descriptor_StreamEndpoint_Spc_t), .Type = DTYPE_CSEndpoint},
.Subtype = AUDIO_DSUBTYPE_CSEndpoint_General, .Subtype = AUDIO_DSUBTYPE_CSEndpoint_General,
.Attributes = AUDIO_EP_ACCEPTS_SMALL_PACKETS, .Attributes = (AUDIO_EP_ACCEPTS_SMALL_PACKETS | AUDIO_EP_SAMPLE_FREQ_CONTROL),
.LockDelayUnits = 0x00, .LockDelayUnits = 0x00,
.LockDelay = 0x0000 .LockDelay = 0x0000

@ -186,12 +186,12 @@ void EVENT_USB_Device_ControlRequest(void)
case AUDIO_REQ_SetCurrent: case AUDIO_REQ_SetCurrent:
if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_ENDPOINT)) if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_ENDPOINT))
{ {
/* Extract out the relevant request information to get the target Endpoint index and control being set */ /* Extract out the relevant request information to get the target Endpoint address and control being set */
uint8_t EndpointIndex = (uint8_t)USB_ControlRequest.wIndex; uint8_t EndpointAddress = (uint8_t)USB_ControlRequest.wIndex;
uint8_t EndpointControl = (USB_ControlRequest.wValue >> 8); uint8_t EndpointControl = (USB_ControlRequest.wValue >> 8);
/* Only handle SET CURRENT requests to the audio endpoint's sample frequency property */ /* Only handle SET CURRENT requests to the audio endpoint's sample frequency property */
if ((EndpointIndex == AUDIO_STREAM_EPNUM) && (EndpointControl == AUDIO_EPCONTROL_SamplingFreq)) if ((EndpointAddress == (ENDPOINT_DESCRIPTOR_DIR_OUT | AUDIO_STREAM_EPNUM)) && (EndpointControl == AUDIO_EPCONTROL_SamplingFreq))
{ {
uint8_t SampleRate[3]; uint8_t SampleRate[3];
@ -211,12 +211,12 @@ void EVENT_USB_Device_ControlRequest(void)
case AUDIO_REQ_GetCurrent: case AUDIO_REQ_GetCurrent:
if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_ENDPOINT)) if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_ENDPOINT))
{ {
/* Extract out the relevant request information to get the target Endpoint index and control being retrieved */ /* Extract out the relevant request information to get the target Endpoint address and control being retrieved */
uint8_t EndpointIndex = (uint8_t)USB_ControlRequest.wIndex; uint8_t EndpointAddress = (uint8_t)USB_ControlRequest.wIndex;
uint8_t EndpointControl = (USB_ControlRequest.wValue >> 8); uint8_t EndpointControl = (USB_ControlRequest.wValue >> 8);
/* Only handle GET CURRENT requests to the audio endpoint's sample frequency property */ /* Only handle GET CURRENT requests to the audio endpoint's sample frequency property */
if ((EndpointIndex == AUDIO_STREAM_EPNUM) && (EndpointControl == AUDIO_EPCONTROL_SamplingFreq)) if ((EndpointAddress == (ENDPOINT_DESCRIPTOR_DIR_OUT | AUDIO_STREAM_EPNUM)) && (EndpointControl == AUDIO_EPCONTROL_SamplingFreq))
{ {
uint8_t SampleRate[3]; uint8_t SampleRate[3];

@ -235,7 +235,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
.Header = {.Size = sizeof(USB_Audio_Descriptor_StreamEndpoint_Spc_t), .Type = DTYPE_CSEndpoint}, .Header = {.Size = sizeof(USB_Audio_Descriptor_StreamEndpoint_Spc_t), .Type = DTYPE_CSEndpoint},
.Subtype = AUDIO_DSUBTYPE_CSEndpoint_General, .Subtype = AUDIO_DSUBTYPE_CSEndpoint_General,
.Attributes = AUDIO_EP_ACCEPTS_SMALL_PACKETS, .Attributes = (AUDIO_EP_ACCEPTS_SMALL_PACKETS | AUDIO_EP_SAMPLE_FREQ_CONTROL),
.LockDelayUnits = 0x00, .LockDelayUnits = 0x00,
.LockDelay = 0x0000 .LockDelay = 0x0000

@ -42,9 +42,6 @@ void Audio_Device_ProcessControlRequest(USB_ClassInfo_Audio_Device_t* const Audi
if (!(Endpoint_IsSETUPReceived())) if (!(Endpoint_IsSETUPReceived()))
return; return;
if (USB_ControlRequest.wIndex != AudioInterfaceInfo->Config.StreamingInterfaceNumber)
return;
if ((USB_ControlRequest.bmRequestType & CONTROL_REQTYPE_RECIPIENT) == REQREC_INTERFACE) if ((USB_ControlRequest.bmRequestType & CONTROL_REQTYPE_RECIPIENT) == REQREC_INTERFACE)
{ {
if (USB_ControlRequest.wIndex != AudioInterfaceInfo->Config.StreamingInterfaceNumber) if (USB_ControlRequest.wIndex != AudioInterfaceInfo->Config.StreamingInterfaceNumber)
@ -52,13 +49,16 @@ void Audio_Device_ProcessControlRequest(USB_ClassInfo_Audio_Device_t* const Audi
} }
else if ((USB_ControlRequest.bmRequestType & CONTROL_REQTYPE_RECIPIENT) == REQREC_ENDPOINT) else if ((USB_ControlRequest.bmRequestType & CONTROL_REQTYPE_RECIPIENT) == REQREC_ENDPOINT)
{ {
if (!((AudioInterfaceInfo->Config.DataINEndpointNumber && bool EndpointFilterMatch = false;
(USB_ControlRequest.wIndex == AudioInterfaceInfo->Config.DataINEndpointNumber)) ||
(AudioInterfaceInfo->Config.DataOUTEndpointNumber && EndpointFilterMatch |= (AudioInterfaceInfo->Config.DataINEndpointNumber &&
(USB_ControlRequest.wIndex == AudioInterfaceInfo->Config.DataOUTEndpointNumber)))) ((uint8_t)USB_ControlRequest.wIndex == (ENDPOINT_DESCRIPTOR_DIR_IN | AudioInterfaceInfo->Config.DataINEndpointNumber)));
{
return; EndpointFilterMatch |= (AudioInterfaceInfo->Config.DataOUTEndpointNumber &&
} ((uint8_t)USB_ControlRequest.wIndex == (ENDPOINT_DESCRIPTOR_DIR_OUT | AudioInterfaceInfo->Config.DataOUTEndpointNumber)));
if (!(EndpointFilterMatch))
return;
} }
switch (USB_ControlRequest.bRequest) switch (USB_ControlRequest.bRequest)
@ -89,10 +89,10 @@ void Audio_Device_ProcessControlRequest(USB_ClassInfo_Audio_Device_t* const Audi
if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_ENDPOINT)) if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_ENDPOINT))
{ {
uint8_t EndpointProperty = USB_ControlRequest.bRequest; uint8_t EndpointProperty = USB_ControlRequest.bRequest;
uint8_t EndpointIndex = (uint8_t)USB_ControlRequest.wIndex; uint8_t EndpointAddress = (uint8_t)USB_ControlRequest.wIndex;
uint8_t EndpointControl = (USB_ControlRequest.wValue >> 8); uint8_t EndpointControl = (USB_ControlRequest.wValue >> 8);
if (CALLBACK_Audio_GetSetEndpointProperty(AudioInterfaceInfo, EndpointProperty, EndpointIndex, EndpointControl, NULL, NULL)) if (CALLBACK_Audio_GetSetEndpointProperty(AudioInterfaceInfo, EndpointProperty, EndpointAddress, EndpointControl, NULL, NULL))
{ {
uint16_t ValueLength = USB_ControlRequest.wLength; uint16_t ValueLength = USB_ControlRequest.wLength;
uint8_t Value[ValueLength]; uint8_t Value[ValueLength];
@ -101,7 +101,7 @@ void Audio_Device_ProcessControlRequest(USB_ClassInfo_Audio_Device_t* const Audi
Endpoint_Read_Control_Stream_LE(Value, ValueLength); Endpoint_Read_Control_Stream_LE(Value, ValueLength);
Endpoint_ClearIN(); Endpoint_ClearIN();
CALLBACK_Audio_GetSetEndpointProperty(AudioInterfaceInfo, EndpointProperty, EndpointIndex, EndpointControl, &ValueLength, Value); CALLBACK_Audio_GetSetEndpointProperty(AudioInterfaceInfo, EndpointProperty, EndpointAddress, EndpointControl, &ValueLength, Value);
} }
} }
@ -113,12 +113,12 @@ void Audio_Device_ProcessControlRequest(USB_ClassInfo_Audio_Device_t* const Audi
if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_ENDPOINT)) if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_ENDPOINT))
{ {
uint8_t EndpointProperty = USB_ControlRequest.bRequest; uint8_t EndpointProperty = USB_ControlRequest.bRequest;
uint8_t EndpointIndex = (uint8_t)USB_ControlRequest.wIndex; uint8_t EndpointAddress = (uint8_t)USB_ControlRequest.wIndex;
uint8_t EndpointControl = (USB_ControlRequest.wValue >> 8); uint8_t EndpointControl = (USB_ControlRequest.wValue >> 8);
uint16_t ValueLength = USB_ControlRequest.wLength; uint16_t ValueLength = USB_ControlRequest.wLength;
uint8_t Value[ValueLength]; uint8_t Value[ValueLength];
if (CALLBACK_Audio_GetSetEndpointProperty(AudioInterfaceInfo, EndpointProperty, EndpointIndex, EndpointControl, &ValueLength, Value)) if (CALLBACK_Audio_GetSetEndpointProperty(AudioInterfaceInfo, EndpointProperty, EndpointAddress, EndpointControl, &ValueLength, Value))
{ {
Endpoint_ClearSETUP(); Endpoint_ClearSETUP();
Endpoint_Write_Control_Stream_LE(Value, ValueLength); Endpoint_Write_Control_Stream_LE(Value, ValueLength);

@ -143,7 +143,7 @@
* *
* \param[in,out] AudioInterfaceInfo Pointer to a structure containing an Audio Class configuration and state. * \param[in,out] AudioInterfaceInfo Pointer to a structure containing an Audio Class configuration and state.
* \param[in] EndpointProperty Property of the endpoint to get or set, a value from \ref Audio_ClassRequests_t. * \param[in] EndpointProperty Property of the endpoint to get or set, a value from \ref Audio_ClassRequests_t.
* \param[in] EndpointIndex Index of the streaming endpoint whose property is being referenced. * \param[in] EndpointAddress Address of the streaming endpoint whose property is being referenced.
* \param[in] EndpointControl Parameter of the endpoint to get or set, a value from \ref Audio_EndpointControls_t. * \param[in] EndpointControl Parameter of the endpoint to get or set, a value from \ref Audio_EndpointControls_t.
* \param[in,out] DataLength For SET operations, the length of the parameter data to set. For GET operations, the maximum * \param[in,out] DataLength For SET operations, the length of the parameter data to set. For GET operations, the maximum
* length of the retrieved data. When NULL, the function should return whether the given property * length of the retrieved data. When NULL, the function should return whether the given property
@ -155,7 +155,7 @@
*/ */
bool CALLBACK_Audio_GetSetEndpointProperty(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo, bool CALLBACK_Audio_GetSetEndpointProperty(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo,
const uint8_t EndpointProperty, const uint8_t EndpointProperty,
const uint8_t EndpointIndex, const uint8_t EndpointAddress,
const uint8_t EndpointControl, const uint8_t EndpointControl,
uint16_t* const DataLength, uint16_t* const DataLength,
uint8_t* Data); uint8_t* Data);

@ -33,7 +33,6 @@
* -# Add class driver support for Test and Measurement class * -# Add class driver support for Test and Measurement class
* -# Add class driver support for EEM class * -# Add class driver support for EEM class
* -# Add class driver support for ECM class * -# Add class driver support for ECM class
* -# Extend Low Level Audio demos to include sample rate switching
* - Ports * - Ports
* -# Complete AVR32 port for existing devices, add UC3C support * -# Complete AVR32 port for existing devices, add UC3C support
* -# Atmel ARM7 series microcontrollers * -# Atmel ARM7 series microcontrollers

Loading…
Cancel
Save