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 *****/
@@ -872,7 +906,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2=
.bLength = sizeof(USB_Descriptor_Configuration_Header_t),
.bDescriptorType = USB_DESCTYPE_CONFIGURATION,
.wTotalLength = sizeof(USB_Config_Descriptor_Audio2_t),
.bNumInterfaces = NUM_INTERFACES,
.bNumInterfaces = INTERFACE_COUNT,
.bConfigurationValue = 0x01,
.iConfiguration = 0x00,
#ifdef SELF_POWERED
@@ -888,7 +922,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2=
.bLength = sizeof(USB_Descriptor_Interface_Association_t),
.bDescriptorType = USB_DESCTYPE_INTERFACE_ASSOCIATION,
.bFirstInterface = 0x00,
.bInterfaceCount = AUDIO_INTERFACES,
.bInterfaceCount = AUDIO_INTERFACE_COUNT,
.bFunctionClass = AUDIO_FUNCTION,
.bFunctionSubClass = FUNCTION_SUBCLASS_UNDEFINED,
.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),
.bDescriptorType = USB_DESCTYPE_INTERFACE,
.bInterfaceNumber = 0x00,
.bInterfaceNumber = INTERFACE_NUMBER_AUDIO_CONTROL,
.bAlternateSetting = 0x00, /* Must be 0 */
#if defined(SPDIF_RX) || defined(ADAT_RX)
.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) */
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, /* 4 bNumEndpoints */
USB_CLASS_AUDIO, /* 5 bInterfaceClass: AUDIO */
@@ -1207,7 +1241,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2=
{
0x09, /* 0 bLength: (in bytes, 9) */
USB_DESCTYPE_INTERFACE, /* 1 bDescriptorType: INTERFACE */
1, /* 2 bInterfaceNumber: Number of interface */
INTERFACE_NUMBER_AUDIO_OUTPUT, /* 2 bInterfaceNumber: Number of interface */
1, /* 3 bAlternateSetting */
2, /* 4 bNumEndpoints */
USB_CLASS_AUDIO, /* 5 bInterfaceClass: AUDIO */
@@ -1280,7 +1314,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2=
{
0x09, /* 0 bLength: (in bytes, 9) */
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, /* 4 bNumEndpoints */
USB_CLASS_AUDIO, /* 5 bInterfaceClass: AUDIO */
@@ -1353,7 +1387,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2=
{
0x09, /* 0 bLength: (in bytes, 9) */
USB_DESCTYPE_INTERFACE, /* 1 bDescriptorType: INTERFACE */
1, /* 2 bInterfaceNumber: Number of interface */
INTERFACE_NUMBER_AUDIO_OUTPUT, /* 2 bInterfaceNumber: Number of interface */
3, /* 3 bAlternateSetting */
2, /* 4 bNumEndpoints */
USB_CLASS_AUDIO, /* 5 bInterfaceClass: AUDIO */
@@ -1430,7 +1464,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2=
{
0x09, /* 0 bLength: (in bytes, 9) */
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, /* 4 bNumEndpoints */
USB_CLASS_AUDIO, /* 5 bInterfaceClass: AUDIO */
@@ -1445,7 +1479,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2=
{
0x09, /* 0 bLength: (in bytes, 9) */
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, /* 4 bNumEndpoints */
USB_CLASS_AUDIO, /* 5 bInterfaceClass: AUDIO */
@@ -1508,7 +1542,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2=
/* Table B-3: MIDI Adapter Standard AC Interface Descriptor */
0x09, /* 0 bLength : Size of this descriptor, in bytes. (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, /* 4 bNumEndpoints : 0 endpoints. (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 */
0x09, /* 0 bLength : Size of this descriptor, in bytes. (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) */
0x02, /* 4 bNumEndpoints : 2 endpoints. (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 */
{0x09, /* 0 bLength : Size of this descriptor, in bytes. (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, /* 4 bNumEndpoints : 0 endpoints. (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),
.bDescriptorType = USB_DESCTYPE_INTERFACE,
.bInterfaceNumber = (INPUT_INTERFACES+OUTPUT_INTERFACES+MIDI_INTERFACES+DFU_INTERFACES+1),
.bInterfaceNumber = INTERFACE_NUMBER_IAP,
.bAlternateSetting = 0x00,
#ifdef IAP_INT_EP
.bNumEndpoints = 0x03,
@@ -1717,7 +1751,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2=
/* Interface descriptor details */
9, /* 0 bLength : Size of descriptor in Bytes */
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 */
1, /* 4: bNumEndpoints : Number of endpoitns for this interface (excluding 0) */
3, /* 5: bInterfaceClass */

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 = */
#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 */
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 */
/* 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))
{
// Stop audio