EP0 changed to use switch statement when handling USB_SET_INTERFACE requests

This commit is contained in:
Sam Chesney
2014-07-29 15:22:51 +01:00
parent cbe78f355c
commit 201c899f23

View File

@@ -268,102 +268,112 @@ void Endpoint0(chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
/* Over-riding USB_StandardRequests implementation */ /* Over-riding USB_StandardRequests implementation */
if(sp.bRequest == USB_SET_INTERFACE) if(sp.bRequest == USB_SET_INTERFACE)
{ {
/* Check for audio stream from host start/stop */ switch (sp.wIndex)
if(sp.wIndex == 1) /* Output interface */
{ {
/* Check the alt is in range */ /* Check for audio stream from host start/stop */
if(sp.wValue <= OUTPUT_FORMAT_COUNT) case INTERFACE_NUMBER_AUDIO_OUTPUT:
{ /* Check the alt is in range */
/* Alt 0 is stream stop */ if(sp.wValue <= OUTPUT_FORMAT_COUNT)
/* Only send change if we need to */
if((sp.wValue > 0) && (g_curStreamAlt_Out != sp.wValue))
{ {
g_curStreamAlt_Out = sp.wValue; /* Alt 0 is stream stop */
/* Only send change if we need to */
/* Send format of data onto buffering */ if((sp.wValue > 0) && (g_curStreamAlt_Out != sp.wValue))
outuint(c_audioControl, SET_STREAM_FORMAT_OUT);
outuint(c_audioControl, g_dataFormat_Out[sp.wValue-1]); /* Data format (PCM/DSD) */
if(g_curUsbSpeed == XUD_SPEED_HS)
{ {
outuint(c_audioControl, NUM_USB_CHAN_OUT); /* Channel count */ g_curStreamAlt_Out = sp.wValue;
outuint(c_audioControl, g_subSlot_Out_HS[sp.wValue-1]); /* Subslot */
outuint(c_audioControl, g_sampRes_Out_HS[sp.wValue-1]); /* Resolution */
}
else
{
outuint(c_audioControl, NUM_USB_CHAN_OUT_FS); /* Channel count */
outuint(c_audioControl, g_subSlot_Out_FS[sp.wValue-1]); /* Subslot */
outuint(c_audioControl, g_sampRes_Out_FS[sp.wValue-1]); /* Resolution */
}
/* Handshake */ /* Send format of data onto buffering */
chkct(c_audioControl, XS1_CT_END); outuint(c_audioControl, SET_STREAM_FORMAT_OUT);
outuint(c_audioControl, g_dataFormat_Out[sp.wValue-1]); /* Data format (PCM/DSD) */
if(g_curUsbSpeed == XUD_SPEED_HS)
{
outuint(c_audioControl, NUM_USB_CHAN_OUT); /* Channel count */
outuint(c_audioControl, g_subSlot_Out_HS[sp.wValue-1]); /* Subslot */
outuint(c_audioControl, g_sampRes_Out_HS[sp.wValue-1]); /* Resolution */
}
else
{
outuint(c_audioControl, NUM_USB_CHAN_OUT_FS); /* Channel count */
outuint(c_audioControl, g_subSlot_Out_FS[sp.wValue-1]); /* Subslot */
outuint(c_audioControl, g_sampRes_Out_FS[sp.wValue-1]); /* Resolution */
}
/* Handshake */
chkct(c_audioControl, XS1_CT_END);
}
} }
} break;
case INTERFACE_NUMBER_AUDIO_INPUT:
/* Check the alt is in range */
if(sp.wValue <= INPUT_FORMAT_COUNT)
{
/* Alt 0 is stream stop */
/* Only send change if we need to */
if((sp.wValue > 0) && (g_curStreamAlt_In != sp.wValue))
{
g_curStreamAlt_In = sp.wValue;
/* Send format of data onto buffering */
outuint(c_audioControl, SET_STREAM_FORMAT_IN);
outuint(c_audioControl, g_dataFormat_In[sp.wValue-1]); /* Data format (PCM/DSD) */
if(g_curUsbSpeed == XUD_SPEED_HS)
{
outuint(c_audioControl, NUM_USB_CHAN_IN); /* Channel count */
outuint(c_audioControl, g_subSlot_In_HS[sp.wValue-1]); /* Subslot */
outuint(c_audioControl, g_sampRes_In_HS[sp.wValue-1]); /* Resolution */
}
else
{
outuint(c_audioControl, NUM_USB_CHAN_IN_FS); /* Channel count */
outuint(c_audioControl, g_subSlot_In_FS[sp.wValue-1]); /* Subslot */
outuint(c_audioControl, g_sampRes_In_FS[sp.wValue-1]); /* Resolution */
}
/* Handshake */
chkct(c_audioControl, XS1_CT_END);
}
}
break;
{
default:
/* Unhandled interface */
break;
} }
else if(sp.wIndex == 2) /* Input interface */
if ((sp.wIndex == INTERFACE_NUMBER_AUDIO_OUTPUT) || (sp.wIndex == INTERFACE_NUMBER_AUDIO_INPUT))
{ {
/* Check the alt is in range */
if(sp.wValue <= INPUT_FORMAT_COUNT)
{
/* Alt 0 is stream stop */
/* Only send change if we need to */
if((sp.wValue > 0) && (g_curStreamAlt_In != sp.wValue))
{
g_curStreamAlt_In = sp.wValue;
/* Send format of data onto buffering */
outuint(c_audioControl, SET_STREAM_FORMAT_IN);
outuint(c_audioControl, g_dataFormat_In[sp.wValue-1]); /* Data format (PCM/DSD) */
if(g_curUsbSpeed == XUD_SPEED_HS)
{
outuint(c_audioControl, NUM_USB_CHAN_IN); /* Channel count */
outuint(c_audioControl, g_subSlot_In_HS[sp.wValue-1]); /* Subslot */
outuint(c_audioControl, g_sampRes_In_HS[sp.wValue-1]); /* Resolution */
}
else
{
outuint(c_audioControl, NUM_USB_CHAN_IN_FS); /* Channel count */
outuint(c_audioControl, g_subSlot_In_FS[sp.wValue-1]); /* Subslot */
outuint(c_audioControl, g_sampRes_In_FS[sp.wValue-1]); /* Resolution */
}
/* Handshake */
chkct(c_audioControl, XS1_CT_END);
}
}
}
#if (NUM_USB_CHAN_OUT > 0) && (NUM_USB_CHAN_IN > 0) #if (NUM_USB_CHAN_OUT > 0) && (NUM_USB_CHAN_IN > 0)
/* Check for stream start stop on output and input audio interfaces */ /* Check for stream start stop on output and input audio interfaces */
if(sp.wValue && !g_interfaceAlt[1] && !g_interfaceAlt[2]) if(sp.wValue && !g_interfaceAlt[1] && !g_interfaceAlt[2])
{ {
/* If start and input AND output not currently running */ /* If start and input AND output not currently running */
UserAudioStreamStart(); UserAudioStreamStart();
} }
else if(((sp.wIndex == 1) && (!sp.wValue)) && g_interfaceAlt[1] && (!g_interfaceAlt[2])) else if(((sp.wIndex == 1) && (!sp.wValue)) && g_interfaceAlt[1] && (!g_interfaceAlt[2]))
{ {
/* if output stop and output running and input not running */ /* if output stop and output running and input not running */
UserAudioStreamStop(); UserAudioStreamStop();
} }
else if(((sp.wIndex == 2) && (!sp.wValue)) && g_interfaceAlt[2] && (!g_interfaceAlt[1])) else if(((sp.wIndex == 2) && (!sp.wValue)) && g_interfaceAlt[2] && (!g_interfaceAlt[1]))
{ {
/* if input stop and input running and output not running */ /* if input stop and input running and output not running */
UserAudioStreamStop(); UserAudioStreamStop();
} }
#elif (NUM_USB_CHAN_OUT > 0) || (NUM_USB_CHAN_IN > 0) #elif (NUM_USB_CHAN_OUT > 0) || (NUM_USB_CHAN_IN > 0)
if(sp.wValue && (!g_interfaceAlt[1])) if(sp.wValue && (!g_interfaceAlt[1]))
{ {
/* if start and not currently running */ /* if start and not currently running */
UserAudioStreamStart(); UserAudioStreamStart();
} }
else if (!sp.wValue && g_interfaceAlt[1]) else if (!sp.wValue && g_interfaceAlt[1])
{ {
/* if stop and currently running */ /* if stop and currently running */
UserAudioStreamStop(); UserAudioStreamStop();
} }
#endif #endif
}
} /* if(sp.bRequest == SET_INTERFACE) */ } /* if(sp.bRequest == SET_INTERFACE) */
break; /* BMREQ_H2D_STANDARD_INT */ break; /* BMREQ_H2D_STANDARD_INT */