TDA7419调试记录(1)——2015/04/17

<span style="font-size:24px;color:#ff0000;"><strong>问题:<a target=_blank href="http://pan.baidu.com/s/1ydhiI">I2C块写入(多字节写入)失败?</a>——</strong></span><pre name="code" class="cpp"><span style="font-size:24px;color:#ff0000;"><strong>tdesp->i2c_write(tdesp->client, addr, buf, len);</strong></span>
</pre><pre name="code" class="cpp">
</pre><pre>
</pre><pre name="code" class="cpp">
/******************************************************************************

                  Copyright (C), 2015-2030, ALONG

 ******************************************************************************
  FileName   : audio_7419.c
  Version    :  v0.1
  Author     : Lawrence
  Create Date    : 2015/04/16
  Recent Modify  :
  Func instruction   : audio_7419 function implementions
  Function list  :
  Modify History   :
  1.DateTime   : 2015/04/16
    Author   : Lawrence
    Modify what   : Create file

******************************************************************************/
#include "audio_7419.h"
#include "tda7419.h"

/*----------------------------------------------*
 * extern var instruction                       *
 *----------------------------------------------*/

/*----------------------------------------------*
 * extern func prototype instruction            *
 *----------------------------------------------*/

/*----------------------------------------------*
 * func prototype instruction                   *
 *----------------------------------------------*/
static void TDA7419_send( uint8 addr, uint8 *buf, int len);
static void TDA7419_volume_calc( uint8 type );

/*----------------------------------------------*
 * General var statement                        *
 *----------------------------------------------*/

/*----------------------------------------------*
 * Const var define                             *
 *----------------------------------------------*/

#define UP 		1
#define DOWN	-1

//val to Volume Addr Register[0x03]
static const unsigned char VolTable[]=
{
	0x7F, // mute// 0
	0x5F, // -79dB
	0x5E, // -78dB
	0x5D, // -77dB
	0x5C, // -76dB
	0x5B, // -75dB
	0x5A, // -74dB
	0x59, // -73dB
	0x58, // -72dB
	0x57, // -71dB
	0x56, // -70dB// 10
	0x55, // -69dB
	0x54, // -68dB
	0x53, // -67dB
	0x52, // -66dB
	0x51, // -65dB
	0x50, // -64dB
	0x4F, // -63dB
	0x4E, // -62dB
	0x4D, // -61dB
	0x4C, // -60dB// 20
	0x4B, // -59dB
	0x4A, // -58dB
	0x49, // -57dB
	0x48, // -56dB
	0x47, // -55dB
	0x46, // -54dB
	0x45, // -53dB
	0x44, // -52dB
	0x43, // -51dB
	0x42, // -50dB// 30
	0x41, // -49dB
	0x40, // -48dB
	0x3F, // -47dB
	0x3E, // -46dB
	0x3D, // -45dB
	0x3C, // -44dB
	0x3B, // -43dB
	0x3A, // -42dB
	0x39, // -41dB
	0x38, // -40dB// 40
	0x37, // -39dB
	0x36, // -38dB
	0x35, // -37dB
	0x34, // -36dB
	0x33, // -35dB
	0x32, // -34dB
	0x31, // -33dB
	0x30, // -32dB
	0x2F, // -31dB
	0x2E, // -30dB// 50
	0x2D, // -29dB
	0x2C, // -28dB
	0x2B, // -27dB
	0x2A, // -26dB
	0x29, // -25dB
	0x28, // -24dB
	0x27, // -23dB
	0x26, // -22dB
	0x25, // -21dB
	0x24, // -20dB// 60
	0x23, // -19dB
	0x22, // -18dB
	0x21, // -17dB
	0x20, // -16dB
	0x1F, // -15dB
	0x1E, // -14dB
	0x1D, // -13dB
	0x1C, // -12dB
	0x1B, // -11dB
	0x1A, // -10dB// 70
	0x19, // -9dB
	0x18, // -8dB
	0x17, // -7dB
	0x16, // -6dB
	0x15, // -5dB
	0x14, // -4dB
	0x13, // -3dB
	0x12, // -2dB
	0x11, // -1dB
	0x00, // +0dB// 80
	0x01, // +1dB
	0x02, // +2dB
	0x03, // +3dB
	0x04, // +4dB
	0x05, // +5dB
	0x06, // +6dB
	0x07, // +7dB
	0x08, // +8dB
	0x09, // +9dB
	0x0A, // +10dB// 90
	0x0B, // +11dB
	0x0C, // +12dB
	0x0D, // +13dB
	0x0E, // +14dB
	0x0F // +15dB
};

//index of VolTable
static const unsigned char VolChangeTable[]=
{
	0,6,11,16,20,24,26,28,30,32,34,
	36,38,40,42,43,44,45,46,47,48,
	49,50,51,52,53,54,55,56,57,58,
	59,60,61,62,63,64,65,66,67,68,
	68,69,70,71,72,73,74,75,76,77,
	78,79,80
};

static const unsigned char SourceTable[]=
{
	0x62,		// y01100010;   Radio, input se2, gain = 12 dB
	0,
	1,          // y00000001; SEL1, gain = 0dB
	3,          // y00000011; SEL3, gain = 0dB
	6           // y00000110; MUTE, gain = 0dB
};

static const unsigned char LoudTable[]=
{
	0x00, // +0dB
	//	0x01, // +1dB
	//	0x02, // +2dB
	//	0x03, // +3dB
	/*0x04, // +4dB
	0x05, // +5dB*/
	0x06, // +6dB		//low
	/*0x07, // +7dB
	0x08, // +8dB
	0x09, // +9dB*/
	0x0A, // +10dB		//mid
	/*0x0B, // +11dB
	0x0C, // +12dB
	0x0D, // +13dB
	0x0E, // +14dB*/
	0x0F // +15dB		//high
};

static const unsigned char SubwTable[]=
{
	0x00, // +0dB
	0x01, // +1dB
	0x02, // +2dB
	0x03, // +3dB
	0x04, // +4dB
	0x05, // +5dB
	0x06, // +6dB
	0x07, // +7dB
	0x08, // +8dB
	0x09, // +9dB
	//	0x0A, // +10dB
	0x0B, // +11dB
	//	0x0C, // +12dB
	0x0D, // +13dB
	//	0x0E, // +14dB
	0x0F, // +15dB

	0x7F // mute
};

static const unsigned char BasTreTable[]=
{
	//0x0F, // -15dB
	//0x0E, // -14dB
	//0x0D, // -13dB
	0x0C, // -12dB
	//0x0B, // -11dB
	0x0A, // -10dB
	//0x09, // -9dB
	0x08, // -8dB
	//0x07, // -7dB
	0x06, // -6dB
	//0x05, // -5dB
	0x04, // -4dB
	//0x03, // -3dB
	0x02, // -2dB
	//0x01, // -1dB
	0x10, // +0dB
	//0x11, // +1dB
	0x12, // +2dB
	//0x13, // +3dB
	0x14, // +4dB
	//0x15, // +5dB
	0x16, // +6dB
	//0x17, // +7dB
	0x18, // +8dB
	//0x19, // +9dB
	0x1A, // +10dB
	//0x1B, // +11dB
	0x1C//,  +12dB
	//0x1D, // +13dB
	//0x1E, // +14dB
	//0x1F, // +15dB
};

static const unsigned char BalFadTable[]=
{
	0x00, // +0dB
	0x13, // -3dB
	0x15, // -5dB
	0x18, // -8dB
	0x1A, // -10dB
	0x1D, // -13dB
	0x1F, // -15dB
	0x22, // -18dB
	0x24, // -20dB
	0x27, // -23dB
	0x29, // -25dB
	0x2C, // -28dB
	0x7F // mute
};

static const unsigned char EQTable[]=
{
	// Bass, Treble
	10,10,	//Classic
	10,12, 	//Pop
	12,12,	//Rock
};
...
/*----------------------------------------------*
 * Module var                                   *
 *----------------------------------------------*/
 //buffer store TDA7419 registers value
#define REGISTER_COUNT  (18)
uint8 TDA7419_register_buf[REGISTER_COUNT] = {0};

//TDA7419 registers description and state
struct TDA7419_desc gTDA7419_desc_val;
extern TDES_T *tdesp;

/*----------------------------------------------*
 * Function Define                              *
 *----------------------------------------------*/
/*****************************************************************************
 Func Name  : TDA7419_init
 Funciont   : init TDA7419 register
 In para    : void
 Out para   :
 Return val : void
 CB func    :
 Be CB func :

 Modify History :
  1.DateTime    : 2015/04/16
    Author      : Lawrence
    Modification: New func

*****************************************************************************/
void TDA7419_init( void )
{
    TDA7419_register_buf[0]    = Bit00110000;         //Main selector: gain 6dB

    TDA7419_register_buf[1]    = Bit11100000;         //Main selector: gain 6dB

    TDA7419_register_buf[2]    = Bit00000111;         //Main selector: gain 6dB

    TDA7419_register_buf[3]    = Bit00000000;         //Main selector: gain 6dB

    TDA7419_register_buf[4]    = Bit00000000;         //Main selector: gain 6dB

    TDA7419_register_buf[5]    = Bit00000000;         //Main selector: gain 6dB

    TDA7419_register_buf[6]    = Bit00000000;         //Main selector: gain 6dB

    TDA7419_register_buf[7]    = Bit00110000;         //Main selector: gain 6dB

    TDA7419_register_buf[8]    = Bit01000000;         //Main selector: gain 6dB

    TDA7419_register_buf[9]    = Bit11110111;         //Main selector: gain 6dB

    TDA7419_register_buf[10]   = Bit00000000;        //Main selector: gain 6dB

    TDA7419_register_buf[11]   = Bit00000000;        //Main selector: gain 6dB

    TDA7419_register_buf[12]   = Bit00000000;        //Main selector: gain 6dB

    TDA7419_register_buf[13]   = Bit00000000;        //Main selector: gain 6dB

    TDA7419_register_buf[14]   = Bit10000000;        //Main selector: gain 6dB

    TDA7419_register_buf[15]   = Bit10000000;        //Main selector: gain 6dB

    TDA7419_register_buf[16]   = Bit00010111;        //Main selector: gain 6dB

    TDA7419_register_buf[17]   = Bit00000000;        //Main selector: gain 6dB

    gTDA7419_desc_val.audio_vol    = 22;
    gTDA7419_desc_val.audio_main_vol    = 22;
    gTDA7419_desc_val.audio_sec_vol     = 22;
    gTDA7419_desc_val.audio_main_source = AUDIO_INPUT_SYS;
    gTDA7419_desc_val.audio_sec_source  = AUDIO_INPUT_SYS;

    gTDA7419_desc_val.audio_work_mode   = AUDIO_MODE_IDLE;
    gTDA7419_desc_val.audio_eq_mode     = EQ_MODE_OFF;

    TDA7419_volume_calc(AUDIO_ALL_VAL);
    TDA7419_send(0, TDA7419_register_buf, REGISTER_COUNT);

}

/*****************************************************************************
 Func Name  : TDA7419_volume_calc
 Funciont   : calculate the volume depend on parameters from various aspects
 In para    : void
 Out para   :
 Return val : void
 CB func    :
 Be CB func :

 Modify History :
  1.DateTime    : 2015/04/17
    Author      : Lawrence
    Modification: New func

*****************************************************************************/
static void TDA7419_volume_calc( uint8 type )
{
#if 0
    TDA7419_register_buf[6]=(TDA7419_register_buf[6] & 0xE0)+BasTreTable[AudioBas];
	TDA7419_register_buf[8]=(TDA7419_register_buf[8] & 0xCF)+(AudioBasFre<<4);
	TDA7419_register_buf[6]=(TDA7419_register_buf[6] & 0x9F)+(AudioBasQ<<5);
	TDA7419_register_buf[4]=(TDA7419_register_buf[4] & 0xE0)+BasTreTable[AudioTre];
	TDA7419_register_buf[4]=(TDA7419_register_buf[4] & 0x9F)+(AudioTreFre<<5);
	TDA7419_register_buf[5]=(TDA7419_register_buf[5] & 0xE0)+BasTreTable[AudioMid];
	TDA7419_register_buf[8]=(TDA7419_register_buf[8] & 0xF3)+(AudioMidFre<<2);
	TDA7419_register_buf[5]=(TDA7419_register_buf[5] & 0x9F)+(AudioMidQ<<5);
	TDA7419_register_buf[1]=(TDA7419_register_buf[1] & 0xF0)+GetRealLoudTable(AudioIXBass);//LoudTable[AudioIXBass];
	TDA7419_register_buf[1]=(TDA7419_register_buf[1] & 0xCF)+(AudioIXBassFre<<4);
	TDA7419_register_buf[15] = SubwTable[AudioSubw];
	TDA7419_register_buf[8]=(TDA7419_register_buf[8] & 0xFC)+AudioSubwFre;
#else
    //choose source channel
    TDA7419_register_buf[0] = (TDA7419_register_buf[0] & 0xF8) + 1 ;

    TDA7419_register_buf[1]=(TDA7419_register_buf[1] & 0xF0) + 0;
	TDA7419_register_buf[1]=(TDA7419_register_buf[1] & 0xCF) + 0;

    //TDA7419_register_buf[3]= ;

    TDA7419_register_buf[4]=(TDA7419_register_buf[4] & 0xE0) + 0;
	TDA7419_register_buf[4]=(TDA7419_register_buf[4] & 0x9F) + 0;

    TDA7419_register_buf[5]=(TDA7419_register_buf[5] & 0xE0) + 0;
    TDA7419_register_buf[5]=(TDA7419_register_buf[5] & 0x9F) + 0;

    TDA7419_register_buf[6]=(TDA7419_register_buf[6] & 0xE0) + 0;
	TDA7419_register_buf[6]=(TDA7419_register_buf[6] & 0x9F) + 0;

    TDA7419_register_buf[8]=(TDA7419_register_buf[8] & 0xCF) + 0;
	TDA7419_register_buf[8]=(TDA7419_register_buf[8] & 0xF3) + 0;
    TDA7419_register_buf[8]=(TDA7419_register_buf[8] & 0xFC) + 0;


	TDA7419_register_buf[15] = SubwTable[10];

    TDA7419_register_buf[10] = 0x00;
    TDA7419_register_buf[11] = 0x00;
    TDA7419_register_buf[12] = 0x00;
    TDA7419_register_buf[13] = 0x00;

    TDA7419_register_buf[16] &= 0x7F;
    TDA7419_register_buf[2] |= 0x01;

#endif
}

/*****************************************************************************
 Func Name  : TDA7419_send
 Funciont   : send register values to tda7419
 In para    : void
 Out para   :
 Return val : void
 CB func    :
 Be CB func :

 Modify History :
  1.DateTime    : 2015/04/17
    Author      : Lawrence
    Modification: New func

*****************************************************************************/
static void TDA7419_send( uint8 addr, uint8 *buf, int len)
{
	//I2C send: addr, send_buf; len, send_bytes;
	tdesp->i2c_write(tdesp->client, addr, buf, len);

}


你可能感兴趣的:(TDA7419)