forked from PAWPAW-Mirror/lib_xua
Added support for I2S/TDM “dummy samples” via XUA_I2S_DUMMY_SAMPS
This commit is contained in:
@@ -197,6 +197,10 @@
|
|||||||
#define I2S_DOWNSAMPLE_CHANS_IN I2S_CHANS_ADC
|
#define I2S_DOWNSAMPLE_CHANS_IN I2S_CHANS_ADC
|
||||||
#endif
|
#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.
|
* @brief Number of bits per channel for I2S/TDM. Supported values: 16/32-bit.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -80,6 +80,14 @@ unsigned dsdMode = DSD_MODE_OFF;
|
|||||||
#endif
|
#endif
|
||||||
#include "xua_audiohub_st.h"
|
#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)
|
static inline int HandleSampleClock(int frameCount, buffered _XUA_CLK_DIR port:32 p_lrclk)
|
||||||
{
|
{
|
||||||
#if CODEC_MASTER
|
#if CODEC_MASTER
|
||||||
@@ -286,6 +294,19 @@ unsigned static AudioHub_MainLoop(chanend ?c_out, chanend ?c_spd_out
|
|||||||
else
|
else
|
||||||
#endif
|
#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 (I2S_CHANS_ADC != 0)
|
||||||
#if (AUD_TO_USB_RATIO > 1)
|
#if (AUD_TO_USB_RATIO > 1)
|
||||||
if (0 == audioToUsbRatioCounter)
|
if (0 == audioToUsbRatioCounter)
|
||||||
@@ -478,6 +499,25 @@ unsigned static AudioHub_MainLoop(chanend ?c_out, chanend ?c_spd_out
|
|||||||
}
|
}
|
||||||
#endif
|
#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)
|
#if (I2S_CHANS_ADC != 0 || I2S_CHANS_DAC != 0)
|
||||||
syncError += HandleSampleClock(frameCount, p_lrclk);
|
syncError += HandleSampleClock(frameCount, p_lrclk);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
// Copyright 2016-2023 XMOS LIMITED.
|
// Copyright 2016-2023 XMOS LIMITED.
|
||||||
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||||
#ifdef SIMULATION
|
#ifdef SIMULATION
|
||||||
|
#include "xua.h"
|
||||||
|
|
||||||
#include <platform.h>
|
#include <platform.h>
|
||||||
#include <print.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_freq = 24576000;
|
||||||
|
|
||||||
const unsigned mclk_bclk_ratio = mclk_freq / (chans_per_frame * samFreq * data_bits);
|
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
|
//bclk
|
||||||
configure_clock_src_divide(clk_audio_bclk_gen, p_mclk_gen, mclk_bclk_ratio/2);
|
configure_clock_src_divide(clk_audio_bclk_gen, p_mclk_gen, mclk_bclk_ratio/2);
|
||||||
|
|||||||
Reference in New Issue
Block a user