From 7f3f1e75b50c065dfa3dbdf3f8363a4f7ac4085a Mon Sep 17 00:00:00 2001 From: xross Date: Wed, 1 Nov 2017 16:06:05 +0000 Subject: [PATCH] Various manual updates pulled over from sc_usb_audio --- examples/app_xua_simple/src/app_xua_simple.xc | 17 ++++- lib_xua/src/core/endpoint0/descriptor_defs.h | 5 +- lib_xua/src/core/main.xc | 68 ++++++++++++++----- lib_xua/src/core/xua_ep0_descriptors.h | 26 +++---- 4 files changed, 82 insertions(+), 34 deletions(-) diff --git a/examples/app_xua_simple/src/app_xua_simple.xc b/examples/app_xua_simple/src/app_xua_simple.xc index b213bfd6..549db580 100644 --- a/examples/app_xua_simple/src/app_xua_simple.xc +++ b/examples/app_xua_simple/src/app_xua_simple.xc @@ -21,7 +21,14 @@ buffered in port:32 p_i2s_adc[] = {PORT_I2S_ADC0}; /* I2S Data-line(s) */ buffered out port:32 p_lrclk = PORT_I2S_LRCLK; /* I2S Bit-clock */ buffered out port:32 p_bclk = PORT_I2S_BCLK; /* I2S L/R-clock */ -port p_mclk_in = PORT_MCLK_IN; /* Audio master clock input */ +/* Note, declared unsafe as sometimes we want to share this port +e.g. PDM mics and I2S use same master clock IO */ +port p_mclk_in_ = PORT_MCLK_IN; + +unsafe +{ + unsafe port p_mclk_in; /* Audio master clock input */ +} in port p_for_mclk_count = PORT_MCLK_COUNT; /* Extra port for counting master clock ticks */ @@ -67,7 +74,13 @@ int main() on tile[1]: XUA_Buffer(c_ep_out[1], c_ep_in[1], c_sof, c_aud_ctl, p_for_mclk_count, c_aud); /* IOHub core does most of the audio IO i.e. I2S (also serves as a hub for all audio) */ - on tile[0]: XUA_AudioHub(c_aud); + on tile[0]: { + unsafe + { + p_mclk_in = p_mclk_in_; + } + XUA_AudioHub(c_aud); + } } return 0; diff --git a/lib_xua/src/core/endpoint0/descriptor_defs.h b/lib_xua/src/core/endpoint0/descriptor_defs.h index 390a66b0..cdf6f0da 100644 --- a/lib_xua/src/core/endpoint0/descriptor_defs.h +++ b/lib_xua/src/core/endpoint0/descriptor_defs.h @@ -27,8 +27,6 @@ #define ENDPOINT_ADDRESS_OUT_IAP (ENDPOINT_NUMBER_OUT_IAP) #define ENDPOINT_ADDRESS_OUT_IAP_EA_NATIVE_TRANS (ENDPOINT_NUMBER_OUT_IAP_EA_NATIVE_TRANS) - - /* Interface numbers enum */ enum USBInterfaceNumber { @@ -43,6 +41,9 @@ enum USBInterfaceNumber INTERFACE_NUMBER_MIDI_CONTROL, INTERFACE_NUMBER_MIDI_STREAM, #endif +#if defined(USB_CONTROL_DESCS) && (USB_CONTROL_DESCS != 0) + INTERFACE_NUMBER_MISC_CONTROL, +#endif #if defined(DFU) && (DFU != 0) INTERFACE_NUMBER_DFU, #endif diff --git a/lib_xua/src/core/main.xc b/lib_xua/src/core/main.xc index 4e467a3c..11ffe228 100755 --- a/lib_xua/src/core/main.xc +++ b/lib_xua/src/core/main.xc @@ -127,8 +127,19 @@ on tile[AUDIO_IO_TILE] : buffered in port:32 p_lrclk = PORT_I2S_LRCLK; on tile[AUDIO_IO_TILE] : buffered in port:32 p_bclk = PORT_I2S_BCLK; #endif -on tile[AUDIO_IO_TILE] : port p_mclk_in = PORT_MCLK_IN; +/* Note, declared unsafe as sometimes we want to share this port +e.g. PDM mics and I2S use same master clock IO */ +on tile[AUDIO_IO_TILE] : port p_mclk_in_ = PORT_MCLK_IN; + +/* TODO p_mclk_in should be delared as an unsafe resource */ +unsafe +{ + unsafe port p_mclk_in; +} + +#ifndef NO_USB on tile[XUD_TILE] : in port p_for_mclk_count = PORT_MCLK_COUNT; +#endif #ifdef SPDIF_TX on tile[SPDIF_TX_TILE] : buffered out port:32 p_spdif_tx = PORT_SPDIF_OUT; @@ -161,7 +172,11 @@ on tile[MIDI_TILE] : buffered in port:1 p_midi_rx = PORT_MIDI_IN; #endif #endif -/* Clock blocks */ +/*** Clock blocks ***/ +#if (NUM_PDM_MICS > 0) +clock clk_pdm = on tile[PDM_TILE]: XS1_CLKBLK_1; +#endif + #ifdef MIDI on tile[MIDI_TILE] : clock clk_midi = CLKBLK_MIDI; #endif @@ -183,7 +198,7 @@ on tile[XUD_TILE] : clock clk_adat_rx = CLKBLK_ADAT_RX; on tile[AUDIO_IO_TILE] : clock clk_audio_mclk = CLKBLK_MCLK; /* Master clock */ -#if(AUDIO_IO_TILE != XUD_TILE) +#if(AUDIO_IO_TILE != XUD_TILE) && !defined(NO_USB) on tile[XUD_TILE] : clock clk_audio_mclk2 = CLKBLK_MCLK; /* Master clock */ on tile[XUD_TILE] : in port p_mclk_in2 = PORT_MCLK_IN2; #endif @@ -340,6 +355,12 @@ VENDOR_REQUESTS_PARAMS_DEC_ unsigned x; thread_speed(); + /* TODO p_mclk_in should be delared as an unsafe resource */ + unsafe + { + p_mclk_in = p_mclk_in_; + } + /* Attach mclk count port to mclk clock-block (for feedback) */ //set_port_clock(p_for_mclk_count, clk_audio_mclk); #if(AUDIO_IO_TILE != XUD_TILE) @@ -347,7 +368,8 @@ VENDOR_REQUESTS_PARAMS_DEC_ set_port_clock(p_for_mclk_count, clk_audio_mclk2); start_clock(clk_audio_mclk2); #else - /* Uses same clock-block as I2S */ + /* Clock port from same clock-block as I2S */ + /* TODO remove asm() */ asm("ldw %0, dp[clk_audio_mclk]":"=r"(x)); asm("setclk res[%0], %1"::"r"(p_for_mclk_count), "r"(x)); #endif @@ -429,7 +451,6 @@ void usb_audio_io(chanend ?c_aud_in, chanend ?c_adc, #if (NUM_PDM_MICS > 0) , chanend c_pdm_pcm #endif - , client audManage_if i_audMan ) { #ifdef MIXER @@ -472,7 +493,6 @@ void usb_audio_io(chanend ?c_aud_in, chanend ?c_adc, #if (NUM_PDM_MICS > 0) , c_pdm_pcm #endif - , i_audMan ); } @@ -565,8 +585,6 @@ int main() #endif #endif - interface audManage_if i_audMan; - USER_MAIN_DECLARATIONS par { @@ -603,22 +621,29 @@ int main() #endif /* NO_USB */ } - on tile[AUDIO_IO_TILE]: usb_audio_io(c_mix_out, c_adc + on tile[AUDIO_IO_TILE]: + { + /* TODO p_mclk_in should be delared as an unsafe resource */ + unsafe + { + p_mclk_in = p_mclk_in_; + } + usb_audio_io(c_mix_out, c_adc #if defined(SPDIF_TX) && (SPDIF_TX_TILE != AUDIO_IO_TILE) - , c_spdif_tx + , c_spdif_tx #endif #ifdef MIXER - , c_mix_ctl + , c_mix_ctl #endif - , c_spdif_rx, c_adat_rx, c_clk_ctl, c_clk_int + , c_spdif_rx, c_adat_rx, c_clk_ctl, c_clk_int #if (XUD_TILE != 0) && (AUDIO_IO_TILE == 0) - , dfuInterface + , dfuInterface #endif #if (NUM_PDM_MICS > 0) - , c_pdm_pcm + , c_pdm_pcm #endif - , i_audMan - ); + ); + } #if defined(SPDIF_TX) && (SPDIF_TX_TILE != AUDIO_IO_TILE) on tile[SPDIF_TX_TILE]: @@ -690,7 +715,16 @@ int main() #ifndef PDM_RECORD #if (NUM_PDM_MICS > 0) - on stdcore[PDM_TILE]: pdm_mic(c_ds_output); + + on stdcore[PDM_TILE]: + { + /* TODO p_mclk_in should be delared as an unsafe resource */ + unsafe + { + p_mclk_in = p_mclk_in_; + } + pdm_mic(c_ds_output); + } #ifdef MIC_PROCESSING_USE_INTERFACE on stdcore[PDM_TILE].core[0]: pdm_buffer(c_ds_output, c_pdm_pcm, i_mic_process); #else diff --git a/lib_xua/src/core/xua_ep0_descriptors.h b/lib_xua/src/core/xua_ep0_descriptors.h index f5632cc3..67adf398 100644 --- a/lib_xua/src/core/xua_ep0_descriptors.h +++ b/lib_xua/src/core/xua_ep0_descriptors.h @@ -2262,10 +2262,10 @@ const unsigned num_freqs_a1 = MAX(3, (0 #ifdef USB_CONTROL_DESCS #define CONTROL_INTERFACE_BYTES 9 -#define NUM_CONTROL_INTERFACES 1 +#define NUM_CONTROL_USB_INTERFACES 1 #else #define CONTROL_INTERFACE_BYTES 0 -#define NUM_CONTROL_INTERFACES 0 +#define NUM_CONTROL_USB_INTERFACES 0 #endif #if (DFU == 1) && (FORCE_UAC1_DFU == 1) @@ -2300,7 +2300,7 @@ const unsigned num_freqs_a1 = MAX(3, (0 /* Number of interfaces for Audio 1.0 (+1 for control ) */ /* Note, this is different that INTERFACE_COUNT since we dont support items such as MIDI, iAP etc in UAC1 mode */ -#define NUM_INTERFACES_A1 (1+INPUT_INTERFACES_A1 + OUTPUT_INTERFACES_A1+NUM_CONTROL_INTERFACES+DFU_INTERFACES_A1) +#define NUM_INTERFACES_A1 (1+INPUT_INTERFACES_A1 + OUTPUT_INTERFACES_A1+NUM_CONTROL_USB_INTERFACES+DFU_INTERFACES_A1) #if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) #define CFG_TOTAL_LENGTH_A1 (18 + AC_TOTAL_LENGTH + (INPUT_INTERFACES_A1 * (49 + num_freqs_a1 * 3)) + (OUTPUT_INTERFACES_A1 * (58 + num_freqs_a1 * 3)) + CONTROL_INTERFACE_BYTES + DFU_INTERFACE_BYTES) @@ -2748,7 +2748,7 @@ unsigned char cfgDesc_Audio1[] = /* 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) */ - (OUTPUT_INTERFACES_A1 + INPUT_INTERFACES_A1 + NUM_CONTROL_INTERFACES + 1), /* 2 bInterfaceNumber : Index of this interface. (field size 1 bytes) */ + (OUTPUT_INTERFACES_A1 + INPUT_INTERFACES_A1 + NUM_CONTROL_USB_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) */ @@ -2765,19 +2765,19 @@ unsigned char cfgDesc_Audio1[] = 0x40, /* 5 wTransferSize */ 0x00, /* 6 wTransferSize */ 0x10, /* 7 bcdDFUVersion */ - 0x01, /* 7 bcdDFUVersion */ + 0x01, /* 7 bcdDFUVersion */ #endif #ifdef USB_CONTROL_DESCS /* 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) */ - (OUTPUT_INTERFACES_A1 + INPUT_INTERFACES_A1 + 1), /* 2 bInterfaceNumber */ - 0x00, /* 3 bAlternateSetting : Index of this setting. (field size 1 bytes) */ - 0x00, /* 4 bNumEndpoints : 0 endpoints. (field size 1 bytes) */ - 0xFF, /* 5 bInterfaceClass : DFU. (field size 1 bytes) */ - 0xFF, /* 6 bInterfaceSubclass : (field size 1 bytes) */ - 0xFF, /* 7 bInterfaceProtocol : Unused. (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 + INPUT_INTERFACES_A1 + 1), /* 2 bInterfaceNumber */ + 0x00, /* 3 bAlternateSetting : Index of this setting. (field size 1 bytes) */ + 0x00, /* 4 bNumEndpoints : 0 endpoints. (field size 1 bytes) */ + 0xFF, /* 5 bInterfaceClass : DFU. (field size 1 bytes) */ + 0xFF, /* 6 bInterfaceSubclass : (field size 1 bytes) */ + 0xFF, /* 7 bInterfaceProtocol : Unused. (field size 1 bytes) */ offsetof(StringDescTable_t, ctrlStr)/sizeof(char *), /* 8 iInterface */ #endif