⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 codec.c

📁 samsung 最新芯片2450 的测试程序.
💻 C
📖 第 1 页 / 共 4 页
字号:
	}
	return SRbit;
}

/*
	// I2S Master Mode ( Codec Slave Mode)
	if ( OpMode == I2S_MASTER )
	{
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x04, uPaif3 );	// R4 HiFI Audio interface 16bit, Codec is Slave
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x05, 0x33);	// R5
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x06, SRbit<<1);	// R6  SR[5:1] adc, dac setting
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x07, 0xa7);	// R7
	}
	// I2S Slave Mode ( Codec Master Mode)
	else if ( OpMode == I2S_SLAVE)
	{
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x04, 0x50|uPaif3);	// R4 HiFI Audio interface 16bit , Codec is Master
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x05, 0x33);	// R5
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x06, 0x22);	// R6  SR[5:1] Normal mode, 44.1Khz used recording			
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x07, 0x87);	// R7
	}
*/
/*---------------------------------- APIs of WM8753 ---------------------------------*/
//////////
// Function Name : I2S_Init8753Driver
// Function Description : 
//   This function prepares the initialization of WM8753 Driver.
// Input : 
//		ucMode	- I2S Operation Mode
//		ucStatus	-I2S Operation Status
// Output : NONE
// Version : 
bool I2SCODEC_InitWm8753(int OpMode,
						int txr, int dataformat, int CodecClkFs, int SyncClkFreq, int BitperCh , int LineMic)
{
	int sNum;
	U16  uBclkRate, uSamplingFreq, uBitSpl, uPaif3, uPaif1, uPaif2, uPaif4, uI2sFmt;
	char SRbit;

	if(BitperCh==16 ||BitperCh==8)
		uBitSpl=0;
	else if(BitperCh==24)
		uBitSpl=2;
	else 
	{
		IIC_close();
		return 0;//assert
	}
		

	if(dataformat==I2S_FORMAT_I2S)
		uI2sFmt = 2;
	else if(dataformat==I2S_FORMAT_MSB)//left justified
		uI2sFmt = 1;
	else if(dataformat==I2S_FORMAT_LSB)//right justified
		uI2sFmt = 0;
	else
	{
		IIC_close();
		return 0;//assert
	}

	if(OpMode>1) 
	{
		IIC_close();		
		return;	
	}


	printf("WM8753 Test Start!\n");
	
	IIC_open(10000);	//	Serial EEPROM IIC clk = 200KHz


	I2SCODEC_SendWmData(WM8753_ID_WR, 0x1f, 0x00);	// R31 reset	
	
	uPaif3 = (uBitSpl<<2)|(uI2sFmt<<0);
	if ( OpMode == I2S_MASTER ) 	SRbit = I2SCODEC_8753SRbit(CodecClkFs, SyncClkFreq,0);//normal mode
	else SRbit = I2SCODEC_8753SRbit(CodecClkFs, SyncClkFreq,1);//usb mode, mclk 12Mhz
	//SRbit = 0x1c;

	I2SCODEC_SendWmData(WM8753_ID_WR, 0x01, 0x00);	// R1  DAC control
	I2SCODEC_SendWmData(WM8753_ID_WR, 0x02, 0x00);	// R2 ADC control
	I2SCODEC_SendWmData(WM8753_ID_WR, 0x03, uPaif3 );	// R3 ADC format
	// OpMode:  0- I2S Master Mode ( Codec Slave Mode)  1-I2S Slave Mode ( Codec Master Mode)
	I2SCODEC_SendWmData(WM8753_ID_WR, 0x04, (OpMode<<6)|uPaif3 );	// R4 HiFI Audio interface 16bit, Codec Slave/Master	
	
	if (OpMode == I2S_MASTER ) 
	{
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x05, 0x08);		// R5  HiFI Audio Interface ADC and DAC at same sample rate		
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x06, SRbit<<1 | OpMode);	// R6  SR[5:1] adc, dac setting, [0] 0.normal mode [1] usb mode mclk 12MHz
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x07, 0x07);	// R7 : adc, dac oversampling rate at 128x(Best SNR, not low power)
	}
	else
	{	//0x5 : 35 : play ok.
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x03, 1<<8|1<<6 | uPaif3 );	// R3 ADC format
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x05, 0x09);		// R5  HiFI Audio Interface ADC and DAC at same sample rate				
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x06, SRbit<<1 | OpMode);	// R6  SR[5:1] adc, dac setting, [0] 0.normal mode [1] usb mode mclk 12MHz
		
		//I2SCODEC_SendWmData(WM8753_ID_WR, 0x07, 0x57);	// R7 : adc, dac oversampling rate at 128x(Best SNR, not low power),
														//[1] =0 (MUST at USB mode 12Mhz operating(cocec is master)
		//ok. 
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x07, 1<<3|0<<1|0);	// R7 : adc, dac oversampling rate at 128x(Best SNR, not low power),
														//[1] =0 (MUST at USB mode 12Mhz operating(cocec is master)
														//bclk = mclk/2 = 6M for 96000Hz*48 max format.
	}

//	if (OpMode == I2S_MASTER ) 	I2SCODEC_SendWmData(WM8753_ID_WR, 0x05, 0x08);	// R5  HiFI Audio Interface ADC and DAC at same sample rate, lrc, vxfs ouput
//	else 						I2SCODEC_SendWmData(WM8753_ID_WR, 0x05, 0x0b);	// R5  HiFI Audio Interface ADC and DAC at same sample rate, lrc, vxfs ouput

	
	// I2S Master Mode ( Codec Slave Mode)
/*	if ( OpMode == I2S_MASTER )
	{
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x05, 0x33);	// R5
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x06, SRbit<<1);	// R6  SR[5:1] adc, dac setting
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x07, 0xa7);	// R7
	}
	// I2S Slave Mode ( Codec Master Mode)
	else if ( OpMode == I2S_SLAVE)
	{
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x04, 0x50|uPaif3);	// R4 HiFI Audio interface 16bit , Codec is Master
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x05, 0x33);	// R5
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x06, 0x22);	// R6  SR[5:1] Normal mode, 44.1Khz used recording			
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x07, 0x87);	// R7
	}
*/	

	
	
	if(txr == I2S_MODE_TX || txr == I2S_MODE_TXR)  
	{
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x08, 0x1ff);	// R8
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x09, 0x1ff);	// R9
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x0a, 0x0f);	// R10
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x0b, 0x0f);	// R11
//		I2SCODEC_SendWmData(WM8753_ID_WR, 0x0c, 0x7b);	// R12
//		I2SCODEC_SendWmData(WM8753_ID_WR, 0x0d, 0x00);	// R13	ALCSR[7:4] 00 48Khz used playing
//		I2SCODEC_SendWmData(WM8753_ID_WR, 0x0d, 0x22);	// R13	ALCSR[7:4] 22 44.1Khz used playing
//		I2SCODEC_SendWmData(WM8753_ID_WR, 0x0e, 0x32);	// R14
//		I2SCODEC_SendWmData(WM8753_ID_WR, 0x0f, 0x00);	// R15
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x10, 0xc3);	// R16
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x11, 0xc3);	// R17
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x12, 0xc0);	// R18
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x13, 0x00);	// R19
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x14, 0xcc);	// R20 Pwr mgt
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x15, 0x00);	// R21
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x17, 0x03);	// R23 Pwr mgt
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x18, 0x00);	// R24
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x19, 0x00);	// R25
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x1a, 0x00);	// R26
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x1b, 0x00);	// R27
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x1c, 0x00);	// R28
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x20, 0x55);	// R32
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x21, 0x05);	// R33
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x22, 0x150);	// R34		LoutMix.. Must be 0x45(not 0x44)
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x23, 0x55);	// R35
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x24, 0x150);	// R36		RoutMix.. Must be 0x49(not 0x48)
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x25, 0x55);	// R37
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x26, 0x50);	// R38
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x27, 0x55);	// R39	
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x28, 0x15f);	// R40(0x51)	Lout1 volume	Must be 0x51(not 0x50)
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x29, 0x15f);	// R41(0x53)	Rout1 volume	Must be 0x53(not 0x52)
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x2a, 0x15f);	// R42(0x55)	Lout2 volume	Must be 0x55(not 0x54)
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x2b, 0x15f);	// R43(0x57)	Rout2 volume	Must be 0x57(not 0x56)		
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x2c, 0x79);	// R44
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x2d, 0x04);	// R45
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x2e, 0x00);	// R46
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x2f, 0x00);	// R47
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x30, 0x00);	// R48
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x31, 0x97);	// R49	: left pga mute
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x32, 0x97);	// R50   :  right pga mute
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x33, 0x00);	// R51
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x34, 0x04);	// R52
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x35, 0x00);	// R53
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x36, 0x83);	// R54
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x37, 0x24);	// R55
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x38, 0x1ba);	// R56
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x39, 0x00);	// R57
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x3a, 0x83);	// R58
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x3b, 0x24);	// R59
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x3c, 0x1ba);	// R60
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x3d, 0x00);	// R61
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x3f, 0x00);	// R63

		I2SCODEC_SendWmData(WM8753_ID_WR, 0x16, 0x180);	// R22(0x2c) Pwr mgt  Lout1, Rout1 on  ==> headphone OK
	
	}
	
	if(txr == I2S_MODE_RX ||  txr == I2S_MODE_TXR)
	{
		
		if(LineMic == CODEC_MICIN)  
		{
//			I2SCODEC_SendWmData(WM8753_ID_WR, 0x02, 0x00);		// R2(0x04) adc high pass filter 3.4Hz at fs = 48KHz
//			I2SCODEC_SendWmData(WM8753_ID_WR, 0x03, uPaif3 );		// R3 adc 16bit i2s format
//			I2SCODEC_SendWmData(WM8753_ID_WR, 0x04, uPaif3);		// R4  codec is slave 16bit	 i2s 
//			I2SCODEC_SendWmData(WM8753_ID_WR, 0x05, 0x08);		// R5  ap is master, HiFI Audio Interface ADC and DAC at same sample rate
//			I2SCODEC_SendWmData(WM8753_ID_WR, 0x06, SRbit<<1);		// R6	mclk input using to adc, dac
			
			I2SCODEC_SendWmData(WM8753_ID_WR, 0x10, 0x1d5);		// R16(0x20)		left adc volume 10db
			I2SCODEC_SendWmData(WM8753_ID_WR, 0x11, 0x1c3);		// R17(0x22)		right adc volume 10db
			
	//	I2SCODEC_SendWmData(WM8753_ID_WR, 0x0c, 0x187);		// R12(0x18)  alc
	//	I2SCODEC_SendWmData(WM8753_ID_WR, 0x0d, 0x00);		// R13(0x1a)
	//	I2SCODEC_SendWmData(WM8753_ID_WR, 0x0e, 0x32); 		// R14(0x1c)

			I2SCODEC_SendWmData(WM8753_ID_WR, 0x14, 0xfc);		// R20(0x28) Pwr_mgt1	VMIDSEL(50Kohm), VREF, MICB enable
			I2SCODEC_SendWmData(WM8753_ID_WR, 0x15, 0x1ff);		// R21(0x2a) Pwr_mgt2	all enable, micamp enable
			I2SCODEC_SendWmData(WM8753_ID_WR, 0x16, 0x1ff);		// R22(0x2c) Pwr_mgt3
			I2SCODEC_SendWmData(WM8753_ID_WR, 0x17, 0x1ff);		// R23(0x2e) Pwr_mgt4
			
			I2SCODEC_SendWmData(WM8753_ID_WR, 0x2e, 0x0c);		// R46	LM select left PGA
			I2SCODEC_SendWmData(WM8753_ID_WR, 0x2f, 0x60);		// R47	Mix preamp1 gain +30db
			I2SCODEC_SendWmData(WM8753_ID_WR, 0x30, 0x02);		// R48(0x60)  Input control2 mic11 into alc mix
			
			I2SCODEC_SendWmData(WM8753_ID_WR, 0x31, 0x13f);		// R49 left pga , unmute, , 0.75 db.
			//I2SCODEC_SendWmData(WM8753_ID_WR, 0x32, 0x13f);	// R50(0x64) right pga unmute
			I2SCODEC_SendWmData(WM8753_ID_WR, 0x33, 0x100);		// R51(0x66)	micbias 0.9AVDD, MIC1 select 
		}
		else if(LineMic == CODEC_LINEIN)  
		{
//			I2SCODEC_SendWmData(WM8753_ID_WR, 0x02, 0x00);		// R2(0x04) 	adc high pass filter 3.4Hz at fs = 48KHz
//		I2SCODEC_SendWmData(WM8753_ID_WR, 0x03, uPaif3 );		// R3 adc 16bit i2s format
//		I2SCODEC_SendWmData(WM8753_ID_WR, 0x04, uPaif3);		// R4  codec is slave 16bit	 i2s format
//		I2SCODEC_SendWmData(WM8753_ID_WR, 0x05, 0x08);		// R5  ap is master, HiFI Audio Interface ADC and DAC at same sample rate
//			I2SCODEC_SendWmData(WM8753_ID_WR, 0x06, SRbit<<1);		// R6	mclk input using to adc, dac

			I2SCODEC_SendWmData(WM8753_ID_WR, 0x10, 0x1c3);		// R16(0x20)		left adc volume 0db
			I2SCODEC_SendWmData(WM8753_ID_WR, 0x11, 0x1c3);		// R17(0x22)		right adc volume 0db			
			
	//		I2SCODEC_SendWmData(WM8753_ID_WR, 0x0c, 0x18b);		// R12(0x18)	; alc off
	//		I2SCODEC_SendWmData(WM8753_ID_WR, 0x0d, 0x00);		// R13(0x1a)
	//		I2SCODEC_SendWmData(WM8753_ID_WR, 0x0e, 0x32); 		// R14(0x1c)
			I2SCODEC_SendWmData(WM8753_ID_WR, 0x0f, 0x03); 		// R15   noise gate, mute adc output.

			//I2SCODEC_SendWmData(WM8753_ID_WR, 0x14, 0x40);		// R20 Pwr_mgt1	VREF enable, mclk to digital
			//I2SCODEC_SendWmData(WM8753_ID_WR, 0x15, 0x06);		// R21 Pwr_mgt2	Left ADC, Right ADC on
			//I2SCODEC_SendWmData(WM8753_ID_WR, 0x16, 0x00);		// R22 Pwr_mgt3  out all off
			//I2SCODEC_SendWmData(WM8753_ID_WR, 0x17, 0x03);		// R23 Pwr_mgt4  rightmix, left mix on
			I2SCODEC_SendWmData(WM8753_ID_WR, 0x14, 0xfc);		// R20(0x28) Pwr_mgt1	VMIDSEL(50Kohm), VREF, MICB enable
			I2SCODEC_SendWmData(WM8753_ID_WR, 0x15, 0x1ff);		// R21(0x2a) Pwr_mgt2	all enable
			I2SCODEC_SendWmData(WM8753_ID_WR, 0x16, 0x1ff);		// R22(0x2c) Pwr_mgt3
			I2SCODEC_SendWmData(WM8753_ID_WR, 0x17, 0x1ff);		// R23(0x2e) Pwr_mgt4

		I2SCODEC_SendWmData(WM8753_ID_WR, 0x2e, 0x05);		// R46	LM select LINE1  RM select LINE2
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x2f, 0x0);		// R47   ADC input direct from LM and RM

	//		I2SCODEC_SendWmData(WM8753_ID_WR, 0x31, 0x13f);		// R49(0x62) 		left pga
	//		I2SCODEC_SendWmData(WM8753_ID_WR, 0x32, 0x13f);		// R50(0x64) 		right pga
		}
	}
		
	IIC_close();
	
	return 1;
}


//////////////////////////////////////////////////////////////
//			Common Codec Functions
/////////////////////////////////////////////////////////////

//I2S_InitCodec(eCodecChip, Opmode,
//				  tx, i2sformat, 384fs, 16bit);

bool I2S_InitCodec(int CodecChipID, int OpMode, 
						int txr, int dataformat, int CodecClkFs, int SyncClkFreq, int BitperCh, int LineMic)
{
	if(CodecChipID == WM8580)	
		return I2SCODEC_InitWm8580(OpMode, 
						txr, dataformat, CodecClkFs, BitperCh);
	else if(CodecChipID == WM8753)	
		return I2SCODEC_InitWm8753(OpMode, 
						txr, dataformat, CodecClkFs, SyncClkFreq, BitperCh, LineMic);//line 0 , mic 1
	else
		return 1;//for example, id is 0 in case of b'd to b'd
	
}







#if 0		
	else if(txr == I2S_MODE_RX && LineMic == CODEC_MICIN)  
		/*Record*/
//		printf("Select MIC1 or MIC2\n");
//		printf("1: MIC1(D), 2: MIC2(externel)\n");

//		sNum = GetIntNum();

		/*Default setting value*/
/*		I2SCODEC_SendWmData(WM8753_ID_WR, 0x1f, 0x00);		// R31(0x3e)   Reset
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x30, 0x02);		// R48(0x60)  Input control2
		
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x02, 0x00);		// R2(0x04)  adc high pass filter 3.4Hz at fs = 48KHz
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x04, 0x02);		// R4(0x08)  codec is slave 16bit	 i2s 	
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x05, 0x0b);		// R5(0x0a)
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x06, 0x00);		// R6(0x0c) 	mclk input using to adc, dac
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x0c, 0x187);		// R12(0x18) alc
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x0d, 0x00);		// R13(0x1a)
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x0e, 0x32); 		// R14(0x1c)

		I2SCODEC_SendWmData(WM8753_ID_WR, 0x14, 0xe0);		// R20(0x28)	VMIDSEL(50Kohm), VREF, MICB enable
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x15, 0x1ff);		// R21(0x2a) all enable, micamp enable
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x16, 0x1ff);		// R22(0x2c)
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x17, 0x1ff);		// R23(0x2e)
		I2SCODEC_SendWmData(WM8753_ID_WR, 0x2f, 0x1e0);		// R47(0x5e)

		I2SCODEC_SendWmData(WM8753_ID_WR, 0x31, 0x13f);		// R49(0x62) 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -