diff --git a/module_usb_audio/devicedefines.h b/module_usb_audio/devicedefines.h index 6813b546..1cb6f0eb 100644 --- a/module_usb_audio/devicedefines.h +++ b/module_usb_audio/devicedefines.h @@ -575,99 +575,80 @@ #endif #endif -#if defined(DFU) && DFU != 0 -#define DFU_INTERFACES (1) /* DFU interface count */ -#else -#define DFU_INTERFACES (0) -#endif - -#ifdef INPUT +/* Audio input USB interface count */ +#if defined(INPUT) && (INTPUT != 0) #define INPUT_INTERFACES (1) #else #define INPUT_INTERFACES (0) #endif -#if defined(OUTPUT) && OUTPUT != 0 -#define OUTPUT_INTERFACES (1) +/* Audio output USB interface count */ +#if defined(OUTPUT) && (OUTPUT != 0) +#define OUTPUT_INTERFACES (1) #else -#define OUTPUT_INTERFACES (0) +#define OUTPUT_INTERFACES (0) #endif -#define EP_CNT_OUT_AUD (OUTPUT_INTERFACES) -#define EP_CNT_IN_AUD (OUTPUT_INTERFACES + INPUT_INTERFACES) +/* Total audio USB interface count (+1 for mandatory control interface) */ +#define AUDIO_INTERFACE_COUNT (1 + OUTPUT_INTERFACES + INPUT_INTERFACES) +/* MIDI USB interface count */ #if defined(MIDI) -#define MIDI_INTERFACES (2) -#define EP_CNT_OUT_MIDI (1) -#define EP_CNT_IN_MIDI (1) +#define MIDI_INTERFACES (2) #else -#define MIDI_INTERFACES (0) -#define EP_CNT_OUT_MIDI (0) -#define EP_CNT_IN_MIDI (0) +#define MIDI_INTERFACES (0) #endif +/* iAP USB interface count */ #if defined(IAP) -#define IAP_INTERFACES (1) +#define IAP_INTERFACES (1) #else -#define IAP_INTERFACES (0) +#define IAP_INTERFACES (0) #endif +/* HID USB interface count */ #if defined(HID_CONTROLS) -#define HID_INTERFACES (1) +#define HID_INTERFACES (1) #else -#define HID_INTERFACES (0) +#define HID_INTERFACES (0) #endif -#define EP_CNT_OUT_IAP (IAP_INTERFACES) -#ifdef IAP_INT_EP -#define EP_CNT_IN_IAP (IAP_INTERFACES * 2) -#else -#define EP_CNT_IN_IAP (IAP_INTERFACES) -#endif - -#define EP_CNT_OUT_HID (0) -#define EP_CNT_IN_HID (HID_INTERFACES) - +/* Endpoint addresses enums */ +enum USBEndpointNumber_In +{ + ENDPOINT_NUMBER_IN_CONTROL, /* Endpoint 0 */ + ENDPOINT_NUMBER_IN_FEEDBACK, + ENDPOINT_NUMBER_IN_AUDIO, #if defined(SPDIF_RX) || defined(ADAT_RX) -#define EP_CNT_IN_AUD_INT (1) -#else -#define EP_CNT_IN_AUD_INT (0) + ENDPOINT_NUMBER_IN_INTERRUPT, /* Audio interrupt/status EP */ #endif - -/* Endpoint Number Defines */ -#define EP_NUM_IN_FB (1) /* Always 1 */ -#define EP_NUM_IN_AUD (2) /* Always 2 */ -#define EP_NUM_IN_AUD_INT (EP_NUM_IN_AUD + EP_CNT_IN_AUD_INT) /* Audio interrupt/status EP */ -#define EP_NUM_IN_MIDI (EP_NUM_IN_AUD_INT + 1) -#define EP_NUM_IN_HID (EP_NUM_IN_AUD_INT + EP_CNT_IN_MIDI + 1) -#define EP_NUM_IN_IAP (EP_NUM_IN_AUD_INT + EP_CNT_IN_MIDI + EP_CNT_IN_HID + 1) /* iAP Bulk */ +#ifdef MIDI + ENDPOINT_NUMBER_IN_MIDI, +#endif +#ifdef HID_CONTROLS + ENDPOINT_NUMBER_IN_HID, +#endif +#ifdef IAP #ifdef IAP_INT_EP -#define EP_NUM_IN_IAP_INT (EP_NUM_IN_AUD_INT + EP_CNT_IN_MIDI + EP_CNT_IN_HID + 2) /* iAP interrupt */ + ENDPOINT_NUMBER_IN_IAP_INT, #endif - -#define EP_NUM_OUT_AUD (1) /* Always 1 */ -#define EP_NUM_OUT_MIDI (2) /* Always 2 */ -#define EP_NUM_OUT_IAP (EP_NUM_OUT_AUD + EP_CNT_OUT_MIDI + 1) - -/* Endpoint Address Defines */ -#define EP_ADR_IN_FB (EP_NUM_IN_FB | 0x80) -#define EP_ADR_IN_AUD (EP_NUM_IN_AUD | 0x80) -#define EP_ADR_IN_AUD_INT (EP_NUM_IN_AUD_INT | 0x80) -#define EP_ADR_IN_MIDI (EP_NUM_IN_MIDI | 0x80) -#define EP_ADR_IN_HID (EP_NUM_IN_HID | 0x80) -#define EP_ADR_IN_IAP (EP_NUM_IN_IAP | 0x80) -#ifdef IAP_INT_EP -#define EP_ADR_IN_IAP_INT (EP_NUM_IN_IAP_INT | 0x80) + ENDPOINT_NUMBER_IN_IAP, #endif + ENDPOINT_COUNT_IN /* End marker */ +}; -#define EP_ADR_OUT_AUD EP_NUM_OUT_AUD -#define EP_ADR_OUT_MIDI EP_NUM_OUT_MIDI -#define EP_ADR_OUT_IAP EP_NUM_OUT_IAP - - -/* Endpoint count totals */ -#define EP_CNT_OUT (1 + 1 /*NUM_EP_OUT_AUD*/ + EP_CNT_OUT_MIDI + EP_CNT_OUT_IAP) /* +1 due to EP0 */ -#define EP_CNT_IN (1 + 2 /*NUM_EP_IN_AUD*/ + EP_CNT_IN_AUD_INT + EP_CNT_IN_MIDI + EP_CNT_IN_IAP + EP_CNT_IN_HID) /* +1 due to EP0 */ +enum USBEndpointNumber_Out +{ + ENDPOINT_NUMBER_OUT_CONTROL, /* Endpoint 0 */ + ENDPOINT_NUMBER_OUT_AUDIO, +#ifdef MIDI + ENDPOINT_NUMBER_OUT_MIDI, +#endif +#ifdef IAP + ENDPOINT_NUMBER_OUT_IAP, +#endif + ENDPOINT_COUNT_OUT /* End marker */ +}; #define AUDIO_STOP_FOR_DFU (0x12345678) #define AUDIO_START_FROM_DFU (0x87654321) @@ -694,13 +675,9 @@ #endif -/* Total number of USB interfaces this device implements (+1 for required control interface) */ -//#define NUM_INTERFACES INPUT_INTERFACES + OUTPUT_INTERFACES + DFU_INTERFACES + MIDI_INTERFACES + IAP_INTERFACES + 1 + HID_INTERFACES - /* Number of interfaces for Audio 1.0 */ #define NUM_INTERFACES_A1 (1+INPUT_INTERFACES+OUTPUT_INTERFACES) - /* Audio Unit ID defines */ #define FU_USBIN 11 /* Feature Unit: USB Audio device -> host */ #define FU_USBOUT 10 /* Feature Unit: USB Audio host -> device*/ @@ -755,7 +732,6 @@ #define VOLUME_RES (0x100) #endif - #ifndef MIN_MIXER_VOLUME /* The minimum volume setting for the mixer unit above -inf. This is a signed 8.8 fixed point diff --git a/module_usb_audio/endpoint0/descriptors.h b/module_usb_audio/endpoint0/descriptors.h index e180bba2..9e3d0be9 100644 --- a/module_usb_audio/endpoint0/descriptors.h +++ b/module_usb_audio/endpoint0/descriptors.h @@ -4,8 +4,6 @@ * @author Ross Owen, XMOS Limited */ - - #ifndef _DEVICE_DESCRIPTORS_ #define _DEVICE_DESCRIPTORS_ @@ -617,13 +615,35 @@ enum USBInterfaceNumber 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 +/* Endpoint address defines */ +#define ENDPOINT_ADDRESS_IN_CONTROL (ENDPOINT_NUMBER_IN_CONTROL | 0x80) +#define ENDPOINT_ADDRESS_IN_FEEDBACK (ENDPOINT_NUMBER_IN_FEEDBACK | 0x80) +#define ENDPOINT_ADDRESS_IN_AUDIO (ENDPOINT_NUMBER_IN_AUDIO | 0x80) +#define ENDPOINT_ADDRESS_IN_INTERRUPT (ENDPOINT_NUMBER_IN_INTERRUPT | 0x80) +#define ENDPOINT_ADDRESS_IN_MIDI (ENDPOINT_NUMBER_IN_MIDI | 0x80) +#define ENDPOINT_ADDRESS_IN_HID (ENDPOINT_NUMBER_IN_HID | 0x80) +#define ENDPOINT_ADDRESS_IN_IAP_INT (ENDPOINT_NUMBER_IN_IAP_INT | 0x80) +#define ENDPOINT_ADDRESS_IN_IAP (ENDPOINT_NUMBER_IN_IAP | 0x80) + +#define ENDPOINT_ADDRESS_OUT_CONTROL (ENDPOINT_NUMBER_OUT_CONTROL) +#define ENDPOINT_ADDRESS_OUT_AUDIO (ENDPOINT_NUMBER_OUT_AUDIO) +#define ENDPOINT_ADDRESS_OUT_MIDI (ENDPOINT_NUMBER_OUT_MIDI) +#define ENDPOINT_ADDRESS_OUT_IAP (ENDPOINT_NUMBER_OUT_IAP) + +#if 0 +#define EP_NUM_IN_FB (1) /* Always 1 */ +#define EP_NUM_IN_AUD (2) /* Always 2 */ +#define EP_NUM_IN_AUD_INT (EP_NUM_IN_AUD + EP_CNT_IN_AUD_INT) /* Audio interrupt/status EP */ +#define EP_NUM_IN_MIDI (EP_NUM_IN_AUD_INT + 1) +#define EP_NUM_IN_HID (EP_NUM_IN_AUD_INT + EP_CNT_IN_MIDI + 1) +#define EP_NUM_IN_IAP (EP_NUM_IN_AUD_INT + EP_CNT_IN_MIDI + EP_CNT_IN_HID + 1) /* iAP Bulk */ +#ifdef IAP_INT_EP +#define EP_NUM_IN_IAP_INT (EP_NUM_IN_AUD_INT + EP_CNT_IN_MIDI + EP_CNT_IN_HID + 2) /* iAP interrupt */ +#endif + +#define EP_NUM_OUT_AUD (1) /* Always 1 */ +#define EP_NUM_OUT_MIDI (2) /* Always 2 */ +#define EP_NUM_OUT_IAP (EP_NUM_OUT_AUD + EP_CNT_OUT_MIDI + 1) #endif /***** Device Descriptors *****/ @@ -1622,7 +1642,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= /* Table B-11: MIDI Adapter Standard Bulk OUT Endpoint Descriptor */ 0x09, /* 0 bLength : Size of this descriptor, in bytes. (field size 1 bytes) */ 0x05, /* 1 bDescriptorType : ENDPOINT descriptor. (field size 1 bytes) */ - EP_ADR_OUT_MIDI, /* 2 bEndpointAddress : OUT Endpoint 3. (field size 1 bytes) */ + ENDPOINT_ADDRESS_OUT_MIDI, /* 2 bEndpointAddress : OUT Endpoint 3. (field size 1 bytes) */ 0x02, /* 3 bmAttributes : Bulk, not shared. (field size 1 bytes) */ 0x00, /* 4 wMaxPacketSize : 512 bytes per packet. (field size 2 bytes) - has to be 0x200 for compliance*/ 0x02, /* 5 wMaxPacketSize */ @@ -1640,7 +1660,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= /* Table B-13: MIDI Adapter Standard Bulk IN Endpoint Descriptor */ 0x09, /* 0 bLength : Size of this descriptor, in bytes. (field size 1 bytes) */ 0x05, /* 1 bDescriptorType : ENDPOINT descriptor. (field size 1 bytes) */ - EP_ADR_IN_MIDI, /* 2 bEndpointAddress : IN Endpoint 3. (field size 1 bytes) */ + ENDPOINT_ADDRESS_IN_MIDI, /* 2 bEndpointAddress : IN Endpoint 3. (field size 1 bytes) */ 0x02, /* 3 bmAttributes : Bulk, not shared. (field size 1 bytes) */ 0x00, /* 4 wMaxPacketSize : 512 bytes per packet. (field size 2 bytes) - has to be 0x200 for compliance*/ 0x02, /* 5 wMaxPacketSize */ @@ -1715,7 +1735,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= { 0x07, /* 0 bLength : Size of this descriptor, in bytes. (field size 1 bytes) */ 0x05, /* 1 bDescriptorType : ENDPOINT descriptor. (field size 1 bytes) */ - EP_ADR_OUT_IAP, /* 2 bEndpointAddress : OUT Endpoint 3. High bit isIn (field size 1 bytes) */ + ENDPOINT_ADDRESS_OUT_IAP, /* 2 bEndpointAddress : OUT Endpoint 3. High bit isIn (field size 1 bytes) */ 0x02, /* 3 bmAttributes : Bulk, not shared. (field size 1 bytes) */ 0x0200, /* 4 wMaxPacketSize : Has to be 0x200 for compliance*/ 0x00, /* 6 bInterval : Ignored for Bulk. Set to zero. (field size 1 bytes) */ @@ -1726,7 +1746,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= { 0x07, /* 0 bLength : Size of this descriptor, in bytes. (field size 1 bytes) */ 0x05, /* 1 bDescriptorType : ENDPOINT descriptor. (field size 1 bytes) */ - EP_ADR_IN_IAP, /* 2 bEndpointAddress : IN Endpoint 5. (field size 1 bytes) */ + ENDPOINT_ADDRESS_IN_IAP, /* 2 bEndpointAddress : IN Endpoint 5. (field size 1 bytes) */ 0x02, /* 3 bmAttributes : Bulk, not shared. (field size 1 bytes) */ 0x0200, /* 4 wMaxPacketSize : Has to be 0x200 for compliance*/ 0x00, /* 6 bInterval : Ignored for Bulk. Set to zero. (field size 1 bytes) */ @@ -1738,9 +1758,9 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= { 0x07, /* 0 bLength : Size of this descriptor, in bytes. (field size 1 bytes) */ 0x05, /* 1 bDescriptorType : ENDPOINT descriptor. (field size 1 bytes) */ - EP_ADR_IN_IAP_INT, /* 2 bEndpointAddress : IN Endpoint 6. (field size 1 bytes) */ + ENDPOINT_ADDRESS_IN_IAP_INT, /* 2 bEndpointAddress : IN Endpoint 6. (field size 1 bytes) */ 0x03, /* 3 bmAttributes : Interrupt, not shared. (field size 1 bytes) */ - 0x0040, /* 4 wMaxPacketSize : 64 bytes per packet. (field size 2 bytes) - has to be 0x40 for compliance*/ + 0x0040, /* 4 wMaxPacketSize : 64 bytes per packet. (field size 2 bytes) - has to be 0x40 for compliance*/ 0x08, /* 6 bInterval : (2^(bInterval-1))/8 ms. Must be between 4 and 32ms (field size 1 bytes) */ } #endif @@ -1773,14 +1793,11 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= /* Endpoint descriptor (IN) */ 0x7, /* 0 bLength */ 5, /* 1 bDescriptorType */ - EP_ADR_IN_HID, /* 2 bEndpointAddress */ + ENDPOINT_ADDRESS_IN_HID, /* 2 bEndpointAddress */ 3, /* 3 bmAttributes (INTERRUPT) */ 64, /* 4 wMaxPacketSize */ 8, /* 6 bInterval */ - #endif - - }; #endif diff --git a/module_usb_audio/main.xc b/module_usb_audio/main.xc index 5807121f..11df9470 100755 --- a/module_usb_audio/main.xc +++ b/module_usb_audio/main.xc @@ -174,7 +174,7 @@ on tile [IAP_TILE] : struct r_i2c r_i2c = {PORT_I2C_SCL, PORT_I2C_SDA}; /* Endpoint type tables for XUD */ -XUD_EpType epTypeTableOut[EP_CNT_OUT] = { XUD_EPTYPE_CTL | XUD_STATUS_ENABLE, +XUD_EpType epTypeTableOut[ENDPOINT_COUNT_OUT] = { XUD_EPTYPE_CTL | XUD_STATUS_ENABLE, XUD_EPTYPE_ISO, /* Audio */ #ifdef MIDI XUD_EPTYPE_BUL, /* MIDI */ @@ -184,7 +184,7 @@ XUD_EpType epTypeTableOut[EP_CNT_OUT] = { XUD_EPTYPE_CTL | XUD_STATUS_ENABLE, #endif }; -XUD_EpType epTypeTableIn[EP_CNT_IN] = { XUD_EPTYPE_CTL | XUD_STATUS_ENABLE, +XUD_EpType epTypeTableIn[ENDPOINT_COUNT_IN] = { XUD_EPTYPE_CTL | XUD_STATUS_ENABLE, XUD_EPTYPE_ISO, XUD_EPTYPE_ISO, #if defined (SPDIF_RX) || defined (ADAT_RX) @@ -244,8 +244,8 @@ void usb_audio_core(chanend c_mix_out ) { chan c_sof; - chan c_xud_out[EP_CNT_OUT]; /* Endpoint channels for XUD */ - chan c_xud_in[EP_CNT_IN]; + chan c_xud_out[ENDPOINT_COUNT_OUT]; /* Endpoint channels for XUD */ + chan c_xud_in[ENDPOINT_COUNT_IN]; chan c_aud_ctl; #ifdef TEST_MODE_SUPPORT #warning Building with test mode support @@ -266,11 +266,11 @@ void usb_audio_core(chanend c_mix_out { /* USB Interface Core */ #if (AUDIO_CLASS==2) - XUD_Manager(c_xud_out, EP_CNT_OUT, c_xud_in, EP_CNT_IN, + XUD_Manager(c_xud_out, ENDPOINT_COUNT_OUT, c_xud_in, ENDPOINT_COUNT_IN, c_sof, epTypeTableOut, epTypeTableIn, p_usb_rst, clk, 1, XUD_SPEED_HS, c_usb_test, pwrConfig); #else - XUD_Manager(c_xud_out, EP_CNT_OUT, c_xud_in, EP_CNT_IN, + XUD_Manager(c_xud_out, ENDPOINT_COUNT_OUT, c_xud_in, ENDPOINT_COUNT_IN, c_sof, epTypeTableOut, epTypeTableIn, p_usb_rst, clk, 1, XUD_SPEED_FS, c_usb_test, pwrConfig); #endif @@ -291,29 +291,29 @@ void usb_audio_core(chanend c_mix_out asm("ldw %0, dp[clk_audio_mclk]":"=r"(x)); asm("setclk res[%0], %1"::"r"(p_for_mclk_count), "r"(x)); #endif - buffer(c_xud_out[EP_NUM_OUT_AUD],/* Audio Out*/ - c_xud_in[EP_NUM_IN_AUD], /* Audio In */ - c_xud_in[EP_NUM_IN_FB], /* Audio FB */ + buffer(c_xud_out[ENDPOINT_NUMBER_OUT_AUDIO],/* Audio Out*/ + c_xud_in[ENDPOINT_NUMBER_IN_AUDIO], /* Audio In */ + c_xud_in[ENDPOINT_NUMBER_IN_FEEDBACK], /* Audio FB */ #ifdef MIDI - c_xud_out[EP_NUM_OUT_MIDI], /* MIDI Out */ // 2 - c_xud_in[EP_NUM_IN_MIDI], /* MIDI In */ // 4 + c_xud_out[ENDPOINT_NUMBER_OUT_MIDI], /* MIDI Out */ // 2 + c_xud_in[ENDPOINT_NUMBER_IN_MIDI], /* MIDI In */ // 4 c_midi, #endif #ifdef IAP - c_xud_out[EP_NUM_OUT_IAP], /* iAP Out */ - c_xud_in[EP_NUM_IN_IAP], /* iAP In */ + c_xud_out[ENDPOINT_NUMBER_OUT_IAP], /* iAP Out */ + c_xud_in[ENDPOINT_NUMBER_IN_IAP], /* iAP In */ #ifdef IAP_INT_EP - c_xud_in[EP_NUM_IN_IAP_INT], /* iAP Interrupt In */ + c_xud_in[ENDPOINT_NUMBER_IN_IAP_INT], /* iAP Interrupt In */ #endif c_iap, #endif #if defined(SPDIF_RX) || defined(ADAT_RX) /* Audio Interrupt - only used for interrupts on external clock change */ - c_xud_in[EP_NUM_IN_AUD_INT], + c_xud_in[ENDPOINT_NUMBER_IN_INTERUUPT], #endif c_sof, c_aud_ctl, p_for_mclk_count #ifdef HID_CONTROLS - , c_xud_in[EP_NUM_IN_HID] + , c_xud_in[ENDPOINT_NUMBER_IN_HID] #endif #ifdef CHAN_BUFF_CTRL , c_buff_ctrl