/************************************************************
  Copyright (C), 2009-2019, eway Tech. Co., Ltd.
  FileName: tas5548.c
  Author: Roger       Version : 1.0          Date: 2013.12.01
  Description:       
  Version:         
  Function List:   
    1. -------
  History:         
      <author>  <time>   <version >   <desc>
      Roger    2017/05/01     1.0     build this moudle 
***********************************************************/
#include "type.h"
#include "stm32f0xx.h"
#include ".\..\system\system_config.h"
#include ".\..\driver\iic_sw.h"
#include "tas5548.h"


#define TAS5548_IIC_ADD     0x34


const u8 ASRC_CONTROL1_C4[]={0xc4, 0x01, 0x00, 0x10, 0x55};
const u8 ASRC_CONTROL2_C4[]={0xc4, 0x01, 0x00, 0x40, 0x55};
const u8 ASRC_MODE1_C5[]={0xc5, 0x07, 0x11, 0x00, 0x02};    // asrc2 master
const u8 ASRC_MODE2_C5[]={0xc5, 0x00, 0x11, 0x00, 0x02};    // asrc2 slave

const u8 BASS_FILTER_SET_DA[]={0xda, 0x01, 0x01, 0x01, 0x01};
const u8 TREBLE_FILTER_SET_DC[]={0xdc, 0x02, 0x02, 0x02, 0x02};

#if 0
const u8 eq_mode_normal_192k[7][20]=
{
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
};
const u8 eq_mode_country_192k[7][20]=
{
    {0x00,0x80,0x0b,0x0c, 0xff,0x00,0x35,0xc9, 0x00,0x7f,0xbf,0x64, 0x00,0xff,0xca,0x37, 0xff,0x80,0x35,0x90,},
    {0x00,0x67,0xae,0x56, 0xff,0x89,0x43,0x4c, 0x00,0x1c,0x10,0x98, 0x00,0x97,0x2a,0x53, 0xff,0xdb,0xd3,0x71,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
};
const u8 eq_mode_heavy_rock_192k[7][20]=
{
    {0x00,0x7f,0xe5,0x7a, 0xff,0x00,0x35,0x0b, 0x00,0x7f,0xe5,0x7a, 0x00,0xff,0xca,0xef, 0xff,0x80,0x35,0x06,},
    {0x00,0x80,0x2e,0x54, 0xff,0x00,0x2a,0xfc, 0x00,0x7f,0xa6,0xd0, 0x00,0xff,0xd5,0x04, 0xff,0x80,0x2a,0xdb,},
    {0x00,0xb2,0xa5,0x65, 0xfe,0xb1,0x7b,0x9c, 0x00,0x9d,0x3d,0x00, 0x00,0xec,0x9e,0xcf, 0xff,0x92,0x03,0x2e,},
    {0x00,0xb0,0x7f,0xbf, 0xfe,0xcc,0x33,0x12, 0x00,0x88,0x77,0x14, 0x00,0xd9,0x26,0xeb, 0xff,0xa1,0xaf,0x2f,},
    {0x00,0x7f,0xf5,0x48, 0xff,0x55,0x5f,0xba, 0x00,0x2a,0xaa,0xfe, 0x00,0xaa,0x99,0x21, 0xff,0xd5,0x58,0x95,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
};
const u8 eq_mode_lite_rock_192k[7][20]=
{
    {0x00,0x7f,0xe9,0x44, 0xff,0x00,0x2d,0x78, 0x00,0x7f,0xe9,0x44, 0x00,0xff,0xd2,0x84, 0xff,0x80,0x2d,0x74,},
    {0x00,0x80,0x25,0x29, 0xff,0x00,0x8b,0x20, 0x00,0x7f,0x4f,0xb6, 0x00,0xff,0x74,0xd2, 0xff,0x80,0x8b,0x12,},
    {0x00,0x34,0xd5,0x20, 0x00,0x02,0x88,0x84, 0xff,0xcd,0xb3,0x64, 0x00,0xbd,0xe9,0xcc, 0xff,0xbd,0x05,0x2c,},
    {0x00,0x80,0x0c,0x82, 0xff,0x00,0x20,0x4c, 0x00,0x7f,0xd3,0x57, 0x00,0xff,0xdf,0xb4, 0xff,0x80,0x20,0x26,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
};
const u8 eq_mode_jazz_192k[7][20]=
{
    {0x00,0xc5,0x31,0x5d, 0xff,0x4e,0x35,0x0f, 0x00,0x00,0x00,0x00, 0x00,0x6c,0x99,0x93, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
};
const u8 eq_mode_rop_192k[7][20]=
{
    {0x00,0x7f,0xf0,0xd7, 0xff,0x00,0x1e,0x51, 0x00,0x7f,0xf0,0xd7, 0x00,0xff,0xe1,0xad, 0xff,0x80,0x1e,0x50,},
    {0x00,0x7f,0xe9,0x44, 0xff,0x00,0x2d,0x78, 0x00,0x7f,0xe9,0x44, 0x00,0xff,0xd2,0x84, 0xff,0x80,0x2d,0x74,},
    {0x00,0x80,0x17,0x2b, 0xff,0x00,0x15,0x90, 0x00,0x7f,0xd3,0x64, 0x00,0xff,0xea,0x70, 0xff,0x80,0x15,0x70,},
    {0x00,0x80,0x1c,0xf6, 0xff,0x00,0x1b,0x14, 0x00,0x7f,0xc8,0x3e, 0x00,0xff,0xe4,0xec, 0xff,0x80,0x1a,0xcb,},
    {0x00,0x7f,0xf3,0x7e, 0xff,0x00,0x39,0xa7, 0x00,0x7f,0xd3,0x5c, 0x00,0xff,0xc6,0x5a, 0xff,0x80,0x39,0x25,},
    {0x00,0x7f,0xa8,0x57, 0xff,0x02,0x5d,0xd9, 0x00,0x7d,0xff,0x5f, 0x00,0xfd,0xa2,0x27, 0xff,0x82,0x58,0x49,},
    {0x00,0xb1,0x36,0xe9, 0xfe,0xc3,0x51,0xe6, 0x00,0x8f,0x1d,0xb7, 0x00,0xdf,0xa8,0xc4, 0xff,0x9c,0xb0,0xb5,},
};

const void* eq_mode_192k[6]=
{
    eq_mode_normal_192k,
    eq_mode_country_192k,
    eq_mode_heavy_rock_192k,
    eq_mode_lite_rock_192k,
    eq_mode_jazz_192k,
    eq_mode_rop_192k,
};
#endif

#if 1
const u8 eq_mode_normal_96k[7][20]=
{
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
};
const u8 eq_mode_country_96k[7][20]=
{
    {0x00,0x80,0x16,0x15, 0xff,0x00,0x6b,0xf5, 0x00,0x7f,0x7e,0xdb, 0x00,0xff,0x94,0x0b, 0xff,0x80,0x6b,0x0f,},
    {0x00,0x69,0x67,0x8f, 0xff,0xba,0xdf,0x39, 0x00,0x00,0x00,0x00, 0x00,0x5b,0xb9,0x37, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
};
const u8 eq_mode_heavy_rock_96k[7][20]=
{
    {0x00,0x7f,0xca,0xf7, 0xff,0x00,0x6a,0x12, 0x00,0x7f,0xca,0xf7, 0x00,0xff,0x95,0xd8, 0xff,0x80,0x69,0xfc,},
    {0x00,0x80,0x5c,0xa0, 0xff,0x00,0x56,0x2e, 0x00,0x7f,0x4d,0xb3, 0x00,0xff,0xa9,0xd2, 0xff,0x80,0x55,0xad,},
    {0x00,0xb0,0x89,0xdc, 0xfe,0xcb,0xb5,0xba, 0x00,0x88,0xd3,0x58, 0x00,0xd8,0x83,0x03, 0xff,0xa1,0x6a,0x0f,},
    {0x00,0xac,0x79,0x55, 0xfe,0xfd,0xc4,0x04, 0x00,0x67,0x8b,0xcc, 0x00,0xb4,0x37,0xfc, 0xff,0xb9,0xfe,0xdf,},
    {0x00,0x7f,0xea,0x91, 0xff,0x80,0x15,0x6f, 0x00,0x00,0x00,0x00, 0x00,0x7f,0xd5,0x22, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
};
const u8 eq_mode_lite_rock_96k[7][20]=
{
    {0x00,0x7f,0xd2,0x89, 0xff,0x00,0x5a,0xee, 0x00,0x7f,0xd2,0x89, 0x00,0xff,0xa5,0x02, 0xff,0x80,0x5a,0xde,},
    {0x00,0x80,0x4a,0x22, 0xff,0x01,0x15,0xd6, 0x00,0x7e,0xa0,0x07, 0x00,0xfe,0xe9,0xf4, 0xff,0x81,0x15,0xa0,},
    {0x00,0x5d,0x8a,0xe9, 0x00,0x08,0xcc,0xf4, 0xff,0xab,0x42,0x0b, 0x00,0x86,0xe4,0x6d, 0xff,0xe7,0x81,0xab,},
    {0x00,0x80,0x19,0x03, 0xff,0x00,0x40,0xdf, 0x00,0x7f,0xa6,0xb5, 0x00,0xff,0xbf,0x21, 0xff,0x80,0x40,0x47,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
};
const u8 eq_mode_jazz_96k[7][20]=
{
    {0x00,0xc0,0x41,0xe4, 0xff,0x64,0x04,0xe5, 0x00,0x00,0x00,0x00, 0x00,0x5b,0xb9,0x37, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
};
const u8 eq_mode_rap_96k[7][20]=
{
    {0x00,0x7f,0xe1,0xaf, 0xff,0x00,0x3c,0xa2, 0x00,0x7f,0xe1,0xaf, 0x00,0xff,0xc3,0x57, 0xff,0x80,0x3c,0x9b,},
    {0x00,0x7f,0xd2,0x89, 0xff,0x00,0x5a,0xee, 0x00,0x7f,0xd2,0x89, 0x00,0xff,0xa5,0x02, 0xff,0x80,0x5a,0xde,},
    {0x00,0x80,0x2e,0x57, 0xff,0x00,0x2b,0x5f, 0x00,0x7f,0xa6,0xca, 0x00,0xff,0xd4,0xa1, 0xff,0x80,0x2a,0xde,},
    {0x00,0x80,0x39,0xeb, 0xff,0x00,0x36,0xb6, 0x00,0x7f,0x90,0x81, 0x00,0xff,0xc9,0x4a, 0xff,0x80,0x35,0x93,},
    {0x00,0x7f,0xe7,0x01, 0xff,0x00,0x74,0x3c, 0x00,0x7f,0xa6,0xc7, 0x00,0xff,0x8b,0xc4, 0xff,0x80,0x72,0x37,},
    {0x00,0x7f,0x52,0x40, 0xff,0x04,0xbb,0xe3, 0x00,0x7c,0x07,0xea, 0x00,0xfb,0x44,0x1d, 0xff,0x84,0xa5,0xd6,},
    {0x00,0xad,0xcd,0xb8, 0xfe,0xed,0x75,0xe5, 0x00,0x71,0x9f,0xe4, 0x00,0xc0,0x7a,0x1a, 0xff,0xb2,0xa2,0x65,},
};

const void* eq_mode_96k[6]=
{
    eq_mode_normal_96k,
    eq_mode_country_96k,
    eq_mode_heavy_rock_96k,
    eq_mode_lite_rock_96k,
    eq_mode_jazz_96k,
    eq_mode_rap_96k,
};
#endif

#if 1
const u8 eq_mode_normal_48k[7][20]=
{
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
};
const u8 eq_mode_country_48k[7][20]=
{
    {0x00,0x80,0x2c,0x17, 0xff,0x00,0xd9,0x5a, 0x00,0x7e,0xfe,0x23, 0x00,0xff,0x26,0xa6, 0xff,0x80,0xd5,0xc5,},
    {0x00,0x6c,0x58,0x82, 0xff,0xd4,0x88,0x1b, 0x00,0x00,0x00,0x00, 0x00,0x3f,0x1f,0x63, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
};
const u8 eq_mode_heavy_rock_48k[7][20]=
{
    {0x00,0x7f,0x96,0x04, 0xff,0x00,0xd3,0xf8, 0x00,0x7f,0x96,0x04, 0x00,0xff,0x2b,0xb0, 0xff,0x80,0xd3,0xa0,},
    {0x00,0x80,0xb9,0x02, 0xff,0x00,0xad,0x25, 0x00,0x7e,0x9b,0xdd, 0x00,0xff,0x52,0xdb, 0xff,0x80,0xab,0x21,},
    {0x00,0xac,0x79,0x55, 0xfe,0xfd,0xc4,0x04, 0x00,0x67,0x8b,0xcc, 0x00,0xb4,0x37,0xfc, 0xff,0xb9,0xfe,0xdf,},
    {0x00,0xa5,0x05,0x8a, 0xff,0x58,0x13,0x1f, 0x00,0x3b,0x91,0x37, 0x00,0x6e,0x9b,0x8b, 0xff,0xd8,0xba,0x94,},
    {0x00,0x7f,0xd5,0x29, 0xff,0x80,0x2a,0xd7, 0x00,0x00,0x00,0x00, 0x00,0x7f,0xaa,0x53, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
};
const u8 eq_mode_lite_rock_48k[7][20]=
{
    {0x00,0x7f,0xa5,0x22, 0xff,0x00,0xb5,0xbb, 0x00,0x7f,0xa5,0x22, 0x00,0xff,0x4a,0x05, 0xff,0x80,0xb5,0x7a,},
    {0x00,0x80,0x93,0x6f, 0xff,0x02,0x29,0xbe, 0x00,0x7d,0x42,0xd2, 0x00,0xfd,0xd5,0x6c, 0xff,0x82,0x28,0xe9,},
    {0x00,0x9c,0xe3,0x80, 0x00,0x1c,0x72,0x06, 0xff,0x7f,0x8e,0x86, 0x00,0x2a,0x13,0xa3, 0x00,0x1d,0x08,0x4f,},
    {0x00,0x80,0x31,0xf9, 0xff,0x00,0x82,0xcc, 0x00,0x7f,0x4d,0x98, 0x00,0xff,0x7d,0x34, 0xff,0x80,0x80,0x6e,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
};
const u8 eq_mode_jazz_48k[7][20]=
{
    {0x00,0xb7,0xe4,0xa6, 0xff,0x88,0xfb,0xf7, 0x00,0x00,0x00,0x00, 0x00,0x3f,0x1f,0x63, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
    {0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,},
};
const u8 eq_mode_rop_48k[7][20]=
{
    {0x00,0x7f,0xc3,0x65, 0xff,0x00,0x79,0x36, 0x00,0x7f,0xc3,0x65, 0x00,0xff,0x86,0xae, 0xff,0x80,0x79,0x19,},
    {0x00,0x7f,0xa5,0x22, 0xff,0x00,0xb5,0xbb, 0x00,0x7f,0xa5,0x22, 0x00,0xff,0x4a,0x05, 0xff,0x80,0xb5,0x7a,},
    {0x00,0x80,0x5c,0xa0, 0xff,0x00,0x57,0xb2, 0x00,0x7f,0x4d,0xb3, 0x00,0xff,0xa8,0x4e, 0xff,0x80,0x55,0xad,},
    {0x00,0x80,0x73,0xbe, 0xff,0x00,0x6f,0x9a, 0x00,0x7f,0x21,0x32, 0x00,0xff,0x90,0x66, 0xff,0x80,0x6b,0x0f,},
    {0x00,0x7f,0xce,0x19, 0xff,0x00,0xec,0x17, 0x00,0x7f,0x4d,0xde, 0x00,0xff,0x13,0xe9, 0xff,0x80,0xe4,0x09,},
    {0x00,0x7e,0xaa,0xa4, 0xff,0x09,0x78,0x3c, 0x00,0x78,0x33,0xbc, 0x00,0xf6,0x87,0xc4, 0xff,0x89,0x21,0x9f,},
    {0x00,0xa7,0x68,0xef, 0xff,0x3b,0x51,0xae, 0x00,0x47,0x80,0xda, 0x00,0x85,0x12,0x88, 0xff,0xd0,0xb2,0x01,},
};

const void* eq_mode_48k[6]=
{
    eq_mode_normal_48k,
    eq_mode_country_48k,
    eq_mode_heavy_rock_48k,
    eq_mode_lite_rock_48k,
    eq_mode_jazz_48k,
    eq_mode_rop_48k,
};
#endif



const u8 eq_channel_reg[4]=
{0x51,0x58,0x6d,0x74};

void tda5548_eq_set(u32 mode)
{
    u8 buf[21];
    u8* eq_point;
    u32 ii,jj,kk;
    for(ii=0;ii<4;ii++)
    {
        eq_point = (u8*)eq_mode_96k[mode];
        for(jj=0;jj<7;jj++)
        {
            for(kk=0;kk<20;kk++)
            {
                buf[kk+1] = eq_point[kk];
            }
            buf[0] = eq_channel_reg[ii]+jj;
            iic_write(TAS5548_IIC_ADD,21,buf);
            eq_point += 20;
        }
    }
}


const u8 LOUDNESS_table_95[21]={0x95, 0x00,0x00,0x20,0x23, 0x00,0x00,0x00,0x00, 0xff,0xff,0xdf,0xdd, 0x00,0xff,0xbf,0x98, 0xff,0x80,0x40,0x47};
void tda5548_set_loudness(u8 flag)
{
    u8 buf[5];
    memset(buf,0x00,sizeof(buf));
    if(flag)
    {
        buf[2] = 0x80;
    }
    else
    {
        
    }   
    buf[0] = 0x93;
    iic_write(TAS5548_IIC_ADD,5,buf);
}

const u8 bass_treble_table[15]={0x20,0x1e,0x1c,0x1a,0x18,0x16,0x14,0x12,0x10,0x0e,0x0c,0x0a,0x08,0x06,0x04};

void tda5548_set_bass(u32 bass)
{
    u8 buf[5];
    memset(buf,0x00,sizeof(buf));

    buf[1] = bass_treble_table[bass];
    buf[2] = bass_treble_table[bass];
    buf[3] = bass_treble_table[bass];
    buf[4] = bass_treble_table[bass];
    buf[0] = 0xdb;
    iic_write(TAS5548_IIC_ADD,5,buf);

}
void tda5548_set_treble(u32 treble)
{
    u8 buf[9];
    memset(buf,0x00,sizeof(buf));

    buf[1] = bass_treble_table[treble];
    buf[2] = bass_treble_table[treble];
    buf[3] = bass_treble_table[treble];
    buf[4] = bass_treble_table[treble];
    buf[0] = 0xdd;
    iic_write(TAS5548_IIC_ADD,5,buf);
}

void tda5548_set_volume(u32 voluem)
{
    u8 buf[5];
    u32 temp;
    memset(buf,0x00,sizeof(buf));
    if(0==voluem)
    {
        temp = 0x245;
    }
    else
    {
        temp = 2*(99-voluem)+0x38;       
    }
    buf[0] = 0xd9;
    buf[3] = temp>>8;
    buf[4] = temp;
    iic_write(TAS5548_IIC_ADD,5,buf);
}



const u32 input_gain_table[] =
{
    0x00800000,     // usb
    0x00800000,     // 
    0x00800000,     // bt
    0x00500000,     // spdif
    0x00800000,
};
void tda5548_input_select(u32 channel, u32 mic)
{
    u8 buf[33];
    if(TAS5548_IIS_INPUT1 == channel)
    {
        iic_write(TAS5548_IIC_ADD,sizeof(ASRC_CONTROL1_C4),(u8 *)ASRC_CONTROL1_C4);
    }
    else
    {
        iic_write(TAS5548_IIC_ADD,sizeof(ASRC_CONTROL2_C4),(u8 *)ASRC_CONTROL2_C4);
    }
    if(channel>=TAS5548_IIS_INPUT0)
    {
        memset(buf,0x00,sizeof(buf));
        buf[0] = 0x41;
        iic_write(TAS5548_IIC_ADD,33,buf);
        buf[0] = 0x42;
        iic_write(TAS5548_IIC_ADD,33,buf);
        buf[0] = 0x45;
        iic_write(TAS5548_IIC_ADD,33,buf);
        buf[0] = 0x46;
        iic_write(TAS5548_IIC_ADD,33,buf);
        iic_write(TAS5548_IIC_ADD,sizeof(ASRC_MODE1_C5),(u8 *)ASRC_MODE1_C5);
    }
    else
    {
        iic_write(TAS5548_IIC_ADD,sizeof(ASRC_MODE2_C5),(u8 *)ASRC_MODE2_C5);
        memset(buf,0x00,sizeof(buf));
        buf[0] = 0x41;
        buf[1+8*channel] = (input_gain_table[channel]>>24);
        buf[2+8*channel] = (input_gain_table[channel]>>16);
        buf[3+8*channel] = (input_gain_table[channel]>>8);
        buf[4+8*channel] = input_gain_table[channel];
        iic_write(TAS5548_IIC_ADD,33,buf);
        memset(buf,0x00,sizeof(buf));
        buf[0] = 0x42;
        buf[5+8*channel] = (input_gain_table[channel]>>24);
        buf[6+8*channel] = (input_gain_table[channel]>>16);
        buf[7+8*channel] = (input_gain_table[channel]>>8);
        buf[8+8*channel] = input_gain_table[channel];
        iic_write(TAS5548_IIC_ADD,33,buf);  
        
        memset(buf,0x00,sizeof(buf));
        buf[0] = 0x45;
        buf[1+8*channel] = (input_gain_table[channel]>>24);
        buf[2+8*channel] = (input_gain_table[channel]>>16);
        buf[3+8*channel] = (input_gain_table[channel]>>8);
        buf[4+8*channel] = input_gain_table[channel];
        iic_write(TAS5548_IIC_ADD,33,buf);
        memset(buf,0x00,sizeof(buf));
        buf[0] = 0x46;
        buf[5+8*channel] = (input_gain_table[channel]>>24);
        buf[6+8*channel] = (input_gain_table[channel]>>16);
        buf[7+8*channel] = (input_gain_table[channel]>>8);
        buf[8+8*channel] = input_gain_table[channel];
        iic_write(TAS5548_IIC_ADD,33,buf);
    }
        
    if(mic&TAS5548_IIS_MIC1)
    {
        memset(buf,0x00,sizeof(buf));
        buf[0] = 0xec;
        buf[2] = 0x80;
        iic_write(TAS5548_IIC_ADD,9,buf);
        memset(buf,0x00,sizeof(buf));
        buf[0] = 0xed;
        buf[6] = 0x80;
        iic_write(TAS5548_IIC_ADD,9,buf);        
    }
    else
    {
        memset(buf,0x00,sizeof(buf));
        buf[0] = 0xec;
        iic_write(TAS5548_IIC_ADD,9,buf);
        buf[0] = 0xed;
        iic_write(TAS5548_IIC_ADD,9,buf);
    }
    if(mic&TAS5548_IIS_MIC3)
    {
        memset(buf,0x00,sizeof(buf));
        buf[0] = 0xf0;
        buf[2] = 0x80;
        iic_write(TAS5548_IIC_ADD,9,buf);
        memset(buf,0x00,sizeof(buf));
        buf[0] = 0xf1;
        buf[6] = 0x80;
        iic_write(TAS5548_IIC_ADD,9,buf);
    }
    else
    {
        memset(buf,0x00,sizeof(buf));
        buf[0] = 0xf0;
        iic_write(TAS5548_IIC_ADD,9,buf);
        buf[0] = 0xf1;
        iic_write(TAS5548_IIC_ADD,9,buf);
    }    
}

u8 TAS5548_1BYTE_REG[][2]=
{
    {0x03, 0xa0},    
};




void tas5548_init(void)
{
    u8 buf[9];
    buf[0] = 0x03;
    buf[1] = 0xa0;
    iic_write(TAS5548_IIC_ADD,2,buf);
    buf[0] = 0x27;
    buf[1] = 0xcc;
    iic_write(TAS5548_IIC_ADD,2,buf);
    buf[0] = 0x0f;
    buf[1] = 0xcc;
    iic_write(TAS5548_IIC_ADD,2,buf);
    // config asrc
    iic_write(TAS5548_IIC_ADD,sizeof(ASRC_CONTROL2_C4),(u8 *)ASRC_CONTROL2_C4);
    iic_write(TAS5548_IIC_ADD,sizeof(ASRC_MODE2_C5),(u8 *)ASRC_MODE2_C5);
    
    // mute
    memset(buf,0x00,sizeof(buf));
    buf[3] = 0x02;
    buf[4] = 0x45;
    buf[0] = 0xd3;
    iic_write(TAS5548_IIC_ADD,5,buf);
    buf[0] = 0xd4;
    iic_write(TAS5548_IIC_ADD,5,buf);
    buf[0] = 0xd7;
    iic_write(TAS5548_IIC_ADD,5,buf);
    buf[0] = 0xd8;
    iic_write(TAS5548_IIC_ADD,5,buf);
    
    
    // bass treble
    memset(buf,0x00,sizeof(buf));
    buf[2] = 0x80;
    buf[6] = 0x80;
    buf[0] = 0x89;
    iic_write(TAS5548_IIC_ADD,9,buf);
    buf[0] = 0x8a;
    iic_write(TAS5548_IIC_ADD,9,buf);
    buf[0] = 0x8d;
    iic_write(TAS5548_IIC_ADD,9,buf);
    buf[0] = 0x8e;
    iic_write(TAS5548_IIC_ADD,9,buf);
    
    iic_write(TAS5548_IIC_ADD,sizeof(BASS_FILTER_SET_DA),(u8 *)BASS_FILTER_SET_DA);
    iic_write(TAS5548_IIC_ADD,sizeof(TREBLE_FILTER_SET_DC),(u8 *)TREBLE_FILTER_SET_DC);    
    
    iic_write(TAS5548_IIC_ADD,sizeof(LOUDNESS_table_95),(u8 *)LOUDNESS_table_95);
    tda5548_set_loudness(0);
}
