Merge branch 'master' of github.com:xmos/lib_xua

This commit is contained in:
xross
2018-01-08 11:38:38 +00:00
11 changed files with 101 additions and 73 deletions

View File

@@ -22,7 +22,7 @@
* CODEC configuration functions.
*/
void XUA_AudioHub(chanend ?c_aud
#if defined(SPDIF_TX) && (SPDIF_TX_TILE != AUDIO_IO_TILE)
#if (XUA_SPDIF_TX_EN) && (SPDIF_TX_TILE != AUDIO_IO_TILE)
, chanend c_spdif_tx
#endif
#if(defined(SPDIF_RX) || defined(ADAT_RX))

View File

@@ -299,13 +299,8 @@
/**
* @brief Enables SPDIF Tx. Default: 0 (Disabled)
*/
#ifndef SPDIF_TX
#define SPDIF_TX (0)
#endif
/* Tidy up old SPDIF usage */
#if defined(SPDIF_TX) && (SPDIF_TX == 0)
#undef SPDIF_TX
#ifndef XUA_SPDIF_TX_EN
#define XUA_SPDIF_TX_EN (0)
#endif
/**
@@ -412,10 +407,10 @@
*
* Default: 1 (Enabled)
*/
#if !defined(DFU)
#define DFU (1)
#elif defined(DFU) && (DFU == 0)
#undef DFU
#if !defined(XUA_DFU_EN)
#define XUA_DFU_EN (1)
#elif defined(XUA_DFU_EN) && (XUA_DFU_EN == 0)
#undef XUA_DFU_EN
#endif
/**
@@ -521,21 +516,21 @@
* @brief Device firmware version number in Binary Coded Decimal format: 0xJJMN where JJ: major, M: minor, N: sub-minor version number.
*/
#ifndef BCD_DEVICE_J
#define BCD_DEVICE_J 1
#define BCD_DEVICE_J (1)
#endif
/**
* @brief Device firmware version number in Binary Coded Decimal format: 0xJJMN where JJ: major, M: minor, N: sub-minor version number.
*/
#ifndef BCD_DEVICE_M
#define BCD_DEVICE_M 0
#define BCD_DEVICE_M (0)
#endif
/**
* @brief Device firmware version number in Binary Coded Decimal format: 0xJJMN where JJ: major, M: minor, N: sub-minor version number.
*/
#ifndef BCD_DEVICE_N
#define BCD_DEVICE_N
#define BCD_DEVICE_N (0)
#endif
/**

17
lib_xua/doc/rst/index.rst Normal file
View File

@@ -0,0 +1,17 @@
.. include:: ../../../README.rst
XMOS USB Audio
==============
This document details the XMOS USB Audio Library. This library
enables the development of USB Audio devices on the XMOS xCORE architecture.
This document describes the structure of the library, its basic use
and resources required.
This document assumes familiarity with the XMOS xCORE architecture, the
Universal Serial Bus 2.0 Specification (and related specifications),
the XMOS tool chain and XC language.

View File

@@ -0,0 +1,2 @@
XMOSNEWSTYLE = 1
DOXYGEN_DIRS=../../api

View File

@@ -1,6 +1,6 @@
/**
* @file audio.xc
* @brief XMOS L1/L2 USB 2,0 Audio Reference Design. Audio Functions.
* @file xua_audiohub.xc
* @brief XMOS USB 2.0 Audio Reference Design. Audio Functions.
* @author Ross Owen, XMOS Semiconductor Ltd
*
* This thread handles I2S and pars an additional SPDIF Tx thread. It forwards samples to the SPDIF Tx thread.
@@ -19,7 +19,7 @@
#include "audioports.h"
#include "audiohw.h"
#include "mic_array_conf.h"
#ifdef SPDIF_TX
#if (XUA_SPDIF_TX_EN)
#include "SpdifTransmit.h"
#endif
#ifdef ADAT_TX
@@ -103,7 +103,7 @@ unsigned dsdMode = DSD_MODE_OFF;
extern unsafe port p_mclk_in;
extern in port p_mclk_in2;
#ifdef SPDIF_TX
#if (XUA_SPDIF_TX_EN)
extern buffered out port:32 p_spdif_tx;
#endif
@@ -113,9 +113,12 @@ extern buffered out port:32 p_adat_tx;
extern clock clk_audio_mclk;
extern clock clk_audio_bclk;
extern clock clk_mst_spd;
extern void device_reboot(void);
#if XUA_SPDIF_TX_EN || defined(ADAT_TX)
extern clock clk_mst_spd;
#endif
//extern void device_reboot(void);
#define MAX_DIVIDE_48 (MCLK_48/MIN_FREQ_48/64)
#define MAX_DIVIDE_44 (MCLK_44/MIN_FREQ_44/64)
@@ -816,7 +819,7 @@ unsigned static deliver(chanend ?c_out, chanend ?c_spd_out
/* Request digital data (with prefill) */
outuint(c_dig_rx, 0);
#endif
#if defined(SPDIF_TX) && (NUM_USB_CHAN_OUT > 0)
#if (XUA_SPDIF_TX_EN) && (NUM_USB_CHAN_OUT > 0)
outuint(c_spd_out, samplesOut[SPDIF_TX_INDEX]); /* Forward sample to S/PDIF Tx thread */
unsigned sample = samplesOut[SPDIF_TX_INDEX + 1];
outuint(c_spd_out, sample); /* Forward sample to S/PDIF Tx thread */
@@ -1023,7 +1026,7 @@ unsigned static deliver(chanend ?c_out, chanend ?c_spd_out
return 0;
}
#if defined(SPDIF_TX) && (SPDIF_TX_TILE != AUDIO_IO_TILE)
#if (XUA_SPDIF_TX_EN) && (SPDIF_TX_TILE != AUDIO_IO_TILE)
void SpdifTxWrapper(chanend c_spdif_tx)
{
unsigned portId;
@@ -1102,21 +1105,21 @@ static void dummy_deliver(chanend ?c_out, unsigned &command)
}
void XUA_AudioHub(chanend ?c_mix_out
#if defined(SPDIF_TX) && (SPDIF_TX_TILE != AUDIO_IO_TILE)
chanend c_spdif_out,
#if (XUA_SPDIF_TX_EN) && (SPDIF_TX_TILE != AUDIO_IO_TILE)
, chanend c_spdif_out
#endif
#if (defined(ADAT_RX) || defined(SPDIF_RX))
chanend c_dig_rx,
, chanend c_dig_rx
#endif
#if (XUD_TILE != 0) && (AUDIO_IO_TILE == 0) && (XUA_DFU_EN == 1)
, server interface i_dfu ?dfuInterface
, server interface i_dfu ?dfuInterface
#endif
#if (NUM_PDM_MICS > 0)
, chanend c_pdm_in
, chanend c_pdm_in
#endif
)
{
#if defined (SPDIF_TX) && (SPDIF_TX_TILE == AUDIO_IO_TILE)
#if (XUA_SPDIF_TX_EN) && (SPDIF_TX_TILE == AUDIO_IO_TILE)
chan c_spdif_out;
#endif
#ifdef ADAT_TX
@@ -1152,16 +1155,22 @@ chanend c_dig_rx,
#endif
#ifdef ADAT_TX
/* Share SPDIF clk blk */
configure_clock_src(clk_mst_spd, p_mclk_in);
unsafe
{
configure_clock_src(clk_mst_spd, (port)p_mclk_in);
}
configure_out_port_no_ready(p_adat_tx, clk_mst_spd, 0);
set_clock_fall_delay(clk_mst_spd, 7);
#ifndef SPDIF_TX
#if (XUA_SPDIF_TX_EN == 0)
start_clock(clk_mst_spd);
#endif
#endif
/* Configure ADAT/SPDIF tx ports */
#if defined(SPDIF_TX) && (SPDIF_TX_TILE == AUDIO_IO_TILE)
SpdifTransmitPortConfig(p_spdif_tx, clk_mst_spd, p_mclk_in);
#if (XUA_SPDIF_TX_EN) && (SPDIF_TX_TILE == AUDIO_IO_TILE)
unsafe
{
SpdifTransmitPortConfig(p_spdif_tx, clk_mst_spd, (port)p_mclk_in);
}
#endif
/* Perform required CODEC/ADC/DAC initialisation */
@@ -1307,7 +1316,7 @@ chanend c_dig_rx,
par
{
#if defined(SPDIF_TX) && (SPDIF_TX_TILE == AUDIO_IO_TILE)
#if (XUA_SPDIF_TX_EN) && (SPDIF_TX_TILE == AUDIO_IO_TILE)
{
set_thread_fast_mode_on();
SpdifTransmit(p_spdif_tx, c_spdif_out);
@@ -1321,7 +1330,7 @@ chanend c_dig_rx,
}
#endif
{
#ifdef SPDIF_TX
#if (XUA_SPDIF_TX_EN)
/* Communicate master clock and sample freq to S/PDIF thread */
outuint(c_spdif_out, curSamFreq);
outuint(c_spdif_out, mClk);
@@ -1346,7 +1355,7 @@ chanend c_dig_rx,
outuint(c_adat_out, adatSmuxMode);
#endif
command = deliver(c_mix_out
#ifdef SPDIF_TX
#if (XUA_SPDIF_TX_EN)
, c_spdif_out
#else
, null
@@ -1379,7 +1388,7 @@ chanend c_dig_rx,
curSamRes_DAC = inuint(c_mix_out);
}
#if (XUA_DFU == 1)
#if (XUA_DFU_EN == 1)
/* Currently no more audio will happen after this point */
if ((curSamFreq / AUD_TO_USB_RATIO) == AUDIO_STOP_FOR_DFU)
{
@@ -1412,7 +1421,7 @@ chanend c_dig_rx,
#endif /* NO_USB */
#ifdef SPDIF_TX
#if (XUA_SPDIF_TX_EN)
/* Notify S/PDIF task of impending new freq... */
outct(c_spdif_out, XS1_CT_END);
#endif

View File

@@ -44,7 +44,7 @@ enum USBInterfaceNumber
#if defined(USB_CONTROL_DESCS) && (USB_CONTROL_DESCS != 0)
INTERFACE_NUMBER_MISC_CONTROL,
#endif
#if defined(DFU) && (DFU != 0)
#if defined(XUA_DFU_EN) && (XUA_DFU_EN != 0)
INTERFACE_NUMBER_DFU,
#endif
#if defined(IAP) && (IAP != 0)

View File

@@ -11,6 +11,7 @@
#ifndef NO_USB
#include "xud_device.h" /* Standard descriptor requests */
#include "dfu_types.h"
#include "usbaudio20.h" /* Defines from USB Audio 2.0 spec */
#include "xua_ep0_descriptors.h" /* This devices descriptors */
#include "commands.h"
@@ -52,8 +53,8 @@
#warning DFU_PID not defined, Using PID_AUDIO_2. This is probably fine!
#endif
#if (XUA_DFU == 1)
#include "dfu.h"
#if (XUA_DFU_EN == 1)
#include "xua_dfu.h"
#define DFU_IF_NUM INPUT_INTERFACES + OUTPUT_INTERFACES + MIDI_INTERFACES + 1
extern void device_reboot(chanend);
#endif
@@ -281,7 +282,7 @@ void XUA_Endpoint0(chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
VendorAudioRequestsInit(c_audioControl, c_mix_ctl, c_clk_ctl);
#endif
#if (XUA_DFU == 1)
#if (XUA_DFU_EN == 1)
/* Check if device has started in DFU mode */
if (DFUReportResetState(null))
{
@@ -547,7 +548,7 @@ void XUA_Endpoint0(chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
//unsigned request = (sp.bmRequestType.Recipient ) | (sp.bmRequestType.Type << 5);
/* TODO Check on return value retval = */
#if (XUA_DFU == 1)
#if (XUA_DFU_EN == 1)
unsigned DFU_IF = INTERFACE_NUMBER_DFU;
/* DFU interface number changes based on which mode we are currently running in */
@@ -587,7 +588,7 @@ void XUA_Endpoint0(chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
* - Audio endpoint request (Audio 1.0 Sampling freq requests are sent to the endpoint)
*/
if(((interfaceNum == 0) || (interfaceNum == 1) || (interfaceNum == 2))
#if (XUA_DFU == 1)
#if (XUA_DFU_EN == 1)
&& !DFU_mode_active
#endif
)
@@ -639,7 +640,7 @@ void XUA_Endpoint0(chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
if(result == XUD_RES_ERR)
{
#ifdef DFU
#if (XUA_DFU_EN == 1)
if (!DFU_mode_active)
{
#endif
@@ -750,8 +751,9 @@ void XUA_Endpoint0(chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
cfgDesc_Null, sizeof(cfgDesc_Null),
(char**)&g_strTable, sizeof(g_strTable)/sizeof(char *), &sp, g_curUsbSpeed);
#endif
#if (XUA_DFU_EN == 1)
}
#if (XUA_DFU == 1)
else
{
/* Running in DFU mode - always return same descs for DFU whether HS or FS */
@@ -776,7 +778,7 @@ void XUA_Endpoint0(chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
g_curStreamAlt_Out = 0;
g_curStreamAlt_In = 0;
#if (XUA_DFU == 1)
#if (XUA_DFU_EN == 1)
if (DFUReportResetState(null))
{
if (!DFU_mode_active)

View File

@@ -1,5 +1,5 @@
#include "xua.h"
#if (XUD_DFU == 1)
#if (XUA_DFU_EN == 1)
#include "uac_hwresources.h"
#include <xs1.h>
#include <xclib.h>

View File

@@ -1,5 +1,5 @@
#include "xua.h" /* Device specific defines */
#include "xua.h" /* Device specific defines */
#ifndef EXCLUDE_USB_AUDIO_MAIN
/**
@@ -137,7 +137,7 @@ unsafe
on tile[XUD_TILE] : in port p_for_mclk_count = PORT_MCLK_COUNT;
#endif
#ifdef SPDIF_TX
#if (XUA_SPDIF_TX_EN == 1)
on tile[SPDIF_TX_TILE] : buffered out port:32 p_spdif_tx = PORT_SPDIF_OUT;
#endif
@@ -177,7 +177,7 @@ clock clk_pdm = on tile[PDM_TILE]:
on tile[MIDI_TILE] : clock clk_midi = CLKBLK_MIDI;
#endif
#if defined(SPDIF_TX) || defined(ADAT_TX)
#if XUA_SPDIF_TX_EN || defined(ADAT_TX)
on tile[SPDIF_TX_TILE] : clock clk_mst_spd = CLKBLK_SPDIF_TX;
#endif
@@ -370,8 +370,11 @@ VENDOR_REQUESTS_PARAMS_DEC_
asm("setclk res[%0], %1"::"r"(p_for_mclk_count), "r"(x));
#endif
//:buffer
XUA_Buffer(c_xud_out[ENDPOINT_NUMBER_OUT_AUDIO], /* Audio Out*/
XUA_Buffer(c_xud_out[ENDPOINT_NUMBER_OUT_AUDIO],/* Audio Out*/
#if (NUM_USB_CHAN_IN > 0)
c_xud_in[ENDPOINT_NUMBER_IN_AUDIO], /* Audio In */
#endif
#if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP)
c_xud_in[ENDPOINT_NUMBER_IN_FEEDBACK], /* Audio FB */
#endif
@@ -423,7 +426,7 @@ VENDOR_REQUESTS_PARAMS_DEC_
#endif /* NO_USB */
void usb_audio_io(chanend ?c_aud_in, chanend ?c_adc,
#if defined(SPDIF_TX) && (SPDIF_TX_TILE != AUDIO_IO_TILE)
#if (XUA_SPDIF_TX_EN) && (SPDIF_TX_TILE != AUDIO_IO_TILE)
chanend c_spdif_tx,
#endif
#ifdef MIXER
@@ -433,7 +436,7 @@ void usb_audio_io(chanend ?c_aud_in, chanend ?c_adc,
chanend ?c_adat_rx,
chanend ?c_clk_ctl,
chanend ?c_clk_int
#if (XUD_TILE != 0) && (AUDIO_IO_TILE == 0)
#if (XUD_TILE != 0) && (AUDIO_IO_TILE == 0) && (XUA_DFU_EN == 1)
, server interface i_dfu ?dfuInterface
#endif
#if (NUM_PDM_MICS > 0)
@@ -469,11 +472,11 @@ void usb_audio_io(chanend ?c_aud_in, chanend ?c_adc,
#define AUDIO_CHANNEL c_aud_in
#endif
XUA_AudioHub(AUDIO_CHANNEL
#if defined(SPDIF_TX) && (SPDIF_TX_TILE != AUDIO_IO_TILE)
c_spdif_tx,
#if (XUA_SPDIF_TX_EN) && (SPDIF_TX_TILE != AUDIO_IO_TILE)
, c_spdif_tx
#endif
#if defined(SPDIF_RX) || defined(ADAT_RX)
c_dig_rx,
, c_dig_rx
#endif
#if (XUD_TILE != 0) && (AUDIO_IO_TILE == 0) && (XUA_DFU_EN == 1)
, dfuInterface
@@ -545,7 +548,7 @@ int main()
#define c_adat_rx null
#endif
#if defined(SPDIF_TX) && (SPDIF_TX_TILE != AUDIO_IO_TILE)
#if (XUA_SPDIF_TX_EN) && (SPDIF_TX_TILE != AUDIO_IO_TILE)
chan c_spdif_tx;
#endif
@@ -558,7 +561,7 @@ int main()
#define c_clk_ctl null
#endif
#ifdef DFU
#if (XUA_DFU_EN == 1)
interface i_dfu dfuInterface;
#else
#define dfuInterface null
@@ -583,7 +586,7 @@ int main()
{
#if (XUD_TILE == 0)
/* Check if USB is on the flash tile (tile 0) */
#ifdef DFU
#if (XUA_DFU_EN == 1)
[[distribute]]
DFUHandler(dfuInterface, null);
#endif
@@ -617,7 +620,7 @@ int main()
p_mclk_in = p_mclk_in_;
}
usb_audio_io(c_mix_out, c_adc
#if defined(SPDIF_TX) && (SPDIF_TX_TILE != AUDIO_IO_TILE)
#if (XUA_SPDIF_TX_EN) && (SPDIF_TX_TILE != AUDIO_IO_TILE)
, c_spdif_tx
#endif
#ifdef MIXER
@@ -633,7 +636,7 @@ int main()
);
}
#if defined(SPDIF_TX) && (SPDIF_TX_TILE != AUDIO_IO_TILE)
#if (XUA_SPDIF_TX_EN) && (SPDIF_TX_TILE != AUDIO_IO_TILE)
on tile[SPDIF_TX_TILE]:
{
thread_speed();

View File

@@ -76,7 +76,7 @@ void pdm_buffer(streaming chanend c_ds_output[2], chanend c_audio)
mic_array_frame_time_domain * unsafe current;
mic_array_decimator_config_t dc[2];
/* Get initial sample-rate and compute decimation factor */
/* Get initial sample-rate to run this thread at and compute decimation factor */
c_audio :> samplerate;
unsigned decimationfactor = 96000/samplerate;

View File

@@ -60,7 +60,7 @@ typedef struct
STR_TABLE_ENTRY(adatClockSourceStr); /* iClockSource for external S/PDIF clock */
#endif
#endif
#ifdef DFU
#if (XUA_DFU_EN == 1)
STR_TABLE_ENTRY(dfuStr); /* iInterface for DFU interface */
#endif
#ifdef USB_CONTROL_DESCS
@@ -333,7 +333,7 @@ StringDescTable_t g_strTable =
.adatClockSourceStr = APPEND_VENDOR_STR(ADAT Clock),
#endif
#endif
#ifdef DFU
#if (XUA_DFU_EN == 1)
.dfuStr = APPEND_VENDOR_STR(DFU),
#endif
#ifdef USB_CONTROL_DESCS
@@ -517,7 +517,7 @@ unsigned char devQualDesc_Null[] =
#define MIDI_LENGTH (0)
#endif
#ifdef DFU
#if (XUA_DFU_EN == 1)
#define DFU_LENGTH (18)
#else
#define DFU_LENGTH (0)
@@ -739,7 +739,7 @@ typedef struct
unsigned char configDesc_Midi[MIDI_LENGTH];
#endif
#ifdef DFU
#if (XUA_DFU_EN == 1)
/* DFU descriptors currently handled as a single block */
unsigned char configDesc_DFU[DFU_LENGTH];
#endif
@@ -1978,14 +1978,14 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2=
},
#endif
#ifdef DFU
#if (XUA_DFU_EN == 1)
/* 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) */
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) */
0xFE, /* 5 bInterfaceClass : DFU. (Application Specific) (field size 1 bytes) */
0x01, /* 6 bInterfaceSubclass : (field size 1 bytes) */
0x01, /* 7 bInterfaceProtocol : Unused. (field size 1 bytes) */
offsetof(StringDescTable_t, dfuStr)/sizeof(char *), /* 8 iInterface */
@@ -2268,7 +2268,7 @@ const unsigned num_freqs_a1 = MAX(3, (0
#define NUM_CONTROL_USB_INTERFACES 0
#endif
#if (DFU == 1) && (FORCE_UAC1_DFU == 1)
#if (XUA_DFU_EN == 1) && (FORCE_UAC1_DFU == 1)
#define DFU_INTERFACE_BYTES 18
#define DFU_INTERFACES_A1 1
#else
@@ -2741,7 +2741,7 @@ unsigned char cfgDesc_Audio1[] =
0x00, 0x00, /* Unused */
#endif
#if (DFU == 1) && (FORCE_UAC1_DFU == 1)
#if (XUA_DFU_EN == 1) && (FORCE_UAC1_DFU == 1)
/* NOTE: By default we turn off DFU in UAC1.0 mode for a better user experiance in Windows */
@@ -2751,7 +2751,7 @@ unsigned char cfgDesc_Audio1[] =
(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) */
0xFE, /* 5 bInterfaceClass : DFU. (Application Specific) (field size 1 bytes) */
0x01, /* 6 bInterfaceSubclass : (field size 1 bytes) */
0x01, /* 7 bInterfaceProtocol : Unused. (field size 1 bytes) */
offsetof(StringDescTable_t, dfuStr)/sizeof(char *), /* 8 iInterface */
@@ -2775,7 +2775,7 @@ unsigned char cfgDesc_Audio1[] =
(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) */
USB_CLASS_VENDOR_SPECIFIC, /* 5 bInterfaceClass : Vendor specific. (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 */