9.2. AUDIO_DAC
概述
提供DAC的配置介绍、推荐使用方式和注意点
9.2.1. 应用实例
示例演示:
进入
demo_DevKitBoard/include/demo_config.h
,开启宏USE_AUDIO_DEMO
按键切换使用本地播放模式和录音模式将进行音频dac播放
9.2.2. 常见问题
Note
DAC模拟通道hw_channel配置说明
FL(Front Left Channel) 左前声道 BIT(0)
FR(Front Right Channel) 右前声道 BIT(1)
RL(Rear Left Channel) 左后声道 BIT(2)
RR(Rear Right Channel) 右后声道 BIT(3)
例如:模拟通道hw_channel = BIT(0) (使用FL),hw_channel = BIT(0) | BIT(2) (使用FL和RL)
DAC数字通道数量ch_num配置说明
当使用到RDAC时,FDAC对应的数字通道也需要打开(注意不是模拟通道);当使用到硬件差分时(FL和FR或者RL和RR单通道差分),每一对单通道差分只需打开一路数字通道即可,例如(FL和FR单通道硬件差分只需填ch_num=1
DAC开机第一声出声延时默认1秒,延时时间可通过配置板级的vcm_init_delay_ms参数调整
9.2.3. 配置说明
//DAC配置参数说明 struct dac_platform_data { u8 sw_differ; //软件差分 0:不使用 1:使用 (只针对FL和RL两路通道作为软件差分输出时的配置) u8 pa_auto_mute; //暂停DAC时是否自动MUTE功放 0:不mute功放 1:MUTE功放 u8 pa_mute_port; //功放MUTE IO u8 pa_mute_value; //MUTE电平值 0:低电平 1:高电平 u8 differ_output; //是否使用硬件差分输出模式 0:不使用 1:使用 (只适用于FL和FR、RL和RR) u8 hw_channel; //硬件DAC模拟通道 u8 ch_num; //数字通道,软件DMA输出通道数量 u8 fade_enable; //模拟音量淡入淡出使能位 u16 mute_delay_ms; //解MUTE延时ms u16 fade_delay_ms; //模拟音量每级模拟增益淡入淡出延时ms u16 sr_points; //多少个采样点进一次中断,一般不建议修改 u16 vcm_init_delay_ms; //VCM电压初始化后等待稳定的延时ms u32 poweron_delay; //低功耗睡眠时恢复DAC模块的延迟us }; //单声道单端输出 static const struct dac_platform_data dac_data = { .sw_differ = 0, .pa_auto_mute = 0, .pa_mute_port = IO_PORTB_02, .pa_mute_value = 0, .differ_output = 0, .hw_channel = BIT(0), .ch_num = 1, }; //软件单声道差分输出 static const struct dac_platform_data dac_data = { .sw_differ = 1, .pa_auto_mute = 0, .pa_mute_port = IO_PORTB_02, .pa_mute_value = 0, .differ_output = 0, .hw_channel = BIT(0) | BIT(2), .ch_num = 4, }; //软件双声道单端输出 static const struct dac_platform_data dac_data = { .sw_differ = 0, .pa_auto_mute = 0, .pa_mute_port = IO_PORTB_02, .pa_mute_value = 0, .differ_output = 0, .hw_channel = BIT(0) | BIT(2), .ch_num = 4, }; /*************************以下配置仅适用于具有4路DAC的封装******************************/ //单声道差分输出 static const struct dac_platform_data dac_data = { .sw_differ = 0, .pa_auto_mute = 0, .pa_mute_port = IO_PORTB_02, .pa_mute_value = 0, .differ_output = 1, .hw_channel = BIT(0) | BIT(1), .ch_num = 1, }; //双声道单端输出 static const struct dac_platform_data dac_data = { .sw_differ = 0, .pa_auto_mute = 0, .pa_mute_port = IO_PORTB_02, .pa_mute_value = 0, .differ_output = 0, .hw_channel = BIT(0) | BIT(1), .ch_num = 2, }; //双声道差分输出 static const struct dac_platform_data dac_data = { .sw_differ = 0, .pa_auto_mute = 0, .pa_mute_port = IO_PORTB_02, .pa_mute_value = 0, .differ_output = 1, .hw_channel = BIT(0) | BIT(1) | BIT(2) | BIT(3), .ch_num = 2, }; //三声道单端输出 static const struct dac_platform_data dac_data = { .sw_differ = 0, .pa_auto_mute = 0, .pa_mute_port = IO_PORTB_02, .pa_mute_value = 0, .differ_output = 0, .hw_channel = BIT(0) | BIT(1) | BIT(2), .ch_num = 3, }; //四声道单端输出 static const struct dac_platform_data dac_data = { .sw_differ = 0, .pa_auto_mute = 0, .pa_mute_port = IO_PORTB_02, .pa_mute_value = 0, .differ_output = 0, .hw_channel = BIT(0) | BIT(1) | BIT(2) | BIT(3), .ch_num = 4, };
9.2.4. API参考
淡入淡出状态
-
FADE_DISABLE
淡入淡出失能
-
FADE_VOL_OUT
淡入淡出模拟音量淡出
-
FADE_VOL_IN
淡入淡出模拟音量淡入
-
FADE_VOL_UPDOWN
淡入淡出模拟音量调节
-
void dac_early_init(u8 trim_en, u8 hw_channel, u32 dly_msecs)
dac_early_init, dac初始化
- Parameters
trim_en – 0:初始化不trim dac 1:初始化时trim dac
hw_channel – 硬件dac通道配置BIT(x)
dly_msecs – 延时时间
-
int dac_open(const struct dac_platform_data *pd)
打开dac模块
- Parameters
struct – dac_platform_data *pd dac配置参数结构体参数指针
-
int dac_on(void)
dac模块使能
-
int dac_off(void)
dac模块失能
-
int dac_close(void)
关闭dac模块
-
void dac_power_on(void)
低功耗休眠起来后恢复dac模块
-
void dac_power_off(void)
低功耗进入前挂起dac模块
-
void dac_set_volume(s16 volume)
dac数字音量设置
- Parameters
volume – 音量0-16384
-
int dac_set_sample_rate(u32 sample_rate)
dac采样率设置
- Parameters
sample_rate – 采样率
-
int dac_get_sample_rate(void)
获取当前dac采样率
- Returns
DAC当前采样率
-
void dac_irq_handler(void)
dac中断函数
-
void dac_set_data_handler(void *priv, void (*handler)(void*, u8 *data, int len))
dac中断的回调函数设置
- Parameters
priv – 传入指针
handler – 传入的回调函数
-
void dac_set_gain(u8 gain, u8 fade_opt)
dac模拟增益设置
- Parameters
gain – 模拟增益0-31
fade_opt – 淡入淡出状态位
-
void dac_direct_set_gain(u8 gain)
dac直通模拟增益设置
- Parameters
gain – 模拟增益0-31
-
void dac_fade_inout_set(u8 enable)
dac模拟增益淡入淡出设置
- Parameters
enable – 0:关闭 1:使能
-
int audio_dac_read_single_channel(u16 *read_pos, s16 points_offset, void *data, int len)
读取DAC DMA BUF的单通道数据
- Parameters
read_pos – 读指针
points_offset – 偏移量
data – 数据指针
len – 数据长度
- Returns
数据长度