// DAC业务驱动(I2C接口)
// 杭州秒寻科技有限公司
// 周涛
// 2023-09-30

#ifndef DRIVERAPPDAC_H
#define DRIVERAPPDAC_H

#include "sysdef.h"

#define DAC_SLAVE_ADDRESS 0x98   // DAC地址
#define DAC_REG_ADDRESS_OFFSET 0 // 寄存器地址偏移，取决于ADR6和ADR5两个管脚的状态

// DAC寄存器地址
#define DAC_REG_ADDRESS_16 DAC_REG_ADDRESS_OFFSET + 16 // 16号寄存器
#define DAC_REG_ADDRESS_17 DAC_REG_ADDRESS_OFFSET + 17 // 省电+I2S接口配置
#define DAC_REG_ADDRESS_18 DAC_REG_ADDRESS_OFFSET + 18 // 操作控制和数字滤波
#define DAC_REG_ADDRESS_19 DAC_REG_ADDRESS_OFFSET + 19 // 输出相位管理
#define DAC_REG_ADDRESS_20 DAC_REG_ADDRESS_OFFSET + 20 // 软件静音
#define DAC_REG_ADDRESS_21 DAC_REG_ADDRESS_OFFSET + 21 // 0标识
#define DAC_REG_ADDRESS_22 DAC_REG_ADDRESS_OFFSET + 22 // 数字衰减、去加重、自动静音和0标识选择、0标识功能选择、0标识极性选择
#define DAC_REG_ADDRESS_24 DAC_REG_ADDRESS_OFFSET + 24 // 左通道衰减级别选择
#define DAC_REG_ADDRESS_25 DAC_REG_ADDRESS_OFFSET + 25 // 右通道衰减级别选择

// 供外部使用接口
uint8 driverapp_dac_init();
uint8 driverapp_dac_init_config(uint8 bySwitch, uint8 byGain);
uint8 driverapp_dac_set_attenuation(uint8 byChannel, uint8 byAttenuation);
uint8 driverapp_dac_turn_on(uint8 byChannel);
uint8 driverapp_dac_turn_off(uint8 byChannel);

// 内部接口
uint8 driverapp_dac_write_data(uint8 byRegAddress, uint8 *pbyData, uint16 wLen);
uint8 driverapp_dac_read_data(uint8 byRegAddress, uint8 *pbyData, uint16 wLen);
uint8 driverapp_dac_init_reg();

#endif
