#ifndef _IIC_CONFIG_H_
#define _IIC_CONFIG_H_

#include "codec_adc.h"
#include "codec_dac.h"

#define CONFIG_DEBUG   1

#if CONFIG_DEBUG
    #define config_bug(fmt, ...)      debug(fmt, ##__VA_ARGS__)
#else
    #define config_bug(fmt, ...)
#endif

#define DENOISE_CFG_ADDR             ((uint32_t)(FW_HEADER->BIN[3].ADDR))
#define AEC_CFG_ADDR                 ((uint32_t)(FW_HEADER->BIN[3].ADDR))
#define AGC_CFG_ADDR                 (DENOISE_CFG_ADDR + sizeof(denoise_param_def))
#define EQ_CFG_ADDR                  (AGC_CFG_ADDR + sizeof(agc_param_def))
#define DRC_CFG_ADDR                 (EQ_CFG_ADDR + sizeof(eq_param_def))
#define HARD_WARE_CFG_ADDR           (DRC_CFG_ADDR + sizeof(drc_param_def))


#define DENOISE_EN_ADDR               0X01    /*降噪使能地址*/
#define DENOISE_LEVEL_ADDR            0X02    /*降噪等级地址*/

#define DENOISE_MIC_GAIN_ADDR         0X03    /*MIC增益地址*/
#define DENOISE_MIC0_GAIN_ADDR        0X30    /*MIC0增益地址*/
#define DENOISE_MIC1_GAIN_ADDR        0X31    /*MIC1增益地址*/
#define DENOISE_MIC_CHOOSE_ADDR       0X04    /*MIC选择地址*/

#define DENOISE_HP_VOLUME_ADDR        0X05    /*音量等级地址*/
#define DENOISE_HP_OUT_CHOOSE_ADDR    0X06    /*HP输出选择地址*/
#define DAC_EQ_TYPE_ADDR              0X07    /*DAC EQ类型地址*/

#define DENOISE_ENTER_WFI             0X08    /*系统进入WFI*/
#define DENOISE_ENTER_HIBERNATE       0X09    /*系统进入HIBERNATE*/

#define SYSTEM_RESET                  0XF0    /*系统重启*/



typedef enum
{
    BOTH_AFTER_DENOISE,   /*左右声道同时输出降噪后的音频*/
    BOTH_PRIMITIVE,       /*左右声道同时输出原始数据*/
    SEPARATE_AUDIO,       /*左右声道输出降噪前后的音频*/

} output_option_e;

typedef enum
{
    AI_DENOISE,                /*AI降噪功能*/
    MMSE_DENOISE,              /*MMSE降噪功能*/
    AEC_FUNCTION,              /*回声消除*/
    HOWLING_SUPPRESSION,       /*啸叫抑制*/
} function_option_e;


typedef enum
{
   BY_GPIO0,
   BY_ONOFF,
   NO_CONTROL,
} power_control_e;

typedef enum
{
   NONE_BUS,
   IIC_BUS,
   UART_BUS,
} codec_bus_e;

typedef enum
{
    A_TO_A,                    /*模拟进模拟出*/
    A_TO_D,                    /*模拟进数字出*/
    D_TO_A,                    /*数字进模拟出*/
    D_TO_D,                    /*数字进数字出*/
} mode_option_e;


typedef struct denoise_param_t
{
    uint32_t start_magic;
    uint32_t param_version;
    uint32_t function;
    uint32_t mode;
    uint32_t enable;
    uint32_t level;
    input_option_e input_option;
    output_option_e output_option;
    uint32_t mic_gain;
    output_hp_volume_e hp_volume;
    dac_param_inverse_type dac_output_inverse;
    uint32_t iis_smplerate;
    uint32_t iis_bitwidth;
    uint32_t iis_rx_function;
    uint32_t iis_tx_function;
    uint32_t reserve5;
    uint32_t reserve6;
    uint32_t reserve7;
    uint32_t reserve8;
    uint32_t reserve9;
    uint32_t reserve10;
    uint32_t stop_magic;

} denoise_param_def;

typedef struct AEC_param_t
{
    uint32_t start_magic;
    uint32_t param_version;
    uint32_t function;
    uint32_t mode;
    uint32_t enable;
    uint32_t level;
    input_option_e mian_mic_option;
    uint32_t mian_mic_gain;
    output_option_e sub_mic_option;
    uint32_t sub_mic_gain;
    output_option_e output_option;
    output_hp_volume_e hp_volume;
    dac_param_inverse_type dac_output_inverse;
    uint32_t iis_smplerate;
    uint32_t iis_bitwidth;
    uint32_t iis_rx_function;
    uint32_t iis_tx_function;
    uint32_t reserve5;
    uint32_t reserve6;
    uint32_t reserve7;
    uint32_t reserve8;
    uint32_t stop_magic;

} AEC_param_def;

typedef struct agc_param_t
{
    uint32_t agc_start_magic;
    uint32_t agc_param_type;
    uint32_t agc_param_enable;
    adc_AGC_config_typedef_def  agc_config;
    uint32_t reserved_1;
    uint32_t reserved_2;
    uint32_t reserved_3;
    uint32_t reserved_4;
    uint32_t reserved_5;
    uint32_t reserved_6;
    uint32_t reserved_7;
    uint32_t reserved_8;
    uint32_t agc_stop_magic;
} agc_param_def;


typedef struct eq_param_t
{
    uint32_t eq_start_magic;
    uint32_t eq_param_type;
    uint32_t eq_param_enable;
    uint32_t eq_enable;
    uint32_t eq_type;
    uint32_t data[40];
    uint32_t eq_stop_magic;
} eq_param_def;


typedef struct drc_param_t
{
    uint32_t drc_start_magic;
    uint32_t drc_param_type;
    uint32_t drc_param_enable;
    dac_drc_config_typedef_def  drc_config;
    uint32_t reserved_1;
    uint32_t reserved_2;
    uint32_t reserved_3;
    uint32_t reserved_4;
    uint32_t reserved_5;
    uint32_t reserved_6;
    uint32_t reserved_7;
    uint32_t reserved_8;
    uint32_t reserved_9;
    uint32_t reserved_10;
    uint32_t agc_stop_magic;
} drc_param_def;

typedef struct user_function_t
{
    uint32_t start_magic;
    uint32_t param_type;
    uint32_t param_enable;
    uint32_t function_switch_pin;
    uint32_t mute_switch_pin;
    uint32_t function_led_pin;
    uint32_t mute_led_pin;
    uint32_t power_contrl;
    uint32_t codec_bus;
    uint32_t reserve[10];
    uint32_t stop_magic;
} user_function_def;

typedef struct set_param_t
{
    unsigned char addr;
    unsigned char value;
} set_param_def;

//设置DSP音频通路
#define A__TO__A                 //模拟进->降噪->模拟出
#define A__TO__D_MASTER          //模拟进->降噪->IIS主机出
#define A__TO__D_SLAVE           //模拟进->降噪->IIS从机出
#define D_MASTER__TO__A          //IIS主机进->降噪->模拟出
#define D_SLAVE__TO__A           //IIS从机进->降噪->模拟出
#define D_MASTER__TO__D_TASTER   //IIS主机进->降噪->IIS主机出
#define D_SLAVE__TO__D_SLAVE     //IIS从机进->降噪->IIS从机出


extern __ALIGNED(4) denoise_param_def   denoise_param;
extern __ALIGNED(4) AEC_param_def       aec_param;
extern __ALIGNED(4) agc_param_def       agc_param;
extern __ALIGNED(4) eq_param_def        eq_param;
extern __ALIGNED(4) drc_param_def       drc_param;
extern __ALIGNED(4) user_function_def   user_param;
extern __ALIGNED(4) set_param_def       set_param;

void get_param_from_ext(void);
void i2c_init(void);
void show_default_user_config(void);
void system_restart(void);

extern short sin_tab[256 * 2];

#endif
