Added support for I2S/TDM “dummy samples” via XUA_I2S_DUMMY_SAMPS

This commit is contained in:
Ross Owen
2023-06-12 16:22:35 +01:00
parent 355df6d6b8
commit c92a640439
3 changed files with 46 additions and 1 deletions

View File

@@ -197,6 +197,10 @@
#define I2S_DOWNSAMPLE_CHANS_IN I2S_CHANS_ADC
#endif
#ifndef XUA_I2S_DUMMY_SAMPS
#define XUA_I2S_DUMMY_SAMPS (1)
#endif
/**
* @brief Number of bits per channel for I2S/TDM. Supported values: 16/32-bit.
*

View File

@@ -80,6 +80,14 @@ unsigned dsdMode = DSD_MODE_OFF;
#endif
#include "xua_audiohub_st.h"
static inline void PortOutput(buffered out port:32 p, int bits, int value)
{
if(bits == 32)
p <: value;
else
partout(p, bits, value);
}
static inline int HandleSampleClock(int frameCount, buffered _XUA_CLK_DIR port:32 p_lrclk)
{
#if CODEC_MASTER
@@ -286,6 +294,19 @@ unsigned static AudioHub_MainLoop(chanend ?c_out, chanend ?c_spd_out
else
#endif
{
#if XUA_I2S_DUMMY_SAMPS
if(frameCount == 0)
{
for(int j = 0; j < XUA_I2S_DUMMY_SAMPS; j++)
for(int i = 0; i < I2S_WIRES_DAC; i++)
{
PortOutput(p_i2s_dac[i], XUA_I2S_N_BITS, 0);
}
}
#endif
#if (I2S_CHANS_ADC != 0)
#if (AUD_TO_USB_RATIO > 1)
if (0 == audioToUsbRatioCounter)
@@ -478,6 +499,25 @@ unsigned static AudioHub_MainLoop(chanend ?c_out, chanend ?c_spd_out
}
#endif
#if XUA_I2S_DUMMY_SAMPS
if(frameCount == 1)
{
int dummyBits;
for(int j = 0; j < XUA_I2S_DUMMY_SAMPS; j++)
{
for(int i = 0; i < I2S_WIRES_ADC; i++)
{
asm volatile("in %0, res[%1]" : "=r"(dummyBits) : "r"(p_i2s_adc[i]));
if(XUA_I2S_N_BITS)
set_port_shift_count(p_i2s_adc[i], XUA_I2S_N_BITS);
}
asm volatile("in %0, res[%1]" : "=r"(dummyBits) : "r"(p_lrclk));
if(XUA_I2S_N_BITS)
set_port_shift_count(p_lrclk, XUA_I2S_N_BITS);
}
}
#endif
#if (I2S_CHANS_ADC != 0 || I2S_CHANS_DAC != 0)
syncError += HandleSampleClock(frameCount, p_lrclk);
#endif

View File

@@ -1,6 +1,7 @@
// Copyright 2016-2023 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
#ifdef SIMULATION
#include "xua.h"
#include <platform.h>
#include <print.h>
@@ -45,7 +46,7 @@ void slave_mode_clk_setup(const unsigned samFreq, const unsigned chans_per_frame
const unsigned mclk_freq = 24576000;
const unsigned mclk_bclk_ratio = mclk_freq / (chans_per_frame * samFreq * data_bits);
const unsigned bclk_lrclk_ratio = (chans_per_frame * data_bits); // 48.828Hz LRCLK
const unsigned bclk_lrclk_ratio = (chans_per_frame * data_bits + (data_bits * XUA_I2S_DUMMY_SAMPS)); // 48.828Hz LRCLK
//bclk
configure_clock_src_divide(clk_audio_bclk_gen, p_mclk_gen, mclk_bclk_ratio/2);