海思hi3531d音频外接codec (tlv320aic32x4)(二)

与set_divs和get_divs函数有关,c文件中定义了结构体变量aic32x4_divs[]

typedef union { struct audio_interface_t interface; struct other_config_t other; struct adc_dac_config_t adc; struct adc_dac_config_t dac; struct agc_config1_t agc_conf1; struct agc_config2_t agc_conf2; struct agc_config3_t agc_conf3; struct agc_config4_t agc_conf4; struct audio_power_up_t powerup; struct hp_route_t hp; struct lo_route_t lo; struct output_volume_t output_volume; struct output_mute_t output_mute; struct micpga_left_t micpga_left; struct micpga_right_t micpga_right; struct micpga_volum_t micpga_volume; struct float_input_t float_input; }Audio_Ctrl;

由于有众多的选项需要配置,为了方便应用层调用ioctl,同时也方便ioctl 的cmd定义,做了这样一个联合体,需要配置哪个部分,就对哪个部分进行赋值 在c文件中,可以看到ioctl中有这么一段,其实就是接收应用层的cmd参数

Audio_Ctrl temp; Audio_Ctrl* audio_ctrl; if (argp != NULL) { if (copy_from_user(&temp, argp, sizeof(Audio_Ctrl))) { return -EFAULT; } } audio_ctrl = (Audio_Ctrl*)(&temp);

结构体说明 接下来详细解释一下各个结构体,为了理解这些结构体的含义,需要看3254的手册,那个路由的图,以及各个寄存器说明

struct audio_interface_t { unsigned int sample_rate; unsigned char transfer_mode; unsigned char master_slave_mode; unsigned char chn_num; unsigned char bit_width; unsigned char data_offset; };

sample_rate是音频的采样率,目前常用的是48k,44.1k和8k transfer_mode传输模式,只做了i2s的调试,pcm理论上是可以,但是没有调过 master_slave_mode规定了3254的主从模式,注意是3254,不是海思的 chn_num通道数,可以分时复用传输多个声道的数据,但是一般是两个声道的立体声 bit_width位深,也叫采样精度,目前固定为16bit data_offset数据在bclk时钟的偏移,这个参数给0就行,实际上从波形看,海思和codec都是偏移了一个blck周期 这个结构体针对dac和adc,联合体Audio_Ctrl中,既定义了adc,也定义了dac

struct adc_dac_config_t { unsigned char power_up; unsigned char left_power_up; unsigned char right_power_up; unsigned char mute; unsigned char left_mute; unsigned char right_mute; unsigned char volume; unsigned char left_volume; unsigned char right_volume; };

power_up左右都使能 left_power_up左边使能 right_power_up右边使能 3254这款codec的配置做的很细,为了减少代码量,可以直接用power_up,实现left_power_up加right_power_up的功能,如果想要分开设置,也可以单独进行left_power_up或者right_power_up,ioctl提供了三个命令(ADC_POWER_UP 、ADC_LEFT_POWER_UP 、ADC_RIGHT_POWER_UP)来实现这种功能。在其它的结构体中也可以看到大量这种形式的处理,下文不再单独描述 mute静音设置 volume音量调节

struct other_config_t { unsigned char loop_data_in_to_data_out; unsigned char loop_adc_to_dac; unsigned char micbias_power_up; unsigned char micbias_output_voltage; unsigned char micbias_voltage_source; unsigned char adc_signal_block; unsigned char dac_signal_block; };

loop_data_in_to_data_out 数据从data in进入后,直接环出到data out,不经过任何通道、adc、dac之类的,这个一般是不用的,测试可以看有没用声音 loop_adc_to_dac 数据从adc进入,然后环出到dac,中间不经过其它处理,同上,一般不用,仅做测试 micbias_xxx 针对数字麦克风的,用不上的话就不用管,需要使用就参考3254的文档说明 adc_signal_block和dac_signal_block,是内置的处理算法,一般用默认的就行

struct agc_config1_t struct agc_config2_t struct agc_config3_t struct agc_config4_t

agc这些参数我也不怎么懂,按照手册做了一下

struct audio_power_up_t { unsigned char hp_power_up; unsigned char hpl_power_up; unsigned char hpr_power_up; unsigned char lo_power_up; unsigned char lol_power_up; unsigned char lor_power_up; unsigned char ma_power_up; unsigned char mal_power_up; unsigned char mar_power_up; };

headphone,Mixer Amplifier、line out的使能

struct hp_route_t { unsigned char ldac_hpl; unsigned char in1l_hpl; unsigned char mal_hpl; unsigned char mar_hpl; unsigned char ldac_hpr; unsigned char rdac_hpr; unsigned char in1r_hpr; unsigned char mar_hpr; unsigned char hpl_hpr; };

headphone左右通道数据的来源,可以来自dac,in1,或者ma

struct lo_route_t { unsigned char ldac_lol; unsigned char rdac_lol; unsigned char mal_lol; unsigned char lor_lol; unsigned char rdac_lor; unsigned char mar_lor; };

line out的左右通道数据来源

struct output_volume_t { unsigned char hp_volume; unsigned char hpl_volume; unsigned char hpr_volume; unsigned char lo_volume; unsigned char lol_volume; unsigned char lor_volume; unsigned char in1l_hpl_volume; unsigned char in1r_hpr_volume; unsigned char ma_volume; unsigned char mal_volume; unsigned char mar_volume; };

输出音频,主要是hp、lo、ma的音量,另外in1可以不经过其它处理,直接路由到hp,这个音量也是可以调节的

struct output_mute_t { unsigned char hp_mute; unsigned char hpl_mute; unsigned char hpr_mute; unsigned char lo_mute; unsigned char lol_mute; unsigned char lor_mute; };

输出静音,没什么好说的

struct micpga_left_t { unsigned char in1l_micpga; unsigned char in2l_micpga; unsigned char in3l_micpga; unsigned char in1r_micpga; unsigned char cm_micpga_via_cm1l; unsigned char in2r_micpga; unsigned char in3r_micpga; unsigned char cm_micpga_via_cm2l; }; struct micpga_right_t { unsigned char in1r_micpga; unsigned char in2r_micpga; unsigned char in3r_micpga; unsigned char in1l_micpga; unsigned char cm_micpga_via_cm1r; unsigned char in2l_micpga; unsigned char in3l_micpga; unsigned char cm_micpga_via_cm2r; }; struct micpga_volum_t { unsigned char power_up; unsigned char left_power_up; unsigned char right_power_up; unsigned char volume; unsigned char left_volume; unsigned char right_volume; };
<

https://blog.csdn.net/whitefish520/article/details/108129844

免责声明:文章内容来自互联网,本站不对其真实性负责,也不承担任何法律责任,如有侵权等情况,请与本站联系删除。
转载请注明出处:海思hi3531d音频外接codec (tlv320aic32x4)(二) https://www.yhzz.com.cn/a/14899.html

上一篇 2023-05-12
下一篇 2023-05-12

相关推荐

联系云恒

在线留言: 我要留言
客服热线:400-600-0310
工作时间:周一至周六,08:30-17:30,节假日休息。