📄 codeccontrol.cpp
字号:
}
return good;
}
// Return boost enabled status flag
DWORD CODECControl::codecIsBoosted(void)
{
return m_codecboostEnable;
}
// Set curent boost levels, basslvl must be between 0(no boost) and
// 0xF(max boost) and treblvl must be between 0(no boost) and
// 0x3(max boost)
DWORD CODECControl::codecSetBoostLevel(UINT16 basslvl,
UINT16 treblvl)
{
UINT32 testBoostLvl;
UINT16 regval;
DWORD good = 0;
// Limit values
basslvl &= ~0xF;
treblvl &= ~0x3;
// Skip if no changes are needed
testBoostLvl = (((UINT32) basslvl) << 16) | ((UINT32) treblvl);;
if (m_codecSavedBoostLevel == testBoostLvl)
{
return 1;
}
// Read current value first
if (codecReadReg(®val, UDA1380_REG_MODEBBT) != 0)
{
regval &= ~0x3F3F;
regval |= (basslvl | (basslvl << 8) | (treblvl << 4) | (treblvl << 12));
if (codecWriteReg(regval, UDA1380_REG_MODEBBT) != 0)
{
good = 1;
m_codecSavedBoostLevel = testBoostLvl;
}
}
return good;
}
// Returns current boost levels, High 16 bits=bass, low 16 bits=treble
UINT32 CODECControl::codecGetBoostLevel(void)
{
return m_codecSavedBoostLevel;
}
// Enable and disable CODEC mute
DWORD CODECControl::codecMute(DWORD mute)
{
UINT16 regval;
DWORD good = 0;
// Skip if no changes are needed
if (m_codecmuteEnabled == mute)
{
return 1;
}
// Read current value first
if (codecReadReg(®val, UDA1380_REG_MSTRMUTE) != 0)
{
if (mute != 0)
{
// Mute output
regval |= 0x4000;
}
else
{
// Unmute output
regval &= ~0x4000;
}
if (codecWriteReg(regval, UDA1380_REG_MSTRMUTE) != 0)
{
good = 1;
m_codecmuteEnabled = mute;
}
}
return good;
}
// Returns current CODEC mute enabled status flag
DWORD CODECControl::codecIsMuted(void)
{
return m_codecmuteEnabled;
}
//********************************************************************
// Miscellaneous control functions
//********************************************************************
// Select line input or MIC for audio input, if MIC is used, the LNA amp
// is selectable with the VGA settings
DWORD CODECControl::codecSelectLineIn(DWORD use_line_in)
{
UINT16 regval;
DWORD good = 0;
// Skip if no changes are needed
if (m_codecLineInUsedFlag == use_line_in)
{
return 1;
}
// Read current value first
if (codecReadReg(®val, UDA1380_REG_ADC) != 0)
{
if (use_line_in == 0)
{
// Disable line in, enable MIC input and DC filter
regval &= ~0x0008;
regval |= 0x0005;
}
else
{
// Disable MIC and filter, enable line in
regval &= ~0x0007;
regval |= 0x0008;
}
if (codecWriteReg(regval, UDA1380_REG_ADC) != 0)
{
good = 1;
m_codecLineInUsedFlag = use_line_in;
}
}
return good;
}
// Return line in selection (TRUE) or MIC selection (FALSE);
DWORD CODECControl::codecLineInUsed(void)
{
return m_codecLineInUsedFlag;
}
// Function for disabling and enabling headphone output driver
DWORD CODECControl::codecHeadPhoneEnable(DWORD enable)
{
UINT16 regval;
DWORD good = 0;
// Skip if no changes are needed
if (m_codecHeadPhoneEnabledFlag == enable)
{
return 1;
}
// Read current value first
if (codecReadReg(®val, UDA1380_REG_PWRCTRL) != 0)
{
if (enable != 0)
{
regval = regval | PWR_PON_HP_EN;
}
else
{
regval = regval & ~PWR_PON_HP_EN;
}
if (codecWriteReg(regval, UDA1380_REG_PWRCTRL) != 0)
{
good = 1;
m_codecHeadPhoneEnabledFlag = enable;
}
}
return good;
}
// Return headphone driver enabled status
DWORD CODECControl::codecHeadPhoneEnabled(void)
{
return m_codecHeadPhoneEnabledFlag;
}
//********************************************************************
// Mixer and gain control functions
//********************************************************************
// Select output from digital mixer or decimator. The Digital mixer
// is used to route input signals directly to the output in the CODEC
DWORD CODECControl::codecDigitalMixerEnable(DWORD enable)
{
UINT16 regval;
DWORD good = 0;
// Skip if no changes are needed
if (m_codecDigitalMixerEnabled == enable)
{
return 1;
}
// Read current value first
if (codecReadReg(®val, UDA1380_REG_I2S) != 0)
{
if (enable != 0)
{
regval = regval | 0x0040;
}
else
{
regval = regval & ~0x0040;;
}
if (codecWriteReg(regval, UDA1380_REG_I2S) != 0)
{
good = 1;
m_codecDigitalMixerEnabled = enable;
}
}
return good;
}
// Returns digital mixer enabled status flag
DWORD CODECControl::codecIsDigitalMixerEnabled(void)
{
return m_codecDigitalMixerEnabled;
}
// Select PGA (programmable gain) for ADC (must be between 0 (0db gain)
// and 0x8 (24db gain))
DWORD CODECControl::codecSetADCPGA(UINT16 lgain,
UINT16 rgain)
{
UINT16 regval;
UINT testGain;
DWORD good = 0;
// Limit values
lgain &= ~0xF;
rgain &= ~0xF;
// Skip if no changes are needed
testGain = (((UINT32) rgain) << 16) | ((UINT32) lgain);
if (m_codecGainADCPGA == testGain)
{
return 1;
}
regval = (rgain << 8) | lgain;
if (codecWriteReg(regval, UDA1380_REG_PGA) != 0)
{
good = 1;
m_codecGainADCPGA = testGain;
}
return good;
}
// Get current PGA gain, High 16 bits=right, low 16 bits=left
UINT32 CODECControl::codecGetADCPGA(void)
{
return m_codecGainADCPGA;
}
// Select VGA (variable gain) for ADC (must be between 0 (0db gain)
// and 0xF (30db gain) in 2db gain steps). Used with the MIC only.
DWORD CODECControl::codecSetADCVGA(UINT16 gain)
{
UINT16 regval;
DWORD good = 0;
// Limit value
gain &= ~0xF;
// Skip if no changes are needed
if (m_codecGainADCVGA == gain)
{
return 1;
}
// Read current value first
if (codecReadReg(®val, UDA1380_REG_ADC) != 9)
{
regval &= ~0x0F00;
regval |= (gain << 8);
if (codecWriteReg(regval, UDA1380_REG_ADC) != 9)
{
good = 1;
m_codecGainADCVGA = gain;
}
}
return good;
}
// Get current ADC VGA gain
UINT16 CODECControl::codecGetADCVGA(void)
{
return m_codecGainADCVGA;
}
// Set decimator volume, must be a value between 0 (24db gain) and
// 0x81 (-63.5db gain), >0x81 is -inf
DWORD CODECControl::codecSetDecimatorVol(UINT16 lgain,
UINT16 rgain)
{
UINT16 regval;
UINT32 testDec;
DWORD good = 0;
// Limit values
lgain &= ~0xFF;
rgain &= ~0xFF;
// Skip if no changes are needed
testDec = (((UINT32) rgain) << 16) | ((UINT32) lgain);
if (m_codecVolDecimator == testDec)
{
return 1;
}
regval = (lgain << 8) | rgain;
if (codecWriteReg(regval, UDA1380_REG_DECVOL) != 0)
{
good = 1;
m_codecVolDecimator = testDec;
}
return good;
}
// Get current decimator volume, High 16 bits=right, low 16 bits=left
UINT32 CODECControl::codecGetDecimatorVol(void)
{
return m_codecVolDecimator;
}
// Diagnostic function for dumping current CODEC registers
void CODECControl::codecDumpRegs(void)
{
static UNS_8 regs[] = {UDA1380_REG_EVALCLK, UDA1380_REG_I2S,
UDA1380_REG_PWRCTRL, UDA1380_REG_ANAMIX, UDA1380_REG_HEADAMP,
UDA1380_REG_MSTRVOL, UDA1380_REG_MIXVOL, UDA1380_REG_MODEBBT,
UDA1380_REG_MSTRMUTE, UDA1380_REG_MIXSDO, UDA1380_REG_DECVOL,
UDA1380_REG_PGA, UDA1380_REG_ADC, UDA1380_REG_AGC, 0xFF};
int idx;
UINT16 val16;
RETAILMSG(1,
(TEXT("CODECControl: Dumping CODEC registers\r\n")));
idx = 0;
while (regs[idx] != 0xFF)
{
codecReadReg(&val16, regs[idx]);
RETAILMSG(1,
(TEXT("CODECControl: Reg 0x%x = 0x%x\r\n"), regs[idx], val16));
idx++;
}
}
//********************************************************************
// I2C interface related functions
//********************************************************************
// Perform a transaction on the I2S device via I2C
DWORD CODECControl::codecI2CTransaction(I2C_OUT_XFER_T *pI2COut,
I2C_IN_XFER_T *pI2CIn)
{
DWORD bytesRead;
DWORD good = 0;
// Continue if driver was previously initialized
if (m_codecdrvI2CCtl != INVALID_HANDLE_VALUE)
{
good = DeviceIoControl(m_codecdrvI2CCtl, IOCTL_APP_I2CREQ, pI2COut,
sizeof(I2C_OUT_XFER_T), pI2CIn, sizeof(I2C_IN_XFER_T),
&bytesRead, NULL);
}
return good;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -