⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 t103_util.c

📁 这是T118和T103的通用程序
💻 C
📖 第 1 页 / 共 3 页
字号:
/****************************************************************************
* File: T803_Util.c                                                         *
* Description: Define T803 chip control policy                              *
* History:     2005/08/12                                                   *
*                                                                           *
* 		Copyright 2005 (c) Terawins Inc.                            *
****************************************************************************/

/****************************************************************************
*                               Include File                                *
****************************************************************************/

#include "reg51.h"
#include "math.h"

#include "system.h"
#include "Resolution.h"
#include "twowire.h"
#include "filter.h"
#include "keypad.h"
#include "Nvram.h"
#include "T803_Util.h"
#include "TW803Reg.h"
#include "remote.h"
#include "osddraw.h"
#include "tuner.h"
#include "timer0.h"
#include "T515.h"
#include "ModeCtrl.h"
#define __GLOBAL_H__
#include "Global.h"
#include "display.h"
#include "cfgdsply.h"
#include "keypad.h"
#include "Gamma.h"
#define __INIT_H__
#include "INIT.h"
#define __VBI_PARSING__
#include "VBI_Parser.h" // kenny 20060403
#include "SRC_565.h"
#include "RGB565.h"
#include "panel.h"

/****************************************************************************
*                           Public Global Variable                          *
****************************************************************************/


/****************************************************************************
*                              Public Function                              *
****************************************************************************/
void InitT803(void)
{
	uCHAR RegIndex,RegAdr;

	RegIndex=0;
	RegAdr=stInitT10xP0[0].ucRegAdr;
	while (RegAdr != 0xFF)		// bruce, 2006/01/09
	{
		if(RegAdr==0x30){
			I2CWriteByte(TW803_P0,RegAdr,(I2CReadByte(TW803_P0,0x30)|0x01));  // enable Shadow
			I2CWriteByte(TW803_P0,RegAdr,(I2CReadByte(TW803_P0,0x30)&(~0x02))| DEINTERLACE); //Bruce, 2006/01/10
		}
		else{
			I2CWriteByte(TW803_P0,RegAdr,stInitT10xP0[RegIndex].ucRegVal);
		}
		RegAdr=stInitT10xP0[++RegIndex].ucRegAdr;
	}
	RegIndex=0;
	RegAdr=stInitT10xP2[0].ucRegAdr;
	while (RegAdr != 0xFF)		// bruce, 2006/01/09
	{
		if(RegAdr==0x01)
			I2CWriteByte(TW803_P2,RegAdr,(I2CReadByte(TW803_P2,0x01)|0x01));// enable black level correction for 10 blank-to-black pedestal
		else
			I2CWriteByte(TW803_P2,RegAdr,stInitT10xP2[RegIndex].ucRegVal);
		RegAdr=stInitT10xP2[++RegIndex].ucRegAdr;
	}
	//=========================================================================
	// Panel specified register settings
	//=========================================================================

	for(RegIndex=0;RegIndex < PanelSpecP0Cnt;RegIndex++)
	{
		I2CWriteByte(TW803_P0,ucaPanelSpecAdrP0[RegIndex],ucaPanelSpecDataP0[RegIndex]);
    }


   	for(RegIndex=0;RegIndex < PanelSpecP2Cnt;RegIndex++)
	{
		I2CWriteByte(TW803_P2,ucaPanelSpecAdrP2[RegIndex],ucaPanelSpecDataP2[RegIndex]);
    }

	#ifdef ROTATE
   		SET_Dismod();
	#endif

	//kenny 20060403
	#ifdef VBI_CC
		VBI_Init();
	#endif
	//kenny 20060403

	// kenny 20060512
	#ifdef IR_DECODE
		IR_Init();
	#endif
	// kenny 20060512

}

#ifdef TCON
void TconInit(void)
{
	uCHAR TconIndex;

	for(TconIndex=0;TconIndex < P1TconCnt;TconIndex++)
	       	I2CWriteByte(TW803_P1, TconAddress+TconIndex, TconP1Data[TconIndex]);
}
#endif

#ifdef ROTATE
void SET_Dismod(void)
{
	switch (Dis_Mode){
		case  TOP_LEFT: //Start from top-left
			#ifdef ANALOG_PANEL
				I2CWriteByte(TW803_P0,0xE1, ScanMode[0]);
			#else
				UP_DOWN	   = DigiPanlScanMode[0]>>1;
				LEFT_RIGHT = DigiPanlScanMode[0]&0x01;
				I2CWriteByte(TW803_P0,0xE1, ScanMode[0]&0xF0);
			#endif
			break;
		case  TOP_RIGHT: //Start from top-right
			#ifdef ANALOG_PANEL
				I2CWriteByte(TW803_P0,0xE1, ScanMode[1]);
			#else
				UP_DOWN	   = DigiPanlScanMode[1]>>1;
				LEFT_RIGHT = DigiPanlScanMode[1]&0x01;
				I2CWriteByte(TW803_P0,0xE1, ScanMode[1]&0xF0);
			#endif
			break;
		case  BOTTOM_RIGHT:  //Start from bottom-right
			#ifdef ANALOG_PANEL
				I2CWriteByte(TW803_P0,0xE1, ScanMode[2]);
			#else
				UP_DOWN	   = DigiPanlScanMode[2]>>1;
				LEFT_RIGHT = DigiPanlScanMode[2]&0x01;
				I2CWriteByte(TW803_P0,0xE1, ScanMode[2]&0xF0);
			#endif
			break;
		case  BOTTOM_LEFT: //Start from bottom-left
			#ifdef ANALOG_PANEL
				I2CWriteByte(TW803_P0,0xE1, ScanMode[3]);
			#else
				UP_DOWN	   = DigiPanlScanMode[3]>>1;
				LEFT_RIGHT = DigiPanlScanMode[3]&0x01;
				I2CWriteByte(TW803_P0,0xE1, ScanMode[3]&0xF0);
			#endif
			break;
	}
	#ifdef OUT_PIN_CONF
	I2CWriteByte(TW803_P0,0xE1, OUT_PIN_CONF);
	#endif
	return;
}
#endif


/*   S O U R C E   S E L E C T   */
/*-------------------------------------------------------------------------
    
-------------------------------------------------------------------------*/
void SourceSelect(void)
{
   	
   	ClosePanel(0x10, 0xff, 0x40);
   	if((EepPublic.cSource==1)||(uiaSrcMux1[EepPublic.cSource].VideoType==itypeRGB565)||(uiaSrcMux1[EepPublic.cSource].VideoType==itypeSVIDEO))
    {
		SetSignalStd();             //set the chroma and the comb filter
	    SetOPTiming();              //set the scaler,line buffer,output PLL,display window
    }
	
	I2CWriteByte(TW803_P0,0x0f,0x70);  //2005-03030 for position shift,ADC Power Down Control
	I2CWriteByte(TW803_P0,0x0f,0x00);  //2005-03030 for position shift
	I2CWriteByte(TW803_P0,0x31,0x00);   //Source Select Reg,
	I2CWriteByte(TW803_P0,0x1a, 0x87);  //ADC Analog AGC Selection,dynamic gain


	if(uiaSrcMux1[EepPublic.cSource].SourceRoute==isrcVIDEO)
	{
		I2CWriteByte(TW803_P0,0x18, uiaSrcMux1[EepPublic.cSource].ADCMUX>>8);  // cMux1);
		I2CWriteByte(TW803_P0,0x19, uiaSrcMux1[EepPublic.cSource].ADCMUX&0xFF);  // cMux2);

		if(uiaSrcMux1[EepPublic.cSource].VideoType==itypeSVIDEO)
		{	
			I2CWriteByte(TW803_P2,0x07, 0x06|0x20);  //Y/C Output Control
 			I2CWriteByte(TW803_P0,0x11, 0x05);	//YPbPr Clamping Control	
			I2CWriteByte(TW803_P2,0x00, I2CReadByte(TW803_P2,0x00)|0x01);
			I2CWriteByte(TW803_P2,0x01, I2CReadByte(TW803_P2,0x01)&~ENYPbPr);
			I2CWriteByte(TW803_P0,0x16, 0xD3);   //Line Lock PLL Divider Reg
 			I2CWriteByte(TW803_P2,0x03, I2CReadByte(TW803_P2,0x03)|0x03);
		
			twdDelay(500);
			//m_cBuff[0]= I2CReadByte(TW803_P2, 0x3A);
			//if((m_cBuff[0]&0x06)==0x06)
			if((I2CReadByte(TW803_P2, 0x3A)&0x06)==0x06)
			{
	  			NoSignal=0;
				OpenPanel();
				//I2CWriteByte(TW803_P0, 0xC2, I2CReadByte(TW803_P0, 0xC2)&~(PSYNC_STR|IGNORE_VSYNC));
	  			//I2CWriteByte(TW803_P0, PATTERN_CTRL, 0x00);
/*-------------------------------------------------------------------------
20060809  Phil add sound control    
-------------------------------------------------------------------------*/
				twdDelay(10);
				AV_AUDIO_SW1 = OFF;
				TV_AUDIO_SW2 = OFF;
                SV_AUDIO_SW3 = ON;
                twdDelay(10);
				AUDIO_STBY = OFF;
				twdDelay(10);
				AUDIO_MUTE = OFF;   //Play				
/*-------------------------------------------------------------------------
20060809  Phil add sound control    
-------------------------------------------------------------------------*/
			}			
		}else if ( (uiaSrcMux1[EepPublic.cSource].VideoType==itypeCVBS)
#ifdef TV
    	||(uiaSrcMux1[EepPublic.cSource].VideoType==itypeTV)
#endif
    	){	// CVBS
 			I2CWriteByte(TW803_P0,0x11, 0x00);//YPbPr Clamping Control
			I2CWriteByte(TW803_P2,0x07, 0x21);//0x05|0x22);Y/C Output Control
			I2CWriteByte(TW803_P2,0x00, I2CReadByte(TW803_P2,0x00)&0xfe);
			I2CWriteByte(TW803_P2,0x01, I2CReadByte(TW803_P2,0x01)&~ENYPbPr);
			I2CWriteByte(TW803_P0,0x16, 0xD3);//Line Lock PLL Divider Reg
			I2CWriteByte(TW803_P2,0x07, 0x02|0x20);
			if(m_cChroma==S_NTSC_4)  
				I2CWriteByte(TW803_P2,0x03, I2CReadByte(TW803_P2,0x03)&0xf8|0x03);
			else
				I2CWriteByte(TW803_P2,0x03, I2CReadByte(TW803_P2,0x03)&0xfc);
//thomas
#ifdef TV
			if (uiaSrcMux1[EepPublic.cSource].VideoType==itypeTV){
        		I2CWriteByte(TW803_P2, 0x07 ,0x00);
        		ChannelSel();
        		OpenPanel();
/*-------------------------------------------------------------------------
20060809  Phil add sound control    
-------------------------------------------------------------------------*/
				twdDelay(10);
				AV_AUDIO_SW1 = OFF;
                TV_AUDIO_SW2 = ON;
				SV_AUDIO_SW3 = OFF;
                twdDelay(10);
				AUDIO_STBY = OFF;
                twdDelay(10);
				AUDIO_MUTE = OFF;   //Play

/*-------------------------------------------------------------------------
20060809  Phil add sound control    
-------------------------------------------------------------------------*/				
        	}
#endif
			twdDelay(500);
/*-------------------------------------------------------------------------
20060818  Phil for CVBS not detect the signal when power on status
-------------------------------------------------------------------------*/
            I2CWriteByte(TW803_P2, 0x3f, 0x00);  //for cvbs detected
            I2CWriteByte(TW803_P2, 0x2E, 0x88);  
            I2CWriteByte(TW803_P2, 0x2F, 0x50);  
            I2CWriteByte(TW803_P2, 0x30, 0x28);  
            
            I2CWriteByte(TW803_P0, 0x75, 0x10);
			I2CWriteByte(TW803_P0, 0x73, 0x1C);
			I2CWriteByte(TW803_P0, 0x72, 0xCC);
			I2CWriteByte(TW803_P0, 0x70, 0x20);

			I2CWriteByte(TW803_P0, 0x85, 0x00);
			I2CWriteByte(TW803_P0, 0xB0, 0x20);
			I2CWriteByte(TW803_P0, 0xB2, 0x2C);
			I2CWriteByte(TW803_P0, 0xB8, 0x38);
			I2CWriteByte(TW803_P0, 0xC8, 0x30);
			I2CWriteByte(TW803_P0, 0xE0, 0xB1);

			I2CWriteByte(TW803_P0, 0x21, 0x04);
			I2CWriteByte(TW803_P0, 0x14, 0x7C);
			I2CWriteByte(TW803_P0, 0x17, 0xC8);
			I2CWriteByte(TW803_P0, 0x30, 0x03);
			I2CWriteByte(TW803_P0, 0x33, 0xB0);
			I2CWriteByte(TW803_P0, 0x40, 0x00);
			I2CWriteByte(TW803_P0, 0x50, 0x00);
						
			twdDelay(50);
/*-------------------------------------------------------------------------
20060818  
-------------------------------------------------------------------------*/			
			if((I2CReadByte(TW803_P2, 0x3A)&0x06)==0x06){
	  			NoSignal=0;
				OpenPanel();
				//I2CWriteByte(TW803_P0, 0xC2, I2CReadByte(TW803_P0, 0xC2)&~(PSYNC_STR|IGNORE_VSYNC));
	  			//I2CWriteByte(TW803_P0, PATTERN_CTRL, 0x00);
/*-------------------------------------------------------------------------
20060809  Phil add sound control    
-------------------------------------------------------------------------*/
				twdDelay(10);
                AV_AUDIO_SW1 = ON;
				TV_AUDIO_SW2 = OFF;
				SV_AUDIO_SW3 = OFF;
                twdDelay(10);
				AUDIO_STBY = OFF;
                twdDelay(10);
				AUDIO_MUTE = OFF;   //Play
/*-------------------------------------------------------------------------
20060809  Phil add sound control    
-------------------------------------------------------------------------*/					
			}	
		}else if (uiaSrcMux1[EepPublic.cSource].VideoType==itypeYPBPR)
		{
 			I2CWriteByte(TW803_P0,0x11, 0x55);
			I2CWriteByte(TW803_P2,0x07, 0x20);
			I2CWriteByte(TW803_P2,0x01, I2CReadByte(TW803_P2,0x01)|ENYPbPr);
		}
		}else if(uiaSrcMux1[EepPublic.cSource].SourceRoute==isrcANALOG)	 //rouce route videodecoder
		{
			I2CWriteByte(TW803_P0,0x18, uiaSrcMux1[EepPublic.cSource].ADCMUX>>8);  // cMux1);
			I2CWriteByte(TW803_P0,0x19, uiaSrcMux1[EepPublic.cSource].ADCMUX&0xFF);  // cMux2);
			I2CWriteByte(TW803_P2,0x07, 0x06&~0x20);
#ifdef PC_MODE
	 if (uiaSrcMux1[EepPublic.cSource].VideoType==itypeRGB)
	{
		I2CWriteByte(TW803_P0,0x16, 0x00);       // line lock PLL reg
		I2CWriteByte(TW803_P0,0x31, 0x40);       // Source select reg
		I2CWriteByte(TW803_P0,0x40, 0xC2);       // enable hsync&ysync offset and enable RGB path
		I2CWriteByte(TW803_P0,0x17, 0xC8);       // set ADC VCO 3,set ADC ChargePump 1
		I2CWriteByte(TW803_P0,0x1A, I2CReadByte(TW803_P0,0x1A)&0xF8);  //  set the Auto Gain Control Mode
		//~ Enable Interrupt ~//
		I2CWriteByte(TW803_P0,0x33, 0xB0);    //Hsync&Vsync Timing changed, lost Hsync&Vsync
		I2CWriteByte(TW803_P0,0x32, 0xFF);    //write to clear the flag
		I2CWriteByte(TW803_P0,0x37, 0x40);    //64ms trigger Vsync interrupt
		I2CWriteByte(TW803_P0,0x39, 0x10);    //Hsync Missing Counter MSB
		twdDelay(50);        // For H/W stable.
	}
	else
#endif
			if (uiaSrcMux1[EepPublic.cSource].VideoType==itypeRGB565)
			{
				I2CWriteByte(TW803_P0,0x16, 0xD3);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -