Opts for fitting beclear

This commit is contained in:
Ross Owen
2016-12-05 19:26:14 +00:00
parent 9c5bff58c4
commit ca1925db7a
15 changed files with 224 additions and 121 deletions

View File

@@ -45,9 +45,9 @@ extern unsigned char mixSel[MAX_MIX_COUNT][MIX_INPUTS];
/* Global var for current frequency, set to default freq */
unsigned int g_curSamFreq = DEFAULT_FREQ;
//unsigned int g_curSamFreq48000Family = DEFAULT_FREQ % 48000 == 0;
#if 0
unsigned int g_curSamFreq48000Family = DEFAULT_FREQ % 48000 == 0;
/* Original feedback implementation */
long long g_curSamFreqMultiplier = (DEFAULT_FREQ * 512 * 4) / (DEFAULT_MCLK_FREQ);
#endif
@@ -131,6 +131,7 @@ static void setG_curSamFreqMultiplier(unsigned x)
}
#endif
#if (OUTPUT_VOLUME_CONTROL == 1) || (INPUT_VOLUME_CONTROL == 1)
/* Update master volume i.e. i.e update weights for all channels */
static void updateMasterVol( int unitID, chanend ?c_mix_ctl)
{
@@ -266,6 +267,7 @@ static void updateVol(int unitID, int channel, chanend ?c_mix_ctl)
}
}
}
#endif
/* Handles the audio class specific requests
* returns: XUD_RES_OKAY if request dealt with successfully without error,
@@ -275,7 +277,7 @@ static void updateVol(int unitID, int channel, chanend ?c_mix_ctl)
int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, chanend c_audioControl, chanend ?c_mix_ctl, chanend ?c_clk_ctl
)
{
unsigned char buffer[512];
unsigned char buffer[128];
int unitID;
XUD_Result_t result;
unsigned datalength;
@@ -312,6 +314,7 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
return result;
}
#if MAX_FREQ != MIN_FREQ
if(datalength == 4)
{
/* Re-construct Sample Freq */
@@ -369,7 +372,7 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
/* Allow time for our feedback to stabilise*/
FeedbackStabilityDelay();
}
#endif /* MAX_FREQ != MIN_FREQ */
/* Send 0 Length as status stage */
XUD_DoSetRequestStatus(ep0_in);
}
@@ -514,6 +517,7 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
break;
}
#if (OUTPUT_VOLUME_CONTROL == 1) || (INPUT_VOLUME_CONTROL == 1)
/* Feature Units */
case FU_USBOUT:
case FU_USBIN:
@@ -629,6 +633,7 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
}
break; /* FU_USBIN */
#endif
#if defined(MIXER) && (MAX_MIX_COUNT > 0)
case ID_XU_OUT:
@@ -1076,7 +1081,7 @@ int AudioEndpointRequests_1(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp
*/
XUD_Result_t result;
unsigned char buffer[1024];
unsigned char buffer[128];
unsigned length;
/* Host to Device */
@@ -1094,7 +1099,7 @@ int AudioEndpointRequests_1(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp
{
return result;
}
#if (MAX_FREQ != MIN_FREQ)
if(controlSelector == SAMPLING_FREQ_CONTROL)
{
/* Expect length 3 for sample rate */
@@ -1116,22 +1121,6 @@ int AudioEndpointRequests_1(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp
if(curSamFreq48000Family || curSamFreq44100Family)
{
g_curSamFreq = newSampleRate;
#if 0
/* Original feedback implementation */
int newMasterClock;
if(g_curSamFreq48000Family)
{
newMasterClock = MCLK_48;
}
else
{
newMasterClock = MCLK_441;
}
setG_curSamFreqMultiplier((g_curSamFreq*512*4)/newMasterClock);
#endif
/* Instruct audio thread to change sample freq */
outuint(c_audioControl, SET_SAMPLE_FREQ);
@@ -1147,6 +1136,9 @@ int AudioEndpointRequests_1(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp
return XUD_SetBuffer(ep0_in, buffer, 0);
}
}
#else
return XUD_SetBuffer(ep0_in, buffer, 0);
#endif
}
break;
}
@@ -1171,12 +1163,13 @@ int AudioEndpointRequests_1(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp
int AudioClassRequests_1(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, chanend c_audioControl, chanend ?c_mix_ctl, chanend ?c_clk_ctl
)
{
unsigned char buffer[1024];
unsigned char buffer[128];
unsigned unitID;
XUD_Result_t result;
/* Inspect request */
/* Note we could check sp.bmRequestType.Direction if we wanted to be really careful */
#if (OUTPUT_VOLUME_CONTROL == 1) || (INPUT_VOLUME_CONTROL == 1)
switch(sp.bRequest)
{
case UAC_B_REQ_SET_CUR:
@@ -1288,7 +1281,7 @@ int AudioClassRequests_1(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
buffer[1] = (VOLUME_RES_MIXER >> 8);
return XUD_DoGetRequest(ep0_out, ep0_in, buffer, 2, sp.wLength);
}
#endif
return 1;
}
#endif

View File

@@ -35,13 +35,14 @@ typedef struct
STR_TABLE_ENTRY(vendorStr);
STR_TABLE_ENTRY(serialStr);
#if (AUDIO_CLASS == 2)
/* Audio 2.0 Strings */
STR_TABLE_ENTRY(productStr_Audio2); /* Product string for Audio 2 */
STR_TABLE_ENTRY(outputInterfaceStr_Audio2); /* iInterface for streaming intefaces */
STR_TABLE_ENTRY(inputInterfaceStr_Audio2); /* iInterface for streaming intefaces */
STR_TABLE_ENTRY(usbInputTermStr_Audio2); /* Users sees as output from host */
STR_TABLE_ENTRY(usbOutputTermStr_Audio2); /* User sees as input to host */
#endif
#if defined (AUDIO_CLASS_FALLBACK) || (AUDIO_CLASS == 1)
/* Audio 1.0 Strings */
STR_TABLE_ENTRY(productStr_Audio1); /* Product string for Audio 1 */
@@ -50,6 +51,7 @@ typedef struct
STR_TABLE_ENTRY(usbInputTermStr_Audio1); /* Users sees as output from host */
STR_TABLE_ENTRY(usbOutputTermStr_Audio1); /* User sees as input to host */
#endif
#if (AUDIO_CLASS == 2)
STR_TABLE_ENTRY(clockSelectorStr); /* iClockSel */
STR_TABLE_ENTRY(internalClockSourceStr); /* iClockSource for internal clock */
#ifdef SPDIF_RX
@@ -58,6 +60,7 @@ typedef struct
#ifdef ADAT_RX
STR_TABLE_ENTRY(adatClockSourceStr); /* iClockSource for external S/PDIF clock */
#endif
#endif
#ifdef DFU
STR_TABLE_ENTRY(dfuStr); /* iInterface for DFU interface */
#endif
@@ -291,7 +294,9 @@ typedef struct
#if defined(MIXER) && (MAX_MIX_COUNT > 7)
STR_TABLE_ENTRY(mixOutStr_8);
#endif
#ifdef IAP
STR_TABLE_ENTRY(iAPInterfaceStr);
#endif
#ifdef IAP_EA_NATIVE_TRANS
STR_TABLE_ENTRY(iAP_EANativeTransport_InterfaceStr);
#endif
@@ -302,12 +307,13 @@ StringDescTable_t g_strTable =
.langID = "\x09\x04", /* US English */
.vendorStr = VENDOR_STR,
.serialStr = "",
#if (AUDIO_CLASS == 2)
.productStr_Audio2 = PRODUCT_STR_A2,
.outputInterfaceStr_Audio2 = APPEND_PRODUCT_STR_A2(),
.inputInterfaceStr_Audio2 = APPEND_PRODUCT_STR_A2(),
.usbInputTermStr_Audio2 = APPEND_PRODUCT_STR_A2(),
.usbOutputTermStr_Audio2 = APPEND_PRODUCT_STR_A2(),
#endif
#if defined (AUDIO_CLASS_FALLBACK) || (AUDIO_CLASS == 1)
.productStr_Audio1 = PRODUCT_STR_A1,
.outputInterfaceStr_Audio1 = APPEND_PRODUCT_STR_A1(),
@@ -315,6 +321,7 @@ StringDescTable_t g_strTable =
.usbInputTermStr_Audio1 = APPEND_PRODUCT_STR_A1(),
.usbOutputTermStr_Audio1 = APPEND_PRODUCT_STR_A1(),
#endif
#if (AUDIO_CLASS == 2)
.clockSelectorStr = APPEND_VENDOR_STR(Clock Selector),
.internalClockSourceStr = APPEND_VENDOR_STR(Internal Clock),
#ifdef SPDIF_RX
@@ -323,6 +330,7 @@ StringDescTable_t g_strTable =
#ifdef ADAT_RX
.adatClockSourceStr = APPEND_VENDOR_STR(ADAT Clock),
#endif
#endif
#ifdef DFU
.dfuStr = APPEND_VENDOR_STR(DFU),
#endif
@@ -368,7 +376,9 @@ StringDescTable_t g_strTable =
#if defined(MIXER) && (MAX_MIX_COUNT > 8)
#error
#endif
#ifdef IAP
.iAPInterfaceStr = "iAP Interface",
#endif
#ifdef IAP_EA_NATIVE_TRANS
.iAP_EANativeTransport_InterfaceStr = IAP2_EA_NATIVE_TRANS_PROTOCOL_NAME,
#endif
@@ -397,6 +407,7 @@ USB_Descriptor_Device_t devDesc_Audio1 =
};
#endif
#if (AUDIO_CLASS == 2)
/* Device Descriptor for Audio Class 2.0 (Assumes High-Speed ) */
USB_Descriptor_Device_t devDesc_Audio2 =
{
@@ -438,7 +449,7 @@ unsigned char devDesc_Null[] =
0, /* 16 iSerialNumber : Index of serial number decriptor */
0x01 /* 17 bNumConfigurations : Number of possible configs */
};
#endif
/****** Device Qualifier Descriptors *****/
@@ -751,7 +762,7 @@ typedef struct
}__attribute__((packed)) USB_Config_Descriptor_Audio2_t;
#if 1
#if (AUDIO_CLASS == 2)
USB_Config_Descriptor_Audio2_t cfgDesc_Audio2=
{
.Config =
@@ -2252,7 +2263,10 @@ const unsigned num_freqs_a1 = MAX(3, (0
#define NUM_CONTROL_INTERFACES 0
#endif
#define AC_TOTAL_LENGTH (AC_LENGTH + (INPUT_INTERFACES_A1 * (17 + NUM_USB_CHAN_IN_FS + num_freqs_a1 * 3)) + (OUTPUT_INTERFACES_A1 * (17 + NUM_USB_CHAN_OUT_FS + (num_freqs_a1 *3))))
#define AC_TOTAL_LENGTH (AC_LENGTH + \
(INPUT_INTERFACES_A1 * (9 + (7* INPUT_VOLUME_CONTROL) + (NUM_USB_CHAN_IN_FS * INPUT_VOLUME_CONTROL) + num_freqs_a1 * 3)) +\
(OUTPUT_INTERFACES_A1 * (9 + (7 * OUTPUT_VOLUME_CONTROL) + (NUM_USB_CHAN_OUT_FS * OUTPUT_VOLUME_CONTROL) + (num_freqs_a1 *3))))
#define STREAMING_INTERFACES (INPUT_INTERFACES_A1 + OUTPUT_INTERFACES_A1)
/* Number of interfaces for Audio 1.0 (+1 for control ) */
@@ -2297,7 +2311,7 @@ unsigned char cfgDesc_Audio1[] =
USB_CLASS_AUDIO,
UAC_INT_SUBCLASS_AUDIOCONTROL,
0x00, /* Unused */
8, /* iInterface - re-use iProduct */
offsetof(StringDescTable_t, productStr_Audio1)/sizeof(char *), /* iInterface - re-use iProduct */
/* CS (Class Specific) AudioControl interface header descriptor (4.3.2) */
AC_LENGTH,
@@ -2325,8 +2339,9 @@ unsigned char cfgDesc_Audio1[] =
NUM_USB_CHAN_OUT_FS, /* bNrChannels */
0x03, 0x00, /* wChannelConfig */
offsetof(StringDescTable_t, outputChanStr_1)/sizeof(char *), /* iChannelNames */
11, /* iTerminal */
offsetof(StringDescTable_t, usbInputTermStr_Audio1)/sizeof(char *), /* iTerminal */
#if (OUTPUT_VOLUME_CONTROL == 1)
/* CS_Interface class specific AC interface feature unit descriptor - mute & volume for dac */
(8 + NUM_USB_CHAN_OUT_FS),
UAC_CS_DESCTYPE_INTERFACE,
@@ -2364,6 +2379,7 @@ unsigned char cfgDesc_Audio1[] =
#error NUM_USB_CHAN_OUT_FS > 8 currently supported
#endif
0x00, /* String table index */
#endif
/* CS_Interface Output Terminal Descriptor - Analogue out to speaker */
0x09,
@@ -2372,7 +2388,11 @@ unsigned char cfgDesc_Audio1[] =
0x06, /* Terminal ID */
0x01, 0x03, /* Type - streaming out, speaker */
0x00, /* Associated terminal - unused */
0x0A, /* sourceID */
#if (OUTPUT_VOLUME_CONTROL == 1)
0x0A, /* sourceID - FU */
#else
0x01, /* sourceID - IT */
#endif
0x00, /* Unused */
#endif
@@ -2387,7 +2407,7 @@ unsigned char cfgDesc_Audio1[] =
NUM_USB_CHAN_IN_FS, /* bNrChannels */
0x03, 0x00, /* wChannelConfigs */
offsetof(StringDescTable_t, inputChanStr_1)/sizeof(char *), /* iChannelNames */
12, /* iTerminal */
offsetof(StringDescTable_t, usbOutputTermStr_Audio1)/sizeof(char *), /* iTerminal */
/* CS_Interface Output Terminal Descriptor - USB Streaming Device to Host*/
0x09,
@@ -2396,9 +2416,14 @@ unsigned char cfgDesc_Audio1[] =
0x07, /* Terminal ID */
0x01, 0x01, /* Type - streaming */
0x01, /* Associated terminal - unused */
0x0B, /* sourceID - from selector unit ?? */
#if INPUT_VOLUME_CONTROL
0x0B, /* sourceID - FU */
#else
0x02, /* sourceID - IT */
#endif
0x00, /* Unused */
#if (INPUT_VOLUME_CONTROL == 1)
/* CS_Interface class specific AC interface feature unit descriptor - mute & volume for adc */
(8 + NUM_USB_CHAN_IN_FS),
UAC_CS_DESCTYPE_INTERFACE,
@@ -2436,6 +2461,7 @@ unsigned char cfgDesc_Audio1[] =
#endif
0x00, /* String table index */
#endif
#endif
#if (NUM_USB_CHAN_OUT > 0)
/* Standard AS Interface Descriptor (4.5.1) */
@@ -2447,7 +2473,7 @@ unsigned char cfgDesc_Audio1[] =
0x01, /* bInterfaceClass - AUDIO */
0x02, /* bInterfaceSubclass - AUDIO_STREAMING */
0x00, /* bInterfaceProtocol - Not used */
0x09, /* iInterface */
offsetof(StringDescTable_t, outputInterfaceStr_Audio1)/sizeof(char *), /* iInterface */
/* Standard As Interface Descriptor (4.5.1) */
0x09,
@@ -2462,7 +2488,7 @@ unsigned char cfgDesc_Audio1[] =
0x01, /* Interface class - AUDIO */
0x02, /* subclass - AUDIO_STREAMING */
0x00, /* Unused */
0x09, /* String table index */
offsetof(StringDescTable_t, outputInterfaceStr_Audio1)/sizeof(char *), /* iInterface */
/* Class-Specific AS Interface Descriptor (4.5.2) */
0x07,
@@ -2580,7 +2606,7 @@ unsigned char cfgDesc_Audio1[] =
0x01, /* Interface class - AUDIO */
0x02, /* subclass - AUDIO_STREAMING */
0x00, /* Unused */
0x0A, /* iInterface */
offsetof(StringDescTable_t, inputInterfaceStr_Audio1)/sizeof(char *),
/* Standard Interface Descriptor - Audio streaming IN */
0x09,
@@ -2591,7 +2617,7 @@ unsigned char cfgDesc_Audio1[] =
0x01, /* Interface class - AUDIO */
0x02, /* Subclass - AUDIO_STREAMING */
0x00, /* Unused */
0x0A, /* iInterface*/
offsetof(StringDescTable_t, inputInterfaceStr_Audio1)/sizeof(char *),
/* CS_Interface AC interface header descriptor */
0x07,
@@ -2688,7 +2714,7 @@ unsigned char cfgDesc_Audio1[] =
#ifdef XVSM
/* 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) */
(OUTPUT_INTERFACES_A1 + 2), /* bInterfaceNumber */
0x00, /* 3 bAlternateSetting : Index of this setting. (field size 1 bytes) */

View File

@@ -206,6 +206,8 @@ void Endpoint0(chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
XUD_ep ep0_out = XUD_InitEp(c_ep0_out);
XUD_ep ep0_in = XUD_InitEp(c_ep0_in);
#if 0
/* Dont need to init globals.. */
/* Init tables for volumes (+ 1 for master) */
for(int i = 0; i < NUM_USB_CHAN_OUT + 1; i++)
{
@@ -218,7 +220,7 @@ void Endpoint0(chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
volsIn[i] = 0;
mutesIn[i] = 0;
}
#endif
VendorRequests_Init(VENDOR_REQUESTS_PARAMS);
#ifdef MIXER
@@ -295,7 +297,7 @@ void Endpoint0(chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
{
/* Returns XUD_RES_OKAY for success, XUD_RES_RST for bus reset */
XUD_Result_t result = USB_GetSetupPacket(ep0_out, ep0_in, &sp);
if (result == XUD_RES_OKAY)
{
result = XUD_RES_ERR;
@@ -311,7 +313,7 @@ void Endpoint0(chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
switch (sp.wIndex)
{
/* Check for audio stream from host start/stop */
#if (NUM_USB_CHAN_OUT > 0)
#if (NUM_USB_CHAN_OUT > 0) && (AUDIO_CLASS == 2)
case INTERFACE_NUMBER_AUDIO_OUTPUT:
/* Check the alt is in range */
if(sp.wValue <= OUTPUT_FORMAT_COUNT)
@@ -346,7 +348,7 @@ void Endpoint0(chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
break;
#endif
#if (NUM_USB_CHAN_IN > 0)
#if (NUM_USB_CHAN_IN > 0) && (AUDIO_CLASS == 2)
case INTERFACE_NUMBER_AUDIO_INPUT:
/* Check the alt is in range */
if(sp.wValue <= INPUT_FORMAT_COUNT)
@@ -641,6 +643,8 @@ void Endpoint0(chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
if (!DFU_mode_active)
{
#endif
printintln(2);
#ifdef AUDIO_CLASS_FALLBACK
/* Return Audio 2.0 Descriptors with Audio 1.0 as fallback */
result = USB_StandardRequests(ep0_out, ep0_in,