modified AudioEndpointRequests_1 to distinguish between ep0 request for USB in and out

This commit is contained in:
Keith Au
2020-01-13 10:15:10 +08:00
parent f6d0ede133
commit 1ef566a570
2 changed files with 24 additions and 17 deletions

View File

@@ -2656,7 +2656,7 @@ unsigned char cfgDesc_Audio1[] =
/* Standard AS Isochronous Audio Data Endpoint Descriptor 4.6.1.1 */
0x09,
0x05, /* ENDPOINT */
0x01, /* endpointAddress - D7, direction (0 OUT, 1 IN). D6..4 reserved (0). D3..0 endpoint no. */
ENDPOINT_ADDRESS_OUT_AUDIO, /* endpointAddress - D7, direction (0 OUT, 1 IN). D6..4 reserved (0). D3..0 endpoint no. */
#ifdef XUA_ADAPTIVE
ISO_EP_ATTRIBUTES_ADAPTIVE,
#else

View File

@@ -18,6 +18,7 @@
#include "mixer.h"
#endif
#include "xua_conf_default.h"
#include "descriptor_defs.h"
#define DEBUG_UNIT XUA_EP0_UACREQS
@@ -58,10 +59,13 @@ extern unsigned int g_curAudOut_SamFreq;
/* Global var for current frequency, set to default freq */
#ifdef USB_CMD_CFG_SAMP_FREQ
#define g_curSamFreq g_curAudOut_SamFreq
//unsigned int g_curSamFreq = DEFAULT_AUDOUT_FREQ;
#define g_curUSBin_SamFreq g_curAudOut_SamFreq
unsigned int g_curUSBout_SamFreq = DEFAULT_FREQ;
unsigned int g_curSamFreq = DEFAULT_FREQ; // should no longer be used
#else
unsigned int g_curSamFreq = DEFAULT_FREQ;
unsigned int g_curUSBin_SamFreq = DEFAULT_FREQ;
unsigned int g_curUSBout_SamFreq = DEFAULT_FREQ;
unsigned int g_curSamFreq = DEFAULT_FREQ; // should no longer be used
#endif
#if 0
unsigned int g_curSamFreq48000Family = DEFAULT_FREQ % 48000 == 0;
@@ -341,9 +345,6 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
int newMasterClock;
g_curSamFreq = newSampleRate;
#ifdef USB_CMD_CFG_SAMP_FREQ
g_curAudOut_SamFreq = newSampleRate;
#endif
#if 0
/* Original feedback implementation */
g_curSamFreq48000Family = ((MCLK_48 % g_curSamFreq) == 0);
@@ -1096,6 +1097,7 @@ int AudioEndpointRequests_1(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp
* bmRequestType.Recipient = Endpoint
* bmRequestType.Type = Class
* endpoint (wIndex & 0xff) is 0x01 or 0x82
* wIndex is endpoint address for distinguishing input and output
*/
XUD_Result_t result;
@@ -1126,7 +1128,8 @@ int AudioEndpointRequests_1(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp
/* Recontruct sample-freq */
int newSampleRate = (buffer, unsigned char[])[0] | ((buffer, unsigned char[])[1] << 8) | ((buffer, unsigned char[])[2] << 16);
if(newSampleRate != g_curSamFreq)
if(((sp.wIndex == ENDPOINT_ADDRESS_IN_AUDIO) && (newSampleRate != g_curUSBin_SamFreq)) || \
((sp.wIndex == ENDPOINT_ADDRESS_OUT_AUDIO) && (newSampleRate != g_curUSBout_SamFreq)))
{
int curSamFreq44100Family;
int curSamFreq48000Family;
@@ -1138,21 +1141,25 @@ int AudioEndpointRequests_1(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp
if(curSamFreq48000Family || curSamFreq44100Family)
{
g_curSamFreq = newSampleRate;
#ifdef USB_CMD_CFG_SAMP_FREQ
g_curAudOut_SamFreq = newSampleRate;
#endif
/* Instruct audio thread to change sample freq */
outuint(c_audioControl, SET_SAMPLE_FREQ);
outuint(c_audioControl, g_curSamFreq);
if(sp.wIndex == ENDPOINT_ADDRESS_IN_AUDIO){
g_curUSBin_SamFreq = newSampleRate;
/* Instruct audio thread to change sample freq */
outuint(c_audioControl, SET_SAMPLE_FREQ);
outuint(c_audioControl, g_curUSBin_SamFreq);
}
else{ //if sp.wIndex == ENDPOINT_ADDRESS_OUT_AUDIO
g_curUSBout_SamFreq = newSampleRate;
/* Instruct audio thread to change sample freq */
//outuint(c_audioControl, SET_SAMPLE_FREQ);
//outuint(c_audioControl, g_curUSBout_SamFreq); // FIXME: not implemented yet
}
/* Wait for handshake back - i.e. pll locked and clocks okay */
chkct(c_audioControl, XS1_CT_END);
/* Allow time for the change - feedback to stabilise */
FeedbackStabilityDelay();
}
}
}
return XUD_SetBuffer(ep0_in, (buffer, unsigned char[]), 0);
}