HRESULT akm4384_msgFunc (CODEC_MSG msg, uint32 data0, uint32 data1) { switch (msg) { case MM_LOST_LOCK: targetWriteCodecSPIWord(0x608c); //pwr down, set for I2C break; case MM_GOT_LOCK: targetWriteCodecSPIWord(0x608f); //pwr up, set for I2C break; case MM_SET_OUTGAIN: targetWriteCodecSPIWord(0x6300 | (data0&0xff)); //left gain targetWriteCodecSPIWord(0x6400 | (data0&0xff)); //right gain break; } return NO_ERROR; }
static HRESULT cliSpi(uint32 dev, uint32 w) { if (dev==0) targetWriteCodecSPIWord (w); else if (dev==1) targetWriteLEDSPIWord(w); else if (dev==2) targetWriteDisplaySPIWord(w); else if (dev==3) targetWriteDspSPIWord(w); return NO_ERROR; }
//This function is called when lock is obtained, lost or when the //rate mode has changed. //This particular codec is programmed to use I2S and to use the //following MCLK frequency: //@32k-48k use MCLK=256fs (~12MHz range) //@88.2k-96k use MCLK=245fs (~24MHz range) //@176.4-192k use MCLK=128gs (~24MHz range) HRESULT akm4620_msgFunc (CODEC_MSG msg, uint32 data0, uint32 data1) { switch (msg) { case MM_LOST_LOCK: targetWriteCodecSPIWord (0xa100); //reset AKM codec, this will also mute break; case MM_GOT_LOCK: //some codec's might need the I2S setup to change when the mode changes //that is not the case with our AKM4620 as we always run 512 base rate. targetWriteCodecSPIWord (0xa100); //reset switch (data0) { default: case eDAL_RATE_MODE_LOW: targetWriteCodecSPIWord (0xa264); break; case eDAL_RATE_MODE_MID: targetWriteCodecSPIWord (0xa265); break; case eDAL_RATE_MODE_HIGH: targetWriteCodecSPIWord (0xa266); break; } targetWriteCodecSPIWord (0xa103); //un-reset break; } return NO_ERROR; }
static void uiFSMdo (void) { int delta; uint8 chg=0; if (displayClicked ()) { //toggle mute evmCfg.mute = !evmCfg.mute; chg=1; } delta = displayEncoderDelta (); if (delta) { //if muted, exit mute if (evmCfg.mute) { evmCfg.mute = 0; chg=1; } delta += evmCfg.hpgain; if (delta < 0) delta=0; if (delta > 38) delta=38; if (delta != evmCfg.hpgain) { evmCfg.hpgain = delta; chg=1; } } if (chg) { updateUI(); //tell CODEC targetWriteCodecSPIWord (0xa600 | DAC_GAIN); targetWriteCodecSPIWord (0xa700 | DAC_GAIN); spsChanged(); //schedule update of flash } }
// updateCodec is called whenever DAL tells us that things have changed. // The function checks if any important stuff changed such as the rateMode // or the locked state. // We also handle some appliction specific LED stuff here. static void updateCodec(DAL_STATUS * pStatus) { uint16 w; if (((pStatus->state == eDAL_STATE_LOCKED) && !isLocked) || ((pStatus->state == eDAL_STATE_LOCKED) && (pStatus->lockedRateMode != lastLockedMode))) { //So either we became locked, or we slid into a new rate mode, in all cases //the codec/ADC/DAC should be told. if (firstInit) { //we got clocks, bring the device out of RESET amCtrlSetBit(LED_CODEC_NRST); TCTaskWait(10); //needs a little time?? firstInit=FALSE; } //Call the codec function for the selected mode targetWriteCodecSPIWord (0xa100); //reset switch (pStatus->lockedRateMode) { default: case eDAL_RATE_MODE_LOW: w=0xa264; break; case eDAL_RATE_MODE_MID: w=0xa265; break; case eDAL_RATE_MODE_HIGH: w=0xa266; break; } targetWriteCodecSPIWord (w); targetWriteCodecSPIWord (0xa600 | DAC_GAIN); targetWriteCodecSPIWord (0xa700 | DAC_GAIN); targetWriteCodecSPIWord (0xa103); //un-reset isLocked = true; lastLockedMode = pStatus->lockedRateMode; } else if ((pStatus->state != eDAL_STATE_LOCKED) && isLocked) { //we just lost lock //Call the codec function for the selected mode targetWriteCodecSPIWord (0xa100); //reset AKM codec, this will also mute isLocked = false; } }