From 7bc53853c4ad8b3c67ca7577ec2e5567b8deed5e Mon Sep 17 00:00:00 2001 From: Russell Gallop Date: Fri, 8 Jul 2011 15:12:28 +0100 Subject: [PATCH] Copy across from apps_usb_aud_shared --- module_usb_aud_shared/audio.h | 4 +- module_usb_aud_shared/audio.xc | 43 +-- module_usb_aud_shared/clocking/clocking.h | 4 +- module_usb_aud_shared/codec/codec.h | 4 +- module_usb_aud_shared/devicedefines.h | 47 +-- .../endpoint0/audiorequests.xc | 10 +- .../endpoint0/descriptors_2.h | 305 ++++++++---------- module_usb_aud_shared/endpoint0/endpoint0.xc | 64 ++-- module_usb_aud_shared/i2c/i2c.h | 6 + module_usb_aud_shared/i2c/i2c.xc | 22 ++ module_usb_aud_shared/pll/pll.h | 4 +- module_usb_aud_shared/usb_buffer/decouple.xc | 30 +- module_usb_aud_shared/usb_buffer/usb_buffer.h | 2 +- .../usb_buffer/usb_buffer.xc | 8 +- 14 files changed, 248 insertions(+), 305 deletions(-) diff --git a/module_usb_aud_shared/audio.h b/module_usb_aud_shared/audio.h index 8fc0568d..77da8b77 100644 --- a/module_usb_aud_shared/audio.h +++ b/module_usb_aud_shared/audio.h @@ -12,7 +12,9 @@ * receiving/transmitting samples * \param c_config An optional channel that will be passed on to the * CODEC configuration functions. + * \param c_i2c An optional channel that will be passed on to the + * functions requiring i2c. */ -void audio(chanend c_in, chanend ?c_dig, chanend ?c_config); +void audio(chanend c_in, chanend ?c_dig, chanend ?c_config, chanend ?c_i2c); #endif // __audio_h__ diff --git a/module_usb_aud_shared/audio.xc b/module_usb_aud_shared/audio.xc index 42cbd908..6e78f6f4 100755 --- a/module_usb_aud_shared/audio.xc +++ b/module_usb_aud_shared/audio.xc @@ -12,6 +12,7 @@ #include #include #include +#include #include "clocking.h" #include "audioports.h" @@ -63,27 +64,24 @@ extern void device_reboot(void); unsigned deliver(chanend c_out, chanend c_spd_out, unsigned divide, chanend ?c_dig_rx) { unsigned sample; -#if NUM_USB_CHAN_OUT > 0 unsigned samplesOut[NUM_USB_CHAN_OUT]; -#endif -#if NUM_USB_CHAN_IN > 0 unsigned samplesIn[NUM_USB_CHAN_IN]; unsigned samplesInPrev[NUM_USB_CHAN_IN]; -#endif unsigned tmp; unsigned index; #ifdef RAMP_CHECK unsigned prev=0; int started = 0; #endif +#ifndef CODEC_SLAVE + int oldtime; +#endif -#if NUM_USB_CHAN_IN > 0 for (int i=0;i 0 #pragma loop unroll for(int i = 0; i < NUM_USB_CHAN_IN; i++) { outuint(c_out, samplesIn[i]); } -#endif - -#if NUM_USB_CHAN_OUT > 0 #pragma loop unroll for(int i = 0; i < NUM_USB_CHAN_OUT; i++) { samplesOut[i] = inuint(c_out); } -#endif #else #pragma loop unroll for(int i = 0; i < NUM_USB_CHAN_OUT; i++) @@ -208,7 +201,6 @@ unsigned deliver(chanend c_out, chanend c_spd_out, unsigned divide, chanend ?c_d tmp += 33; #if (I2S_CHANS_DAC != 0) -#pragma loop unroll for(int i = 0; i < I2S_WIRES_DAC; i++) { p_i2s_dac[i] @ tmp <: 0; @@ -222,6 +214,7 @@ unsigned deliver(chanend c_out, chanend c_spd_out, unsigned divide, chanend ?c_d { clearbuf(p_i2s_adc[i]); } + oldtime = tmp-1+32; /* TODO In master mode, the i/o loop assumes L/RCLK = 32bit clocks. We should check this every interation * and resync if we got a bclk glitch */ @@ -244,22 +237,17 @@ unsigned deliver(chanend c_out, chanend c_spd_out, unsigned divide, chanend ?c_d { #ifndef MIXER // Interfaces straight to decouple() (void) inuint(c_out); - -#if NUM_USB_CHAN_IN > 0 #pragma loop unroll for(int i = 0; i < NUM_USB_CHAN_IN; i++) { outuint(c_out, samplesIn[i]); } -#endif -#if NUM_USB_CHAN_OUT > 0 #pragma loop unroll for(int i = 0; i < NUM_USB_CHAN_OUT; i++) { samplesOut[i] = inuint(c_out); } -#endif #else #pragma loop unroll for(int i = 0; i < NUM_USB_CHAN_OUT; i++) @@ -309,7 +297,7 @@ unsigned deliver(chanend c_out, chanend c_spd_out, unsigned divide, chanend ?c_d #pragma xta endpoint "i2s_output_l" -#if (I2S_CHANS_DAC != 0) && (NUM_USB_CHAN_OUT != 0) +#if (I2S_CHANS_DAC != 0) #pragma loop unroll for(int i = 0; i < I2S_CHANS_DAC; i+=2) { @@ -367,16 +355,14 @@ unsigned deliver(chanend c_out, chanend c_spd_out, unsigned divide, chanend ?c_d for(int i = 1; i < I2S_CHANS_ADC; i += 2) { p_i2s_adc[index++] :> sample; -#if NUM_USB_CHAN_IN > 0 samplesIn[i] = bitrev(sample); /* Store the previous left in left */ samplesIn[i-1] = samplesInPrev[i]; -#endif } #endif -#if defined(SPDIF) && (NUM_USB_CHAN_OUT > 0) +#ifdef SPDIF outuint(c_spd_out, samplesOut[SPDIF_TX_INDEX]); /* Forward sample to SPDIF txt thread */ sample = samplesOut[SPDIF_TX_INDEX + 1]; outuint(c_spd_out, sample); /* Forward sample to SPDIF txt thread */ @@ -399,7 +385,7 @@ unsigned deliver(chanend c_out, chanend c_spd_out, unsigned divide, chanend ?c_d tmp = 0; #pragma xta endpoint "i2s_output_r" -#if (I2S_CHANS_DAC != 0) && (NUM_USB_CHAN_OUT != 0) +#if (I2S_CHANS_DAC != 0) #pragma loop unroll for(int i = 1; i < I2S_CHANS_DAC; i+=2) { @@ -454,10 +440,7 @@ unsigned deliver(chanend c_out, chanend c_spd_out, unsigned divide, chanend ?c_d for(int i = 1; i < I2S_CHANS_ADC; i += 2) { p_i2s_adc[index++] :> sample; - -#if NUM_USB_CHAN_IN > 0 samplesInPrev[i] = bitrev(sample); -#endif } @@ -513,7 +496,7 @@ static unsigned dummy_deliver(chanend c_out) { return 0; } -void audio(chanend c_mix_out, chanend ?c_dig_rx, chanend ?c_config) +void audio(chanend c_mix_out, chanend ?c_dig_rx, chanend ?c_config, chanend ?c_i2c) { chan c_spdif_out; unsigned curSamFreq = DEFAULT_FREQ; @@ -526,10 +509,10 @@ void audio(chanend c_mix_out, chanend ?c_dig_rx, chanend ?c_config) #endif /* Initialise master clock generation */ - ClockingInit(); + ClockingInit(c_i2c); /* Perform required CODEC/ADC/DAC initialisation */ - CodecInit(c_config); + CodecInit(c_config, c_i2c); while(1) { @@ -548,7 +531,7 @@ void audio(chanend c_mix_out, chanend ?c_dig_rx, chanend ?c_config) divide = mClk / ( curSamFreq * 64 ); /* Configure clocking for required master clock */ - ClockingConfig(mClk); + ClockingConfig(mClk, c_i2c); if(!firstRun) { @@ -568,7 +551,7 @@ void audio(chanend c_mix_out, chanend ?c_dig_rx, chanend ?c_config) firstRun = 0; /* Configure CODEC/DAC/ADC for SampleFreq/MClk */ - CodecConfig(curSamFreq, mClk, c_config); + CodecConfig(curSamFreq, mClk, c_config, c_i2c); /* Configure audio ports */ ConfigAudioPorts(divide); diff --git a/module_usb_aud_shared/clocking/clocking.h b/module_usb_aud_shared/clocking/clocking.h index 88fc786b..a02ebf15 100644 --- a/module_usb_aud_shared/clocking/clocking.h +++ b/module_usb_aud_shared/clocking/clocking.h @@ -5,10 +5,10 @@ /* Functions that handle master clock generation. These need modifying for an existing design */ /* Any initialisation required for master clock generation - run once at start up */ -void ClockingInit(void); +void ClockingInit(chanend ?c); /* Configuration for a specific master clock frequency - run every sample frequency change */ -void ClockingConfig(unsigned mClkFreq); +void ClockingConfig(unsigned mClkFreq, chanend ?c); /** Clock generation and digital audio I/O handling. diff --git a/module_usb_aud_shared/codec/codec.h b/module_usb_aud_shared/codec/codec.h index 452ac900..c97662ec 100644 --- a/module_usb_aud_shared/codec/codec.h +++ b/module_usb_aud_shared/codec/codec.h @@ -6,9 +6,9 @@ /* TODO Are the channel args required? */ /* Any required CODEC initialisation - run once at start up */ -void CodecInit(chanend ?c_codec); +void CodecInit(chanend ?c_codec, chanend ?c_i2c); /* Configure condec for a specific mClk/Sample frquency - run on every sample frequency change */ -void CodecConfig(unsigned samFreq, unsigned mClk, chanend ?c_codec); +void CodecConfig(unsigned samFreq, unsigned mClk, chanend ?c_codec, chanend ?c_i2c); #endif diff --git a/module_usb_aud_shared/devicedefines.h b/module_usb_aud_shared/devicedefines.h index 04a0e3c3..e1c37770 100644 --- a/module_usb_aud_shared/devicedefines.h +++ b/module_usb_aud_shared/devicedefines.h @@ -9,27 +9,6 @@ #include "customdefines.h" -/* Tidy up historical INPUT/OUTPUT defines. INPUT/OUTPUT now enabled based on channel count defines */ -#if !defined(NUM_USB_CHAN_IN) - #error NUM_USB_CHAN_IN must be defined! -#else - #if (NUM_USB_CHAN_IN == 0) - #undef INPUT - #else - #define INPUT 1 - #endif -#endif - -#if !defined(NUM_USB_CHAN_OUT) - #error NUM_USB_CHAN_OUT must be defined! -#else - #if (NUM_USB_CHAN_OUT == 0) - #undef OUTPUT - #else - #define OUTPUT 1 - #endif -#endif - #if defined(MIDI) && (MIDI == 0) #undef MIDI #endif @@ -180,6 +159,12 @@ #define MIDI_INTERFACES (0) #endif +#if defined(IAP) +#define IAP_INTERFACES (1) +#else +#define IAP_INTERFACES (0) +#endif + #define AUDIO_STOP_FOR_DFU (0x12345678) #define AUDIO_START_FROM_DFU (0x87654321) #define AUDIO_REBOOT_FROM_DFU (0xa5a5a5a5) @@ -187,8 +172,8 @@ #define MAX_VOL (0x20000000) -#define NUM_EP_OUT 3 /* Max number of device endpoints used */ -#define NUM_EP_IN 5 +#define NUM_EP_OUT 4 /* Max number of device endpoints used */ +#define NUM_EP_IN 7 /* Length of clock unit/clock-selector units */ #if defined(SPDIF_RX) && defined(ADAT_RX) #define NUM_CLOCKS 3 @@ -200,7 +185,7 @@ /* Total number of USB interfaces this device implements (+1 for required control interface) */ -#define NUM_INTERFACES INPUT_INTERFACES + OUTPUT_INTERFACES + DFU_INTERFACES + MIDI_INTERFACES + 1 +#define NUM_INTERFACES INPUT_INTERFACES + OUTPUT_INTERFACES + DFU_INTERFACES + MIDI_INTERFACES + IAP_INTERFACES + 1 /* Audio Unit ID defines */ #define FU_USBIN 11 /* Feature Unit: USB Audio device -> host */ #define FU_USBOUT 10 /* Feature Unit: USB Audio host -> device*/ @@ -214,18 +199,18 @@ #define ID_CLKSRC_EXT 42 /* Clock source ID (external) */ #define ID_CLKSRC_ADAT 43 /* Clock source ID (external) */ -#define ID_XU_MIXSEL 50 -#define ID_XU_OUT 51 -#define ID_XU_IN 52 +#define ID_XU_MIXSEL 50 +#define ID_XU_OUT 51 +#define ID_XU_IN 52 -#define ID_MIXER_1 60 +#define ID_MIXER_1 60 #ifndef SERIAL_STR -#define SERIAL_STR "0000" /* Serial number string */ +#define SERIAL_STR "0000" /* Serial number string */ #endif -#define SERIAL_STR_INDEX 0x03 -#define MANUFACTURER_STR_INDEX 0x01 +#define SERIAL_STR_INDEX 0x03 +#define MANUFACTURER_STR_INDEX 0x01 #define PRODUCT_STR_INDEX 0x02 /* Mixer defines */ diff --git a/module_usb_aud_shared/endpoint0/audiorequests.xc b/module_usb_aud_shared/endpoint0/audiorequests.xc index f14ecc3d..72145d84 100644 --- a/module_usb_aud_shared/endpoint0/audiorequests.xc +++ b/module_usb_aud_shared/endpoint0/audiorequests.xc @@ -35,25 +35,27 @@ extern int volsIn[]; extern unsigned int mutesIn[]; /* Mixer settings */ +#ifdef MIXER extern unsigned char mixer1Crossbar[]; extern short mixer1Weights[]; /* Device channel mapping */ -#if NUM_USB_CHAN_OUT > 0 extern unsigned char channelMapAud[NUM_USB_CHAN_OUT]; -#endif -#if NUM_USB_CHAN_IN > 0 extern unsigned char channelMapUsb[NUM_USB_CHAN_IN]; -#endif /* Mixer input mapping */ extern unsigned char mixSel[MIX_INPUTS]; +#endif /* Global var for current frequency */ extern unsigned int g_curSamFreq; extern unsigned int g_curSamFreq48000Family; extern unsigned int g_curSamFreqMultiplier; +/* Global level data */ +//unsigned short g_lvlMixOut[MAX_MIX_COUNT]; +//unsigned short g_lvlMixIn[NUM_USB_CHAN_IN + NUM_USB_CHAN_OUT]; + /* Store an int into a char array: Note this allows non-word aligned access unlike reinerpret cast */ void storeInt(unsigned char buffer[], int index, int val) { diff --git a/module_usb_aud_shared/endpoint0/descriptors_2.h b/module_usb_aud_shared/endpoint0/descriptors_2.h index c1b86fee..81561714 100644 --- a/module_usb_aud_shared/endpoint0/descriptors_2.h +++ b/module_usb_aud_shared/endpoint0/descriptors_2.h @@ -170,6 +170,18 @@ unsigned char devQualDesc_Null[] = #define MIDI_LENGTH (0) #endif +#ifdef MIXER +#define MIXER_LENGTH (13+1+18) +#else +#define MIXER_LENGTH (0) +#endif + +#ifdef IAP +#define IAP_LENGTH (30) +#else +#define IAP_LENGTH (0) +#endif + #ifdef AUDIO_PATH_XUS #define LEN_XU_OUT (16 * OUTPUT_INTERFACES) #define LEN_XU_IN (16 * INPUT_INTERFACES) @@ -179,18 +191,9 @@ unsigned char devQualDesc_Null[] = #endif #ifdef MIXER - #define LEN_XU_MIX (17) - #define MIX_BMCONTROLS_LEN_TMP ((MAX_MIX_COUNT * MIX_INPUTS) / 8) - - #if ((MAX_MIX_COUNT * MIX_INPUTS)%8)==0 - #define MIX_BMCONTROLS_LEN (MIX_BMCONTROLS_LEN_TMP) - #else - #define MIX_BMCONTROLS_LEN (MIX_BMCONTROLS_LEN_TMP+1) - #endif - #define MIXER_LENGTH (13+1+MIX_BMCONTROLS_LEN) +#define LEN_XU_MIX (17) #else - #define LEN_XU_MIX (0) - #define MIXER_LENGTH (0) +#define LEN_XU_MIX (0) #endif #define LEN_CLK (8) @@ -216,7 +219,7 @@ unsigned char devQualDesc_Null[] = /* Total length of config descriptor */ -#define CFG_TOTAL_LENGTH_A2 (7 + 26 + (INPUT_INTERFACES * 55) + (OUTPUT_INTERFACES * 62) + (MIDI_LENGTH) + (DFU_INTERFACES * 18) + TLEN_AC + (MIXER_LENGTH) + INPUT_ALT_LENGTH + OUTPUT_ALT_LENGTH) +#define CFG_TOTAL_LENGTH_A2 (7 + 26 + (INPUT_INTERFACES * 55) + (OUTPUT_INTERFACES * 62) + (MIDI_LENGTH) + (DFU_INTERFACES * 16) + TLEN_AC + (MIXER_LENGTH) + IAP_LENGTH + INPUT_ALT_LENGTH + OUTPUT_ALT_LENGTH) /* Define for number of audio interfaces (+1 for mandatory control interface) */ #define AUDIO_INTERFACES (INPUT_INTERFACES + OUTPUT_INTERFACES + 1) @@ -233,7 +236,7 @@ unsigned char cfgDesc_Audio2[] = 0x00, /* 6 iConfiguration */ #ifdef SELF_POWERED 192, /* 7 bmAttributes */ - 5, /* 8 bMaxPower */ + 1, /* 8 bMaxPower */ #else 128, /* 7 bmAttributes */ 250, /* 8 bMaxPower */ @@ -362,7 +365,7 @@ unsigned char cfgDesc_Audio2[] = ID_CLKSEL, /* 7 bCSourceID: ID of Clock Entity */ NUM_USB_CHAN_OUT, /* 8 bNrChannels */ 0,0,0,0, /* 9 bmChannelConfig */ - 15, /* 13 iChannelNames */ + 13, /* 13 iChannelNames */ 0x00, 0x00, /* 14 bmControls */ 6, /* 16 iTerminal */ @@ -481,7 +484,7 @@ unsigned char cfgDesc_Audio2[] = ID_CLKSEL, /* 7 bCSourceID: ID of Clock Entity */ NUM_USB_CHAN_IN, /* 8 bNrChannels */ 0,0,0,0, /* 9 bmChannelConfig */ - 33, /* 13 iChannelNames */ + 31, /* 13 iChannelNames */ 0x00, 0x00, /* 14 bmControls */ 0, /* 16 iTerminal */ @@ -601,7 +604,7 @@ unsigned char cfgDesc_Audio2[] = 2, /* 6 bNrPins */ ID_IT_USB, /* 7 baSourceId(1) */ ID_IT_AUD, /* 7 baSourceId(2) */ - MIX_INPUTS, /* 8+p bNrChannels */ + MIX_INPUTS, /* 8+p bNrChannels */ 0, /* 9+p bmChannelConfig */ 0, /* 10+p bmChannelConfig */ 0, /* 11+p bmChannelConfig */ @@ -615,76 +618,23 @@ unsigned char cfgDesc_Audio2[] = /* Mixer Unit Descriptors */ - /* N = 144 (18 * 8) */ /* Mixer Unit Bitmap - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff */ - MIXER_LENGTH, /* 0 bLength : 13 + num inputs + bit map (inputs * outputs) */ + 0x0D+0x01+0x12, /* 0 bLength : 13 + num inputs + bit map (inputs * outputs) */ CS_INTERFACE, /* 1 bDescriptorType: 0x24 */ 0x04, /* bDescriptorSubtype: MIXER_UNIT */ ID_MIXER_1, /* Mixer unit id */ 0x01, /* Number of input pins */ - ID_XU_MIXSEL, /* Connected terminal or unit id for input pin */ - MAX_MIX_COUNT, /* Number of mixer output channels */ + ID_XU_MIXSEL, /* Connected terminal or unit id for input pin*/ + 0x08, /* Number of mixer output channels */ 0x00, 0x00, 0x00, 0x00, /* Spacial location ???? */ - 49, /* Channel name index */ -#if MIX_BMCONTROLS_LEN > 0 /* Mixer programmable control bitmap */ - 0xff, -#endif -#if MIX_BMCONTROLS_LEN > 1 - 0xff, -#endif -#if MIX_BMCONTROLS_LEN > 2 - 0xff, -#endif -#if MIX_BMCONTROLS_LEN > 3 - 0xff, -#endif -#if MIX_BMCONTROLS_LEN > 4 - 0xff, -#endif -#if MIX_BMCONTROLS_LEN > 5 - 0xff, -#endif -#if MIX_BMCONTROLS_LEN > 6 - 0xff, -#endif -#if MIX_BMCONTROLS_LEN > 7 - 0xff, -#endif -#if MIX_BMCONTROLS_LEN > 8 - 0xff, -#endif -#if MIX_BMCONTROLS_LEN > 9 - 0xff, -#endif -#if MIX_BMCONTROLS_LEN > 10 - 0xff, -#endif -#if MIX_BMCONTROLS_LEN > 11 - 0xff, -#endif -#if MIX_BMCONTROLS_LEN > 12 - 0xff, -#endif -#if MIX_BMCONTROLS_LEN > 13 - 0xff, -#endif -#if MIX_BMCONTROLS_LEN > 14 - 0xff, -#endif -#if MIX_BMCONTROLS_LEN > 15 - 0xff, -#endif -#if MIX_BMCONTROLS_LEN > 16 - 0xff, -#endif -#if MIX_BMCONTROLS_LEN > 17 - 0xff, -#endif -#if MIX_BMCONTROLS_LEN > 18 -#error unxpected BMCONTROLS_LEN -#endif + 49, /* Channel name index */ + 0xff, 0xff, 0xff, 0xff, /* Mixer programmable control bitmap */ + 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0x00, /* bmControls */ 0, /* Mixer unit string descriptor index */ #endif @@ -730,9 +680,9 @@ unsigned char cfgDesc_Audio2[] = 0x00, /* 4 bmControls */ 0x01, /* 5 bFormatType */ PCM, 0x00, 0x00, 0x00, /* 6:10 bmFormats (note this is a bitmap) */ - NUM_USB_CHAN_OUT, /* 11 bNrChannels */ + NUM_USB_CHAN_OUT, /* 11 bNrChannels */ 0,0,0,0, /* 12:14: bmChannelConfig */ - 15, /* 15 iChannelNames */ + 13, /* 15 iChannelNames */ /* Type 1 Format Type Descriptor */ 0x06, /* 0 bLength (in bytes): 6 */ @@ -765,7 +715,7 @@ unsigned char cfgDesc_Audio2[] = 0x81, /* 2 bEndpointAddress (D7: 0:out, 1:in) */ 17, /* 3 bmAttributes (bitmap) */ 4,0, /* 4 wMaxPacketSize */ - 4, /* 6 bInterval. Only values <= 1 frame (8) supported by MS */ + 8, /* 6 bInterval */ #ifdef ADAT_TX /* Standard AS Interface Descriptor (4.9.1) (Alt) */ @@ -789,7 +739,7 @@ unsigned char cfgDesc_Audio2[] = PCM, 0x00, 0x00, 0x00, /* 6:10 bmFormats (note this is a bitmap) */ NUM_USB_CHAN_OUT, /* 11 bNrChannels */ 0,0,0,0, /* 12:14: bmChannelConfig */ - 15, /* 15 iChannelNames */ + 13, /* 15 iChannelNames */ /* Type 1 Format Type Descriptor */ 0x06, /* 0 bLength (in bytes): 6 */ @@ -860,7 +810,7 @@ unsigned char cfgDesc_Audio2[] = PCM, 0x00, 0x00, 0x00, /* 6:10 bmFormats (note this is a bitmap) */ NUM_USB_CHAN_IN, /* 11 bNrChannels */ 0,0,0,0, /* 12:14: bmChannelConfig */ - 33, /* 15 iChannelNames */ + 31, /* 15 iChannelNames */ /* Type 1 Format Type Descriptor */ 0x06, /* 0 bLength (in bytes): 6 */ @@ -909,7 +859,7 @@ unsigned char cfgDesc_Audio2[] = PCM, 0x00, 0x00, 0x00, /* 6:10 bmFormats (note this is a bitmap) */ NUM_USB_CHAN_IN - 4, /* 11 bNrChannels */ 0,0,0,0, /* 12:14: bmChannelConfig */ - 33, /* 15 iChannelNames */ + 31, /* 15 iChannelNames */ /* Type 1 Format Type Descriptor */ 0x06, /* 0 bLength (in bytes): 6 */ @@ -1048,7 +998,7 @@ unsigned char cfgDesc_Audio2[] = 0x02, /* 2 bDescriptorSubtype : MIDI_IN_JACK subtype. (field size 1 bytes) */ 0x02, /* 3 bJackType : EXTERNAL. (field size 1 bytes) */ 0x02, /* 4 bJackID : ID of this Jack. (field size 1 bytes) */ - 14, /* 5 iJack : Unused. (field size 1 bytes) */ + 0x00, /* 5 iJack : Unused. (field size 1 bytes) */ /* Table B-9: MIDI Adapter MIDI OUT Jack Descriptor (Embedded) */ 0x09, /* 0 bLength : Size of this descriptor, in bytes. (field size 1 bytes) */ @@ -1070,7 +1020,7 @@ unsigned char cfgDesc_Audio2[] = 0x01, /* 5 bNrInputPins : Number of Input Pins of this Jack. (field size 1 bytes) */ 0x01, /* 6 BaSourceID(1) : ID of the Entity to which this Pin is connected. (field size 1 bytes) */ 0x01, /* 7 BaSourcePin(1) : Output Pin number of the Entity to which this Input Pin is connected. */ - 13, /* 8 iJack : Unused. (field size 1 bytes) */ + 0x00, /* 8 iJack : Unused. (field size 1 bytes) */ /* Table B-11: MIDI Adapter Standard Bulk OUT Endpoint Descriptor */ 0x09, /* 0 bLength : Size of this descriptor, in bytes. (field size 1 bytes) */ @@ -1118,33 +1068,60 @@ unsigned char cfgDesc_Audio2[] = 0x00, /* 4 bNumEndpoints : 0 endpoints. (field size 1 bytes) */ 0xFE, /* 5 bInterfaceClass : DFU. (field size 1 bytes) */ 0x01, /* 6 bInterfaceSubclass : (field size 1 bytes) */ - 0x01, /* 7 bInterfaceProtocol : Unused. (field size 1 bytes) */ - 12, /* 8 iInterface : Unused. (field size 1 bytes) */ + 0x00, /* 7 bInterfaceProtocol : Unused. (field size 1 bytes) */ + 12, /* 8 iInterface : Used. (field size 1 bytes) */ -#if 0 - /* DFU 1.0 Run-Time DFU Functional Descriptor */ + /* Standard DFU class functional descriptor */ 0x07, 0x21, 0x07, 0xFA, 0x00, 0x40, - 0x00 -#else - /* DFU 1.1 Run-Time DFU Functional Descriptor */ - 0x09, /* 0 Size */ - 0x21, /* 1 bDescriptorType : DFU FUNCTIONAL */ - 0x07, /* 2 bmAttributes */ - 0xFA, /* 3 wDetachTimeOut */ - 0x00, /* 4 wDetachTimeOut */ - 0x40, /* 5 wTransferSize */ - 0x00, /* 6 wTransferSize */ - 0x10, /* 7 bcdDFUVersion */ - 0x01, /* 7 bcdDFUVersion */ - -#endif + 0x00, #endif +#ifdef IAP + /* Please write an iAP descriptor here */ + /* 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+1), /* 2 bInterfaceNumber : Index of this interface. (field size 1 bytes) */ + 0x00, /* 3 bAlternateSetting : Index of this setting. (field size 1 bytes) */ + 0x03, /* 4 bNumEndpoints : 0 endpoints. (field size 1 bytes) */ + 0xFF, /* 5 bInterfaceClass : DFU. (field size 1 bytes) */ + 0xF0, /* 6 bInterfaceSubclass : (field size 1 bytes) */ + 0x00, /* 7 bInterfaceProtocol : Unused. (field size 1 bytes) */ + 57, /* 8 iInterface : Used. (field size 1 bytes) */ + + /* iAP Bulk OUT Endpoint Descriptor */ + 0x07, /* 0 bLength : Size of this descriptor, in bytes. (field size 1 bytes) */ + 0x05, /* 1 bDescriptorType : ENDPOINT descriptor. (field size 1 bytes) */ + 0x03, /* 2 bEndpointAddress : OUT Endpoint 3. High bit isIn (field size 1 bytes) */ + 0x02, /* 3 bmAttributes : Bulk, not shared. (field size 1 bytes) */ + 0x00, /* 4 wMaxPacketSize : 64 bytes per packet. (field size 2 bytes) - has to be 0x200 for compliance*/ + 0x02, /* 5 wMaxPacketSize */ + 0x00, /* 6 bInterval : Ignored for Bulk. Set to zero. (field size 1 bytes) */ + + /* iAP Bulk IN Endpoint Descriptor */ + 0x07, /* 0 bLength : Size of this descriptor, in bytes. (field size 1 bytes) */ + 0x05, /* 1 bDescriptorType : ENDPOINT descriptor. (field size 1 bytes) */ + 0x85, /* 2 bEndpointAddress : IN Endpoint 5. (field size 1 bytes) */ + 0x02, /* 3 bmAttributes : Bulk, not shared. (field size 1 bytes) */ + 0x00, /* 4 wMaxPacketSize : 64 bytes per packet. (field size 2 bytes) - has to be 0x200 for compliance*/ + 0x02, /* 5 wMaxPacketSize */ + 0x00, /* 6 bInterval : Ignored for Bulk. Set to zero. (field size 1 bytes) */ + + /* iAP Interrupt IN Endpoint Descriptor */ + 0x07, /* 0 bLength : Size of this descriptor, in bytes. (field size 1 bytes) */ + 0x05, /* 1 bDescriptorType : ENDPOINT descriptor. (field size 1 bytes) */ + 0x86, /* 2 bEndpointAddress : IN Endpoint 6. (field size 1 bytes) */ + 0x03, /* 3 bmAttributes : Interrupt, not shared. (field size 1 bytes) */ + 0x00, /* 4 wMaxPacketSize : 64 bytes per packet. (field size 2 bytes) - has to be 0x200 for compliance*/ + 0x02, /* 5 wMaxPacketSize */ + 0x08, /* 6 bInterval : in ms must be between 4 and 32ms (field size 1 bytes) */ +#endif + }; #define APPEND_VENDOR_STR(x) VENDOR_STR#x @@ -1168,56 +1145,54 @@ static unsigned char strDescs_Audio2[][40] = APPEND_VENDOR_STR(S/PDIF Clock), // 10 iClockSource APPEND_VENDOR_STR(ADAT Clock), // 11 iClockSource APPEND_VENDOR_STR(DFU), // 12 iInterface for DFU interface - - APPEND_VENDOR_STR(MIDI Out), // 13 - APPEND_VENDOR_STR(MIDI In ), // 14 - "Analogue 1", // 15 Output channel name place holders - Get customised at runtime based on device config - "Analogue 2", // 16 - "Analogue 3", // 17 - "Analogue 4", // 18 - "Analogue 5", // 19 - "Analogue 6", // 20 - "Analogue 7", // 21 - "Analogue 8", // 22 - "Analogue 9", // 23 - "Analogue 10", // 24 - "Analogue 11", // 25 - "Analogue 12", // 26 - "Analogue 13", // 27 - "Analogue 14", // 28 - "Analogue 15", // 29 - "Analogue 16", // 30 - "Analogue 17", // 31 - "Analogue 18", // 32 + "Analogue 1", // 13 Output channel name place holders - Get customised at runtime based on device config + "Analogue 2", // 14 + "Analogue 3", // 15 + "Analogue 4", // 16 + "Analogue 5", // 17 + "Analogue 6", // 18 + "Analogue 7", // 19 + "Analogue 8", // 20 + "Analogue 9", // 21 + "Analogue 10", // 22 + "Analogue 11", // 23 + "Analogue 12", // 24 + "Analogue 13", // 25 + "Analogue 14", // 26 + "Analogue 15", // 27 + "Analogue 16", // 28 + "Analogue 17", // 29 + "Analogue 18", // 30 - "Analogue 1", // 33 Input channel name place holders - Get customised at runtime based on device config */ - "Analogue 2", // 34 Input channel name place holders - Get customised at runtime based on device config */ - "Analogue 3", // 35 Input channel name place holders - Get customised at runtime based on device config */ - "Analogue 4", // 36 Input channel name place holders - Get customised at runtime based on device config */ - "Analogue 5", // 37 Input channel name place holders - Get customised at runtime based on device config */ - "Analogue 6", // 38 Input channel name place holders - Get customised at runtime based on device config */ - "Analogue 7", // 39 Input channel name place holders - Get customised at runtime based on device config */ - "Analogue 8", // 40 Input channel name place holders - Get customised at runtime based on device config */ - "Analogue 9", // 41 Input channel name place holders - Get customised at runtime based on device config */ - "Analogue 10", // 42 Input channel name place holders - Get customised at runtime based on device config */ - "Analogue 11", // 43 Input channel name place holders - Get customised at runtime based on device config */ - "Analogue 12", // 44 Input channel name place holders - Get customised at runtime based on device config */ - "Analogue 13", // 45 Input channel name place holders - Get customised at runtime based on device config */ - "Analogue 14", // 46 Input channel name place holders - Get customised at runtime based on device config */ - "Analogue 15", // 47 Input channel name place holders - Get customised at runtime based on device config */ - "Analogue 16", // 48 Input channel name place holders - Get customised at runtime based on device config */ - "Analogue 17", // 49 Input channel name place holders - Get customised at runtime based on device config */ - "Analogue 18", // 50 Input channel name place holders - Get customised at runtime based on device config */ + "Analogue 1", // 31 Input channel name place holders - Get customised at runtime based on device config */ + "Analogue 2", // 32 Input channel name place holders - Get customised at runtime based on device config */ + "Analogue 3", // 33 Input channel name place holders - Get customised at runtime based on device config */ + "Analogue 4", // 34 Input channel name place holders - Get customised at runtime based on device config */ + "Analogue 5", // 35 Input channel name place holders - Get customised at runtime based on device config */ + "Analogue 6", // 36 Input channel name place holders - Get customised at runtime based on device config */ + "Analogue 7", // 37 Input channel name place holders - Get customised at runtime based on device config */ + "Analogue 8", // 38 Input channel name place holders - Get customised at runtime based on device config */ + "Analogue 9", // 39 Input channel name place holders - Get customised at runtime based on device config */ + "Analogue 10", // 40 Input channel name place holders - Get customised at runtime based on device config */ + "Analogue 11", // 41 Input channel name place holders - Get customised at runtime based on device config */ + "Analogue 12", // 42 Input channel name place holders - Get customised at runtime based on device config */ + "Analogue 13", // 43 Input channel name place holders - Get customised at runtime based on device config */ + "Analogue 14", // 44 Input channel name place holders - Get customised at runtime based on device config */ + "Analogue 15", // 45 Input channel name place holders - Get customised at runtime based on device config */ + "Analogue 16", // 46 Input channel name place holders - Get customised at runtime based on device config */ + "Analogue 17", // 47 Input channel name place holders - Get customised at runtime based on device config */ + "Analogue 18", // 48 Input channel name place holders - Get customised at runtime based on device config */ - "Mixer Out 1", // 51/* Mixer output names */ - "Mixer Out 2", // 52 /* Mixer output names */ - "Mixer Out 3", // 53 /* Mixer output names */ - "Mixer Out 4", // 54 /* Mixer output names */ - "Mixer Out 5", // 55 /* Mixer output names */ - "Mixer Out 6", // 56 /* Mixer output names */ - "Mixer Out 7", // 57 /* Mixer output names */ - "Mixer Out 8", // 58 /* Mixer output names */ + "Mixer Out 1", // 49/* Mixer output names */ + "Mixer Out 2", // 50 /* Mixer output names */ + "Mixer Out 3", // 51 /* Mixer output names */ + "Mixer Out 4", // 52 /* Mixer output names */ + "Mixer Out 5", // 53 /* Mixer output names */ + "Mixer Out 6", // 54 /* Mixer output names */ + "Mixer Out 7", // 55 /* Mixer output names */ + "Mixer Out 8", // 56 /* Mixer output names */ + "iAP Interface", // 57 /* Required name for iAP interface */ }; /* Configuration Descriptor for Null device */ @@ -1235,7 +1210,7 @@ unsigned char cfgDesc_Null[] = #else 128, #endif - 250, /* 8 bMaxPower */ + 1, /* 8 bMaxPower */ 0x09, /* 0 bLength : Size of this descriptor, in bytes. (field size 1 bytes) */ 0x04, /* 1 bDescriptorType : INTERFACE descriptor. (field size 1 bytes) */ @@ -1282,7 +1257,7 @@ unsigned char oSpeedCfgDesc[] = #define STREAMING_INTERFACES (INPUT_INTERFACES + OUTPUT_INTERFACES) -#define CFG_TOTAL_LENGTH_A1 (18 + AC_TOTAL_LENGTH + (INPUT_INTERFACES * 61) + (OUTPUT_INTERFACES * 70) + (DFU_INTERFACES * 18)) +#define CFG_TOTAL_LENGTH_A1 (18 + AC_TOTAL_LENGTH + (INPUT_INTERFACES * 61) + (OUTPUT_INTERFACES * 70) + (DFU_INTERFACES * 16)) #ifdef AUDIO_CLASS_FALLBACK unsigned char cfgDesc_Audio1[] = { @@ -1299,7 +1274,7 @@ unsigned char cfgDesc_Audio1[] = 0x00, /* Unused */ #ifdef SELF_POWERED 192, /* 7 bmAttributes */ - 5, /* 8 bMaxPower */ + 1, /* 8 bMaxPower */ #else 128, /* 7 bmAttributes */ 250, /* 8 bMaxPower */ @@ -1561,19 +1536,19 @@ unsigned char cfgDesc_Audio1[] = 0x00, 0x00, /* Unused */ #endif +#ifdef DFU /* 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+1), /* 2 bInterfaceNumber : Index of this interface. (field size 1 bytes) */ + (INPUT_INTERFACES+OUTPUT_INTERFACES+1), /* 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) */ 0x01, /* 6 bInterfaceSubclass : (field size 1 bytes) */ - 0x01, /* 7 bInterfaceProtocol : Unused. (field size 1 bytes) */ - 8, /* 8 iInterface : Unused. (field size 1 bytes) */ + 0x00, /* 7 bInterfaceProtocol : Unused. (field size 1 bytes) */ + 0x08, /* 8 iInterface : Unused. (field size 1 bytes) */ -#if 0 - /* DFU 1.0 Run-Time DFU Functional Descriptor */ + /* Standard DFU class functional descriptor */ 0x07, 0x21, 0x07, @@ -1581,18 +1556,6 @@ unsigned char cfgDesc_Audio1[] = 0x00, 0x40, 0x00 -#else - /* DFU 1.1 Run-Time DFU Functional Descriptor */ - 0x09, /* 0 Size */ - 0x21, /* 1 bDescriptorType : DFU FUNCTIONAL */ - 0x07, /* 2 bmAttributes */ - 0xFA, /* 3 wDetachTimeOut */ - 0x00, /* 4 wDetachTimeOut */ - 0x40, /* 5 wTransferSize */ - 0x00, /* 6 wTransferSize */ - 0x10, /* 7 bcdDFUVersion */ - 0x01, /* 7 bcdDFUVersion */ - #endif }; diff --git a/module_usb_aud_shared/endpoint0/endpoint0.xc b/module_usb_aud_shared/endpoint0/endpoint0.xc index 51d3c687..a2361f57 100755 --- a/module_usb_aud_shared/endpoint0/endpoint0.xc +++ b/module_usb_aud_shared/endpoint0/endpoint0.xc @@ -20,7 +20,7 @@ #include "vendorrequests.h" #include "dfu_types.h" -/* Windows does not have a built in DFU driver (windows will prompt), so warn that DFU will not be functional in Audio 1.0 mode.Udi +/* Windows does not have a built in DFU driver (windows will prompt), so warn that DFU will not be functional in Audio 1.0 mode. * Of course, OSX is unaffected. */ #if ((AUDIO_CLASS==1) || defined(AUDIO_CLASS_FALLBACK)) && defined(DFU) @@ -63,18 +63,17 @@ int volsIn[NUM_USB_CHAN_IN + 1]; unsigned int mutesIn[NUM_USB_CHAN_IN + 1]; //unsigned int multIn[NUM_USB_CHAN_IN + 1]; +#ifdef MIXER unsigned char mixer1Crossbar[18]; short mixer1Weights[18*8]; //#define MAX_MIX_COUNT 8 unsigned char channelMap[NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN + MAX_MIX_COUNT]; -#if NUM_USB_CHAN_OUT > 0 unsigned char channelMapAud[NUM_USB_CHAN_OUT]; -#endif -#if NUM_USB_CHAN_IN > 0 unsigned char channelMapUsb[NUM_USB_CHAN_IN]; -#endif + unsigned char mixSel[MIX_INPUTS]; +#endif int min(int x, int y); @@ -161,6 +160,7 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, cha mutesIn[i] = 0; } +#ifdef MIXER /* Set up mixer default state */ for (int i = 0; i < 18*8; i++) { mixer1Weights[i] = 0x8001; //-inf @@ -176,20 +176,17 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, cha mixer1Weights[54] = 0; mixer1Weights[63] = 0; -#if NUM_USB_CHAN_OUT > 0 /* Setup up audio output channel mapping */ for(int i = 0; i < NUM_USB_CHAN_OUT; 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; } -#endif + /* Set up channel mapping default */ for (int i = 0; i < NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN; i++) @@ -210,6 +207,7 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, cha { mixSel[i] = i; } +#endif /* Copy langIDs string desc into string[0] */ /* TODO: Macro? */ @@ -221,33 +219,33 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, cha /* Build up channel string table - By default all channels are marked as analogue * TODO We really want to do this an build time... */ #if defined(SPDIF_RX) && (SPDIF_RX_INDEX != 0) - safestrcpy(strDescs_Audio2[SPDIF_RX_INDEX + 33], "S/PDIF 1"); - safestrcpy(strDescs_Audio2[SPDIF_RX_INDEX + 34], "S/PDIF 2"); + safestrcpy(strDescs_Audio2[SPDIF_RX_INDEX + 31], "S/PDIF 1"); + safestrcpy(strDescs_Audio2[SPDIF_RX_INDEX + 32], "S/PDIF 2"); #endif #if defined(ADAT_RX) && (ADAT_RX_INDEX != 0) - safestrcpy(strDescs_Audio2[ADAT_RX_INDEX + 33], "ADAT 1"); - safestrcpy(strDescs_Audio2[ADAT_RX_INDEX + 34], "ADAT 2"); - safestrcpy(strDescs_Audio2[ADAT_RX_INDEX + 35], "ADAT 3"); - safestrcpy(strDescs_Audio2[ADAT_RX_INDEX + 36], "ADAT 4"); - safestrcpy(strDescs_Audio2[ADAT_RX_INDEX + 37], "ADAT 5"); - safestrcpy(strDescs_Audio2[ADAT_RX_INDEX + 38], "ADAT 6"); - safestrcpy(strDescs_Audio2[ADAT_RX_INDEX + 39], "ADAT 7"); - safestrcpy(strDescs_Audio2[ADAT_RX_INDEX + 40], "ADAT 8"); + safestrcpy(strDescs_Audio2[ADAT_RX_INDEX + 31], "ADAT 1"); + safestrcpy(strDescs_Audio2[ADAT_RX_INDEX + 32], "ADAT 2"); + safestrcpy(strDescs_Audio2[ADAT_RX_INDEX + 33], "ADAT 3"); + safestrcpy(strDescs_Audio2[ADAT_RX_INDEX + 34], "ADAT 4"); + safestrcpy(strDescs_Audio2[ADAT_RX_INDEX + 35], "ADAT 5"); + safestrcpy(strDescs_Audio2[ADAT_RX_INDEX + 36], "ADAT 6"); + safestrcpy(strDescs_Audio2[ADAT_RX_INDEX + 37], "ADAT 7"); + safestrcpy(strDescs_Audio2[ADAT_RX_INDEX + 38], "ADAT 8"); #endif #if defined(SPDIF) && (SPDIF_TX_INDEX != 0) /* "Analogue naming gets priority */ - safestrcpy(strDescs_Audio2[SPDIF_TX_INDEX + 15], "S/PDIF 1"); - safestrcpy(strDescs_Audio2[SPDIF_TX_INDEX + 16], "S/PDIF 2"); + safestrcpy(strDescs_Audio2[SPDIF_TX_INDEX + 13], "S/PDIF 1"); + safestrcpy(strDescs_Audio2[SPDIF_TX_INDEX + 14], "S/PDIF 2"); #endif #if defined(ADAT_TX) && (ADAT_TX_INDEX != 0) - safestrcpy(strDescs_Audio2[ADAT_TX_INDEX + 15], "ADAT 1"); - safestrcpy(strDescs_Audio2[ADAT_TX_INDEX + 16], "ADAT 2"); - safestrcpy(strDescs_Audio2[ADAT_TX_INDEX + 17], "ADAT 3"); - safestrcpy(strDescs_Audio2[ADAT_TX_INDEX + 18], "ADAT 4"); - safestrcpy(strDescs_Audio2[ADAT_TX_INDEX + 19], "ADAT 5"); - safestrcpy(strDescs_Audio2[ADAT_TX_INDEX + 20], "ADAT 6"); - safestrcpy(strDescs_Audio2[ADAT_TX_INDEX + 21], "ADAT 7"); - safestrcpy(strDescs_Audio2[ADAT_TX_INDEX + 22], "ADAT 8"); + safestrcpy(strDescs_Audio2[ADAT_TX_INDEX + 13], "ADAT 1"); + safestrcpy(strDescs_Audio2[ADAT_TX_INDEX + 14], "ADAT 2"); + safestrcpy(strDescs_Audio2[ADAT_TX_INDEX + 15], "ADAT 3"); + safestrcpy(strDescs_Audio2[ADAT_TX_INDEX + 16], "ADAT 4"); + safestrcpy(strDescs_Audio2[ADAT_TX_INDEX + 17], "ADAT 5"); + safestrcpy(strDescs_Audio2[ADAT_TX_INDEX + 18], "ADAT 6"); + safestrcpy(strDescs_Audio2[ADAT_TX_INDEX + 19], "ADAT 7"); + safestrcpy(strDescs_Audio2[ADAT_TX_INDEX + 20], "ADAT 8"); #endif #ifdef VENDOR_AUDIO_REQS @@ -492,6 +490,7 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, cha // Handshake //chkct(c_audioControl, XS1_CT_END); + //printint(8); break; #endif @@ -730,7 +729,7 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, cha device_reboot(); } - /* TODO we should not make the assumption that all DFU requests are handled */ + /* TODO we should not make the assumtion that all DFU requests are handled */ retVal = 0; } /* Check for: Audio interface request - always 0, note we check for DFU first @@ -739,7 +738,6 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, cha || (request == CLASS_ENDPOINT_REQUEST && ((interfaceNum == 0x82) || (interfaceNum == 0x01)))) { #endif - #if (AUDIO_CLASS == 2) && defined(AUDIO_CLASS_FALLBACK) if(g_curUsbSpeed == XUD_SPEED_HS) { @@ -772,6 +770,7 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, cha break; default: + // TODO: STALL //printstr("unrecognised request\n"); //printhexln(sp.bRequest); //printhexln(sp.bmRequestType.Type); @@ -793,8 +792,7 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, cha transfer, and the STALL condition terminates at the beginning of the next control transfer (Setup). The remainder of this section refers to the general case of a functional stall */ - XUD_SetStall_Out(0); - XUD_SetStall_In(0); + //XUD_ProtocolStall(ep0_out, ep0_in): } if (retVal < 0) diff --git a/module_usb_aud_shared/i2c/i2c.h b/module_usb_aud_shared/i2c/i2c.h index 6248e914..9c10f969 100644 --- a/module_usb_aud_shared/i2c/i2c.h +++ b/module_usb_aud_shared/i2c/i2c.h @@ -1,4 +1,10 @@ +// Channel interface +void I2cRegWriteC(int deviceAdrs, int Adrs, int WrData, chanend c); + +int I2cRegReadC(int deviceAdrs, int Adrs, chanend c); + +// Function interface void I2cRegWrite(int deviceAdrs, int Adrs, int WrData, port AUD_SCLK, port AUD_SDIN); int I2cRegRead(int deviceAdrs, int Adrs, port AUD_SCLK, port AUD_SDIN); diff --git a/module_usb_aud_shared/i2c/i2c.xc b/module_usb_aud_shared/i2c/i2c.xc index fd252260..48632445 100755 --- a/module_usb_aud_shared/i2c/i2c.xc +++ b/module_usb_aud_shared/i2c/i2c.xc @@ -1,6 +1,28 @@ #include #include +int I2cRegReadC(int device, int addr, chanend c) { + int read; + int retVal; + c <: 0; // isWrite + c <: device; + c <: addr; + c <: 1; // only ever one byte + c :> read; + c :> retVal; + return read; +} + +void I2cRegWriteC(int device, int addr, int data, chanend c) { + int retVal; + c <: 1; // isWrite + c <: device; + c <: addr; + c <: 1; // only ever one byte + c <: data; + c :> retVal; +} + int I2cRegRead(int device, int addr, port scl, port sda) { //int Result; diff --git a/module_usb_aud_shared/pll/pll.h b/module_usb_aud_shared/pll/pll.h index d79ca14f..bc555fcf 100644 --- a/module_usb_aud_shared/pll/pll.h +++ b/module_usb_aud_shared/pll/pll.h @@ -1,4 +1,4 @@ -void PllInit(void); +void PllInit(chanend c); -void PllMult(unsigned mult); +void PllMult(unsigned mult, chanend c); diff --git a/module_usb_aud_shared/usb_buffer/decouple.xc b/module_usb_aud_shared/usb_buffer/decouple.xc index 861f2b0f..fec2fa8c 100644 --- a/module_usb_aud_shared/usb_buffer/decouple.xc +++ b/module_usb_aud_shared/usb_buffer/decouple.xc @@ -1,24 +1,6 @@ -/** - * Module: module_usb_aud_shared - * Version: 2v3 - * Build: 920238b18f6b0967226369682640e1b063865f02 - * File: decouple.xc - * - * The copyrights, all other intellectual and industrial - * property rights are retained by XMOS and/or its licensors. - * Terms and conditions covering the use of this code can - * be found in the Xmos End User License Agreement. - * - * Copyright XMOS Ltd 2010 - * - * In the case where this code is a modification of existing code - * under a separate license, the separate license terms are shown - * below. The modifications to the code are still covered by the - * copyright notice above. - * - **/ #include #include +#include #include "xc_ptr.h" #define NO_INLINE_MIDI_SELECT_HANDLER 1 #include "usb_midi.h" @@ -175,7 +157,7 @@ int int_usb_ep = 0; unsigned int g_midi_to_host_buffer_A[MAX_USB_MIDI_PACKET_SIZE/4+4]; unsigned int g_midi_to_host_buffer_B[MAX_USB_MIDI_PACKET_SIZE/4+4]; -int g_midi_from_host_buffer[MAX_USB_MIDI_PACKET_SIZE+4]; +int g_midi_from_host_buffer[MAX_USB_MIDI_PACKET_SIZE/4+4]; // shared global aud buffering variables @@ -805,18 +787,12 @@ void decouple(chanend c_mix_out, } /* Reset OUT buffer state */ + outOverflow = 0; outUnderflow = 1; SET_SHARED_GLOBAL(g_aud_from_host_rdptr, aud_from_host_fifo_start); SET_SHARED_GLOBAL(g_aud_from_host_wrptr, aud_from_host_fifo_start); SET_SHARED_GLOBAL(aud_data_remaining_to_device, 0); - if(outOverflow) - { - XUD_SetReady(aud_from_host_usb_ep, 1); - outOverflow = 0; - } - - /* Wait for handshake back and pass back up */ chkct(c_mix_out, XS1_CT_END); diff --git a/module_usb_aud_shared/usb_buffer/usb_buffer.h b/module_usb_aud_shared/usb_buffer/usb_buffer.h index 746320c5..2850017d 100644 --- a/module_usb_aud_shared/usb_buffer/usb_buffer.h +++ b/module_usb_aud_shared/usb_buffer/usb_buffer.h @@ -19,7 +19,7 @@ void buffer(chanend c_aud_out, chanend c_aud_in, chanend c_aud_fb, chanend c_midi_from_host, chanend c_midi_to_host, - chanend c_int, + chanend? c_int, chanend c_sof, chanend c_aud_ctl, in port p_off_mclk); diff --git a/module_usb_aud_shared/usb_buffer/usb_buffer.xc b/module_usb_aud_shared/usb_buffer/usb_buffer.xc index 16f8d177..35053cc1 100644 --- a/module_usb_aud_shared/usb_buffer/usb_buffer.xc +++ b/module_usb_aud_shared/usb_buffer/usb_buffer.xc @@ -73,7 +73,7 @@ extern unsigned g_numUsbChanIn; void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud_fb, chanend c_midi_from_host, chanend c_midi_to_host, - chanend c_int, chanend c_sof, + chanend ?c_int, chanend c_sof, chanend c_aud_ctl, in port p_off_mclk ) @@ -85,7 +85,9 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud XUD_ep ep_midi_from_host = XUD_Init_Ep(c_midi_from_host); XUD_ep ep_midi_to_host = XUD_Init_Ep(c_midi_to_host); #endif +#if defined(SPDIF_RX) || defined(ADAT_RX) XUD_ep ep_int = XUD_Init_Ep(c_int); +#endif unsigned datalength; unsigned tmp; @@ -116,7 +118,9 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud set_thread_fast_mode_on(); +#if defined(SPDIF_RX) || defined(ADAT_RX) asm("stw %0, dp[int_usb_ep]"::"r"(ep_int)); +#endif asm("stw %0, dp[aud_from_host_usb_ep]"::"r"(ep_aud_out)); asm("stw %0, dp[aud_to_host_usb_ep]"::"r"(ep_aud_in)); asm("stw %0, dp[buffer_aud_ctl_chan]"::"r"(c_aud_ctl)); @@ -195,6 +199,7 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud /* Wait for response from XUD and service relevant EP */ select { +#if defined(SPDIF_RX) || defined(ADAT_RX) /* Interrupt EP, send back interrupt data. Note, request made from decouple */ case inuint_byref(c_int, tmp): { @@ -221,6 +226,7 @@ void buffer(register chanend c_aud_out, register chanend c_aud_in, chanend c_aud XUD_SetNotReady(ep_int); break; } +#endif /* Sample Freq our chan count update from ep 0 */ case inuint_byref(c_aud_ctl, tmp):