Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib_xua/api/xua_audiohub.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
void XUA_AudioHub(
NULLABLE_RESOURCE(chanend, c_aud),
NULLABLE_RESOURCE(clock, clk_audio_mclk),
NULLABLE_RESOURCE(clock, clk_audio_bclk), NULLABLE_RESOURCE(in_port_t, p_mclk_in)
NULLABLE_RESOURCE(clock, clk_audio_bclk)
, NULLABLE_RESOURCE(in_port_t, p_mclk_in)
, NULLABLE_RESOURCE(i2s_clk_port_type, p_lrclk)
, NULLABLE_RESOURCE(i2s_clk_port_type, p_bclk)
, NULLABLE_ARRAY_OF_SIZE(out_buffered_port_32_t, p_i2s_dac, I2S_WIRES_DAC)
Expand All @@ -75,6 +76,9 @@ void XUA_AudioHub(
#if (XUA_NUM_PDM_MICS > 0 || defined(__DOXYGEN__))
, chanend c_pdm_in
#endif
#if (XUA_PWM_CHANNELS > 0) || defined(__DOXYGEN__)
, chanend c_pwm_channels
#endif
);

void SpdifTxWrapper(chanend c_spdif_tx);
Expand Down
30 changes: 30 additions & 0 deletions lib_xua/api/xua_conf_default.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@
#define SPDIF_TX_TILE AUDIO_IO_TILE
#endif

/**
* @brief Location (tile) of SPDIF Tx. Default: XUD_TILE
*/
#ifndef PWM_CHANNELS_TILE
#define PWM_CHANNELS_TILE XUD_TILE
#endif

/**
* @brief Location (tile) of PDM Rx. Default: AUDIO_IO_TILE
*/
Expand Down Expand Up @@ -85,6 +92,27 @@
#define XUA_NUM_PDM_MICS (0)
#endif

/**
* @brief Number of PWM output channels in the design. Must be 2 or 0.
*
* Default: 0
*/
#ifndef XUA_NUM_PWM_CHANNELS
#define XUA_NUM_PWM_CHANNELS (0)
#endif
#if (XUA_NUM_PWM_CHANNELS != 0 && XUA_NUM_PWM_CHANNELS != 2)
#error "Only none or two PWM channels supported at present"
#endif

/**
* @brief Defines which output channels (stereo) should be output on PWM. Note, Output channels indexed from 0.
*
* Default: 0 (i.e. channels 0 & 1)
* */
#ifndef PWM_CHANNELS_INDEX
#define PWM_CHANNELS_INDEX (0)
#endif

/**
* @brief Number of DSD output channels.
*
Expand Down Expand Up @@ -124,6 +152,8 @@
#define I2S_WIRES_ADC (I2S_CHANS_ADC / I2S_CHANS_PER_FRAME)
#endif

#define XUA_I2S_EN ((I2S_WIRES_ADC) > 0 || (I2S_WIRES_DAC) > 0)

/*
* Defines relating to the interface to external audio hardware i.e. DAC/ADC
*/
Expand Down
40 changes: 40 additions & 0 deletions lib_xua/api/xua_pwm_conf_default.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#ifndef _xua_pwm_conf_default_h_
#define _xua_pwm_conf_default_h_

#ifdef __xua_pwm_conf_h_exists__
#include "xua_pwm_conf.h"
#endif

#ifndef XUA_PWM_SD_COEFFS
#define XUA_PWM_SD_COEFFS sd_coeffs_o6_f1_5_n8
#endif

#ifndef XUA_PWM_SCALE
#define XUA_PWM_SCALE 2.8544
#endif

#ifndef XUA_PWM_LIMIT
#define XUA_PWM_LIMIT 2.8684735298
#endif

#ifndef XUA_PWM_FLAT_COMP_X2
#define XUA_PWM_FLAT_COMP_X2 (-1.0/29000)
#endif

#ifndef XUA_PWM_FLAT_COMP_X3
#define XUA_PWM_FLAT_COMP_X3 (1.0/120000)
#endif

#ifndef XUA_PWM_PWM_COMP_X2
#define XUA_PWM_PWM_COMP_X2 (-3.0/190)
#endif

#ifndef XUA_PWM_PWM_COMP_X3
#define XUA_PWM_PWM_COMP_X3 (0.63/80)
#endif

#ifndef XUA_PWM_NEGATE
#define XUA_PWM_NEGATE 1
#endif

#endif
2 changes: 1 addition & 1 deletion lib_xua/lib_build_info.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ set(LIB_INCLUDES api
src/core/user/hostactive
src/hid
src/midi)
set(LIB_OPTIONAL_HEADERS xua_conf.h static_hid_report.h)
set(LIB_OPTIONAL_HEADERS xua_conf.h static_hid_report.h xua_pwm_conf.h)
set(LIB_DEPENDENT_MODULES "lib_adat(2.0.1)"
"lib_locks(2.3.1)"
"lib_logging(3.3.1)"
Expand Down
53 changes: 46 additions & 7 deletions lib_xua/src/core/audiohub/xua_audiohub.xc
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ static inline int HandleSampleClock(int frameCount, buffered _XUA_CLK_DIR port:3

#pragma unsafe arrays
unsigned static AudioHub_MainLoop(chanend ?c_out, chanend ?c_spd_out
#if (XUA_PWM_CHANNELS > 0)
, chanend c_pwm_channels
#endif
#if (XUA_ADAT_TX_EN)
, chanend c_adat_out
, unsigned adatSmuxMode
Expand Down Expand Up @@ -407,6 +410,10 @@ unsigned static AudioHub_MainLoop(chanend ?c_out, chanend ?c_spd_out
outuint(c_spd_out, samplesOut[SPDIF_TX_INDEX]); /* Forward samples to S/PDIF Tx thread */
outuint(c_spd_out, samplesOut[SPDIF_TX_INDEX + 1]);
#endif
#if (XUA_PWM_CHANNELS > 0) && (NUM_USB_CHAN_OUT > 0)
outuint(c_pwm_channels, samplesOut[PWM_CHANNELS_INDEX]); /* Forward samples to PWM generator threads */
outuint(c_pwm_channels, samplesOut[PWM_CHANNELS_INDEX + 1]);
#endif

#if (XUA_NUM_PDM_MICS > 0)
if ((AUD_TO_MICS_RATIO - 1) == audioToMicsRatioCounter)
Expand Down Expand Up @@ -567,11 +574,15 @@ void testct_byref(chanend c, int &returnVal)
returnVal = 1;
}

#if (XUA_DFU_EN == 1) && ((NUM_USB_CHAN_OUT > 0) || (NUM_USB_CHAN_IN > 0))
#if (XUA_DFU_EN == 1) && ((NUM_USB_CHAN_OUT > 0) || (NUM_USB_CHAN_IN > 0) || (XUA_PWM_CHANNELS > 0))
/* This function is a dummy version of the deliver thread that does not
connect to the codec ports. It is used during DFU reset. */
[[combinable]]
static void dummy_deliver(chanend ?c_out, unsigned &command)
static void dummy_deliver(chanend ?c_out,
#if XUA_PWM_CHANNELS > 0
chanend c_pwm,
#endif
unsigned &command)
{
int ct;

Expand Down Expand Up @@ -606,6 +617,13 @@ static void dummy_deliver(chanend ?c_out, unsigned &command)
{
outuint(c_out, 0);
}
#endif
#if XUA_PWM_CHANNELS > 0
#pragma loop unroll
for(int i = 0; i < XUA_PWM_CHANNELS; i++)
{
outuint(c_pwm, 0);
}
#endif
}
const int wait_ticks = XS1_TIMER_HZ/48000;
Expand All @@ -626,8 +644,8 @@ static void dummy_deliver(chanend ?c_out, unsigned &command)
void DFUHandler(server interface i_dfu i, chanend ?c_user_cmd);
#endif

void XUA_AudioHub(chanend ?c_aud, clock ?clk_audio_mclk, clock ?clk_audio_bclk,
in port ?p_mclk_in,
void XUA_AudioHub(chanend ?c_aud, clock ?clk_audio_mclk, clock ?clk_audio_bclk
, in port ?p_mclk_in,
buffered _XUA_CLK_DIR port:32 ?p_lrclk,
buffered _XUA_CLK_DIR port:32 ?p_bclk,
buffered out port:32 (&?p_i2s_dac)[I2S_WIRES_DAC],
Expand All @@ -647,6 +665,9 @@ void XUA_AudioHub(chanend ?c_aud, clock ?clk_audio_mclk, clock ?clk_audio_bclk,
#if (XUA_NUM_PDM_MICS > 0)
, chanend c_pdm_in
#endif
#if (XUA_PWM_CHANNELS > 0) || defined(__DOXYGEN__)
, chanend c_pwm_channels
#endif
)
{
#if (XUA_ADAT_TX_EN)
Expand All @@ -662,6 +683,10 @@ void XUA_AudioHub(chanend ?c_aud, clock ?clk_audio_mclk, clock ?clk_audio_bclk,
unsigned divide;
unsigned firstRun = 1;

/* Clock master clock-block from master-clock port */
/* Note, marked unsafe since other cores may be using this mclk port */
configure_clock_src(clk_audio_mclk, p_mclk_in);

#if (DSD_CHANS_DAC > 0)
/* Make sure the DSD ports are on and buffered - just in case they are not shared with I2S */
EnableBufferedPort(p_dsd_clk, 32);
Expand Down Expand Up @@ -771,7 +796,8 @@ void XUA_AudioHub(chanend ?c_aud, clock ?clk_audio_mclk, clock ?clk_audio_bclk,
#endif // (I2S_CHANS_ADC != 0)
p_lrclk,
p_bclk,
p_mclk_in, clk_audio_bclk, divide, curSamFreq);
p_mclk_in,
clk_audio_bclk, divide, curSamFreq);
}
#endif // (I2S_CHANS_DAC != 0) || (I2S_CHANS_ADC != 0)

Expand Down Expand Up @@ -849,6 +875,12 @@ void XUA_AudioHub(chanend ?c_aud, clock ?clk_audio_mclk, clock ?clk_audio_bclk,
outuint(c_spdif_out, mClk);
#endif

#if (XUA_PWM_CHANNELS > 0)
/* Communicate master clock and sample freq to PWM thread */
outct(c_pwm_channels, XS1_CT_END);
outuint(c_pwm_channels, curSamFreq);
#endif

#if (XUA_NUM_PDM_MICS > 0)
/* Send decimation factor to PDM task(s) */
user_pdm_init();
Expand All @@ -875,6 +907,9 @@ void XUA_AudioHub(chanend ?c_aud, clock ?clk_audio_mclk, clock ?clk_audio_bclk,
#else
, null
#endif
#if (XUA_PWM_CHANNELS > 0)
, c_pwm_channels
#endif
#if (XUA_ADAT_TX_EN)
, c_adat_out
, adatSmuxMode
Expand Down Expand Up @@ -921,8 +956,12 @@ void XUA_AudioHub(chanend ?c_aud, clock ?clk_audio_mclk, clock ?clk_audio_bclk,
#if (XUD_TILE != 0) && (AUDIO_IO_TILE == 0)
DFUHandler(dfuInterface, null);
#endif
#if (NUM_USB_CHAN_OUT > 0) || (NUM_USB_CHAN_IN > 0)
dummy_deliver(c_aud, command);
#if (NUM_USB_CHAN_OUT > 0) || (NUM_USB_CHAN_IN > 0) || (XUA_PWM_CHANNELS > 0)
dummy_deliver(c_aud,
#if XUA_PWM_CHANNELS > 0
c_pwm_channels,
#endif
command);
#endif
}
/* Note, we shouldn't reach here. Audio, once stopped for DFU, cannot be resumed */
Expand Down
3 changes: 3 additions & 0 deletions lib_xua/src/core/endpoint0/xua_endpoint0.c
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,7 @@ void XUA_Endpoint0_loop(XUD_Result_t result, USB_SetupPacket_t sp, chanend c_ep0

if(reset)
{
UserAudioStreamStop();
DFUDelay(DELAY_BEFORE_REBOOT_TO_DFU_MS * 100000);
device_reboot();
}
Expand Down Expand Up @@ -1037,6 +1038,7 @@ void XUA_Endpoint0_loop(XUD_Result_t result, USB_SetupPacket_t sp, chanend c_ep0
result = DFUDeviceRequests(ep0_out, &ep0_in, &sp, null, 0 /*this is unused in DFUDeviceRequests()??*/, dfuInterface, &reset);
if(reset)
{
UserAudioStreamStop();
DFUDelay(DELAY_BEFORE_REBOOT_TO_DFU_MS * 100000);
device_reboot();
}
Expand Down Expand Up @@ -1245,6 +1247,7 @@ void XUA_Endpoint0_loop(XUD_Result_t result, USB_SetupPacket_t sp, chanend c_ep0
#else
g_curUsbSpeed = XUD_ResetEndpoint(ep0_out, &ep0_in);
#endif
UserAudioStreamStop();
g_currentConfig = 0;
g_curStreamAlt_Out = 0;
g_curStreamAlt_In = 0;
Expand Down
Loading