Interface numbers now built up in an enum

This commit is contained in:
Ross Owen
2014-03-26 13:16:12 +00:00
parent 1488353b8d
commit 1023599a48
2 changed files with 211 additions and 177 deletions

View File

@@ -591,6 +591,40 @@ StringDescTable_t g_strTable =
}; };
/* Interface numbers enum */
enum USBInterfaceNumber
{
INTERFACE_NUMBER_AUDIO_CONTROL = 0,
#if defined(OUTPUT) && (OUTPUT != 0)
INTERFACE_NUMBER_AUDIO_OUTPUT,
#endif
#if defined(INPUT) && (INPUT != 0)
INTERFACE_NUMBER_AUDIO_INPUT,
#endif
#if defined(MIDI) && (MIDI != 0)
INTERFACE_NUMBER_MIDI_OUTPUT,
INTERFACE_NUMBER_MIDI_INPUT,
#endif
#if defined(DFU) && (DFU != 0)
INTERFACE_NUMBER_DFU,
#endif
#if defined(IAP) && (IAP != 0)
INTERFACE_NUMBER_IAP,
#endif
#if defined(HID_CONTROLS) && (HID_CONTROLS != 0)
INTERFACE_NUMBER_HID,
#endif
INTERFACE_COUNT /* End marker */
};
/* Define for number of audio interfaces (+1 for mandatory control interface) */
#if defined(OUTPUT) && defined(INPUT)
#define AUDIO_INTERFACE_COUNT 3
#elif #defined(OUTPUT) || defined(INPUT)
#define AUDIO_INTERFACE_COUNT 2
#else
#define AUDIO_INTERFACE_COUNT 1
#endif
/***** Device Descriptors *****/ /***** Device Descriptors *****/
@@ -872,7 +906,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2=
.bLength = sizeof(USB_Descriptor_Configuration_Header_t), .bLength = sizeof(USB_Descriptor_Configuration_Header_t),
.bDescriptorType = USB_DESCTYPE_CONFIGURATION, .bDescriptorType = USB_DESCTYPE_CONFIGURATION,
.wTotalLength = sizeof(USB_Config_Descriptor_Audio2_t), .wTotalLength = sizeof(USB_Config_Descriptor_Audio2_t),
.bNumInterfaces = NUM_INTERFACES, .bNumInterfaces = INTERFACE_COUNT,
.bConfigurationValue = 0x01, .bConfigurationValue = 0x01,
.iConfiguration = 0x00, .iConfiguration = 0x00,
#ifdef SELF_POWERED #ifdef SELF_POWERED
@@ -888,7 +922,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2=
.bLength = sizeof(USB_Descriptor_Interface_Association_t), .bLength = sizeof(USB_Descriptor_Interface_Association_t),
.bDescriptorType = USB_DESCTYPE_INTERFACE_ASSOCIATION, .bDescriptorType = USB_DESCTYPE_INTERFACE_ASSOCIATION,
.bFirstInterface = 0x00, .bFirstInterface = 0x00,
.bInterfaceCount = AUDIO_INTERFACES, .bInterfaceCount = AUDIO_INTERFACE_COUNT,
.bFunctionClass = AUDIO_FUNCTION, .bFunctionClass = AUDIO_FUNCTION,
.bFunctionSubClass = FUNCTION_SUBCLASS_UNDEFINED, .bFunctionSubClass = FUNCTION_SUBCLASS_UNDEFINED,
.bFunctionProtocol = UAC_FUNC_PROTOCOL_AF_VERSION_02_00, .bFunctionProtocol = UAC_FUNC_PROTOCOL_AF_VERSION_02_00,
@@ -900,7 +934,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2=
{ {
.bLength = sizeof(USB_Descriptor_Interface_t), .bLength = sizeof(USB_Descriptor_Interface_t),
.bDescriptorType = USB_DESCTYPE_INTERFACE, .bDescriptorType = USB_DESCTYPE_INTERFACE,
.bInterfaceNumber = 0x00, .bInterfaceNumber = INTERFACE_NUMBER_AUDIO_CONTROL,
.bAlternateSetting = 0x00, /* Must be 0 */ .bAlternateSetting = 0x00, /* Must be 0 */
#if defined(SPDIF_RX) || defined(ADAT_RX) #if defined(SPDIF_RX) || defined(ADAT_RX)
.bNumEndpoints = 0x01, /* 0 or 1 if optional interrupt endpoint is present */ .bNumEndpoints = 0x01, /* 0 or 1 if optional interrupt endpoint is present */
@@ -1192,7 +1226,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2=
{ {
0x09, /* 0 bLength: (in bytes, 9) */ 0x09, /* 0 bLength: (in bytes, 9) */
USB_DESCTYPE_INTERFACE, /* 1 bDescriptorType: INTERFACE */ USB_DESCTYPE_INTERFACE, /* 1 bDescriptorType: INTERFACE */
1, /* 2 bInterfaceNumber: Number of interface */ INTERFACE_NUMBER_AUDIO_OUTPUT, /* 2 bInterfaceNumber: Number of interface */
0, /* 3 bAlternateSetting */ 0, /* 3 bAlternateSetting */
0, /* 4 bNumEndpoints */ 0, /* 4 bNumEndpoints */
USB_CLASS_AUDIO, /* 5 bInterfaceClass: AUDIO */ USB_CLASS_AUDIO, /* 5 bInterfaceClass: AUDIO */
@@ -1207,12 +1241,12 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2=
{ {
0x09, /* 0 bLength: (in bytes, 9) */ 0x09, /* 0 bLength: (in bytes, 9) */
USB_DESCTYPE_INTERFACE, /* 1 bDescriptorType: INTERFACE */ USB_DESCTYPE_INTERFACE, /* 1 bDescriptorType: INTERFACE */
1, /* 2 bInterfaceNumber: Number of interface */ INTERFACE_NUMBER_AUDIO_OUTPUT, /* 2 bInterfaceNumber: Number of interface */
1, /* 3 bAlternateSetting */ 1, /* 3 bAlternateSetting */
2, /* 4 bNumEndpoints */ 2, /* 4 bNumEndpoints */
USB_CLASS_AUDIO, /* 5 bInterfaceClass: AUDIO */ USB_CLASS_AUDIO, /* 5 bInterfaceClass: AUDIO */
UAC_INT_SUBCLASS_AUDIOSTREAMING, /* 6 bInterfaceSubClass: AUDIO_STREAMING */ UAC_INT_SUBCLASS_AUDIOSTREAMING, /* 6 bInterfaceSubClass: AUDIO_STREAMING */
UAC_INT_PROTOCOL_IP_VERSION_02_00, /* 7 bInterfaceProtocol: IP_VERSION_02_00 */ UAC_INT_PROTOCOL_IP_VERSION_02_00,/* 7 bInterfaceProtocol: IP_VERSION_02_00 */
4, /* 8 iInterface: (Sting index) */ 4, /* 8 iInterface: (Sting index) */
}, },
/* STREAMING_OUTPUT_ALT1_OFFSET: */ /* STREAMING_OUTPUT_ALT1_OFFSET: */
@@ -1280,7 +1314,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2=
{ {
0x09, /* 0 bLength: (in bytes, 9) */ 0x09, /* 0 bLength: (in bytes, 9) */
USB_DESCTYPE_INTERFACE, /* 1 bDescriptorType: INTERFACE */ USB_DESCTYPE_INTERFACE, /* 1 bDescriptorType: INTERFACE */
1, /* 2 bInterfaceNumber: Number of interface */ INTERFACE_NUMBER_AUDIO_OUTPUT, /* 2 bInterfaceNumber: Number of interface */
2, /* 3 bAlternateSetting */ 2, /* 3 bAlternateSetting */
2, /* 4 bNumEndpoints */ 2, /* 4 bNumEndpoints */
USB_CLASS_AUDIO, /* 5 bInterfaceClass: AUDIO */ USB_CLASS_AUDIO, /* 5 bInterfaceClass: AUDIO */
@@ -1353,7 +1387,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2=
{ {
0x09, /* 0 bLength: (in bytes, 9) */ 0x09, /* 0 bLength: (in bytes, 9) */
USB_DESCTYPE_INTERFACE, /* 1 bDescriptorType: INTERFACE */ USB_DESCTYPE_INTERFACE, /* 1 bDescriptorType: INTERFACE */
1, /* 2 bInterfaceNumber: Number of interface */ INTERFACE_NUMBER_AUDIO_OUTPUT, /* 2 bInterfaceNumber: Number of interface */
3, /* 3 bAlternateSetting */ 3, /* 3 bAlternateSetting */
2, /* 4 bNumEndpoints */ 2, /* 4 bNumEndpoints */
USB_CLASS_AUDIO, /* 5 bInterfaceClass: AUDIO */ USB_CLASS_AUDIO, /* 5 bInterfaceClass: AUDIO */
@@ -1430,7 +1464,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2=
{ {
0x09, /* 0 bLength: (in bytes, 9) */ 0x09, /* 0 bLength: (in bytes, 9) */
USB_DESCTYPE_INTERFACE, /* 1 bDescriptorType: INTERFACE */ USB_DESCTYPE_INTERFACE, /* 1 bDescriptorType: INTERFACE */
(OUTPUT_INTERFACES + 1), /* 2 bInterfaceNumber: Number of interface */ INTERFACE_NUMBER_AUDIO_INPUT, /* 2 bInterfaceNumber: Number of interface */
0, /* 3 bAlternateSetting */ 0, /* 3 bAlternateSetting */
0, /* 4 bNumEndpoints */ 0, /* 4 bNumEndpoints */
USB_CLASS_AUDIO, /* 5 bInterfaceClass: AUDIO */ USB_CLASS_AUDIO, /* 5 bInterfaceClass: AUDIO */
@@ -1445,12 +1479,12 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2=
{ {
0x09, /* 0 bLength: (in bytes, 9) */ 0x09, /* 0 bLength: (in bytes, 9) */
USB_DESCTYPE_INTERFACE, /* 1 bDescriptorType: INTERFACE */ USB_DESCTYPE_INTERFACE, /* 1 bDescriptorType: INTERFACE */
(OUTPUT_INTERFACES + 1), /* 2 bInterfaceNumber: Number of interface */ INTERFACE_NUMBER_AUDIO_INPUT, /* 2 bInterfaceNumber: Number of interface */
1, /* 3 bAlternateSetting */ 1, /* 3 bAlternateSetting */
1, /* 4 bNumEndpoints */ 1, /* 4 bNumEndpoints */
USB_CLASS_AUDIO, /* 5 bInterfaceClass: AUDIO */ USB_CLASS_AUDIO, /* 5 bInterfaceClass: AUDIO */
UAC_INT_SUBCLASS_AUDIOSTREAMING, /* 6 bInterfaceSubClass: AUDIO_STREAMING */ UAC_INT_SUBCLASS_AUDIOSTREAMING, /* 6 bInterfaceSubClass: AUDIO_STREAMING */
UAC_INT_PROTOCOL_IP_VERSION_02_00, /* 7 bInterfaceProtocol: IP_VERSION_02_00 */ UAC_INT_PROTOCOL_IP_VERSION_02_00,/* 7 bInterfaceProtocol: IP_VERSION_02_00 */
5, /* 8 iInterface: (Sting index) */ 5, /* 8 iInterface: (Sting index) */
}, },
@@ -1463,7 +1497,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2=
ID_OT_USB, /* 3 bTerminalLink */ ID_OT_USB, /* 3 bTerminalLink */
0x00, /* 4 bmControls */ 0x00, /* 4 bmControls */
0x01, /* 5 bFormatType */ 0x01, /* 5 bFormatType */
UAC_FORMAT_TYPEI_PCM,/* 6:10 bmFormats (note this is a bitmap) */ UAC_FORMAT_TYPEI_PCM, /* 6:10 bmFormats (note this is a bitmap) */
NUM_USB_CHAN_IN, /* 11 bNrChannels */ NUM_USB_CHAN_IN, /* 11 bNrChannels */
0x00000000, /* 12:14: bmChannelConfig */ 0x00000000, /* 12:14: bmChannelConfig */
.iChannelNames = offsetof(StringDescTable_t, inputChanStr_1)/sizeof(char *), .iChannelNames = offsetof(StringDescTable_t, inputChanStr_1)/sizeof(char *),
@@ -1508,7 +1542,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2=
/* Table B-3: MIDI Adapter Standard AC Interface Descriptor */ /* Table B-3: MIDI Adapter Standard AC Interface Descriptor */
0x09, /* 0 bLength : Size of this descriptor, in bytes. (field size 1 bytes) */ 0x09, /* 0 bLength : Size of this descriptor, in bytes. (field size 1 bytes) */
0x04, /* 1 bDescriptorType : INTERFACE descriptor. (field size 1 bytes) */ 0x04, /* 1 bDescriptorType : INTERFACE descriptor. (field size 1 bytes) */
(INPUT_INTERFACES + OUTPUT_INTERFACES + 1),/* 2 bInterfaceNumber : Index of this interface. (field size 1 bytes) */ INTERFACE_NUMBER_MIDI_CONTROL, /* 2 bInterfaceNumber : Index of this interface. (field size 1 bytes) */
0x00, /* 3 bAlternateSetting : Index of this setting. (field size 1 bytes) */ 0x00, /* 3 bAlternateSetting : Index of this setting. (field size 1 bytes) */
0x00, /* 4 bNumEndpoints : 0 endpoints. (field size 1 bytes) */ 0x00, /* 4 bNumEndpoints : 0 endpoints. (field size 1 bytes) */
0x01, /* 5 bInterfaceClass : AUDIO. (field size 1 bytes) */ 0x01, /* 5 bInterfaceClass : AUDIO. (field size 1 bytes) */
@@ -1530,7 +1564,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2=
/* Table B-5: MIDI Adapter Standard MS Interface Descriptor */ /* Table B-5: MIDI Adapter Standard MS Interface Descriptor */
0x09, /* 0 bLength : Size of this descriptor, in bytes. (field size 1 bytes) */ 0x09, /* 0 bLength : Size of this descriptor, in bytes. (field size 1 bytes) */
0x04, /* 1 bDescriptorType : INTERFACE descriptor. (field size 1 bytes) */ 0x04, /* 1 bDescriptorType : INTERFACE descriptor. (field size 1 bytes) */
(INPUT_INTERFACES+OUTPUT_INTERFACES+2), /* 2 bInterfaceNumber : Index of this interface. (field size 1 bytes) */ INTERFACE_NUMBER_MIDI_STREAM, /* 2 bInterfaceNumber : Index of this interface. (field size 1 bytes) */
0x00, /* 3 bAlternateSetting : Index of this alternate setting. (field size 1 bytes) */ 0x00, /* 3 bAlternateSetting : Index of this alternate setting. (field size 1 bytes) */
0x02, /* 4 bNumEndpoints : 2 endpoints. (field size 1 bytes) */ 0x02, /* 4 bNumEndpoints : 2 endpoints. (field size 1 bytes) */
0x01, /* 5 bInterfaceClass : AUDIO. (field size 1 bytes) */ 0x01, /* 5 bInterfaceClass : AUDIO. (field size 1 bytes) */
@@ -1626,7 +1660,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2=
/* Standard DFU class Interface descriptor */ /* Standard DFU class Interface descriptor */
{0x09, /* 0 bLength : Size of this descriptor, in bytes. (field size 1 bytes) */ {0x09, /* 0 bLength : Size of this descriptor, in bytes. (field size 1 bytes) */
0x04, /* 1 bDescriptorType : INTERFACE descriptor. (field size 1 bytes) */ 0x04, /* 1 bDescriptorType : INTERFACE descriptor. (field size 1 bytes) */
(INPUT_INTERFACES+OUTPUT_INTERFACES+MIDI_INTERFACES+1), /* 2 bInterfaceNumber : Index of this interface. (field size 1 bytes) */ INTERFACE_NUMBER_DFU, /* 2 bInterfaceNumber : Index of this interface. (field size 1 bytes) */
0x00, /* 3 bAlternateSetting : Index of this setting. (field size 1 bytes) */ 0x00, /* 3 bAlternateSetting : Index of this setting. (field size 1 bytes) */
0x00, /* 4 bNumEndpoints : 0 endpoints. (field size 1 bytes) */ 0x00, /* 4 bNumEndpoints : 0 endpoints. (field size 1 bytes) */
0xFE, /* 5 bInterfaceClass : DFU. (field size 1 bytes) */ 0xFE, /* 5 bInterfaceClass : DFU. (field size 1 bytes) */
@@ -1663,7 +1697,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2=
{ {
.bLength = sizeof(USB_Descriptor_Interface_t), .bLength = sizeof(USB_Descriptor_Interface_t),
.bDescriptorType = USB_DESCTYPE_INTERFACE, .bDescriptorType = USB_DESCTYPE_INTERFACE,
.bInterfaceNumber = (INPUT_INTERFACES+OUTPUT_INTERFACES+MIDI_INTERFACES+DFU_INTERFACES+1), .bInterfaceNumber = INTERFACE_NUMBER_IAP,
.bAlternateSetting = 0x00, .bAlternateSetting = 0x00,
#ifdef IAP_INT_EP #ifdef IAP_INT_EP
.bNumEndpoints = 0x03, .bNumEndpoints = 0x03,
@@ -1717,7 +1751,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2=
/* Interface descriptor details */ /* Interface descriptor details */
9, /* 0 bLength : Size of descriptor in Bytes */ 9, /* 0 bLength : Size of descriptor in Bytes */
4, /* 1 bDescriptorType (Interface: 0x04)*/ 4, /* 1 bDescriptorType (Interface: 0x04)*/
INTERFACE_NUM_HID, /* 2 bInterfacecNumber : Number of interface */ INTERFACE_NUMBER_HID, /* 2 bInterfaceNumber : Number of interface */
0, /* 3 bAlternateSetting : Value used alternate interfaces using SetInterface Request */ 0, /* 3 bAlternateSetting : Value used alternate interfaces using SetInterface Request */
1, /* 4: bNumEndpoints : Number of endpoitns for this interface (excluding 0) */ 1, /* 4: bNumEndpoints : Number of endpoitns for this interface (excluding 0) */
3, /* 5: bInterfaceClass */ 3, /* 5: bInterfaceClass */
@@ -1733,7 +1767,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2=
0, /* 4 bCountryCode */ 0, /* 4 bCountryCode */
1, /* 5 bNumDescriptors */ 1, /* 5 bNumDescriptors */
0x22, /* 6 bDescriptorType[0] (Report) */ 0x22, /* 6 bDescriptorType[0] (Report) */
sizeof(hidReportDescriptor) & 0xff, /* 7 wDescriptorLength[0] */ sizeof(hidReportDescriptor) & 0xff,/* 7 wDescriptorLength[0] */
sizeof(hidReportDescriptor) >> 8, /* 8 wDescriptorLength[0] */ sizeof(hidReportDescriptor) >> 8, /* 8 wDescriptorLength[0] */
/* Endpoint descriptor (IN) */ /* Endpoint descriptor (IN) */

View File

@@ -406,7 +406,7 @@ void Endpoint0(chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
/* TODO Check on return value retval = */ /* TODO Check on return value retval = */
#ifdef DFU #ifdef DFU
unsigned DFU_IF = DFU_IF_NUM; unsigned DFU_IF = INTERFACE_NUMBER_DFU;
/* DFU interface number changes based on which mode we are currently running in */ /* DFU interface number changes based on which mode we are currently running in */
if (DFU_mode_active) if (DFU_mode_active)
@@ -418,7 +418,7 @@ void Endpoint0(chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
{ {
/* If running in application mode stop audio */ /* If running in application mode stop audio */
/* Don't interupt audio for save and restore cmds */ /* Don't interupt audio for save and restore cmds */
if ((DFU_IF == DFU_IF_NUM) && (sp.bRequest != XMOS_DFU_SAVESTATE) && if ((DFU_IF == INTERFACE_NUMBER_DFU) && (sp.bRequest != XMOS_DFU_SAVESTATE) &&
(sp.bRequest != XMOS_DFU_RESTORESTATE)) (sp.bRequest != XMOS_DFU_RESTORESTATE))
{ {
// Stop audio // Stop audio