forked from PAWPAW-Mirror/lib_xua
added toplevel makefile for xpd
This commit is contained in:
@@ -24,7 +24,7 @@ extern unsigned int multIn[NUM_USB_CHAN_IN + 1];
|
||||
|
||||
extern int interfaceAlt[];
|
||||
|
||||
/* Global volume and mute tables */
|
||||
/* Global volume and mute tables */
|
||||
extern int volsOut[];
|
||||
extern unsigned int mutesOut[];
|
||||
|
||||
@@ -51,7 +51,7 @@ extern unsigned char mixSel[MIX_INPUTS];
|
||||
/* Global var for current frequency, set to default freq */
|
||||
unsigned int g_curSamFreq = DEFAULT_FREQ;
|
||||
unsigned int g_curSamFreq48000Family = DEFAULT_FREQ % 48000 == 0;
|
||||
unsigned int g_curSamFreqMultiplier = DEFAULT_FREQ / (DEFAULT_MCLK_FREQ / 512);
|
||||
unsigned int g_curSamFreqMultiplier = DEFAULT_FREQ / (DEFAULT_MCLK_FREQ / 512);
|
||||
|
||||
/* Store an int into a char array: Note this allows non-word aligned access unlike reinerpret cast */
|
||||
static void storeInt(unsigned char buffer[], int index, int val)
|
||||
@@ -83,14 +83,14 @@ static void storeFreq(unsigned char buffer[], int &i, int freq)
|
||||
/* Delay based on USB speed. Feedback takes longer to stabilise at FS */
|
||||
void FeedbackStabilityDelay()
|
||||
{
|
||||
|
||||
unsigned usbSpeed;
|
||||
|
||||
unsigned usbSpeed;
|
||||
timer t;
|
||||
unsigned time;
|
||||
unsigned delay;
|
||||
|
||||
|
||||
asm("ldw %0, dp[g_curUsbSpeed]" : "=r" (usbSpeed) :);
|
||||
|
||||
|
||||
if (usbSpeed == XUD_SPEED_HS)
|
||||
{
|
||||
delay = FEEDBACK_STABILITY_DELAY_HS;
|
||||
@@ -138,7 +138,7 @@ static void updateMasterVol( int unitID, chanend ?c_mix_ctl)
|
||||
case FU_USBOUT:
|
||||
{
|
||||
unsigned master_vol = volsOut[0] == 0x8000 ? 0 : db_to_mult(volsOut[0], 8, 29);
|
||||
|
||||
|
||||
for (int i = 1; i < (NUM_USB_CHAN_OUT + 1); i++)
|
||||
{
|
||||
/* Calc multipliers with 29 fractional bits from a db value with 8 fractional bits */
|
||||
@@ -148,9 +148,9 @@ static void updateMasterVol( int unitID, chanend ?c_mix_ctl)
|
||||
x = longMul(master_vol, vol, 29) * !mutesOut[0] * !mutesOut[i];
|
||||
|
||||
#ifdef OUT_VOLUME_IN_MIXER
|
||||
if (!isnull(c_mix_ctl))
|
||||
if (!isnull(c_mix_ctl))
|
||||
{
|
||||
outuint(c_mix_ctl, SET_MIX_OUT_VOL);
|
||||
outuint(c_mix_ctl, SET_MIX_OUT_VOL);
|
||||
outuint(c_mix_ctl, i-1);
|
||||
outuint(c_mix_ctl, x);
|
||||
outct(c_mix_ctl, XS1_CT_END);
|
||||
@@ -165,7 +165,7 @@ static void updateMasterVol( int unitID, chanend ?c_mix_ctl)
|
||||
case FU_USBIN:
|
||||
{
|
||||
unsigned master_vol = volsIn[0] == 0x8000 ? 0 : db_to_mult(volsIn[0], 8, 29);
|
||||
for (int i = 1; i < (NUM_USB_CHAN_IN + 1); i++)
|
||||
for (int i = 1; i < (NUM_USB_CHAN_IN + 1); i++)
|
||||
{
|
||||
/* Calc multipliers with 29 fractional bits from a db value with 8 fractional bits */
|
||||
/* 0x8000 is a special value representing -inf (i.e. mute) */
|
||||
@@ -176,7 +176,7 @@ static void updateMasterVol( int unitID, chanend ?c_mix_ctl)
|
||||
#ifdef IN_VOLUME_IN_MIXER
|
||||
if (!isnull(c_mix_ctl))
|
||||
{
|
||||
outuint(c_mix_ctl, SET_MIX_IN_VOL);
|
||||
outuint(c_mix_ctl, SET_MIX_IN_VOL);
|
||||
outuint(c_mix_ctl, i-1);
|
||||
outuint(c_mix_ctl, x);
|
||||
outct(c_mix_ctl, XS1_CT_END);
|
||||
@@ -191,10 +191,10 @@ static void updateMasterVol( int unitID, chanend ?c_mix_ctl)
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void updateVol(int unitID, int channel, chanend ?c_mix_ctl)
|
||||
{
|
||||
{
|
||||
int x;
|
||||
#ifndef OUT_VOLUME_IN_MIXER
|
||||
xc_ptr p_multOut = array_to_xc_ptr(multOut);
|
||||
@@ -211,7 +211,7 @@ static void updateVol(int unitID, int channel, chanend ?c_mix_ctl)
|
||||
{
|
||||
switch( unitID )
|
||||
{
|
||||
case FU_USBOUT:
|
||||
case FU_USBOUT:
|
||||
{
|
||||
/* Calc multipliers with 29 fractional bits from a db value with 8 fractional bits */
|
||||
/* 0x8000 is a special value representing -inf (i.e. mute) */
|
||||
@@ -223,7 +223,7 @@ static void updateVol(int unitID, int channel, chanend ?c_mix_ctl)
|
||||
#ifdef OUT_VOLUME_IN_MIXER
|
||||
if (!isnull(c_mix_ctl))
|
||||
{
|
||||
outuint(c_mix_ctl, SET_MIX_OUT_VOL);
|
||||
outuint(c_mix_ctl, SET_MIX_OUT_VOL);
|
||||
outuint(c_mix_ctl, channel-1);
|
||||
outuint(c_mix_ctl, x);
|
||||
outct(c_mix_ctl, XS1_CT_END);
|
||||
@@ -233,7 +233,7 @@ static void updateVol(int unitID, int channel, chanend ?c_mix_ctl)
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case FU_USBIN:
|
||||
case FU_USBIN:
|
||||
{
|
||||
/* Calc multipliers with 29 fractional bits from a db value with 8 fractional bits */
|
||||
/* 0x8000 is a special value representing -inf (i.e. mute) */
|
||||
@@ -243,26 +243,26 @@ static void updateVol(int unitID, int channel, chanend ?c_mix_ctl)
|
||||
x = longMul(master_vol, vol, 29) * !mutesIn[0] * !mutesIn[channel];
|
||||
|
||||
#ifdef IN_VOLUME_IN_MIXER
|
||||
if (!isnull(c_mix_ctl))
|
||||
if (!isnull(c_mix_ctl))
|
||||
{
|
||||
outuint(c_mix_ctl, SET_MIX_IN_VOL);
|
||||
outuint(c_mix_ctl, SET_MIX_IN_VOL);
|
||||
outuint(c_mix_ctl, channel-1);
|
||||
outuint(c_mix_ctl, x);
|
||||
outct(c_mix_ctl, XS1_CT_END);
|
||||
}
|
||||
#else
|
||||
asm("stw %0, %1[%2]"::"r"(x),"r"(p_multIn),"r"(channel-1));
|
||||
#endif
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Handles the audio class specific requests
|
||||
* returns: 0 if request dealt with successfully without error,
|
||||
/* Handles the audio class specific requests
|
||||
* returns: 0 if request dealt with successfully without error,
|
||||
* <0 for device reset
|
||||
* else 1
|
||||
* else 1
|
||||
*/
|
||||
int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, chanend c_audioControl, chanend ?c_mix_ctl, chanend ?c_clk_ctl
|
||||
)
|
||||
@@ -276,9 +276,9 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
|
||||
/* Inspect request, NOTE: these are class specific requests */
|
||||
switch( sp.bRequest )
|
||||
{
|
||||
|
||||
|
||||
/* CUR Request*/
|
||||
case CUR:
|
||||
case CUR:
|
||||
{
|
||||
/* Extract unitID from wIndex */
|
||||
unitID = sp.wIndex >> 8;
|
||||
@@ -286,32 +286,32 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
|
||||
switch( unitID )
|
||||
{
|
||||
/* Clock Unit(s) */
|
||||
case ID_CLKSRC_INT:
|
||||
case ID_CLKSRC_EXT:
|
||||
case ID_CLKSRC_INT:
|
||||
case ID_CLKSRC_EXT:
|
||||
case ID_CLKSRC_ADAT:
|
||||
{
|
||||
/* Check Control selector (CS) */
|
||||
switch( sp.wValue >> 8 )
|
||||
{
|
||||
/* Sample Frequency control */
|
||||
case CS_SAM_FREQ_CONTROL:
|
||||
case CS_SAM_FREQ_CONTROL:
|
||||
{
|
||||
/* Direction: Host-to-device */
|
||||
if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_H2D)
|
||||
if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_H2D)
|
||||
{
|
||||
/* Get OUT data with Sample Rate into buffer*/
|
||||
datalength = XUD_GetBuffer(ep0_out, buffer);
|
||||
|
||||
|
||||
/* Check for reset/suspend */
|
||||
if(datalength < 0)
|
||||
{
|
||||
return datalength;
|
||||
}
|
||||
|
||||
|
||||
if(datalength == 4)
|
||||
{
|
||||
/* Re-construct Sample Freq */
|
||||
i_tmp = buffer[0] | (buffer[1] << 8) | buffer[2] << 16 | buffer[3] << 24;
|
||||
i_tmp = buffer[0] | (buffer[1] << 8) | buffer[2] << 16 | buffer[3] << 24;
|
||||
|
||||
/* Instruct audio thread to change sample freq (if change required) */
|
||||
if(i_tmp != g_curSamFreq)
|
||||
@@ -331,30 +331,30 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
|
||||
setG_curSamFreqMultiplier(g_curSamFreq/(i_tmp/512));
|
||||
|
||||
outuint(c_audioControl, SET_SAMPLE_FREQ);
|
||||
outuint(c_audioControl, g_curSamFreq);
|
||||
outuint(c_audioControl, g_curSamFreq);
|
||||
|
||||
/* Wait for handshake back - i.e. PLL locked and clocks okay */
|
||||
chkct(c_audioControl, XS1_CT_END);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/* Allow time for our feedback to stabilise*/
|
||||
FeedbackStabilityDelay();
|
||||
}
|
||||
|
||||
|
||||
/* Send 0 Length as status stage */
|
||||
XUD_DoSetRequestStatus(ep0_in);
|
||||
XUD_DoSetRequestStatus(ep0_in);
|
||||
}
|
||||
/* Direction: Device-to-host: Send Current Sample Freq */
|
||||
else
|
||||
{
|
||||
switch(unitID)
|
||||
switch(unitID)
|
||||
{
|
||||
case ID_CLKSRC_EXT:
|
||||
case ID_CLKSRC_ADAT:
|
||||
#ifdef REPORT_SPDIF_FREQ
|
||||
/* Interogate clockgen thread for SPDIF freq */
|
||||
if (!isnull(c_clk_ctl))
|
||||
if (!isnull(c_clk_ctl))
|
||||
{
|
||||
outuint(c_clk_ctl, GET_FREQ);
|
||||
outuint(c_clk_ctl, CLOCK_SPDIF_INDEX);
|
||||
@@ -368,40 +368,40 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
|
||||
(buffer, unsigned[])[0] = g_curSamFreq;
|
||||
return XUD_DoGetRequest(ep0_out, ep0_in, buffer, 4, sp.wLength );
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
break;
|
||||
#endif
|
||||
case ID_CLKSRC_INT:
|
||||
/* Always report our current operating frequency */
|
||||
(buffer, unsigned[])[0] = g_curSamFreq;
|
||||
return XUD_DoGetRequest(ep0_out, ep0_in, buffer, 4, sp.wLength );
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
/* Unknown Unit ID in Sample Frequency Control Request: unitID */
|
||||
/* Unknown Unit ID in Sample Frequency Control Request: unitID */
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
/* Clock Valid Control */
|
||||
case CS_CLOCK_VALID_CONTROL:
|
||||
case CS_CLOCK_VALID_CONTROL:
|
||||
{
|
||||
switch(unitID)
|
||||
switch(unitID)
|
||||
{
|
||||
case ID_CLKSRC_INT:
|
||||
|
||||
|
||||
/* Internal clock always valid */
|
||||
buffer[0] = 1;
|
||||
return XUD_DoGetRequest(ep0_out, ep0_in, buffer, 1, sp.wLength);
|
||||
break;
|
||||
|
||||
|
||||
case ID_CLKSRC_EXT:
|
||||
|
||||
/* Interogate clockgen thread for validity */
|
||||
if (!isnull(c_clk_ctl))
|
||||
if (!isnull(c_clk_ctl))
|
||||
{
|
||||
outuint(c_clk_ctl, GET_VALID);
|
||||
outuint(c_clk_ctl, CLOCK_SPDIF_INDEX);
|
||||
@@ -415,7 +415,7 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
|
||||
|
||||
case ID_CLKSRC_ADAT:
|
||||
|
||||
if (!isnull(c_clk_ctl))
|
||||
if (!isnull(c_clk_ctl))
|
||||
{
|
||||
outuint(c_clk_ctl, GET_VALID);
|
||||
outuint(c_clk_ctl, CLOCK_ADAT_INDEX);
|
||||
@@ -425,7 +425,7 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
|
||||
return XUD_DoGetRequest(ep0_out, ep0_in, buffer, 1, sp.wLength);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
//Unknown Unit ID in Clock Valid Control Request
|
||||
break;
|
||||
@@ -436,28 +436,28 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
|
||||
default:
|
||||
//Unknown Control Selector for Clock Unit: sp.wValue >> 8
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
break; /* Clock Unit IDs */
|
||||
}
|
||||
|
||||
/* Clock Selector Unit(s) */
|
||||
case ID_CLKSEL:
|
||||
case ID_CLKSEL:
|
||||
{
|
||||
if ((sp.wValue >> 8) == CX_CLOCK_SELECTOR_CONTROL)
|
||||
if ((sp.wValue >> 8) == CX_CLOCK_SELECTOR_CONTROL)
|
||||
{
|
||||
/* Direction: Host-to-device */
|
||||
if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_H2D )
|
||||
{
|
||||
if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_H2D )
|
||||
{
|
||||
datalength = XUD_GetBuffer(ep0_out, buffer);
|
||||
|
||||
|
||||
if(datalength < 0)
|
||||
return datalength;
|
||||
|
||||
/* Check for correct datalength for clock sel */
|
||||
if(datalength == 1)
|
||||
if(datalength == 1)
|
||||
{
|
||||
if (!isnull(c_clk_ctl))
|
||||
if (!isnull(c_clk_ctl))
|
||||
{
|
||||
outuint(c_clk_ctl, SET_SEL);
|
||||
outuint(c_clk_ctl, buffer[0]);
|
||||
@@ -466,48 +466,48 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
|
||||
/* Send 0 Length as status stage */
|
||||
return XUD_DoSetRequestStatus(ep0_in);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Direction: Device-to-host: Send Current Selection */
|
||||
buffer[0] = 1;
|
||||
if (!isnull(c_clk_ctl))
|
||||
buffer[0] = 1;
|
||||
if (!isnull(c_clk_ctl))
|
||||
{
|
||||
outuint(c_clk_ctl, GET_SEL);
|
||||
outct(c_clk_ctl, XS1_CT_END);
|
||||
buffer[0] = inuint(c_clk_ctl);
|
||||
buffer[0] = inuint(c_clk_ctl);
|
||||
chkct(c_clk_ctl, XS1_CT_END);
|
||||
}
|
||||
return XUD_DoGetRequest( ep0_out, ep0_in, buffer, 1, sp.wLength );
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
/* Feature Units */
|
||||
case FU_USBOUT:
|
||||
case FU_USBIN:
|
||||
|
||||
/* Feature Units */
|
||||
case FU_USBOUT:
|
||||
case FU_USBIN:
|
||||
|
||||
/* Inspect Control Selector (CS) */
|
||||
switch(sp.wValue >> 8)
|
||||
{
|
||||
case FU_VOLUME_CONTROL:
|
||||
|
||||
if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_H2D)
|
||||
case FU_VOLUME_CONTROL:
|
||||
|
||||
if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_H2D)
|
||||
{
|
||||
/* Expect OUT here (with volume) */
|
||||
loop = XUD_GetBuffer(ep0_out, buffer);
|
||||
|
||||
/* Check for reset */
|
||||
|
||||
/* Check for reset */
|
||||
if(loop < 0)
|
||||
return loop;
|
||||
|
||||
if(unitID == FU_USBOUT)
|
||||
{
|
||||
if ((sp.wValue & 0xff) <= NUM_USB_CHAN_OUT)
|
||||
{
|
||||
{
|
||||
if ((sp.wValue & 0xff) <= NUM_USB_CHAN_OUT)
|
||||
{
|
||||
volsOut[ sp.wValue&0xff ] = buffer[0] | (((int) (signed char) buffer[1]) << 8);
|
||||
updateVol( unitID, ( sp.wValue & 0xff ), c_mix_ctl );
|
||||
return XUD_DoSetRequestStatus(ep0_in);
|
||||
@@ -515,8 +515,8 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((sp.wValue & 0xff) <= NUM_USB_CHAN_IN)
|
||||
{
|
||||
if ((sp.wValue & 0xff) <= NUM_USB_CHAN_IN)
|
||||
{
|
||||
volsIn[ sp.wValue&0xff ] = buffer[0] | (((int) (signed char) buffer[1]) << 8);
|
||||
updateVol( unitID, ( sp.wValue & 0xff ), c_mix_ctl );
|
||||
return XUD_DoSetRequestStatus(ep0_in);
|
||||
@@ -527,28 +527,28 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
|
||||
{
|
||||
if(unitID == FU_USBOUT)
|
||||
{
|
||||
if ((sp.wValue & 0xff) <= NUM_USB_CHAN_OUT)
|
||||
{
|
||||
if ((sp.wValue & 0xff) <= NUM_USB_CHAN_OUT)
|
||||
{
|
||||
buffer[0] = volsOut[ sp.wValue&0xff ];
|
||||
buffer[1] = volsOut[ sp.wValue&0xff ] >> 8;
|
||||
return XUD_DoGetRequest(ep0_out, ep0_in, buffer, 2, sp.wLength);
|
||||
return XUD_DoGetRequest(ep0_out, ep0_in, buffer, 2, sp.wLength);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((sp.wValue & 0xff) <= NUM_USB_CHAN_IN)
|
||||
{
|
||||
if ((sp.wValue & 0xff) <= NUM_USB_CHAN_IN)
|
||||
{
|
||||
buffer[0] = volsIn[ sp.wValue&0xff ];
|
||||
buffer[1] = volsIn[ sp.wValue&0xff ] >> 8;
|
||||
return XUD_DoGetRequest(ep0_out, ep0_in, buffer, 2, sp.wLength);
|
||||
return XUD_DoGetRequest(ep0_out, ep0_in, buffer, 2, sp.wLength);
|
||||
}
|
||||
}
|
||||
}
|
||||
break; /* FU_VOLUME_CONTROL */
|
||||
|
||||
case FU_MUTE_CONTROL:
|
||||
|
||||
if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_H2D)
|
||||
|
||||
case FU_MUTE_CONTROL:
|
||||
|
||||
if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_H2D)
|
||||
{
|
||||
/* Expect OUT here with mute */
|
||||
loop = XUD_GetBuffer(ep0_out, buffer);
|
||||
@@ -558,8 +558,8 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
|
||||
|
||||
if (unitID == FU_USBOUT)
|
||||
{
|
||||
if ((sp.wValue & 0xff) <= NUM_USB_CHAN_OUT)
|
||||
{
|
||||
if ((sp.wValue & 0xff) <= NUM_USB_CHAN_OUT)
|
||||
{
|
||||
mutesOut[sp.wValue & 0xff] = buffer[0];
|
||||
updateVol( unitID, ( sp.wValue & 0xff ), c_mix_ctl);
|
||||
return XUD_DoSetRequestStatus(ep0_in);
|
||||
@@ -579,10 +579,10 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
|
||||
{
|
||||
if(unitID == FU_USBOUT)
|
||||
{
|
||||
if ((sp.wValue & 0xff) <= NUM_USB_CHAN_OUT)
|
||||
{
|
||||
if ((sp.wValue & 0xff) <= NUM_USB_CHAN_OUT)
|
||||
{
|
||||
buffer[0] = mutesOut[sp.wValue&0xff];
|
||||
return XUD_DoGetRequest(ep0_out, ep0_in, buffer, sp.wLength, sp.wLength);
|
||||
return XUD_DoGetRequest(ep0_out, ep0_in, buffer, sp.wLength, sp.wLength);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -590,19 +590,19 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
|
||||
if((sp.wValue & 0xff) <= NUM_USB_CHAN_IN)
|
||||
{
|
||||
buffer[0] = mutesIn[ sp.wValue&0xff ];
|
||||
return XUD_DoGetRequest(ep0_out, ep0_in, buffer, sp.wLength, sp.wLength);
|
||||
return XUD_DoGetRequest(ep0_out, ep0_in, buffer, sp.wLength, sp.wLength);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
// Unknown Control Selector for FU
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
break; /* FU_USBIN */
|
||||
|
||||
|
||||
#if defined(MIXER) && (MAX_MIX_COUNT > 0)
|
||||
case ID_XU_OUT:
|
||||
{
|
||||
@@ -618,9 +618,9 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
|
||||
|
||||
channelMapAud[c] = buffer[0] | buffer[1] << 8;
|
||||
|
||||
if (!isnull(c_mix_ctl))
|
||||
if (!isnull(c_mix_ctl))
|
||||
{
|
||||
if (c < NUM_USB_CHAN_OUT)
|
||||
if (c < NUM_USB_CHAN_OUT)
|
||||
{
|
||||
outuint(c_mix_ctl, SET_SAMPLES_TO_DEVICE_MAP);
|
||||
outuint(c_mix_ctl, c);
|
||||
@@ -656,9 +656,9 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
|
||||
|
||||
channelMapUsb[c] = buffer[0] | buffer[1] << 8;
|
||||
|
||||
if (c < NUM_USB_CHAN_IN)
|
||||
if (c < NUM_USB_CHAN_IN)
|
||||
{
|
||||
if (!isnull(c_mix_ctl))
|
||||
if (!isnull(c_mix_ctl))
|
||||
{
|
||||
outuint(c_mix_ctl, SET_SAMPLES_TO_HOST_MAP);
|
||||
outuint(c_mix_ctl, c);
|
||||
@@ -683,18 +683,18 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
|
||||
int cn = sp.wValue & 0xff; /* Channel number */
|
||||
|
||||
/* Check for Get or Set */
|
||||
if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_OUT)
|
||||
if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_OUT)
|
||||
{
|
||||
/* Direction: Host-to-device */ /* Host-to-device */
|
||||
/* Direction: Host-to-device */ /* Host-to-device */
|
||||
datalength = XUD_GetBuffer(ep0_out, buffer);
|
||||
|
||||
|
||||
/* Check for reset */
|
||||
if(datalength < 0)
|
||||
return datalength;
|
||||
|
||||
|
||||
if(datalength > 0)
|
||||
{
|
||||
/* cn bounds check for safety..*/
|
||||
{
|
||||
/* cn bounds check for safety..*/
|
||||
if(cn < MIX_INPUTS)
|
||||
{
|
||||
if(cs == CS_XU_MIXSEL)
|
||||
@@ -713,7 +713,7 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
|
||||
outuint(c_mix_ctl, cn); /* Mixer input */
|
||||
outuint(c_mix_ctl, (int) mixSel[cn]); /* Source */
|
||||
outct(c_mix_ctl, XS1_CT_END);
|
||||
}
|
||||
}
|
||||
return XUD_DoSetRequestStatus(ep0_in);
|
||||
}
|
||||
}
|
||||
@@ -722,8 +722,8 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
|
||||
else
|
||||
{
|
||||
/* Direction: Device-to-Host (GET) */
|
||||
buffer[0] = 0;
|
||||
|
||||
buffer[0] = 0;
|
||||
|
||||
/* Channel Number bounds check for safety */
|
||||
if(cn < MIX_INPUTS)
|
||||
{
|
||||
@@ -737,35 +737,35 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case ID_MIXER_1:
|
||||
|
||||
|
||||
if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_OUT) /* Direction: Host-to-device */
|
||||
{
|
||||
unsigned volume = 0;
|
||||
|
||||
|
||||
/* Expect OUT here with mute */
|
||||
loop = XUD_GetBuffer(ep0_out, buffer);
|
||||
if(loop < 0)
|
||||
return loop;
|
||||
|
||||
|
||||
mixer1Weights[sp.wValue & 0xff] = buffer[0] | buffer[1] << 8;
|
||||
|
||||
if (mixer1Weights[sp.wValue & 0xff] == 0x8000)
|
||||
|
||||
if (mixer1Weights[sp.wValue & 0xff] == 0x8000)
|
||||
{
|
||||
volume = 0;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
volume = db_to_mult(mixer1Weights[sp.wValue & 0xff], 8, 25);
|
||||
volume = db_to_mult(mixer1Weights[sp.wValue & 0xff], 8, 25);
|
||||
}
|
||||
if (!isnull(c_mix_ctl))
|
||||
if (!isnull(c_mix_ctl))
|
||||
{
|
||||
outuint(c_mix_ctl, SET_MIX_MULT);
|
||||
outuint(c_mix_ctl, (sp.wValue & 0xff) % 8);
|
||||
outuint(c_mix_ctl, (sp.wValue & 0xff) / 8);
|
||||
outuint(c_mix_ctl, volume);
|
||||
outct(c_mix_ctl, XS1_CT_END);
|
||||
outct(c_mix_ctl, XS1_CT_END);
|
||||
}
|
||||
|
||||
/* Send 0 Length as status stage */
|
||||
@@ -777,35 +777,35 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
|
||||
buffer[0] = weight & 0xff;
|
||||
buffer[1] = (weight >> 8) & 0xff;
|
||||
|
||||
return XUD_DoGetRequest(ep0_out, ep0_in, buffer, sp.wLength, sp.wLength);
|
||||
return XUD_DoGetRequest(ep0_out, ep0_in, buffer, sp.wLength, sp.wLength);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
#endif
|
||||
default:
|
||||
/* We dont have a unit with this ID! */
|
||||
break;
|
||||
|
||||
} /* switch(sp.wIndex >> 8) i.e Unit ID */
|
||||
|
||||
} /* switch(sp.wIndex >> 8) i.e Unit ID */
|
||||
break;
|
||||
}
|
||||
|
||||
case RANGE:
|
||||
|
||||
case RANGE:
|
||||
{
|
||||
unitID = sp.wIndex >> 8;
|
||||
|
||||
|
||||
switch( unitID )
|
||||
{
|
||||
/* Clock Source Units */
|
||||
case ID_CLKSRC_EXT:
|
||||
case ID_CLKSRC_ADAT:
|
||||
case ID_CLKSRC_INT:
|
||||
case ID_CLKSRC_INT:
|
||||
|
||||
/* Control Selector (CS) */
|
||||
switch( sp.wValue >> 8 )
|
||||
{
|
||||
case CS_SAM_FREQ_CONTROL:
|
||||
|
||||
case CS_SAM_FREQ_CONTROL:
|
||||
|
||||
/* Currently always return all freqs for all clocks */
|
||||
{
|
||||
int num_freqs = 0;
|
||||
@@ -816,15 +816,15 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
|
||||
unsigned maxFreq = MAX_FREQ;
|
||||
|
||||
#if defined (FULL_SPEED_AUDIO_2)
|
||||
unsigned usbSpeed;
|
||||
unsigned usbSpeed;
|
||||
asm("ldw %0, dp[g_curUsbSpeed]" : "=r" (usbSpeed) :);
|
||||
|
||||
if (usbSpeed == XUD_SPEED_FS)
|
||||
{
|
||||
maxFreq = MAX_FREQ_A1;
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
while(1)
|
||||
{
|
||||
if((currentFreq44 <= maxFreq) && (currentFreq44 >= MIN_FREQ))
|
||||
@@ -847,35 +847,35 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
|
||||
}
|
||||
}
|
||||
storeShort(buffer, 0, num_freqs);
|
||||
|
||||
return XUD_DoGetRequest(ep0_out, ep0_in, buffer, i, sp.wLength);
|
||||
|
||||
return XUD_DoGetRequest(ep0_out, ep0_in, buffer, i, sp.wLength);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
//Unknown Control Selector in Clock Source Range Request
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
|
||||
/* Feature Units */
|
||||
case FU_USBIN: /* USB Data into Device */
|
||||
case FU_USBIN: /* USB Data into Device */
|
||||
case FU_USBOUT: /* USB Data from Device */
|
||||
|
||||
/* Control Selector (CS) */
|
||||
switch( sp.wValue >> 8 )
|
||||
{
|
||||
/* Volume control, send back same range for all channels (i.e. ignore CN) */
|
||||
case FU_VOLUME_CONTROL:
|
||||
|
||||
case FU_VOLUME_CONTROL:
|
||||
|
||||
storeShort(buffer, 0, 1);
|
||||
storeShort(buffer, 2, MIN_VOLUME);
|
||||
storeShort(buffer, 4, MAX_VOLUME);
|
||||
storeShort(buffer, 6, VOLUME_RES);
|
||||
return XUD_DoGetRequest(ep0_out, ep0_in, buffer, sp.wLength, sp.wLength);
|
||||
storeShort(buffer, 2, MIN_VOLUME);
|
||||
storeShort(buffer, 4, MAX_VOLUME);
|
||||
storeShort(buffer, 6, VOLUME_RES);
|
||||
return XUD_DoGetRequest(ep0_out, ep0_in, buffer, sp.wLength, sp.wLength);
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
/* Unknown control selector for FU */
|
||||
break;
|
||||
@@ -887,92 +887,92 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
|
||||
/* Mixer Unit */
|
||||
case ID_MIXER_1:
|
||||
storeShort(buffer, 0, 1);
|
||||
storeShort(buffer, 2, MIN_MIXER_VOLUME);
|
||||
storeShort(buffer, 4, MAX_MIXER_VOLUME);
|
||||
storeShort(buffer, 6, VOLUME_RES_MIXER);
|
||||
return XUD_DoGetRequest(ep0_out, ep0_in, buffer, sp.wLength, sp.wLength);
|
||||
storeShort(buffer, 2, MIN_MIXER_VOLUME);
|
||||
storeShort(buffer, 4, MAX_MIXER_VOLUME);
|
||||
storeShort(buffer, 6, VOLUME_RES_MIXER);
|
||||
return XUD_DoGetRequest(ep0_out, ep0_in, buffer, sp.wLength, sp.wLength);
|
||||
break;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
default:
|
||||
/* Unknown Unit ID in Range Request selector for FU */
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
break; /* case: RANGE */
|
||||
}
|
||||
|
||||
#if defined (MIXER) && (MAX_MIX_COUNT > 0)
|
||||
#if defined (MIXER) && (MAX_MIX_COUNT > 0)
|
||||
case MEM: /* Memory Requests (5.2.7.1) */
|
||||
|
||||
unitID = sp.wIndex >> 8;
|
||||
|
||||
|
||||
switch( unitID )
|
||||
{
|
||||
case ID_MIXER_1:
|
||||
|
||||
if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_IN)
|
||||
|
||||
if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_IN)
|
||||
{
|
||||
int length = 0;
|
||||
|
||||
/* Device-to-Host (GET) */
|
||||
|
||||
/* Device-to-Host (GET) */
|
||||
switch(sp.wValue) /* offset */
|
||||
{
|
||||
case 0: /* Input levels */
|
||||
length = (NUM_USB_CHAN_IN + NUM_USB_CHAN_OUT) * 2; /* 2 bytes per chan */
|
||||
|
||||
|
||||
for(int i = 0; i < (NUM_USB_CHAN_IN + NUM_USB_CHAN_OUT); i++)
|
||||
{
|
||||
/* Get the level and truncate to 16-bit */
|
||||
if(i < NUM_USB_CHAN_IN)
|
||||
if(i < NUM_USB_CHAN_IN)
|
||||
{
|
||||
if (!isnull(c_mix_ctl))
|
||||
if (!isnull(c_mix_ctl))
|
||||
{
|
||||
outuint(c_mix_ctl, GET_INPUT_LEVELS);
|
||||
outuint(c_mix_ctl, (i - NUM_USB_CHAN_IN));
|
||||
outct(c_mix_ctl, XS1_CT_END);
|
||||
storeShort(buffer, i*2, (inuint(c_mix_ctl)>>15));
|
||||
chkct(c_mix_ctl, XS1_CT_END);
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
storeShort(buffer, i*2, 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!isnull(c_mix_ctl))
|
||||
if (!isnull(c_mix_ctl))
|
||||
{
|
||||
outuint(c_mix_ctl, GET_STREAM_LEVELS);
|
||||
outuint(c_mix_ctl, (i - NUM_USB_CHAN_IN));
|
||||
outct(c_mix_ctl, XS1_CT_END);
|
||||
storeShort(buffer, i*2, (inuint(c_mix_ctl) >> 15));
|
||||
chkct(c_mix_ctl, XS1_CT_END);
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
storeShort(buffer, i*2, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
|
||||
|
||||
case 1: /* Mixer Output levels */
|
||||
length = MAX_MIX_COUNT * 2; /* 2 bytes per chan */
|
||||
length = MAX_MIX_COUNT * 2; /* 2 bytes per chan */
|
||||
|
||||
for(int i = 0; i < MAX_MIX_COUNT; i++)
|
||||
{
|
||||
if (!isnull(c_mix_ctl))
|
||||
if (!isnull(c_mix_ctl))
|
||||
{
|
||||
outuint(c_mix_ctl, GET_OUTPUT_LEVELS);
|
||||
outuint(c_mix_ctl, i);
|
||||
outct(c_mix_ctl, XS1_CT_END);
|
||||
storeShort(buffer, i*2, (inuint(c_mix_ctl) >> 15));
|
||||
chkct(c_mix_ctl, XS1_CT_END);
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
storeShort(buffer, i*2, 0);
|
||||
}
|
||||
@@ -998,14 +998,14 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
|
||||
int AudioEndpointRequests_1(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, chanend c_audioControl, chanend ?c_mix_ctl, chanend ?c_clk_ctl)
|
||||
{
|
||||
/* At this point we know:
|
||||
* bmRequestType.Recipient = Endpoint
|
||||
* bmRequestType.Recipient = Endpoint
|
||||
* bmRequestType.Type = Class
|
||||
* endpoint (wIndex & 0xff) is 0x01 or 0x82
|
||||
*/
|
||||
|
||||
|
||||
int retVal = 1;
|
||||
unsigned char buffer[1024];
|
||||
|
||||
unsigned char buffer[1024];
|
||||
|
||||
/* Host to Device */
|
||||
if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_H2D)
|
||||
{
|
||||
@@ -1016,27 +1016,27 @@ int AudioEndpointRequests_1(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp
|
||||
{
|
||||
/* Check Control Selector */
|
||||
unsigned short controlSelector = sp.wValue>>8;
|
||||
|
||||
|
||||
retVal = XUD_GetBuffer(ep0_out, buffer);
|
||||
|
||||
/* Inspect for reset */
|
||||
if(retVal < 0)
|
||||
return retVal;
|
||||
|
||||
|
||||
if(controlSelector == SAMPLING_FREQ_CONTROL)
|
||||
{
|
||||
/* Expect length 3 for sample rate */
|
||||
if((sp.wLength == 3)&&(retVal == 3))
|
||||
{
|
||||
|
||||
|
||||
/* Recontruct sample-freq */
|
||||
int i_tmp = buffer[0] | (buffer [1] << 8) | (buffer[2] << 16);
|
||||
|
||||
if(i_tmp != g_curSamFreq)
|
||||
{
|
||||
int curSamFreq44100Family;
|
||||
|
||||
/* Windows Audio Class driver has a nice habbit of sending invalid SF's (e.g. 48001Hz)
|
||||
|
||||
/* Windows Audio Class driver has a nice habbit of sending invalid SF's (e.g. 48001Hz)
|
||||
* when under stress. Lets double check it here and ignore if not valid. */
|
||||
g_curSamFreq48000Family = i_tmp % 48000 == 0;
|
||||
curSamFreq44100Family = i_tmp % 44100 == 0;
|
||||
@@ -1054,16 +1054,16 @@ int AudioEndpointRequests_1(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp
|
||||
i_tmp = MCLK_441;
|
||||
}
|
||||
|
||||
//setG_curSamFreqMultiplier(g_curSamFreq/(i_tmp/512));
|
||||
setG_curSamFreqMultiplier((g_curSamFreq*512)/i_tmp);
|
||||
//setG_curSamFreqMultiplier(g_curSamFreq/(i_tmp/512));
|
||||
setG_curSamFreqMultiplier((g_curSamFreq*512)/i_tmp);
|
||||
|
||||
/* Instruct audio thread to change sample freq */
|
||||
outuint(c_audioControl, SET_SAMPLE_FREQ);
|
||||
outuint(c_audioControl, g_curSamFreq);
|
||||
outuint(c_audioControl, g_curSamFreq);
|
||||
|
||||
/* 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();
|
||||
}
|
||||
@@ -1111,9 +1111,9 @@ int AudioClassRequests_1(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
|
||||
/* Inspect for reset */
|
||||
if(loop < 0)
|
||||
return loop;
|
||||
|
||||
|
||||
unitID = sp.wIndex >> 8;
|
||||
|
||||
|
||||
if (unitID == FU_USBOUT)
|
||||
{
|
||||
switch ((sp.wValue>>8) & 0xff)
|
||||
@@ -1152,49 +1152,49 @@ int AudioClassRequests_1(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
|
||||
switch ((sp.wValue>>8) & 0xff)
|
||||
{
|
||||
case FU_VOLUME_CONTROL:
|
||||
{
|
||||
{
|
||||
buffer[0] = volsOut[ sp.wValue&0xff ];
|
||||
buffer[1] = volsOut[ sp.wValue&0xff ] >> 8;
|
||||
return XUD_DoGetRequest(ep0_out, ep0_in, buffer, 2, sp.wLength);
|
||||
break;
|
||||
}
|
||||
case FU_MUTE_CONTROL:
|
||||
{
|
||||
{
|
||||
buffer[0] = mutesOut[ sp.wValue & 0xff ];
|
||||
return XUD_DoGetRequest(ep0_out, ep0_in, buffer, 1, sp.wLength);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (unitID == FU_USBIN)
|
||||
{
|
||||
switch ((sp.wValue>>8) & 0xff)
|
||||
{
|
||||
case FU_VOLUME_CONTROL:
|
||||
{
|
||||
{
|
||||
buffer[0] = volsIn[ sp.wValue&0xff ];
|
||||
buffer[1] = volsIn[ sp.wValue&0xff ] >> 8;
|
||||
return XUD_DoGetRequest(ep0_out, ep0_in, buffer, 2, sp.wLength);
|
||||
}
|
||||
case FU_MUTE_CONTROL:
|
||||
{
|
||||
{
|
||||
buffer[0] = mutesIn[ sp.wValue & 0xff ];
|
||||
return XUD_DoGetRequest(ep0_out, ep0_in, buffer, 1, sp.wLength);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case UAC_B_REQ_GET_MIN:
|
||||
buffer[0] = (MIN_MIXER_VOLUME & 0xff);
|
||||
buffer[1] = (MIN_MIXER_VOLUME >> 8);
|
||||
return XUD_DoGetRequest(ep0_out, ep0_in, buffer, 2, sp.wLength);
|
||||
|
||||
|
||||
case UAC_B_REQ_GET_MAX:
|
||||
buffer[0] = (MAX_MIXER_VOLUME & 0xff);
|
||||
buffer[1] = (MAX_MIXER_VOLUME >> 8);
|
||||
return XUD_DoGetRequest(ep0_out, ep0_in, buffer, 2, sp.wLength);
|
||||
|
||||
|
||||
case UAC_B_REQ_GET_RES:
|
||||
buffer[0] = (VOLUME_RES_MIXER & 0xff);
|
||||
buffer[1] = (VOLUME_RES_MIXER >> 8);
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
Parameters:
|
||||
db - The db value to convert.
|
||||
db_frac_bits - The number of binary fractional bits in the supplied decibel value
|
||||
db_frac_bits - The number of binary fractional bits in the supplied decibel value
|
||||
result_frac_bits - The number of required fractional bits in the result.
|
||||
|
||||
Returns:
|
||||
|
||||
@@ -21,7 +21,7 @@ static unsigned coef[14] = {2407, 13778, 64588, 308051, 1346110, 5261991, 182775
|
||||
|
||||
Parameters:
|
||||
db - The db value to convert.
|
||||
db_frac_bits - The number of binary fractional bits in the supplied decibel value
|
||||
db_frac_bits - The number of binary fractional bits in the supplied decibel value
|
||||
result_frac_bits - The number of required fractional bits in the result.
|
||||
|
||||
Returns:
|
||||
@@ -37,24 +37,24 @@ unsigned db_to_mult(int db, int db_frac_bits, int result_frac_bits)
|
||||
unsigned mask = ~((1<<DB_CALC_PREC)-1);
|
||||
|
||||
/* Make sure we get 0db bang on */
|
||||
if (db == 0)
|
||||
if (db == 0)
|
||||
return (1 << result_frac_bits);
|
||||
|
||||
|
||||
/* First scale the decibal value to the required precision and divide by 10
|
||||
/* First scale the decibal value to the required precision and divide by 10
|
||||
We scale to DB_CALC_PREC - 4 before the division with to make sure we don't overflow */
|
||||
db = db << (DB_CALC_PREC - 4 - 1 - db_frac_bits);
|
||||
db = db / 10;
|
||||
db = db << 4;
|
||||
|
||||
|
||||
|
||||
/* Extract the integer part of the exponent and calculate the integer power */
|
||||
/* This could have been done a bit more efficiently by extracting the largest multiple log_10(2)
|
||||
and then calculating a power of 2 (with the polynomial calc in the range [-log_10(2),log_10(2)].
|
||||
/* This could have been done a bit more efficiently by extracting the largest multiple log_10(2)
|
||||
and then calculating a power of 2 (with the polynomial calc in the range [-log_10(2),log_10(2)].
|
||||
But we have something that works here and ultra-fast performance is not a requirement */
|
||||
if (db < 0) {
|
||||
intpart = ((-db) & mask);
|
||||
db = db + intpart;
|
||||
db = db + intpart;
|
||||
intpart = intpart >> DB_CALC_PREC;
|
||||
|
||||
if (intpart) {
|
||||
@@ -65,7 +65,7 @@ unsigned db_to_mult(int db, int db_frac_bits, int result_frac_bits)
|
||||
}
|
||||
else {
|
||||
intpart = (db & mask);
|
||||
db = db - intpart;
|
||||
db = db - intpart;
|
||||
intpart = intpart >> DB_CALC_PREC;
|
||||
if (intpart) {
|
||||
val0 = 1 << DB_CALC_PREC;
|
||||
@@ -86,20 +86,20 @@ unsigned db_to_mult(int db, int db_frac_bits, int result_frac_bits)
|
||||
val = (hi << (32-DB_CALC_PREC)) | (lo >> DB_CALC_PREC);
|
||||
val += coef[i] >> (COEF_PREC - DB_CALC_PREC);
|
||||
}
|
||||
|
||||
|
||||
/* Finally multiply by the integer power (if there was an integer part) */
|
||||
if (val0) {
|
||||
int hi=0;
|
||||
unsigned lo=0;
|
||||
|
||||
{hi, lo} = macs(val0,val,hi,lo);
|
||||
val = (hi << (32-DB_CALC_PREC)) | (lo >> DB_CALC_PREC);
|
||||
val = (hi << (32-DB_CALC_PREC)) | (lo >> DB_CALC_PREC);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* We now have the result, just need to scale it to the required precision */
|
||||
ret = val;
|
||||
|
||||
|
||||
if (result_frac_bits > DB_CALC_PREC) {
|
||||
return ret<<(result_frac_bits-DB_CALC_PREC);
|
||||
}
|
||||
@@ -113,7 +113,7 @@ unsigned db_to_mult(int db, int db_frac_bits, int result_frac_bits)
|
||||
|
||||
int main() {
|
||||
|
||||
/* Check that we don't overflow up to 9db
|
||||
/* Check that we don't overflow up to 9db
|
||||
Should give a value just under 0x80000 */
|
||||
printhexln(db_to_mult(9,0,16));
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,12 +2,12 @@
|
||||
#ifndef _ENDPOINT0_H_
|
||||
#define _ENDPOINT0_H_
|
||||
|
||||
/** Function implementing Endpoint 0 for enumeration, control and configuration
|
||||
/** Function implementing Endpoint 0 for enumeration, control and configuration
|
||||
* of USB audio devices. It uses the descriptors defined in ``descriptors_2.h``.
|
||||
*
|
||||
*
|
||||
* \param c_ep0_out Chanend connected to the XUD_Manager() out endpoint array
|
||||
* \param c_ep0_in Chanend connected to the XUD_Manager() in endpoint array
|
||||
* \param c_audioCtrl Chanend connected to the decouple thread for control
|
||||
* \param c_audioCtrl Chanend connected to the decouple thread for control
|
||||
* audio (sample rate changes etc.)
|
||||
* \param c_mix_ctl Optional chanend to be connected to the mixer thread if
|
||||
* present
|
||||
@@ -15,7 +15,7 @@
|
||||
* present.
|
||||
* \param c_usb_test Optional chanend to be connected to XUD if test modes required.
|
||||
*/
|
||||
void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioCtrl,
|
||||
void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioCtrl,
|
||||
chanend ?c_mix_ctl,chanend ?c_clk_ctl, chanend ?c_usb_test);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -59,7 +59,7 @@ int AudioEndpointRequests_1(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp
|
||||
|
||||
|
||||
|
||||
/* Global volume and mute tables */
|
||||
/* Global volume and mute tables */
|
||||
int volsOut[NUM_USB_CHAN_OUT + 1];
|
||||
unsigned int mutesOut[NUM_USB_CHAN_OUT + 1];
|
||||
//unsigned int multOut[NUM_USB_CHAN_OUT + 1];
|
||||
@@ -89,7 +89,7 @@ int min(int x, int y);
|
||||
extern unsigned char g_currentConfig;
|
||||
|
||||
/* Global endpoint status arrays - declared in usb_device.xc */
|
||||
extern unsigned char g_interfaceAlt[];
|
||||
extern unsigned char g_interfaceAlt[];
|
||||
|
||||
/* Global variable for current USB bus speed (i.e. FS/HS) */
|
||||
unsigned g_curUsbSpeed = 0;
|
||||
@@ -108,7 +108,7 @@ unsigned g_dsdMode = 0;
|
||||
void VendorAudioRequestsInit(chanend c_audioControl, chanend ?c_mix_ctl, chanend ?c_clk_ctl);
|
||||
|
||||
/* Endpoint 0 function. Handles all requests to the device */
|
||||
void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
|
||||
void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
|
||||
chanend ?c_mix_ctl, chanend ?c_clk_ctl, chanend ?c_usb_test)
|
||||
{
|
||||
USB_SetupPacket_t sp;
|
||||
@@ -133,7 +133,7 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
|
||||
for (int i = 0; i < 18*8; i++) {
|
||||
mixer1Weights[i] = 0x8001; //-inf
|
||||
}
|
||||
|
||||
|
||||
/* Configure default connections */
|
||||
mixer1Weights[0] = 0;
|
||||
mixer1Weights[9] = 0;
|
||||
@@ -148,26 +148,26 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
|
||||
/* Setup up audio output channel mapping */
|
||||
for(int i = 0; i < NUM_USB_CHAN_OUT; i++)
|
||||
{
|
||||
channelMapAud[i] = i;
|
||||
channelMapAud[i] = i;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if NUM_USB_CHAN_IN > 0
|
||||
for(int i = 0; i < NUM_USB_CHAN_IN; i++)
|
||||
{
|
||||
channelMapUsb[i] = i + NUM_USB_CHAN_OUT;
|
||||
channelMapUsb[i] = i + NUM_USB_CHAN_OUT;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Set up channel mapping default */
|
||||
for (int i = 0; i < NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN; i++)
|
||||
for (int i = 0; i < NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN; i++)
|
||||
{
|
||||
channelMap[i] = i;
|
||||
}
|
||||
|
||||
#if MAX_MIX_COUNT > 0
|
||||
/* Mixer outputs mapping defaults */
|
||||
for (int i = 0; i < MAX_MIX_COUNT; i++)
|
||||
for (int i = 0; i < MAX_MIX_COUNT; i++)
|
||||
{
|
||||
channelMap[NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN + i] = i;
|
||||
}
|
||||
@@ -197,7 +197,7 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
|
||||
safestrcpy(strDescs[ADAT_RX_INDEX + INPUT_INTERFACE_STRING_INDEX + 7], "ADAT 8");
|
||||
#endif
|
||||
|
||||
#if defined(SPDIF) && (SPDIF_TX_INDEX != 0) /* "Analogue naming gets priority */
|
||||
#if defined(SPDIF) && (SPDIF_TX_INDEX != 0) /* "Analogue naming gets priority */
|
||||
safestrcpy(strDescs[SPDIF_TX_INDEX + OUTPUT_INTERFACE_STRING_INDEX], "S/PDIF 1");
|
||||
safestrcpy(strDescs[SPDIF_TX_INDEX + OUTPUT_INTERFACE_STRING_INDEX + 1], "S/PDIF 2");
|
||||
#endif
|
||||
@@ -218,7 +218,7 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
|
||||
|
||||
#ifdef DFU
|
||||
/* Check if device has started in DFU mode */
|
||||
if (DFUReportResetState(null))
|
||||
if (DFUReportResetState(null))
|
||||
{
|
||||
/* Stop audio */
|
||||
outuint(c_audioControl, SET_SAMPLE_FREQ);
|
||||
@@ -226,9 +226,9 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
|
||||
// No Handshake
|
||||
//chkct(c_audioControl, XS1_CT_END);
|
||||
DFU_mode_active = 1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
while(1)
|
||||
{
|
||||
/* Returns 0 for success, -1 for bus reset */
|
||||
@@ -238,11 +238,11 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
|
||||
{
|
||||
retVal = 1;
|
||||
|
||||
/* Inspect Request type and Receipient and direction */
|
||||
/* Inspect Request type and Receipient and direction */
|
||||
switch( (sp.bmRequestType.Direction << 7) | (sp.bmRequestType.Recipient ) | (sp.bmRequestType.Type << 5) )
|
||||
{
|
||||
case USB_BMREQ_H2D_STANDARD_INT:
|
||||
|
||||
|
||||
/* Over-riding USB_StandardRequests implementation */
|
||||
if(sp.bRequest == USB_SET_INTERFACE)
|
||||
{
|
||||
@@ -259,7 +259,7 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
|
||||
{
|
||||
outuint(c_audioControl, SET_DSD_MODE);
|
||||
outuint(c_audioControl, DSD_MODE_OFF);
|
||||
|
||||
|
||||
/* Handshake */
|
||||
chkct(c_audioControl, XS1_CT_END);
|
||||
g_dsdMode = 0;
|
||||
@@ -271,7 +271,7 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
|
||||
/* NOTE there could be a difference between HS/UAC1 and FS/UAC1 channel count */
|
||||
/* Also note, currently we assume with won't be doing ADAT in FS/UAC1...*/
|
||||
if(g_curUsbSpeed == XUD_SPEED_HS)
|
||||
{
|
||||
{
|
||||
outuint(c_audioControl, SET_CHAN_COUNT_OUT);
|
||||
outuint(c_audioControl, NUM_USB_CHAN_OUT);
|
||||
}
|
||||
@@ -285,7 +285,7 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
|
||||
{
|
||||
outuint(c_audioControl, SET_DSD_MODE);
|
||||
outuint(c_audioControl, DSD_MODE_OFF);
|
||||
|
||||
|
||||
// Handshake
|
||||
chkct(c_audioControl, XS1_CT_END);
|
||||
g_dsdMode = 0;
|
||||
@@ -294,9 +294,9 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
|
||||
break;
|
||||
#ifdef NATIVE_DSD
|
||||
case 2:
|
||||
|
||||
|
||||
if(!g_dsdMode)
|
||||
{
|
||||
{
|
||||
outuint(c_audioControl, SET_DSD_MODE);
|
||||
outuint(c_audioControl, DSD_MODE_NATIVE);
|
||||
chkct(c_audioControl, XS1_CT_END);
|
||||
@@ -317,7 +317,7 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
|
||||
/* NOTE there could be a difference between HS/UAC1 and FS/UAC1 channel count */
|
||||
/* Also note, currently we assume with won't be doing ADAT in FS/UAC1...*/
|
||||
if(g_curUsbSpeed == XUD_SPEED_HS)
|
||||
{
|
||||
{
|
||||
outuint(c_audioControl, SET_CHAN_COUNT_IN);
|
||||
outuint(c_audioControl, NUM_USB_CHAN_IN);
|
||||
}
|
||||
@@ -326,20 +326,20 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
|
||||
outuint(c_audioControl, SET_CHAN_COUNT_IN);
|
||||
outuint(c_audioControl, NUM_USB_CHAN_IN_A1);
|
||||
}
|
||||
#ifdef ADAT_RX
|
||||
#ifdef ADAT_RX
|
||||
outuint(c_clk_ctl, SET_SMUX);
|
||||
outuint(c_clk_ctl, 0);
|
||||
outuint(c_clk_ctl, 0);
|
||||
outct(c_clk_ctl, XS1_CT_END);
|
||||
#endif
|
||||
break;
|
||||
|
||||
#ifdef ADAT_RX
|
||||
|
||||
#ifdef ADAT_RX
|
||||
case 2:
|
||||
/* Stream active + 8 chans */
|
||||
outuint(c_audioControl, SET_CHAN_COUNT_IN);
|
||||
outuint(c_audioControl, NUM_USB_CHAN_IN-4);
|
||||
outuint(c_clk_ctl, SET_SMUX);
|
||||
outuint(c_clk_ctl, 1);
|
||||
outuint(c_clk_ctl, 1);
|
||||
outct(c_clk_ctl, XS1_CT_END);
|
||||
break;
|
||||
|
||||
@@ -347,11 +347,11 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
|
||||
outuint(c_audioControl, SET_CHAN_COUNT_IN);
|
||||
outuint(c_audioControl, NUM_USB_CHAN_IN-6);
|
||||
outuint(c_clk_ctl, SET_SMUX);
|
||||
outuint(c_clk_ctl, 1);
|
||||
outuint(c_clk_ctl, 1);
|
||||
outct(c_clk_ctl, XS1_CT_END);
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
#if 1
|
||||
#if defined(OUTPUT) && defined(INPUT)
|
||||
@@ -392,11 +392,11 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
|
||||
retVal = XUD_DoSetRequestStatus(ep0_in);
|
||||
|
||||
} /* if(sp.bRequest == SET_INTERFACE) */
|
||||
|
||||
|
||||
break; /* BMREQ_H2D_STANDARD_INT */
|
||||
|
||||
|
||||
case USB_BMREQ_D2H_STANDARD_INT:
|
||||
|
||||
|
||||
switch(sp.bRequest)
|
||||
{
|
||||
|
||||
@@ -412,29 +412,29 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
|
||||
{
|
||||
case HID_REPORT:
|
||||
/* Return HID report descriptor */
|
||||
retVal = XUD_DoGetRequest(ep0_out, ep0_in, hidReportDescriptor,
|
||||
retVal = XUD_DoGetRequest(ep0_out, ep0_in, hidReportDescriptor,
|
||||
sizeof(hidReportDescriptor), sp.wLength);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
/* Recipient: Device */
|
||||
case USB_BMREQ_H2D_STANDARD_DEV:
|
||||
|
||||
|
||||
/* Inspect for actual request */
|
||||
switch( sp.bRequest )
|
||||
{
|
||||
{
|
||||
/* Standard request: SetConfiguration */
|
||||
/* Overriding implementation in USB_StandardRequests */
|
||||
case USB_SET_CONFIGURATION:
|
||||
|
||||
|
||||
//g_currentConfig = sp.wValue;
|
||||
//if(g_current_config == 1)
|
||||
{
|
||||
@@ -454,19 +454,19 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
|
||||
//if(retVal == 0)
|
||||
// retVal = 1;
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
//Unknown device request"
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
/* Audio Class 1.0 Sampling Freqency Requests go to Endpoint */
|
||||
|
||||
/* Audio Class 1.0 Sampling Freqency Requests go to Endpoint */
|
||||
case USB_BMREQ_H2D_CLASS_EP:
|
||||
case USB_BMREQ_D2H_CLASS_EP:
|
||||
{
|
||||
unsigned epNum = sp.wIndex & 0xff;
|
||||
|
||||
|
||||
if ((epNum == 0x82) || (epNum == 0x01))
|
||||
{
|
||||
#if (AUDIO_CLASS == 2) && defined(AUDIO_CLASS_FALLBACK)
|
||||
@@ -478,12 +478,12 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
|
||||
retVal = AudioEndpointRequests_1(ep0_out, ep0_in, sp, c_audioControl, c_mix_ctl, c_clk_ctl);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_BMREQ_H2D_CLASS_INT:
|
||||
case USB_BMREQ_D2H_CLASS_INT:
|
||||
|
||||
case USB_BMREQ_H2D_CLASS_INT:
|
||||
case USB_BMREQ_D2H_CLASS_INT:
|
||||
{
|
||||
unsigned interfaceNum = sp.wIndex & 0xff;
|
||||
//unsigned request = (sp.bmRequestType.Recipient ) | (sp.bmRequestType.Type << 5);
|
||||
@@ -493,16 +493,16 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
|
||||
unsigned DFU_IF = DFU_IF_NUM;
|
||||
|
||||
/* DFU interface number changes based on which mode we are currently running in */
|
||||
if (DFU_mode_active)
|
||||
if (DFU_mode_active)
|
||||
{
|
||||
DFU_IF = 0;
|
||||
}
|
||||
|
||||
if (interfaceNum == DFU_IF)
|
||||
if (interfaceNum == DFU_IF)
|
||||
{
|
||||
/* If running in application mode stop audio */
|
||||
/* Don't interupt audio for save and restore cmds */
|
||||
if ((DFU_IF == DFU_IF_NUM) && (sp.bRequest != XMOS_DFU_SAVESTATE) &&
|
||||
if ((DFU_IF == DFU_IF_NUM) && (sp.bRequest != XMOS_DFU_SAVESTATE) &&
|
||||
(sp.bRequest != XMOS_DFU_RESTORESTATE))
|
||||
{
|
||||
// Stop audio
|
||||
@@ -511,9 +511,9 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
|
||||
// Handshake
|
||||
chkct(c_audioControl, XS1_CT_END);
|
||||
}
|
||||
|
||||
|
||||
/* This will return 1 if reset requested */
|
||||
if (DFUDeviceRequests(ep0_out, ep0_in, sp, null, g_interfaceAlt[sp.wIndex], 1))
|
||||
if (DFUDeviceRequests(ep0_out, ep0_in, sp, null, g_interfaceAlt[sp.wIndex], 1))
|
||||
{
|
||||
timer tmr;
|
||||
unsigned s;
|
||||
@@ -524,11 +524,11 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
|
||||
|
||||
/* TODO we should not make the assumption that all DFU requests are handled */
|
||||
retVal = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
/* Check for: - Audio CONTROL interface request - always 0, note we check for DFU first
|
||||
/* Check for: - Audio CONTROL interface request - always 0, note we check for DFU first
|
||||
* - Audio STREAMING interface request (In or Out)
|
||||
* - Audio endpoint request (Audio 1.0 Sampling freq requests are sent to the endpoint)
|
||||
* - Audio endpoint request (Audio 1.0 Sampling freq requests are sent to the endpoint)
|
||||
*/
|
||||
if((interfaceNum == 0) || (interfaceNum == 1) || (interfaceNum == 2))
|
||||
{
|
||||
@@ -555,33 +555,33 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
|
||||
retVal = VendorAudioRequests(ep0_out, ep0_in, sp.bRequest,
|
||||
sp.wValue >> 8, sp.wValue & 0xff,
|
||||
sp.wIndex >> 8, sp.bmRequestType.Direction,
|
||||
c_audioControl, c_mix_ctl, c_clk_ctl);
|
||||
c_audioControl, c_mix_ctl, c_clk_ctl);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
} /* if(retVal == 0) */
|
||||
|
||||
|
||||
if(retVal > 0)
|
||||
{
|
||||
#ifdef DFU
|
||||
if (!DFU_mode_active)
|
||||
if (!DFU_mode_active)
|
||||
{
|
||||
#endif
|
||||
#ifdef AUDIO_CLASS_FALLBACK
|
||||
/* Return Audio 2.0 Descriptors with Audio 1.0 as fallback */
|
||||
retVal = USB_StandardRequests(ep0_out, ep0_in,
|
||||
devDesc_Audio2, sizeof(devDesc_Audio2),
|
||||
cfgDesc_Audio2, sizeof(cfgDesc_Audio2),
|
||||
devDesc_Audio1, sizeof(devDesc_Audio1),
|
||||
cfgDesc_Audio1, sizeof(cfgDesc_Audio1),
|
||||
strDescs, sizeof(strDescs)/sizeof(strDescs[0]),
|
||||
retVal = USB_StandardRequests(ep0_out, ep0_in,
|
||||
devDesc_Audio2, sizeof(devDesc_Audio2),
|
||||
cfgDesc_Audio2, sizeof(cfgDesc_Audio2),
|
||||
devDesc_Audio1, sizeof(devDesc_Audio1),
|
||||
cfgDesc_Audio1, sizeof(cfgDesc_Audio1),
|
||||
strDescs, sizeof(strDescs)/sizeof(strDescs[0]),
|
||||
sp, c_usb_test, g_curUsbSpeed);
|
||||
#elif FULL_SPEED_AUDIO_2
|
||||
/* Return Audio 2.0 Descriptors for high_speed and full-speed */
|
||||
@@ -592,75 +592,75 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
|
||||
/* Mod bSlotSize */
|
||||
cfgDesc_Audio2[STREAMING_ALT1_OFFSET+4] = SAMPLE_SUBSLOT_SIZE_HS;
|
||||
|
||||
/* Mod bBitResolution */
|
||||
/* Mod bBitResolution */
|
||||
cfgDesc_Audio2[STREAMING_ALT1_OFFSET+5] = SAMPLE_BIT_RESOLUTION_HS;
|
||||
|
||||
/* wMaxPacketSize */
|
||||
cfgDesc_Audio2[STREAMING_ALT1_OFFSET+10] = MAX_PACKET_SIZE_OUT_HS&0xff;
|
||||
cfgDesc_Audio2[STREAMING_ALT1_OFFSET+10] = MAX_PACKET_SIZE_OUT_HS&0xff;
|
||||
cfgDesc_Audio2[STREAMING_ALT1_OFFSET+11] = (MAX_PACKET_SIZE_OUT_HS&0xff00)>>8;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Mod bSlotSize */
|
||||
cfgDesc_Audio2[STREAMING_ALT1_OFFSET+4] = SAMPLE_SUBSLOT_SIZE_FS;
|
||||
|
||||
/* Mod bBitResolution */
|
||||
|
||||
/* Mod bBitResolution */
|
||||
cfgDesc_Audio2[STREAMING_ALT1_OFFSET+5] = SAMPLE_BIT_RESOLUTION_FS;
|
||||
|
||||
|
||||
/* wMaxPacketSize */
|
||||
cfgDesc_Audio2[STREAMING_ALT1_OFFSET+10] = MAX_PACKET_SIZE_OUT_FS&0xff;
|
||||
cfgDesc_Audio2[STREAMING_ALT1_OFFSET+10] = MAX_PACKET_SIZE_OUT_FS&0xff;
|
||||
cfgDesc_Audio2[STREAMING_ALT1_OFFSET+11] = (MAX_PACKET_SIZE_OUT_FS&0xff00)>>8;
|
||||
}
|
||||
|
||||
retVal = USB_StandardRequests(ep0_out, ep0_in,
|
||||
devDesc_Audio2, sizeof(devDesc_Audio2),
|
||||
cfgDesc_Audio2, sizeof(cfgDesc_Audio2),
|
||||
null, 0,
|
||||
null, 0,
|
||||
retVal = USB_StandardRequests(ep0_out, ep0_in,
|
||||
devDesc_Audio2, sizeof(devDesc_Audio2),
|
||||
cfgDesc_Audio2, sizeof(cfgDesc_Audio2),
|
||||
null, 0,
|
||||
null, 0,
|
||||
strDescs, sizeof(strDescs)/sizeof(strDescs[0]), sp, c_usb_test, g_curUsbSpeed);
|
||||
#else
|
||||
/* Return Audio 2.0 Descriptors with Null device as fallback */
|
||||
retVal = USB_StandardRequests(ep0_out, ep0_in,
|
||||
devDesc_Audio2, sizeof(devDesc_Audio2),
|
||||
cfgDesc_Audio2, sizeof(cfgDesc_Audio2),
|
||||
devDesc_Null, sizeof(devDesc_Null),
|
||||
cfgDesc_Null, sizeof(cfgDesc_Null),
|
||||
retVal = USB_StandardRequests(ep0_out, ep0_in,
|
||||
devDesc_Audio2, sizeof(devDesc_Audio2),
|
||||
cfgDesc_Audio2, sizeof(cfgDesc_Audio2),
|
||||
devDesc_Null, sizeof(devDesc_Null),
|
||||
cfgDesc_Null, sizeof(cfgDesc_Null),
|
||||
strDescs, sizeof(strDescs)/sizeof(strDescs[0]), sp, c_usb_test, g_curUsbSpeed);
|
||||
#endif
|
||||
#ifdef DFU
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Running in DFU mode - always return same descs for DFU whether HS or FS */
|
||||
retVal = USB_StandardRequests(ep0_out, ep0_in,
|
||||
DFUdevDesc, sizeof(DFUdevDesc),
|
||||
DFUcfgDesc, sizeof(DFUcfgDesc),
|
||||
retVal = USB_StandardRequests(ep0_out, ep0_in,
|
||||
DFUdevDesc, sizeof(DFUdevDesc),
|
||||
DFUcfgDesc, sizeof(DFUcfgDesc),
|
||||
null, 0, /* Used same descriptors for full and high-speed */
|
||||
null, 0,
|
||||
null, 0,
|
||||
strDescs, sizeof(strDescs), sp, c_usb_test, g_curUsbSpeed);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (retVal < 0)
|
||||
|
||||
if (retVal < 0)
|
||||
{
|
||||
g_curUsbSpeed = XUD_ResetEndpoint(ep0_out, ep0_in);
|
||||
|
||||
g_currentConfig = 0;
|
||||
|
||||
#ifdef DFU
|
||||
if (DFUReportResetState(null))
|
||||
if (DFUReportResetState(null))
|
||||
{
|
||||
if (!DFU_mode_active)
|
||||
if (!DFU_mode_active)
|
||||
{
|
||||
timer tmr;
|
||||
unsigned s;
|
||||
DFU_mode_active = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
if (DFU_mode_active)
|
||||
if (DFU_mode_active)
|
||||
{
|
||||
timer tmr;
|
||||
unsigned s;
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
*
|
||||
* */
|
||||
|
||||
int VendorAudioRequests(XUD_ep ep0_out, XUD_ep ep0_in, unsigned char bRequest, unsigned char cs, unsigned char cn,
|
||||
int VendorAudioRequests(XUD_ep ep0_out, XUD_ep ep0_in, unsigned char bRequest, unsigned char cs, unsigned char cn,
|
||||
unsigned short unitId, unsigned char direction, chanend c_audioControl, chanend ?c_mix_ctl, chanend ?c_clk_ctL);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user