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

📄 t803_util.c

📁 这是T118和T103的通用程序
💻 C
字号:
/****************************************************************************
* 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 "common.h"
#include "system.h"
#include "panel.h"
#include "Resolution.h"
#include "SRC_ctrl.h"
#include "twowire.h"
#include "filter.h"
#include "keypad.h"
#include "Nvram.h"
//#include "Video.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"

static uCHAR cSVideo=0;
//static uCHAR cYPbPr=0;  // add by Sherman 06'01'12
/****************************************************************************
*                           Public Global Variable                          *
****************************************************************************/
uDWORD 	m_dwTemp[2];
uWORD 	m_wDWHSZ=DWHSZ;
uCHAR 	NoSignal=0;
#ifdef ROTATE
     uCHAR Dis_Mode=TOP_LEFT;
#endif

/****************************************************************************
*                              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
	//=========================================================================
//#if (EMPTY_ARRAY)
	for(RegIndex=0;RegIndex < PanelSpecP0Cnt;RegIndex++)
	{
		I2CWriteByte(TW803_P0,ucaPanelSpecAdrP0[RegIndex],ucaPanelSpecDataP0[RegIndex]);
    }
//#endif

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

	#ifdef ROTATE
   		SET_Dismod();
	#endif				
}

#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

void SourceSelect(void)
{
   if((EepPublic.cSource==1)||(uiaSrcMux1[EepPublic.cSource].VideoType==itypeRGB565)||(uiaSrcMux1[EepPublic.cSource].VideoType==itypeRGB))
    {

		SetSignalStd();
	    SetOPTiming();
    }

 	ClosePanel(0x10, 0xff, 0x40);

	I2CWriteByte(TW803_P0,0x0f,0x70);  //2005-03030 for position shift
	I2CWriteByte(TW803_P0,0x0f,0x00);  //2005-03030 for position shift
	I2CWriteByte(TW803_P0,0x31,0x00);
	I2CWriteByte(TW803_P0,0x1a, 0x87);


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_P0,0x11, 0x05);
		I2CWriteByte(TW803_P2,0x07, 0x24);//0x05|0x22);
		I2CWriteByte(TW803_P2,0x00, I2CReadByte(TW803_P2,0x00)|0x01);
		I2CWriteByte(TW803_P2,0x01, I2CReadByte(TW803_P2,0x01)&~ENYPbPr);
 		I2CWriteByte(TW803_P2,0x03, I2CReadByte(TW803_P2,0x03)|0x03);
		I2CWriteByte(TW803_P2,0x07, 0x06|0x02);
	}
	else if ( (uiaSrcMux1[EepPublic.cSource].VideoType==itypeCVBS)
    #ifdef TV
    ||(uiaSrcMux1[EepPublic.cSource].VideoType==itypeTV)
    #endif
    )

	{
 		I2CWriteByte(TW803_P0,0x11, 0x00);
		I2CWriteByte(TW803_P2,0x07, 0x21);//0x05|0x22);
		I2CWriteByte(TW803_P2,0x00, I2CReadByte(TW803_P2,0x00)&0xfe);
		I2CWriteByte(TW803_P2,0x01, I2CReadByte(TW803_P2,0x01)&~ENYPbPr);
		I2CWriteByte(TW803_P0,0x16, 0xD3);
		I2CWriteByte(TW803_P2,0x07, 0x02);
		if(m_cChroma==S_NTSC_4)  // temporarily add by Sherman 06'01'27
			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();
        }
#endif
	}
	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);
	}
} //rouce route videodecoder
else if(uiaSrcMux1[EepPublic.cSource].SourceRoute==isrcANALOG)
{
	I2CWriteByte(TW803_P0,0x18, uiaSrcMux1[EepPublic.cSource].ADCMUX>>8);  // cMux1);
	I2CWriteByte(TW803_P0,0x19, uiaSrcMux1[EepPublic.cSource].ADCMUX&0xFF);  // cMux2);
#ifdef PC_MODE
	 if (uiaSrcMux1[EepPublic.cSource].VideoType==itypeRGB)
	{
		I2CWriteByte(TW803_P0,0x16, 0x00);
		I2CWriteByte(TW803_P0,0x31, 0x40);
		I2CWriteByte(TW803_P0,0x40, 0xC2);
		I2CWriteByte(TW803_P0,0x17, 0xC8);
		I2CWriteByte(TW803_P0,0x1A, I2CReadByte(TW803_P0,0x1A)&0xF8);
		//~ Enable Interrupt ~//
		I2CWriteByte(TW803_P0,0x33, 0xB0);
		I2CWriteByte(TW803_P0,0x32, 0xFF);
		I2CWriteByte(TW803_P0,0x37, 0x40);
		I2CWriteByte(TW803_P0,0x39, 0x10);
	}
	else
#endif
		if (uiaSrcMux1[EepPublic.cSource].VideoType==itypeRGB565)
	{
		I2CWriteByte(TW803_P0,0x16, 0xD3);
		I2CWriteByte(TW803_P0,0x40, 0xC2);
		I2CWriteByte(TW803_P0,0x17, 0xC8);
		SRC_565();
	}
}
#ifdef DIGI_AVAILABLE
else if(uiaSrcMux1[EepPublic.cSource].SourceRoute==isrcDIGITAL)
{
	if (uiaSrcMux1[EepPublic.cSource].VideoType==itype656)
	{
		SRC_656();
	}
}
#endif
 Detect_Sig(1);

	I2CWriteByte(TW803_P0, 0xE2, 0x11);
}


void DetectSignalStd(void)
{
	uCHAR index=0,SlaveAddr,RegAddrShift;//,tmp;

#ifdef T515
	if(EepPublic.cSource >= isrc_T515_CVIDEO1){
		 SlaveAddr=0xb8;
		 RegAddrShift=0x20;
	}else{
		 SlaveAddr=0x54;
		 RegAddrShift=0x00;
	}	
#else
	SlaveAddr=0x54;
	RegAddrShift=0x00;		
#endif	

	m_cBuff[0]=m_cStandard;	
	if(I2CReadByte(SlaveAddr, 0x3A+RegAddrShift)&0x06)		// Judge vlock and hlock
	{	
		//if(I2CReadByte(SlaveAddr, 0x7B+RegAddrShift)>0x10){//  For no chroma case
			//twdDelay(50);
		//~~~~~~~ set OPTiming ~~~~~~~~~~~~~~~~~~~//
			if(I2CReadByte(TW803_P0,0x59) <= 0xd6)			
				m_cBuff[0]=S_NTSC;  
			else 					
				m_cBuff[0]=S_PAL;  
				 			
			#ifdef T515
	        if((EepPublic.cSource&0x0f) >= isrc_T515_CVIDEO1){
	            m_cBuff[0] = I2CReadByte(TW515, 0x5c)&0x04;			
				if((I2CReadByte(TW515, 0x5c)&0x07)==0)
					m_cBuff[0]=S_NTSC;
	            else if(I2CReadByte(TW515, 0x5c)&0x02)
					m_cBuff[0]=S_SECAM;
	       		else if(I2CReadByte(TW515, 0x5c)&0x04)
					m_cBuff[0]=S_PAL;
				else  
					m_cBuff[0]=0xff;
			}
			#endif			
		if((m_cStandard!=m_cBuff[0])){	// signal std was changed,and output timing must be set again 
			m_cStandard=m_cBuff[0];			
			SetOPTiming();
    	}		
		//~~~~~~~ End of set OPTiming ~~~~~~~~~~~~~~~~~~~//

		//~~~~~~~ set Chroma ~~~~~~~~~~~~~~~~~~~//
		m_cBuff[4]=m_cChroma;	
#ifdef T515
	        if((EepPublic.cSource&0x0f) >= isrc_T515_CVIDEO1){
	            m_cBuff[4] = I2CReadByte(TW515, 0x5c)&0x04;
			//else if((EepPublic.cSource&0x0f) >= isrc_T515_CVIDEO1){
				if((I2CReadByte(TW515, 0x5c)&0x07)==0)
					m_cBuff[4]=S_NTSC;
	            else if(I2CReadByte(TW515, 0x5c)&0x02)
					m_cBuff[4]=S_SECAM;
	       		else if(I2CReadByte(TW515, 0x5c)&0x04)
					m_cBuff[4]=S_PAL;
				else  
					m_cBuff[4]=0xff;
			}		
#endif
	
			twdDelay(25);
			// Set Chroma lock configration
			if(I2CReadByte(TW803_P0,0x59) <= 0xd6)
				I2CWriteByte(SlaveAddr, 0x83+RegAddrShift, 0x39);//6f);  // NTSC	  // change by Sherman 06'02'07
			else 	
				I2CWriteByte(SlaveAddr, 0x83+RegAddrShift, 0x39);  // PAL
			twdDelay(50);
			
			if(I2CReadByte(TW803_P0,0x59) <= 0xd6) { // NTSC-M,NTSC-4,PAL-M		
				m_wBuff[2]=0;
				m_cBuff[1]=m_cChroma;	// Preserve previous status for signal std	
				twdDelay(150);	  		// add by Sherman 06'01'16				
				while (1){	// NTSC-M=1,NTSC-4=4,PAL-M=5									
					if (m_cChroma == S_NTSC_4){
						if ((I2CReadByte(SlaveAddr, 0x3a+RegAddrShift)&0x08)&&(I2CReadByte(SlaveAddr, 0x7a+RegAddrShift)<0x80)) 					
							break;						
					}					
					if ((m_cChroma == S_NTSC)|(m_cChroma == S_PAL_M)){					
						if ((I2CReadByte(SlaveAddr, 0x3a+RegAddrShift)&0x08))
							break;						
					}
										
					if (m_cChroma == S_NTSC)					
						#ifndef	Signal_NTSC_4
							#ifndef Signal_PAL_M
								m_cChroma=S_NTSC;								
							#else
								m_cChroma=S_PAL_M; 
							#endif
						#else
						m_cChroma=S_NTSC_4;
						#endif				
					else if (m_cChroma == S_NTSC_4)					
						#ifndef Signal_PAL_M
						m_cChroma=S_NTSC;		
						#else
						m_cChroma=S_PAL_M;		
						#endif				
					else //if (m_cChroma == S_PAL_M)									
						m_cChroma=S_NTSC;	
													
					SetSignalStd();					// Set Signal flag and DTO
					twdDelay(50);
	
					if ((++m_wBuff[2]) >4) break; 	// Avoid while setting, input switch to NTSC					
				}			
			}else{  // PAL-BD,PAL-CN,SECAM 

#if (defined YPbPr)
				if(EepPublic.cSource == isrYPbPr)
					m_cBuff[4]=S_PAL; 
				else {
#endif								
					m_wBuff[2]=0;
					m_cBuff[1]=m_cChroma;	// Preserve previous status for signal std	
					twdDelay(150);	  		// add by Sherman 06'01'16					
					while (1){	// PAL-BD=2,PAL-CN=6,SECAM=3 						
						if ((m_cChroma == S_PAL)|(m_cChroma == S_PAL_CN)){						
							if ((I2CReadByte(SlaveAddr, 0x3a+RegAddrShift)&0x08) && (I2CReadByte(SlaveAddr, 0x3c+RegAddrShift)&0x01==1))//&& (I2CReadByte(SlaveAddr, 0x7d+RegAddrShift)>0xf0)) 							
									break;							
						}												
						if (m_cChroma == S_SECAM){													
							if ((I2CReadByte(SlaveAddr, 0x3a+RegAddrShift)&0x08) && (I2CReadByte(SlaveAddr, 0x7d+RegAddrShift)>0xf0)) 							
								break;												 
						}						
					
						if (m_cChroma == S_PAL)						
							#ifndef Signal_SECAM
								#ifndef Signal_PAL_CN
								m_cChroma=S_PAL;
								#else
								m_cChroma=S_PAL_CN;
								#endif
							#else 
							m_cChroma=S_SECAM;
							#endif					
						else if (m_cChroma == S_SECAM)					
							#ifndef Signal_PAL_CN
							m_cChroma=S_PAL;	
							#else
							m_cChroma=S_PAL_CN;	
							#endif				
						else //if (m_cChroma == S_PAL_CN)
							m_cChroma=S_PAL;										
						SetSignalStd();					// Set Signal flag and DTO
						twdDelay(50);
						if ((++m_wBuff[2]) >4) break; 	// Avoid while setting, input switch to NTSC					
					}
#if (defined YPbPr)				
		  		}
#endif
			}
		if (m_cBuff[1] != m_cChroma){
			if ((I2CReadByte(SlaveAddr, 0x3a+RegAddrShift)&0x08))
				m_cBuff[4] = m_cChroma;
			m_cChroma=m_cBuff[1] ;
		}			
		if((m_cChroma!=m_cBuff[4])){	
			m_cChroma=m_cBuff[4];	
    	}
	}// 癹伴い

⌨️ 快捷键说明

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