qawesz1

qawesz1

0个粉丝

1

问答

0

专栏

0

资料

qawesz1  发布于  2019-08-23 21:54:50
采纳率 0%
1个问答
5561

音频codec es8374问题

 
目前用到一款芯片es8374,现在一直不通。设计是这样的:由LIN2输入,MONOOUT输出,
主控这边设置为48k采样,16bit。 主控做master,8374做slave。芯片的设置怎么设置,有调试过的兄弟帮个忙,谢谢  [img]D:\InsertPic_(08-23-21-54-38).png[/img]
我来回答
回答8个
时间排序
认可量排序

qawesz1

0个粉丝

1

问答

0

专栏

0

资料

qawesz1 2019-08-23 21:55:35
认可0
这是我目前的设置,是有问题的       
        fvideo_byte_write( chip,0x00,0x3F); //IC Rst start
                fvideo_byte_write( chip,0x00,0x03); //IC Rst stop
///                fvideo_byte_write( chip,0x01,0xFF); //IC clk on
                fvideo_byte_write( chip,0x01,0x7F); //IC clk on
               
               
                fvideo_byte_write( chip,0x6F,0xA0); //pll set:mode enable
                fvideo_byte_write( chip,0x72,0x41); //pll set:mode set
                fvideo_byte_write( chip,0x09,0x01); //pll set:reset on ,set start   //vcoout devided by 8
                #if 0 //original
                /* PLL FOR 26MHZ/44.1KHZ */
                fvideo_byte_write( chip,0x0C,0x27); //pll set:k
                fvideo_byte_write( chip,0x0D,0xDC); //pll set:k
                fvideo_byte_write( chip,0x0E,0x2B); //pll set:k
                fvideo_byte_write( chip,0x0A,0x8A); //pll set:
                fvideo_byte_write( chip,0x0B,0x06);//pll set:n
                #endif

#if 1
                fvideo_byte_write( chip,0x0C,0x08); //pll set:k
                fvideo_byte_write( chip,0x0D,0x13); //pll set:k
                fvideo_byte_write( chip,0x0E,0xe0); //pll set:k
                fvideo_byte_write( chip,0x0A,0x8A); //pll set:
                fvideo_byte_write( chip,0x0B,0x08);//pll set:n
#endif
               
                /* PLL FOR 26MHZ/48KHZ */
                /*
                fvideo_byte_write( chip,0x0C,0x17); //pll set:k
                fvideo_byte_write( chip,0x0D,0xA3); //pll set:k
                fvideo_byte_write( chip,0x0E,0x2F); //pll set:k
                fvideo_byte_write( chip,0x0A,0x8A); //pll set:
                fvideo_byte_write( chip,0x0B,0x07); //pll set:n
                */       
                fvideo_byte_write( chip,0x09,0x41); //pll set:reset off ,set stop
               
                fvideo_byte_write( chip,0x05,0x11); //clk div =1
                fvideo_byte_write( chip,0x03,0x20); //osr =32
                fvideo_byte_write( chip,0x06,0x01); //LRCK div =0100H = 256D
                fvideo_byte_write( chip,0x07,0x00);
///                fvideo_byte_write( chip,0x0F,0x84); //MASTER MODE, BCLK = MCLK/4
                fvideo_byte_write( chip,0x0F,0x04); //MASTER MODE, BCLK = MCLK/4
               
                fvideo_byte_write( chip,0x10,0x0C); //I2S-16BIT, ADC
                fvideo_byte_write( chip,0x11,0x0C); //I2S-16BIT, DAC
                fvideo_byte_write( chip,0x02,0x08);  //select PLL
               
                fvideo_byte_write( chip,0x24,0x08); //adc set
///                fvideo_byte_write( chip,0x36,0x40); //dac set
                fvideo_byte_write( chip,0x36,0x00); //dac set               
               
                fvideo_byte_write( chip,0x12,0x30); //timming set
                fvideo_byte_write( chip,0x13,0x20); //timming set
///                fvideo_byte_write( chip,0x21,0x50); //adc set: SEL LIN1 CH+PGAGAIN=0DB
                fvideo_byte_write( chip,0x21,0x50); //adc set: SEL LIN1 CH+PGAGAIN=0DB
               
                fvideo_byte_write( chip,0x22,0xFF); //adc set: PGA GAIN=0DB
                fvideo_byte_write( chip,0x21,0x14); //adc set: SEL LIN1 CH+PGAGAIN=18DB               
               
                fvideo_byte_write( chip,0x22,0x55); //pga = +15db
                fvideo_byte_write( chip,0x00,0x80); // IC START
               
                usleep(100000); //DELAY_MS
                fvideo_byte_write( chip,0x14,0x8A); // IC START
                fvideo_byte_write( chip,0x15,0x40); // IC START
///                fvideo_byte_write( chip,0x1A,0xA0); // monoout set
                fvideo_byte_write( chip,0x1A,0x01); // monoout set       
               
///                fvideo_byte_write( chip,0x1B,0x19); // monoout set
                fvideo_byte_write( chip,0x1B,0x09); // monoout set       
               
                fvideo_byte_write( chip,0x1C,0x90); // spk set
                fvideo_byte_write( chip,0x1D,0x02); // spk set
                fvideo_byte_write( chip,0x1F,0x00); // spk set
                fvideo_byte_write( chip,0x1E,0xA0); // spk on
                fvideo_byte_write( chip,0x28,0x00); // alc set
                fvideo_byte_write( chip,0x25,0x00); // ADCVOLUME on
                fvideo_byte_write( chip,0x38,0x00); // DACVOLUMEL on
                fvideo_byte_write( chip,0x37,0x30); // dac set
                fvideo_byte_write( chip,0x6D,0x60); //SEL:GPIO1=DMIC CLK OUT+SEL:GPIO2=PLL CLK OUT
               
                fvideo_byte_write( chip,0x71,0x05);
                fvideo_byte_write( chip,0x73,0x70);                       
                fvideo_byte_write( chip,0x36,0x00); //dac set
                fvideo_byte_write( chip,0x37,0x00); // dac set       

ngswfx

2个粉丝

55

问答

1

专栏

40

资料

ngswfx 2020-04-16 11:17:09
认可0
本帖最后由 ngswfx 于 2020-4-17 02:06 编辑

最后的问题在那里,我也遇到这个片子了,也是没有一点反应,片子的i2c地址,CE拉低,感觉是整个i2c命令通道没有调通,海思部分,该做的都尝试了,连个杂音也没出。

经过查找资料,最后我这边卡在了,i2c的地址,使用开源的i2ctool,编译到3536C上运行,得到的i2c-0总线上的ES8374地址为0x22(CE引脚拉高,如果拉低,是0x20,看文档自己算出来时7bit 0x10,但实际不对,所以控制通信出了问题,一旦通信正常,驱动装载时,就可以听到咔嚓一声)

下面是最关键的驱动部分代码

void soft_reset(unsigned int chip_num)
{
        //soft reset
        printk("soft_reset in chip_num:%d addr:0x%x\n",chip_num,IIC_device_addr[chip_num]);

        ES8374_write(IIC_device_addr[chip_num],0x00,0x3F); //IC Rst start
        msleep(1);
        ES8374_write(IIC_device_addr[chip_num],0x00,0x03); //IC Rst stop
        ES8374_write(IIC_device_addr[chip_num],0x01,0x7F); //IC clk on
        ES8374_write(IIC_device_addr[chip_num],0x02,0x08);  //select PLL
        ES8374_write(IIC_device_addr[chip_num],0x03,0x20); //osr =32
        ES8374_write(IIC_device_addr[chip_num],0x6F,0xA0); //pll set:mode enable
        ES8374_write(IIC_device_addr[chip_num],0x72,0x41); //pll set:mode set
        ES8374_write(IIC_device_addr[chip_num],0x09,0x01); //pll set:reset on ,set start   //vcoout devided by 8
        ES8374_write(IIC_device_addr[chip_num],0x0C,0x08); //pll set:k
        ES8374_write(IIC_device_addr[chip_num],0x0D,0x13); //pll set:k
        ES8374_write(IIC_device_addr[chip_num],0x0E,0xe0); //pll set:k
        ES8374_write(IIC_device_addr[chip_num],0x0A,0x8A); //pll set:
        ES8374_write(IIC_device_addr[chip_num],0x0B,0x08);//pll set:n
        ES8374_write(IIC_device_addr[chip_num],0x09,0x41); //pll set:reset off ,set stop
        ES8374_write(IIC_device_addr[chip_num],0x05,0x11); //clk div =1
       
        ES8374_write(IIC_device_addr[chip_num],0x06,0x01); //LRCK div =0100H = 256D
        ES8374_write(IIC_device_addr[chip_num],0x07,0x00);
        ES8374_write(IIC_device_addr[chip_num],0x0F,0x04); //MASTER MODE, BCLK = MCLK/4
        ES8374_write(IIC_device_addr[chip_num],0x10,0x0C); //I2S-16BIT, ADC
        ES8374_write(IIC_device_addr[chip_num],0x11,0x0C); //I2S-16BIT, DAC
       
        ES8374_write(IIC_device_addr[chip_num],0x24,0x08); //adc set
        ES8374_write(IIC_device_addr[chip_num],0x36,0x00); //dac set
        ES8374_write(IIC_device_addr[chip_num],0x12,0x30); //timming set
        ES8374_write(IIC_device_addr[chip_num],0x13,0x20); //timming set
        ES8374_write(IIC_device_addr[chip_num],0x21,0x50); //adc set: SEL LIN1 CH+PGAGAIN=0DB
        ES8374_write(IIC_device_addr[chip_num],0x22,0xFF); //adc set: PGA GAIN=0DB
        ES8374_write(IIC_device_addr[chip_num],0x21,0x14); //adc set: SEL LIN1 CH+PGAGAIN=18DB
        ES8374_write(IIC_device_addr[chip_num],0x22,0x55); //pga = +15db

        ES8374_write(IIC_device_addr[chip_num],0x00,0x80); // IC START
        ES8374_write(IIC_device_addr[chip_num],0x14,0x8A); // IC START
        ES8374_write(IIC_device_addr[chip_num],0x15,0x40); // IC START
        ES8374_write(IIC_device_addr[chip_num],0x1A,0x01); // monoout set
        ES8374_write(IIC_device_addr[chip_num],0x1B,0x09); // monoout set
        ES8374_write(IIC_device_addr[chip_num],0x1C,0x90); // spk set
        ES8374_write(IIC_device_addr[chip_num],0x1D,0x02); // spk set
        ES8374_write(IIC_device_addr[chip_num],0x1F,0x00); // spk set
        ES8374_write(IIC_device_addr[chip_num],0x1E,0xA0); // spk on
        ES8374_write(IIC_device_addr[chip_num],0x28,0x00); // alc set
        ES8374_write(IIC_device_addr[chip_num],0x25,0x00); // ADCVOLUME on
        ES8374_write(IIC_device_addr[chip_num],0x38,0x00); // DACVOLUMEL on
        ES8374_write(IIC_device_addr[chip_num],0x6D,0x60); //SEL:GPIO1=DMIC CLK OUT+SEL:GPIO2=PLL CLK OUT
        ES8374_write(IIC_device_addr[chip_num],0x71,0x05);
        ES8374_write(IIC_device_addr[chip_num],0x73,0x70);

        //开启转换
        ES8374_write(IIC_device_addr[chip_num],0x36,0x00); //dac set
        ES8374_write(IIC_device_addr[chip_num],0x37,0x00); // dac set

        //ALC  10000100=0x84
        ES8374_write(IIC_device_addr[chip_num],0x26,0x84);
        //5bit large=高增益 11011=0x1B
        ES8374_write(IIC_device_addr[chip_num],0x27,0x1B);
        //11110000
        ES8374_write(IIC_device_addr[chip_num],0x28,0xF0);
        //0x29 alc decay time and attack time default:110010=0x32
        ES8374_write(IIC_device_addr[chip_num],0x29,0x32);
        //0x2b noise gate default:0
        ES8374_write(IIC_device_addr[chip_num],0x2B,0x0);


        //////////////////////MONO声音输出控制
        //11100 001=0xe1
        ES8374_write(IIC_device_addr[chip_num],0x1A,0xe1);
        //1001 1011
        ES8374_write(IIC_device_addr[chip_num],0x1B,0x9b);
        //////mix
        //mix  11001000       
        ES8374_write(IIC_device_addr[chip_num],0x1C,0xC8);
        //mixer gain
        //1000 1011
        ES8374_write(IIC_device_addr[chip_num],0x1B,0x9b);
        /////////////////////PGA
        //地址0x21   
        //mic in :0001 1100=0x1c
        //ES8374_write(IIC_device_addr[chip_num],0x21,0x1c);
        //line in:0010 1100=0x3c
        //ES8374_write(IIC_device_addr[chip_num],0x21,0x2c);
        //mic and line in
        //line in:0011 1100=0x3c
        ES8374_write(IIC_device_addr[chip_num],0x21,0x3c);
        //////////////////////ADC
        //jack detect 0x2c default:1101=0xd  通过GPIO或者RLIN1控制是否声音输出,会导致speakers静音
        //7-1:RLin1   1010 1101=0xad
        //ES8374_write(IIC_device_addr[chip_num],0x2c,0xad);
        ////0x2d ADC_SDP_SC-7 11100110=0xe6 会有背景噪声
        //ES8374_write(IIC_device_addr[chip_num],0x2d,0xE6);
        /////////////////////DAC
        //0x36  00000100=0x4 默认 SDP左输出
        ES8374_write(IIC_device_addr[chip_num], 0x36, 0x4);
        //0x37  00000000 DAC DSM not mute=0x0
        ES8374_write(IIC_device_addr[chip_num], 0x37, 0x0);
        //0x38  00000000 衰减 0=0db 最大11000000=-96db
        ES8374_write(IIC_device_addr[chip_num], 0x38, 0x0);

}

海思部分寄存器,参考:
himm 0x120F00E0 0x1; # 0:GPIO12_6  1:I2C_SDA
himm 0x120F00E4 0x1; # 0:GPIO12_7  1:I2C_SCL
#I2S
himm 0x120F00A0 0x1; # 0: GPIO9_0   1: I2S0_BCLK_RX
himm 0x120F00A4 0x1; # 0: GPIO9_1   1: I2S0_WS_RX
himm 0x120F00A8 0x1; # 0: GPIO9_2   1: I2S0_SD_RX

himm 0x120F00AC 0x2; # 00: GPIO9_3  01: I2S1_BCLK_RX  10:I2S2_MCLK
himm 0x120F00B0 0x1; # 0: GPIO9_4   1: I2S1_WS_RX
himm 0x120F00B4 0x1; # 0: GPIO9_5   1: I2S1_SD_RX

himm 0x120F00B8 0x1; # 0: GPIO9_6   1: I2S2_BCLK_TX
himm 0x120F00BC 0x1; # 0: GPIO9_7   1: I2S2_WS_TX
himm 0x120F00C0 0x1; # 0: GPIO5_4   1: I2S2_SD_TX
#I2S0
himm 0x120f08a0 0x120;           #I2S0_BCLK_RX
himm 0x120f08a4 0x130;           #I2S0_WS_RX
himm 0x120f08a8 0x130;           #I2S0_SD_RX
#I2S1               
himm 0x120f08ac 0x120;           #I2S1_BCLK_RX
himm 0x120f08b0 0x130;           #I2S1_WS_RX
himm 0x120f08b4 0x130;           #I2S1_SD_RX
#I2S2               
himm 0x120f08b8 0x120;           #I2S2_BCLK_TX
himm 0x120f08bc 0x130;           #I2S2_WS_TX
himm 0x120f08c0 0x130;           #I2S2_SD_TX
himm 0x120400E4 0x2
himm 0x13140108 0x00AAAAAA
himm 0x1314010C 0x00000131
himm 0x13140140 0x00218DEF
himm 0x13140144 0x00000133
himm 0x1314002C 0xE4000098
himm 0x13141100 0xE4840004
himm 0x1314014c 0x00000133
himm 0x13140148 0x00218DEF
himm 0x13142104 0x10007F00
himm 0x13142004 0x10007F00

ngswfx

2个粉丝

55

问答

1

专栏

40

资料

ngswfx 2020-04-16 22:30:45
认可0
本帖最后由 ngswfx 于 2020-4-16 23:12 编辑

我这边已经出声音了,主要是i2c的地址没对,总以为是7bit,0x10,实际在作驱动es8374.ko时,是CE引脚拉高时,这个地址是0x22,如果拉低,这个地址是0x20,主要通过i2cTools开源工具里面的i2cdetect探测,./i2cdetect -y -r 0 ,得到了i2c-0总线上面的这个设备的确切地址,然后不停修改es8374.ko的代码,不停通过rmmod es8374以及insmod es8374.ko,从而确定是否开启音频,一旦开启成功,虽然没有注入i2s音频流,喇叭也会咔嚓响一下的,然后在到应用层,按照海思的方法,开启相应音频接口即可。

3536C部分:寄存器,我配置了这些,有些可能不合适,但至少出声音了,注意是代功放的speak out通道出声音了,估计驱动还没开line out,暂时还没音:


#I2S0
himm 0x120f08a0 0x120;           #I2S0_BCLK_RX
himm 0x120f08a4 0x130;           #I2S0_WS_RX
himm 0x120f08a8 0x130;           #I2S0_SD_RX
#I2S1               
himm 0x120f08ac 0x120;           #I2S1_BCLK_RX
himm 0x120f08b0 0x130;           #I2S1_WS_RX
himm 0x120f08b4 0x130;           #I2S1_SD_RX
#I2S2               
himm 0x120f08b8 0x120;           #I2S2_BCLK_TX
himm 0x120f08bc 0x130;           #I2S2_WS_TX
himm 0x120f08c0 0x130;           #I2S2_SD_TX
himm 0x120400E4 0x2
himm 0x13140108 0x00AAAAAA
himm 0x1314010C 0x00000131
himm 0x13140140 0x003254E7
himm 0x13140144 0x00000133
himm 0x1314002C 0xE4000098
himm 0x13141100 0xE4840004
himm 0x1314014c 0x00000133
himm 0x13140148 0x00218DEF
himm 0x13142104 0x10007F00
himm 0x13142004 0x10007F00

而es8374.ko,我还要继续整理,

ngswfx

2个粉丝

55

问答

1

专栏

40

资料

ngswfx 2020-04-16 23:15:42
认可0
本帖最后由 ngswfx 于 2020-4-24 03:07 编辑

himm 0x120F00E0 0x1; # 0:GPIO12_6  1:I2C_SDA
himm 0x120F00E4 0x1; # 0:GPIO12_7  1:I2C_SCL
#I2S
himm 0x120F00A0 0x1; # 0: GPIO9_0   1: I2S0_BCLK_RX
himm 0x120F00A4 0x1; # 0: GPIO9_1   1: I2S0_WS_RX
himm 0x120F00A8 0x1; # 0: GPIO9_2   1: I2S0_SD_RX

himm 0x120F00AC 0x2; # 00: GPIO9_3  01: I2S1_BCLK_RX  10:I2S2_MCLK
himm 0x120F00B0 0x1; # 0: GPIO9_4   1: I2S1_WS_RX
himm 0x120F00B4 0x1; # 0: GPIO9_5   1: I2S1_SD_RX

himm 0x120F00B8 0x1; # 0: GPIO9_6   1: I2S2_BCLK_TX
himm 0x120F00BC 0x1; # 0: GPIO9_7   1: I2S2_WS_TX
himm 0x120F00C0 0x1; # 0: GPIO5_4   1: I2S2_SD_TX
#I2S0
himm 0x120f08a0 0x120;           #I2S0_BCLK_RX
himm 0x120f08a4 0x130;           #I2S0_WS_RX
himm 0x120f08a8 0x130;           #I2S0_SD_RX
#I2S1               
himm 0x120f08ac 0x120;           #I2S1_BCLK_RX
himm 0x120f08b0 0x130;           #I2S1_WS_RX
himm 0x120f08b4 0x130;           #I2S1_SD_RX
#I2S2               
himm 0x120f08b8 0x120;           #I2S2_BCLK_TX
himm 0x120f08bc 0x130;           #I2S2_WS_TX
himm 0x120f08c0 0x130;           #I2S2_SD_TX
himm 0x120400E4 0x2
himm 0x13140108 0x00AAAAAA
himm 0x1314010C 0x00000131
himm 0x13140140 0x003254E7
himm 0x13140144 0x00000133
himm 0x1314002C 0xE4000098
himm 0x13141100 0xE4840004
himm 0x1314014c 0x00000133
himm 0x13140148 0x00218DEF
himm 0x13142104 0x10007F00
himm 0x13142004 0x10007F00

ngswfx

2个粉丝

55

问答

1

专栏

40

资料

ngswfx 2020-04-16 23:16:25
认可0
使用如下参数:
himm 0x120F00E0 0x1; # 0:GPIO12_6  1:I2C_SDA
himm 0x120F00E4 0x1; # 0:GPIO12_7  1:I2C_SCL
#I2S
himm 0x120F00A0 0x1; # 0: GPIO9_0   1: I2S0_BCLK_RX
himm 0x120F00A4 0x1; # 0: GPIO9_1   1: I2S0_WS_RX
himm 0x120F00A8 0x1; # 0: GPIO9_2   1: I2S0_SD_RX

himm 0x120F00AC 0x2; # 00: GPIO9_3  01: I2S1_BCLK_RX  10:I2S2_MCLK
himm 0x120F00B0 0x1; # 0: GPIO9_4   1: I2S1_WS_RX
himm 0x120F00B4 0x1; # 0: GPIO9_5   1: I2S1_SD_RX

himm 0x120F00B8 0x1; # 0: GPIO9_6   1: I2S2_BCLK_TX
himm 0x120F00BC 0x1; # 0: GPIO9_7   1: I2S2_WS_TX
himm 0x120F00C0 0x1; # 0: GPIO5_4   1: I2S2_SD_TX
#I2S0
himm 0x120f08a0 0x120;           #I2S0_BCLK_RX
himm 0x120f08a4 0x130;           #I2S0_WS_RX
himm 0x120f08a8 0x130;           #I2S0_SD_RX
#I2S1               
himm 0x120f08ac 0x120;           #I2S1_BCLK_RX
himm 0x120f08b0 0x130;           #I2S1_WS_RX
himm 0x120f08b4 0x130;           #I2S1_SD_RX
#I2S2               
himm 0x120f08b8 0x120;           #I2S2_BCLK_TX
himm 0x120f08bc 0x130;           #I2S2_WS_TX
himm 0x120f08c0 0x130;           #I2S2_SD_TX
himm 0x120400E4 0x2
himm 0x13140108 0x00AAAAAA
himm 0x1314010C 0x00000131
himm 0x13140140 0x003254E7
himm 0x13140144 0x00000133
himm 0x1314002C 0xE4000098
himm 0x13141100 0xE4840004
himm 0x1314014c 0x00000133
himm 0x13140148 0x00218DEF
himm 0x13142104 0x10007F00
himm 0x13142004 0x10007F00

ngswfx

2个粉丝

55

问答

1

专栏

40

资料

ngswfx 2020-04-24 03:20:54
认可0
这个是我修改的驱动源码:
最主要的2个函数,我修改了一下tlv320的源码生成的,然后调整了一下结构,毕竟2中片子功能部分有差异,我没有用原来的配置方法,所以直接把整个结构导入,这样在驱动内部一次性按照配置,一下都执行了
void soft_reset(unsigned int chip_num)
{
        //soft reset
        printk("soft_reset in chip_num:%d addr:0x%x\n",chip_num,IIC_device_addr[chip_num]);

        ES8374_write(IIC_device_addr[chip_num],0x00,0x3F); //IC Rst start
        msleep(1);
        ES8374_write(IIC_device_addr[chip_num],0x00,0x03); //IC Rst stop
        ES8374_write(IIC_device_addr[chip_num],0x01,0x7F); //IC clk on
        ES8374_write(IIC_device_addr[chip_num],0x02,0x08);  //select PLL
        ES8374_write(IIC_device_addr[chip_num],0x03,0x20); //osr =32
        ES8374_write(IIC_device_addr[chip_num],0x6F,0xA0); //pll set:mode enable
        ES8374_write(IIC_device_addr[chip_num],0x72,0x41); //pll set:mode set
        ES8374_write(IIC_device_addr[chip_num],0x09,0x01); //pll set:reset on ,set start   //vcoout devided by 8
        ES8374_write(IIC_device_addr[chip_num],0x0C,0x08); //pll set:k
        ES8374_write(IIC_device_addr[chip_num],0x0D,0x13); //pll set:k
        ES8374_write(IIC_device_addr[chip_num],0x0E,0xe0); //pll set:k
        ES8374_write(IIC_device_addr[chip_num],0x0A,0x4A); //clock manager default:0100 1010=0x4A
        ES8374_write(IIC_device_addr[chip_num],0x0B,0x08);//pll set:n
        ES8374_write(IIC_device_addr[chip_num],0x09,0x41); //pll set:reset off ,set stop
        ES8374_write(IIC_device_addr[chip_num],0x05,0x11); //clk div =1
       
        ES8374_write(IIC_device_addr[chip_num],0x06,0x01); //LRCK div =0100H = 256D
        ES8374_write(IIC_device_addr[chip_num],0x07,0x00);
        ES8374_write(IIC_device_addr[chip_num],0x0F,0x04); //MASTER MODE, BCLK = MCLK/4
        ES8374_write(IIC_device_addr[chip_num],0x10,0x0C); //I2S-16BIT, ADC
        ES8374_write(IIC_device_addr[chip_num],0x11,0x0c); //I2S-16BIT, DAC
       
        ES8374_write(IIC_device_addr[chip_num],0x24,0x08); //adc set
        ES8374_write(IIC_device_addr[chip_num],0x36,0x00); //dac set
        ES8374_write(IIC_device_addr[chip_num],0x12,0x30); //timming set
        ES8374_write(IIC_device_addr[chip_num],0x13,0x20); //timming set
        ES8374_write(IIC_device_addr[chip_num],0x21,0x50); //adc set: SEL LIN1 CH+PGAGAIN=0DB
        ES8374_write(IIC_device_addr[chip_num],0x22,0xFF); //adc set: PGA GAIN=0DB
        ES8374_write(IIC_device_addr[chip_num],0x21,0x14); //adc set: SEL LIN1 CH+PGAGAIN=18DB
        ES8374_write(IIC_device_addr[chip_num],0x22,0x55); //pga = +15db

        ES8374_write(IIC_device_addr[chip_num],0x00,0x80); // IC START
        ES8374_write(IIC_device_addr[chip_num],0x14,0x8A); // IC START
        ES8374_write(IIC_device_addr[chip_num],0x15,0x40); // IC START
        ES8374_write(IIC_device_addr[chip_num],0x1A,0x01); // monoout set
        ES8374_write(IIC_device_addr[chip_num],0x1B,0x09); // monoout set
        ES8374_write(IIC_device_addr[chip_num],0x1C,0x90); // spk set
        ES8374_write(IIC_device_addr[chip_num],0x1D,0x02); // spk set
        ES8374_write(IIC_device_addr[chip_num],0x1F,0x00); // spk set
        ES8374_write(IIC_device_addr[chip_num],0x1E,0xA0); // spk on
        ES8374_write(IIC_device_addr[chip_num],0x28,0x00); // alc set
        ES8374_write(IIC_device_addr[chip_num],0x25,0x00); // ADCVOLUME on
        ES8374_write(IIC_device_addr[chip_num],0x38,0xc0); // DACVOLUMEL on 0db无衰减
        ES8374_write(IIC_device_addr[chip_num],0x6D,0x60); //SEL:GPIO1=DMIC CLK OUT+SEL:GPIO2=PLL CLK OUT
        ES8374_write(IIC_device_addr[chip_num],0x71,0x05);
        ES8374_write(IIC_device_addr[chip_num],0x73,0x70);       

#define CanAutoStartFirst 1
#ifdef CanAutoStartFirst
        //BIAS 11111 100=0xfc -10u
        //BIAS 11111 001=0xf9 -2.5u
        //BIAS 11111 101=0xfd -12.5
        ES8374_write(IIC_device_addr[chip_num],0x18,0xfc);
        //ES8374_write(IIC_device_addr[chip_num],0x18,0xfd);
        //开启转换
        ES8374_write(IIC_device_addr[chip_num],0x36,0x00); //dac set
        ES8374_write(IIC_device_addr[chip_num],0x37,0x00); // dac set

       
        //ADC DMIC
        //1000 1010=0x8a
        //0000 0000=0x0
        ES8374_write(IIC_device_addr[chip_num],0x24,0x0);
        //ALC  10000100=0x84  关闭ALC 00011100=0x1c 不能开启,否则DAC杂音
        //ES8374_write(IIC_device_addr[chip_num],0x26,0x1c);
        //010 10111=0x57 max 34db
        //010 11111=0x5F max 35.5db
        //010 01011=0x4b max 10db
        //010 11001=0x59 max 31db
        //011 11001=0x79 max 31db limit mode
        //000 11001=0x19
        ES8374_write(IIC_device_addr[chip_num],0x26,0x19);
        //PGA Min gain 5bit large=高增益 11011:28.5db=0x1B 01000:0db=0x8  
        //ES8374_write(IIC_device_addr[chip_num],0x27,0x8);
        //000 11011=0x1b 28.5db
        //000 11111=0x1f 30db
        ES8374_write(IIC_device_addr[chip_num],0x27,0x1f);
        //默认1011 0000=0xb0
        ES8374_write(IIC_device_addr[chip_num],0x28,0xb0);
        //0x29 alc decay time and attack time default:110010=0x32
        ES8374_write(IIC_device_addr[chip_num],0x29,0x32);
        //0x2b noise gate default:0
        ES8374_write(IIC_device_addr[chip_num],0x2B,0x0);

        //////////////////////MONO声音输出控制
        //11100 001=0xe1
        //ES8374_write(IIC_device_addr[chip_num],0x1A,0xe1);
        //01100 001=0xe1//必须选择mixer才能确保LINEOUT和SPEAK Out同源
        ES8374_write(IIC_device_addr[chip_num],0x1A,0x62);
        //1001 1011
        ES8374_write(IIC_device_addr[chip_num],0x1B,0x9b);
        //////mix
        //mix  11000000       
        ES8374_write(IIC_device_addr[chip_num],0x1C,0xC0);
        //mixer gain
        //1000 1011
        ES8374_write(IIC_device_addr[chip_num],0x1B,0x9b);
        /////////////////////PGA
        //地址0x21   
        //mic in :0001 1100=0x1c
        //ES8374_write(IIC_device_addr[chip_num],0x21,0x1c);
        //line in:0010 1100=0x2c
        //ES8374_write(IIC_device_addr[chip_num],0x21,0x2c);
        //mic and line in
        //line in:0011 1100=0x3c
        ES8374_write(IIC_device_addr[chip_num],0x21,0x3c);
        //增益
        ES8374_write(IIC_device_addr[chip_num],0x22,0x7);
        //////////////////////ADC
        //jack detect 0x2c default:1101=0xd  通过GPIO或者RLIN1控制是否声音输出,会导致speakers静音
        //7-1:RLin1   1010 1101=0xad
        //ES8374_write(IIC_device_addr[chip_num],0x2c,0xad);
        ////0x2d ADC_SDP_SC-7 11100110=0xe6 会有背景噪声
        //ES8374_write(IIC_device_addr[chip_num],0x2d,0xE6);
        /////////////////////DAC
        //0x36  00000100=0x4 默认 SDP左输出
        //ES8374_write(IIC_device_addr[chip_num], 0x36, 0x4);
        //010 000 00=0x40 SDK右输出 dac soft ramp关闭
        //000 111 00=0x1c 0.5db每512周期
        //000 100 00=0x10 0.5db每64周期
        //000 011 00=0xc 0.5db每32周期
        //000 001 00=0xc 0.5db每4周期
        //000 000 00=0x0 SDK左输出 dac soft ramp关闭
        ES8374_write(IIC_device_addr[chip_num], 0x36, 0x0);
        //0x37  00000000 DAC DSM not mute=0x0
        //double speed 10000000 0x80;
        ES8374_write(IIC_device_addr[chip_num], 0x37, 0x0);
        //0x38  00000000 衰减 0=0db 最大11000000=-96db
        ES8374_write(IIC_device_addr[chip_num], 0x38, 0x0);

        //关闭loop
        ES8374_write(IIC_device_addr[chip_num],0x1C,0x80);

        ///////////////
        //00101100=0x2c
        //11001100=0xcc
        //00000000=0x0
        //00010000=0x10
        //00001100=0xc
        ES8374_write(IIC_device_addr[chip_num],0x10,0xC); //I2S-16BIT, ADC
        //ADC DMIC
        //1000 1010=0x8a
        //0000 0000=0x0
        //1000 0000=0x80 高通滤波关
        //1000 1000=0x88 高通滤波开
        //0000 1011=0xb
        //0000 1100=0xc
        ES8374_write(IIC_device_addr[chip_num],0x24,0x8);
        ES8374_write(IIC_device_addr[chip_num],0x25,0x0);
        //adc
        ////0x2d ADC_SDP_SC-7 11100110=0xe6 会有背景噪声
        //000 00100=0x4;
        ES8374_write(IIC_device_addr[chip_num],0x2D,0x4);
        ////////////////////
#endif

}

void SetCodecPara(ES8374_Audio_Ctrl* audio_ctrl)
{
    if(!audio_ctrl)
        return;
    printk("SetCodecPara:\nbStartMic:%d\n bStartLineIn:%d\n bMicLoopOut:%d\n bLineInLoopOut:%d\n nMicVolume:%d\n nLineInVolume:%d\n nLineOutVolume:%d\n bStartLineOut:%d\n nSpeakOutVolume:%d\n bStartLineOut:%d\n",audio_ctrl->bStartMic,audio_ctrl->bStartLineIn,audio_ctrl->bMicLoopOut,audio_ctrl->bLineInLoopOut,audio_ctrl->nMicVolume,audio_ctrl->nLineInVolume,audio_ctrl->nLineOutVolume,audio_ctrl->bStartLineOut,audio_ctrl->nSpeakOutVolume,audio_ctrl->bStartLineOut);
       
    ////////////////////////////
    audio_ctrl->bStartMic;//MIC输入
    audio_ctrl->bStartLineIn;//线性输入
    audio_ctrl->bStartLineOut;//线性lineout输出
    audio_ctrl->bStartSpeakOut;//带功放输出
    audio_ctrl->bMicLoopOut;//MIC环通输出
    audio_ctrl->bLineInLoopOut;//LINEIN 环通输出
    audio_ctrl->nMicVolume;//MIC音量
    audio_ctrl->nLineInVolume;//LineIn音量
    audio_ctrl->nLineOutVolume;//线性输出音量
    audio_ctrl->nSpeakOutVolume;//功放喇叭输出音量

////////////////////////////////
       
    int chip_num=0;
////////////////////////////
    if((!(audio_ctrl->bStartSpeakOut))&&(!(audio_ctrl->bStartLineOut))){
        //关闭转换
        //001 00000=0x20
        ES8374_write(IIC_device_addr[chip_num],0x36,0x20); //dac set
        //0011 00 0 1=0x31
        ES8374_write(IIC_device_addr[chip_num],0x37,0x31); // dac set
        //-96dB 1100 0000=0xc0
        ES8374_write(IIC_device_addr[chip_num],0x38,0xc0); // DACVOLUMEL 0x0:0db 0xc0:-96db
    }else{
        //开启转换
        ES8374_write(IIC_device_addr[chip_num],0x36,0x00); //dac set
        ES8374_write(IIC_device_addr[chip_num],0x37,0x00); // dac set
        ES8374_write(IIC_device_addr[chip_num],0x38,0x0); // DACVOLUMEL 0x0:0db 0xc0:-96db
    }


    //线性输入 以及MIC输入
    int nHightGain=1;//高增益
    if((audio_ctrl->bStartMic)&&(audio_ctrl->bStartLineIn)){//00111000-0db=0x38 00111100-15db=0x3c MIC and lineIn
            if(nHightGain)
           ES8374_write(IIC_device_addr[chip_num],0x21,0x3c);
        else
           ES8374_write(IIC_device_addr[chip_num],0x21,0x38);
    }
    else if(audio_ctrl->bStartMic&&(!(audio_ctrl->bStartLineIn))){//00011100=0x1c
        if(nHightGain)
           ES8374_write(IIC_device_addr[chip_num],0x21,0x1c);
        else
           ES8374_write(IIC_device_addr[chip_num],0x21,0x18);
    }
    else if(audio_ctrl->bStartLineIn&&(!(audio_ctrl->bStartMic))){//00101100=0x2c
        if(nHightGain)
           ES8374_write(IIC_device_addr[chip_num],0x21,0x2c);
        else
           ES8374_write(IIC_device_addr[chip_num],0x21,0x28);
    }
    else //mic and line in //line in:1100 1100=0xcc
        ES8374_write(IIC_device_addr[chip_num],0x21,0xc8);
    //pga增益调节
    if(nHightGain)
        ES8374_write(IIC_device_addr[chip_num],0x22,0x7);
    else
        ES8374_write(IIC_device_addr[chip_num],0x22,0xf);
   
  
    //线性输出
#if 0
    if(audio_ctrl->bStartLineOut){//01100 001(LineIn)=0x61
            ES8374_write(IIC_device_addr[chip_num],0x1A,0x61);
    }
    else{//01000 001(LineIn)=0x41
        ES8374_write(IIC_device_addr[chip_num],0x1A,0x41);
    }
#else
    if(audio_ctrl->bStartLineOut){//01100 010(diff out1)=0x64
            ES8374_write(IIC_device_addr[chip_num],0x1A,0x62);
    }
    else{//01000 010(diff out1)=0x44
        ES8374_write(IIC_device_addr[chip_num],0x1A,0x42);
    }

#endif
    //line out音量
    if(audio_ctrl->nLineOutVolume<1){
        //01100000=0x60
        ES8374_write(IIC_device_addr[chip_num],0x1B,0x70);
    }else if(audio_ctrl->nLineOutVolume>9){
        //0100 0001=0x9b
        ES8374_write(IIC_device_addr[chip_num],0x1B,0x9b);
    }else{
            switch(audio_ctrl->nLineOutVolume){
          case 1:
            //01100001=0x63
            ES8374_write(IIC_device_addr[chip_num],0x1B,0x73);
            break;       
          case 2:
            //01100010=0x71
            ES8374_write(IIC_device_addr[chip_num],0x1B,0x71);
            break;       
          case 3:
            //01100011=0x50
            ES8374_write(IIC_device_addr[chip_num],0x1B,0x50);
            break;       
          case 4:
            //01100100=0x31
            ES8374_write(IIC_device_addr[chip_num],0x1B,0x31);
            break;       
          case 5:
            //01101000=0x33
            ES8374_write(IIC_device_addr[chip_num],0x1B,0x33);
            break;       
          case 6:
            //01101001=0x38
            ES8374_write(IIC_device_addr[chip_num],0x1B,0x38);
            break;       
          case 7:
            //01101010=0x39
            ES8374_write(IIC_device_addr[chip_num],0x1B,0x39);
            break;       
          case 8:
            //01101011=0x3B
            ES8374_write(IIC_device_addr[chip_num],0x1B,0x3B);
            break;
          case 9:
            //01000000=0x10
            ES8374_write(IIC_device_addr[chip_num],0x1B,0x10);
            break;               
        }
    }
       
        //////mix
        //mix  10000000(DAC to mix)=0x80 01000000(aux to mix)=0x40
        //mix dac and aux 11000000=0xc0       
        //ES8374_write(IIC_device_addr[chip_num],0x1C,0xC8);
        if((audio_ctrl->bMicLoopOut)||(audio_ctrl->bLineInLoopOut)){
                ES8374_write(IIC_device_addr[chip_num],0x1C,0xC0);
               
        }else{
                //no to mix 00000000=0x0
                if((!(audio_ctrl->bStartSpeakOut))&&(!(audio_ctrl->bStartLineOut))){
                        ES8374_write(IIC_device_addr[chip_num],0x1C,0x0);
                        //关闭mix mute 00010000=0x10
                        ES8374_write(IIC_device_addr[chip_num],0x1D,0x10);
                }
                else{////10000000=0x80 dac to mixer
                        ES8374_write(IIC_device_addr[chip_num],0x1C,0x80);
                        //0x1d mixer gain: 0010 0000=0x20 -21db   0x0=-8db
                        ES8374_write(IIC_device_addr[chip_num],0x1D,0x0);
                }
        }
        //mixer gain
        //1000 1011
        ES8374_write(IIC_device_addr[chip_num],0x1B,0x9b);
        ///////Speak ClassD Speaker output
        //10100 111(7.5db)
        if(audio_ctrl->bStartSpeakOut){
                unsigned char nVolume=0;
                if(audio_ctrl->nSpeakOutVolume<1)
                        nVolume=0;
                if(audio_ctrl->nSpeakOutVolume>=8)
                        nVolume=7;
                else
                        nVolume=audio_ctrl->nSpeakOutVolume;
                //10100000+nVolume=0xA0+nVolume
                ES8374_write(IIC_device_addr[chip_num],0x1E,0xA0+nVolume);
        }else{//00000+0
                ES8374_write(IIC_device_addr[chip_num],0x1E,0x0);
        }

}

海思MPI应用层主要就是配置Es8374AudioPara结构体,然后调用如下函数即可:
void SetAudioCodecPara()
{
        int s_fdES8374= -1;
        system("chmod -R 777 /dev/IV_ES8374");
        s_fdES8374 = open(ES8374_FILE,O_RDWR);
    if (s_fdES8374 < 0)
    {
        printf("SetAudioCodecPara can't open ES8374:%s\n",ES8374_FILE);
        return;
    }
    printf("SetAudioCodecPara open ES8374,%s fd:%d\n", ES8374_FILE,s_fdES8374);
    printf(PRINTF_WARNING"SetAudioCodecPara:\nbStartMic:%d\n bStartLineIn:%d\n bMicLoopOut:%d\n bLineInLoopOut:%d\n nMicVolume:%d\n nLineInVolume:%d\n nLineOutVolume:%d\n bStartLineOut:%d\n nSpeakOutVolume:%d\n bStartSpeakOut:%d\n"PRINTF_NONE,Es8374AudioPara.bStartMic,Es8374AudioPara.bStartLineIn,Es8374AudioPara.bMicLoopOut,Es8374AudioPara.bLineInLoopOut,Es8374AudioPara.nMicVolume,Es8374AudioPara.nLineInVolume,Es8374AudioPara.nLineOutVolume,Es8374AudioPara.bStartLineOut,Es8374AudioPara.nSpeakOutVolume,Es8374AudioPara.bStartSpeakOut);
    Es8374AudioPara.chip_num = 0;
    if (ioctl(s_fdES8374,SET_CODEC_PARA,&Es8374AudioPara))
        printf("[Func]:%s [Line]:%d [Info]:%s\n", __FUNCTION__, __LINE__, " ES8374 SET_CODEC_PARA failed");
    close(s_fdES8374);
    s_fdES8374=0;
        ///////////////////
}

初始化芯片时:
int s_fdTlv = -1;
s_fdTlv = open(ES8374_FILE,O_RDWR);
     if (s_fdTlv < 0)
     {
         printf("can't open ES8374,%s\n", ES8374_FILE);
         return -1;
     }
     printf("open ES8374,%s fd:%d\n", ES8374_FILE,s_fdTlv);

     audio_ctrl.chip_num = 0;
     if (ioctl(s_fdTlv,SOFT_RESET,&audio_ctrl))
     {
         printf("[Func]:%s [Line]:%d [Info]:%s\n", __FUNCTION__, __LINE__, " ES8374 reset failed");
     }
//////////////////////////
        memset(&Es8374AudioPara,0,sizeof(ES8374_Audio_Ctrl));
#ifdef LOOP_MIC_LINE_IN_WHEN_START
        Es8374AudioPara.bLineInLoopOut=1;
        Es8374AudioPara.bMicLoopOut=1;
#else
        Es8374AudioPara.bLineInLoopOut=0;
        Es8374AudioPara.bMicLoopOut=0;
#endif
        Es8374AudioPara.bStartLineIn=1;
        Es8374AudioPara.bStartMic=1;
        Es8374AudioPara.bStartSpeakOut=1;
        Es8374AudioPara.bStartLineOut=1;
        Es8374AudioPara.nLineInVolume=5;
        Es8374AudioPara.nMicVolume=5;
        Es8374AudioPara.nLineOutVolume=s32Volume;
        Es8374AudioPara.nSpeakOutVolume=s32Volume;
        ioctl(s_fdTlv,SET_CODEC_PARA,&Es8374AudioPara);
        ////////////////////////////
    close(s_fdTlv);
////////////////////////////////////目前控制lineOut SpeakOut都还是对的,还通输出MIC和LineIn也是对的,声音也比较大,目前唯一的问题,就是MIC和LINEIn输入的声音,经过i2s,进入海思音频输入,编码整个体系后,声音很小,目前我还在找原因。

ngswfx

2个粉丝

55

问答

1

专栏

40

资料

ngswfx 2020-04-24 03:23:15
认可0
回复的有点乱了,主要是每次修改要审核,以为没成功,结果发了一堆,删除也没法及时体现,不太习惯。有几个回复,没有意义,重复了。看的时候,忽略即可。

ngswfx

2个粉丝

55

问答

1

专栏

40

资料

ngswfx 2020-04-24 05:18:44
认可0
MIC以及LINE in 输入音量太小,寄存器是0x21,不能开启LDCM 否则输入的音量非常小,

ES8374_write(IIC_device_addr[chip_num],0x21,0x34); 这个配置是可以的
或将文件直接拖到这里
悬赏:
E币
网盘
* 网盘链接:
* 提取码:
悬赏:
E币

Markdown 语法

  • 加粗**内容**
  • 斜体*内容*
  • 删除线~~内容~~
  • 引用> 引用内容
  • 代码`代码`
  • 代码块```编程语言↵代码```
  • 链接[链接标题](url)
  • 无序列表- 内容
  • 有序列表1. 内容
  • 缩进内容
  • 图片![alt](url)
+ 添加网盘链接/附件

Markdown 语法

  • 加粗**内容**
  • 斜体*内容*
  • 删除线~~内容~~
  • 引用> 引用内容
  • 代码`代码`
  • 代码块```编程语言↵代码```
  • 链接[链接标题](url)
  • 无序列表- 内容
  • 有序列表1. 内容
  • 缩进内容
  • 图片![alt](url)
相关问答
无更多相似问答 去提问
举报反馈

举报类型

  • 内容涉黄/赌/毒
  • 内容侵权/抄袭
  • 政治相关
  • 涉嫌广告
  • 侮辱谩骂
  • 其他

详细说明

易百纳技术社区