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

📄 codec.h

📁 这是个TI公司的TMS320VC5502的专门用的usb通讯程序
💻 H
字号:

/************************************************************************/
//
//	Filename:	CODEC.h
//	Function:	Define data stucture and function used by CODEC
//
/************************************************************************/

#include <csl.h>
#include "type.h"
#ifndef codec_h
#define codec_h

//void Codec_Config(void);
void Open_Codec(void);
void Close_Codec(void);
extern int codec_write_reg(Uint16 * reg);
void codec_sample_rate(unsigned int sample);

/************************************************************************/
/* typedefs & enums                                                     */
/************************************************************************/

// Codec state
typedef enum
{
   CODEC_CLOSED = 0,
   CODEC_OPENED = 1,
   CODEC_TX_DMA = 2,
   CODEC_RX_DMA = 3
} CodecState, *PCodecState;

// Codec instance enumeration
typedef enum
{
    CODEC_DATA  = 0,
	CODEC_COMMAND  = 2
} CodecId, *PCodecId;

// Codec mode of operation
typedef enum
{
   MODE_INT,
   MODE_DMA
} CodecMode, *PCodecMode;

// Codec actions
typedef enum
{
   PLAY,
   CAPTURE
} CodecAction, *PCodecAction;

// TLV320AIC23B register enumeration
typedef enum
{
   Codec_LLIVC   = 0x00,/*Left line input channel volume control*/
   Codec_RLIVC   = 0x01,/*Right line input channel volume control*/
   Codec_LHPVC   = 0x02,/*Left channel headphone volume control*/
   Codec_RHPVC   = 0x03,/*Rihgt channel headphone volume control*/
   Codec_AAPC    = 0x04,/* Analog audio path control*/
   Codec_DAPC    = 0x05,/*Digital audio path control*/
   Codec_PDC     = 0x06,/*Power down control*/
   Codec_DAIF    = 0x07,/*Digital audio interface format*/
   Codec_SRC     = 0x08,/*Sample rate control*/
   Codec_DIA     = 0x09,/*Digital interface activation*/
   Codec_RST     = 0x0f/*Reset register*/
} CodecReg, *PCodecReg;

// Codec Power
typedef enum
{
   CODEC_POWER_ALLON 	= 0x00,// Disable powerdown mode
   CODEC_POWER_ALLOFF   = 0x0f,// Enable powerdown mode
   CLK_POWER_OFF        = 0x40,// Turn off the clock
   OSC_POWER_OFF        = 0x20,// Turn off the oscillator
   OUT_POWER_OFF        = 0x10,// Turn off the output
   DAC_POWER_OFF        = 0x08,// Turn off the DAC
   ADC_POWER_OFF        = 0x04,// Turn off the ADC
   MIC_POWER_OFF        = 0x02,// Turn off the microphone input
   LINE_POWER_OFF       = 0x60,// Turn off the line input
   POWER_CONTROL_BASE   = 0x0c00//寄存器的地址
} CodecPower, *PCodecPower;

// Codec Monitor amplifier gain
typedef enum
{
   CODEC_MON_MUTE          = 0x00,            // mute
   CODEC_MON_MINUS_0dB     = 0x04,            //  0  dB
   CODEC_MON_MINUS_8dB     = 0x08,            // -8  dB
   CODEC_MON_MINUS_18dB    = 0x0C             // -18 dB
} CodecMonGain, *PCodecMonGain;

// Codec loopback
typedef enum
{
   CODEC_LOOP_NONE        = 0x00,             // mute
   CODEC_LOOP_DIGITAL     = 0x02,             // digital loopback
   CODEC_LOOP_ANALOG      = 0x08             // analog loopback
} CodecLoopback, *PCodecLoopback;

// Codec DAC mode
typedef enum
{
   CODEC_DAC_16BIT,                           // 16 bit DAC mode (HW sec. comm.)
   CODEC_DAC_15BIT                            // 15+1 bit DAC mode
} CodecDacMode, *PCodecDacMode;

// Codec ADC mode
typedef enum
{
   CODEC_ADC_16BIT,                           // 16 bit ADC mode (HW sec. comm.)
   CODEC_ADC_15BIT                            // 15+1 bit ADC mode
} CodecAdcMode, *PCodecAdcMode;

// Codec analog input gain
typedef enum
{
   CODEC_AIN_MUTE         = 0x03,             // mute
   CODEC_AIN_12dB         = 0x02,             // 12 dB   
   CODEC_AIN_6dB          = 0x01,             // 6  dB   
   CODEC_AIN_0dB          = 0x00              // 0  dB   
} CodecAinGain, *PCodecAinGain;

// Codec analog output gain
typedef enum
{
   CODEC_AOUT_MUTE         = 0x03,            // mute    
   CODEC_AOUT_MINUS_12dB   = 0x02,            // -12 dB  
   CODEC_AOUT_MINUS_6dB    = 0x01,            // -6 dB   
   CODEC_AOUT_MINUS_0dB    = 0x00             //  0 dB   
} CodecAoutGain, *PCodecAoutGain;

// Codec sample rates (Twelve rates from 2000-16000 Hz)
typedef enum
{
   SR_2000   =  0x80,                        // 2000 Hz
   SR_2285   =  0xF0,                        // 2285 Hz
   SR_2667   =  0xE0,                        // 2667 Hz
   SR_3200   =  0xD0,                        // 3200 Hz
   SR_4000   =  0xC0,                        // 4000 Hz
   SR_5333   =  0xB0,                        // 5333 Hz
   SR_8000   =  0xA0,                        // 8000 Hz
   SR_9142   =  0x70,                        // 9142 Hz
   SR_10667  =  0x60,                        // 10667 Hz
   SR_12800  =  0x50,                        // 12800 Hz
   SR_16000  =  0x90                         // 16000 Hz
} CodecSampleRate, *PCodecSampleRate;

/*Left line input channel volume control*/
#define   	Codec_LLIVC_LPS(x)   	((0<<1)+x)
#define     LLIVC_LIM(x)	(x<<7)	//Left line input mute
#define 	LLIVC_LIV(x)	x		//Left line input volume control(10111=0 db default)

/*Right line input channel volume control*/	
#define   	Codec_RLIVC_RLS(x)		((1<<1)+x)
#define     RLIVC_RIM(x)	(x<<7)	//Right line input mute
#define 	RLIVC_RIV(x)	x		//Right line input volume control(10111=0 db default)

/*Left channel headphone volume control*/	
#define   	Codec_LHPVC_LRS(x)   	((2<<1)+x)
#define     LHPVC_LZC(x)	(x<<7)	//Left-channel zero-cross detect
#define     LHPVC_LHV(x)	x		//Left Headphone volme control(1111001=0db default)

/*Rihgt channel headphone volume control*/	
#define   	Codec_RHPVC_RLS(x)   	((3<<1)+x)
#define     LHPVC_RZC(x)	(x<<7)	//Reft-channel zero-cross detect
#define     LHPVC_RHV(x)	x		//Reft Headphone volme control(1111001=0db default)

/*Analog audio path control*/	
#define    	Codec_AAPC_STA2(x)    	((4<<1)+x)
#define    	AAPC_STA10(x)	(x<<6)	//Added Sidetone 1-0bit
#define    	AAPC_STE(x)		(x<<5)	//Sidetone enable bit
#define    	AAPC_DAC(x)		(x<<4)	//DAC select
#define    	AAPC_BYP(x)		(x<<3)	//Bypass
#define    	AAPC_INSEL(x)	(x<<2)	//Input select for ADC
#define    	AAPC_MICM(x)	(x<<1)	//Microphone mute
#define    	AAPC_MICB(x)	x		//Microphone boost  0=db	1=20db

/*Digital audio path control*/	
#define   	Codec_DAPC_REV    	0x0a
#define   	DAPC_DACM(x)	(x<<3)	//DAC sofe mute
#define   	DAPC_DEEMP(x)	(x<<1)	//De-emphasis control 
#define   	DAPC_ADCHP(x)	x		//ADC highpass filter

/*Power down control*/	
#define   	Codec_PDC_REV     	0x0c
#define   	PDC_OFF(x)		(x<<7)	//Device power	
#define   	PDC_CLK(x)		(x<<6)	//Clock
#define   	PDC_OSC(x)		(x<<5)	//Oscillator
#define   	PDC_OUT(x)		(x<<4)	//Output
#define   	PDC_DAC(x)		(x<<3)	//DAC
#define   	PDC_ADC(x)		(x<<2)	//ADC
#define   	PDC_MIC(x)		(x<<1)	//Microphone input
#define   	PDC_LINE(x)		x		//Line input
#define 	PDC_DEFAULT		0x0

/*Digital audio interface format*/	
#define    	Codec_DAIF_REV    	0x0e	
#define		DAIF_MS(x)		(x<<6)	//Master/slave mode
#define		DAIF_LRSWAP(x)	(x<<5)	//DAC left/right swap
#define		DAIF_LRP(x)		(x<<4)	//DAC left/right phase
#define		DAIF_IWL(x)		(x<<2)	//Input bit length
#define		DAIF_FOR(x)		x		//Data format

/*Sample rate control*/	
#define 	Codec_SRC_REV     	0x10
#define 	SRC_CLKIN(x)	(x<<6)	//Clock input divider
#define 	SRC_CLKOUT(x)	(x<<7)	//Clock output divider
#define 	SRC_SR(x)		(x<<2)	//Sampling rate control
#define 	SRC_BOSR(x)		(x<<1)	//Base oversampling rate
#define 	SRC_USB(x)		x		//Clock mode select 0=normal 1=USB

/*Digital interface activation*/	
#define     Codec_DIA_REV       0x12
#define   	DIA_ACT(x)		x		//Activate interface 0=inactive

/*Reset register*/	
#define     Codec_RST_REV   	0x1e	
#define		RST_RES		    0		//Write 00000000 to this register triggers reset


#endif

/***********************************************************************/
//	No more
/***********************************************************************/

⌨️ 快捷键说明

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