📄 codec.h
字号:
/*****************************************************************************/
/* CODEC.H v1.00 */
/* 版权(c) 2003- 北京合众达电子技术有限责任公司 */
/* 设计者: 段立锋 */
/*****************************************************************************/
/******************************************************************************/
/******************************************************************************/
/* CODEC.H - TLV320AIC23B Audio Codec driver routines */
/* */
/* */
/* FUNCTIONS: */
/* */
/* codec_open() - allocate an identifing handle for an instance of a codec */
/* codec_close() - release a codec handle */
/* codec_reset() - Reset the codec to the default configuration. */
/* codec_read_reg() - Read an AD50 control register */
/* codec_write_reg() - Write an AD50 control register */
/* codec_read() - Read one or more words from the AD50 data stream */
/* codec_write() - Write one or more words to the AD50 data stream */
/* codec_power() - Power up/down the analog and filter functions */
/* codec_monitor_gain() - Sets the monitor amp gain */
/* codec_digital_loopback() - Enables digital loopback */
/* codec_dac_mode() - Set either 16-bit or 15-bit mode for DAC */
/* codec_adc_mode() - Set either 16-bit or 15-bit mode for adc */
/* codec_analog_loopback() - Enables analog loopback */
/* codec_ain_gain() - Sets analog input gain */
/* codec_aout_gain() - Sets analog output gain */
/* codec_sample_rate() - change capture and playback sample rates */
/* codec_fir_flag() - Read decimation filter overflow flag */
/* int codec_cont_play() - Sets continuous play (D/A) mode */
/* int codec_cont_capture() - Sets continuous capture (A/D) mode */
/* */
/******************************************************************************/
#ifndef _CODEC_H_
#define _CODEC_H_
#include "type.h"
/*****************************************************************************/
/* DEFINES */
/*****************************************************************************/
#undef OK
#define OK 0
#undef ERROR
#define ERROR -1
#define CODEC_LINEINGAIN_MODE 0x000 /*Left/right line simultaneous volume/mute update */
#define CODEC_PHONEINGAIN_MODE 0x180 /*Left/right phone simultaneous volume/mute update*/
/*****************************************************************************/
/* 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;
/*****************************************************************************/
/* GLOBAL VARIABLES */
/*****************************************************************************/
/*****************************************************************************/
/* PUBLIC FUNCTION PROTOTYPES */
/*****************************************************************************/
/******************************************************************************/
/* codec_open() - 获得CODEC对应的MCBSP的唯一的句柄,并设置其各寄存器默认值 */
/* */
/* 参数: */
/* codec - 枚举变量CodecId中的一个元素,对应数据接口或是命令接口 */
/* */
/* 返回值: - 对应的有效句柄 */
/* */
/******************************************************************************/
HANDLE codec_open(CodecId codec);
/******************************************************************************/
/* codec_close() - 释放句柄所对应的MCBSP,并且复位对应的MCBSP */
/* 参数: */
/* hDevice - 已打开的有效的句柄 */
/* */
/******************************************************************************/
void codec_close(HANDLE hDevice);
/******************************************************************************/
/* codec_reset() - 控制音频的复位 */
/*参数: */
/* hDevice - 对应控制接口的句柄; */
/*返回值: */
/* 操作是否成功 */
/******************************************************************************/
int codec_reset(HANDLE hDevice);
/******************************************************************************/
/* codec_read_reg() - 读TLV320aic23B的控制寄存器 */
/*参数: */
/* hDevice - 对应控制接口的句柄; */
/* reg - 指示一个在寄存器枚举列表中的一个寄存器地址 */
/* regdata - 要写入的寄存器的数据*/
/*返回值: */
/* 要读的寄存器的值 */
/* */
/******************************************************************************/
int codec_write_reg(HANDLE hDevice, CodecReg reg,unsigned int value);
/******************************************************************************/
/* codec_read() - 从TLV320AIC23B读一个或多个字 */
/*参数: */
/* hDevice - 对应数据接口的句柄
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -