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

📄 aic23.c

📁 dm270 source code
💻 C
字号:

#include <user/aic23.h>

static volatile Uint8 AIC23_i2cDevAddr = AIC23_ADDR_CS0;

static STATUS AIC23_sendCmd(Uint16 cmd );
static STATUS AIC23_i2cSendCmd( Uint16 cmd ); 

STATUS AIC23_reset() {
  volatile Uint16 cmd = 0;

  cmd = ( (AIC23_RESET_ADDR << AIC23_ADDR_SHIFT) | 0x00 );

  return AIC23_sendCmd(cmd);
}

STATUS AIC23_L_lin_vol( const Uint8 lrs,  const Uint8 lim,  const Uint8 liv  ) {
  volatile Uint16 cmd = 0;

  cmd = ( (AIC23_L_LIN_VOL_ADDR << AIC23_ADDR_SHIFT) |
	      ((lrs & AIC23_BIN_MSK) << AIC23_LRS) |
          ((lim & AIC23_BIN_MSK) << AIC23_LIM) |
          ((liv & AIC23_LIV_MSK) << AIC23_LIV) );

  return AIC23_sendCmd(cmd);
}

STATUS AIC23_R_lin_vol(  const Uint8 rls,  const Uint8 rim,  const Uint8 riv  ) {
  volatile Uint16 cmd = 0;

  cmd = ( (AIC23_R_LIN_VOL_ADDR << AIC23_ADDR_SHIFT) |
	      ((rls & AIC23_BIN_MSK) << AIC23_RLS) |
          ((rim & AIC23_BIN_MSK) << AIC23_RIM) |
          ((riv & AIC23_LIV_MSK) << AIC23_RIV) );

  return AIC23_sendCmd(cmd);
}

STATUS AIC23_L_hp_vol(  const Uint8 lrs,  const Uint8 lzc,  const Uint8 lhv  ) {
  volatile Uint16 cmd = 0;

  cmd = ( (AIC23_L_HP_VOL_ADDR << AIC23_ADDR_SHIFT) |
	      ((lrs & AIC23_BIN_MSK) << AIC23_LRS) |
          ((lzc & AIC23_BIN_MSK) << AIC23_LZC) |
          ((lhv & AIC23_LHV_MSK) << AIC23_LHV) );

  return AIC23_sendCmd(cmd);
}

STATUS AIC23_R_hp_vol(  const Uint8 rls,  const Uint8 rzc,  const Uint8 rhv  ) {
  volatile Uint16 cmd = 0;

  cmd = ( (AIC23_R_HP_VOL_ADDR << AIC23_ADDR_SHIFT) |
	      ((rls & AIC23_BIN_MSK) << AIC23_RLS) |
          ((rzc & AIC23_BIN_MSK) << AIC23_RZC) |
          ((rhv & AIC23_RHV_MSK) << AIC23_RHV) );

  return AIC23_sendCmd(cmd);
}


STATUS AIC23_A_path(
  const Uint8 sta,
  const Uint8 ste,
  const Uint8 dac,
  const Uint8 byp,
  const Uint8 insel,
  const Uint8 micm,
  const Uint8 micb
  ) {
  volatile Uint16 cmd = 0;

  cmd = ( (AIC23_A_PATH_ADDR << AIC23_ADDR_SHIFT) |
	      ((sta & AIC23_STA_MSK) << AIC23_STA) |
          ((ste & AIC23_BIN_MSK) << AIC23_STE) |
          ((dac & AIC23_BIN_MSK) << AIC23_DAC) |
          ((byp & AIC23_BIN_MSK) << AIC23_BYP) |
          ((insel & AIC23_BIN_MSK) << AIC23_INSEL) |
          ((micm & AIC23_BIN_MSK) << AIC23_MICM) |
          ((micb & AIC23_BIN_MSK) << AIC23_MICB) );

  return AIC23_sendCmd(cmd);
}

STATUS AIC23_D_path(  const Uint8 dacm,  const Uint8 deemp,  const Uint8 adchp ) {
  volatile Uint16 cmd = 0;
  
  cmd = ( (AIC23_D_PATH_ADDR << AIC23_ADDR_SHIFT) |
	      ((dacm & AIC23_BIN_MSK) << AIC23_DACM) |
          ((deemp & AIC23_DEEMP_MSK) << AIC23_DEEMP) |
          ((adchp & AIC23_BIN_MSK) << AIC23_ADCHP) );

  return AIC23_sendCmd(cmd);
}

STATUS AIC23_pow_ctrl(
  Uint8 off,
  Uint8 clk,
  Uint8 osc,
  Uint8 out,
  Uint8 dacp,
  Uint8 adc,
  Uint8 mic,
  Uint8 line
) {
  volatile Uint16 cmd = 0;
  
  cmd = ( (AIC23_POW_CTRL_ADDR << AIC23_ADDR_SHIFT) |
	      ((off & AIC23_BIN_MSK) << AIC23_OFF) |
          ((clk & AIC23_BIN_MSK) << AIC23_CLK) |
          ((osc & AIC23_BIN_MSK) << AIC23_OSC) |
          ((out & AIC23_BIN_MSK) << AIC23_OUT) |
          ((dacp & AIC23_BIN_MSK) << AIC23_DACP) |
          ((adc & AIC23_BIN_MSK) << AIC23_ADC) |
          ((mic & AIC23_BIN_MSK) << AIC23_MIC) |
          ((line & AIC23_BIN_MSK) << AIC23_LINE) );

  return AIC23_sendCmd(cmd);
}

STATUS AIC23_D_audio_fmt(
  const Uint8 ms,
  const Uint8 lrswap,
  const Uint8 lrp,
  const Uint8 iwl,
  const Uint8 For
 ) {
  volatile Uint16 cmd = 0;
  
  cmd = ( (AIC23_D_AUDIO_FMT_ADDR << AIC23_ADDR_SHIFT) |
	      ((ms & AIC23_BIN_MSK) << AIC23_MS) |
          ((lrswap & AIC23_BIN_MSK) << AIC23_LRSWAP) |
          ((lrp & AIC23_BIN_MSK) << AIC23_LRP) |
          ((iwl & AIC23_IWL_MSK) << AIC23_IWL) |
          ((For & AIC23_FOR_MSK) << AIC23_FOR) );

  return AIC23_sendCmd(cmd);
}

STATUS AIC23_smpl_rate(
  const Uint8 clkout,
  const Uint8 clkin,
  const Uint8 sr,
  const Uint8 bosr,
  const Uint8 usb
 ) {
  volatile Uint16 cmd = 0;
  
  cmd = ( (AIC23_SMPL_RATE_ADDR << AIC23_ADDR_SHIFT) |
	      ((clkout & AIC23_BIN_MSK) << AIC23_CLKOUT) |
          ((clkin & AIC23_BIN_MSK) << AIC23_CLKIN) |
          ((sr & AIC23_SR_MSK) << AIC23_SR) |
          ((bosr & AIC23_BIN_MSK) << AIC23_BOSR) |
          ((usb & AIC23_BIN_MSK) << AIC23_USB) );

  return AIC23_sendCmd(cmd);
}

STATUS AIC23_D_interface(  const Uint8 act) {
  volatile Uint16 cmd = 0;
  
  cmd = ( (AIC23_D_INTERFACE_ADDR << AIC23_ADDR_SHIFT) |
	      ((act & AIC23_BIN_MSK) << AIC23_ACT) );

  return AIC23_sendCmd(cmd);
}

STATUS AIC23_Init() {
	STATUS status;

	i2cInit();

  	status = AIC23_reset();
	if(status!=E_PASS)
		return status;

	status = AIC23_L_lin_vol( 0,  0,  0x1F );
	if(status!=E_PASS)
		return status;

	status = AIC23_R_lin_vol( 0,  0,  0x1F );
	if(status!=E_PASS)
		return status;

	status = AIC23_L_hp_vol(  1,  1,  0x7F );
	if(status!=E_PASS)
		return status;

	status = AIC23_R_hp_vol(  1,  1,  0x7F );
	if(status!=E_PASS)
		return status;

	AIC23_A_path( 0, 0, 1, 1, 0, 0, 0);
	if(status!=E_PASS)
		return status;
  
	status = AIC23_D_path(  0,  1,  0 );
	if(status!=E_PASS)
		return status;

	status = AIC23_pow_ctrl( 0, 0, 0, 0, 0, 0, 0, 0);
	if(status!=E_PASS)
		return status;
	
	status = AIC23_D_audio_fmt( 0, 0, 0, 0, 3);
	if(status!=E_PASS)
		return status;

	status = AIC23_smpl_rate( 0, 0, 3, 0, 0);
	if(status!=E_PASS)
		return status;

	status = AIC23_D_interface( 1 );
	if(status!=E_PASS)
		return status;
		
	status = AIC23_pow_ctrl( 1, 1, 1, 1, 1, 1, 1, 1);	// STOP AIC23		
	if(status!=E_PASS)
		return status;
		
 	return status;
}

void AIC23_stop() {

	i2cInit();

	AIC23_reset();

	AIC23_pow_ctrl( 1, 1, 1, 1, 1, 1, 1, 1);
	
}

static STATUS AIC23_sendCmd(Uint16 cmd ) {

		return AIC23_i2cSendCmd(cmd);
}

static STATUS AIC23_i2cSendCmd( Uint16 cmd ) {
	STATUS status=E_PASS;
 	Uint8 success;

	i2cWriteRegaic((Uchar)AIC23_i2cDevAddr<<1, (Uchar)(cmd >> 8), (Uchar)(cmd & 0xFF ), &success);
 	if(success){
		status=E_INVALID_INPUT;
		}
	return status;
}

void Set_AIC_SampleRate(Uint32 sampleRate){
	Uint8 Rate, bosr;

	i2cInit();
	if(sampleRate == 48000){
		Rate = AIC23_SR_12_48;
		bosr = 0;
	} else if(sampleRate == 44100){
		Rate = AIC23_SR_12_44;
		bosr = 1;
	} else if(sampleRate == 32000){
		Rate = AIC23_SR_12_32;
		bosr = 0;
	} else {
		Rate = AIC23_SR_12_8;
		bosr = 0;
	}
	AIC23_smpl_rate( 0, 0, Rate, bosr, 1);
}


void AIC23_BYPASS_Init(void) {

	i2cInit();

  	AIC23_reset();

	AIC23_L_lin_vol( 0,  0,  0x1F );

	AIC23_R_lin_vol( 0,  0,  0x1F );
	
	AIC23_L_hp_vol(  1,  1,  0x7F );

	AIC23_A_path( 0, 0, 1, 1, 1, 0, 0); 	// test from lineIn
	
	AIC23_D_path(  0,  1,  0 );

	AIC23_pow_ctrl( 0, 0, 0, 0, 0, 0, 0, 0);
	
	AIC23_D_audio_fmt( 0, 0, 0, 0, 3);

	AIC23_smpl_rate( 0, 0, 3, 0, 0);

	AIC23_D_interface( 1 );
	
}

⌨️ 快捷键说明

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