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

📄 pc_eep.c

📁 车载DVD osdIC TW8816原厂代码
💻 C
字号:
//pc_eep.c
//=========================================================================
//	EEPROM structure

//	0x80	----------- PC Color Temp Data --------------------------------
//			0	PC Color Temp Mode
//			1	R G B for Mode 1
//			4	R G B for Mode 2
//			7   R G B for Mode 3
//			A	R G B for User Mode
//
//	0x90	----------- PC Input ------------------------------------------
//
//			0	ADC Coarse
//			1	ADC Phase
//			2	Vertical Active Start
//			3	Horizontal Active Start
//

#include "Config.h"

#if defined( SUPPORT_PC ) || defined( SUPPORT_DTV )

#include "typedefs.h"
#include "main.h"
#include "i2c.h"
#include "pc_eep.h"
#include "printf.h"
#include "TW88.h"
#include "measure.h"
#include "adc.h"
#include "osdmenu.h"
#include "etc_eep.h"
#include "panel.h"

extern  CODE struct _PCMDATA  PCMDATA[];
extern     CODE struct _PANELDATA PanelData; // Hans

extern  IDATA BYTE  PcMode, PcModeLast;
extern	IDATA WORD  IVF;
extern	IDATA DWORD	IHF;

///extern	IDATA BYTE	CurrentADC;

WORD GetVactiveStartEE(BYTE mode)
{
	WORD index;
	WORD start;

	index = EE_PCDATA + mode*LEN_PCDATA + 2;
	start = PCMDATA[mode].Vstart + (char)ReadEEP(index);

	return start;
}

WORD GetHactiveStartEE(BYTE mode)
{
	WORD index;
	WORD start;

	index = EE_PCDATA + mode*LEN_PCDATA + 4;
	start = PCMDATA[mode].Hstart + (char)ReadEEP(index);

	return start;
}

// check whether the mode was saved
BYTE IsModeSaved(BYTE mode)
{
	WORD index;
	BYTE   cTemp;

	index = EE_PCDATA + mode*LEN_PCDATA + 1; // share the storage byte with phase
	cTemp = ReadEEP(index);
	cTemp &= 0xE0; // mode save identify value is saved in bit5-bit7 
#ifdef DEBUG_PC
	dPrintf("\r\n IsModeSaved flag ----------%02x", (WORD)cTemp);
#endif
	if (cTemp == 0x40)
		return TRUE;
	else
		return FALSE;
}

//-----------------------------------------------------------------------------
//			Get PC Function Data from EEPROM
//-----------------------------------------------------------------------------
void GetPCDataEE(BYTE mode)
{
	char dat=0;			// must be signed char
	WORD index, temp;
#ifndef WIDE_SCREEN
	DWORD scale, pres;
#endif
	extern bit Flag4Bypass;
	WORD hstart, vstart;

	vstart = PCMDATA[mode].Vstart;
	hstart = PCMDATA[mode].Hstart;

	index = EE_PCDATA + mode*LEN_PCDATA;

	//--------------------------------------------

	// PPF
//	ChangeInternPLL(PCMDATA[mode].PPF * 100000L);

	// ADC PLL-----(0)
	if( !IsDTVInput() ) dat = ReadEEP(index);

	if(GetInputSelection()==PC) WriteADC(0xc1, 0x30);
       // pll of ADC
	SetCoarse( dat + PCMDATA[mode].CLOCK );

	if(GetInputSelection()==PC) WriteADC(0xc1, 0x20);

	// ADC Phase---(1)
	dat = ReadEEP(index+1);
	dat &= 0x1F; //  phase was saved in bit0 t0 bit4
	if( !IsDTVInput() ) 
	SetPhase( dat );

	// Vertical----(2)
	#ifdef DEBUG_PC
	dPrintf("\r\n  vstart(before add ReadEEP): %d", (WORD)vstart);
	#endif
	if( !IsDTVInput() ) 
	vstart += (char)ReadEEP(index+2);
	#ifdef DEBUG_PC
	dPrintf("\r\n  vstart(after add ReadEEP): %d", (WORD)vstart);
	#endif
	
	SetVactiveStart( vstart );
	if( IsDTVInput() ) {
		SetVactiveLen( PCMDATA[mode].VAN+20 );
	}
	else
		SetVactiveLen( PCMDATA[mode].VAN );

	SetVValueForPanel(vstart);			// Vstart

	dat=0;
	// VBackPorch--(3)
	if( !IsDTVInput() ) 
	dat = (char)ReadEEP(index+3);
	dat += PCMDATA[mode].VBack;
	dat -= ReadTW88(0xb8);				// VOsync value compensation
	#ifdef DEBUG_PC
	dPrintf("\r\nSetVBackPorch( %d )", (WORD)dat);
	#endif
 #ifdef WQVGA
	SetVBackPorch(PanelData.VBackporch);
#else
	SetVBackPorch( dat );
#endif

	// Horizontal--(4)
	if( !IsDTVInput() ) 
		hstart += (char)ReadEEP(index+4);
	temp = hstart + PCMDATA[mode].HAN + 20;

	#ifdef DEBUG_PC
	dPrintf("\r\n  hstart(after add ReadEEP): %d,  pcmode: %d ", (WORD)hstart, (WORD)mode);
	#endif

	SetHactiveStart( hstart );

	if( IsDTVInput() ) temp += 3;

	SetHactiveEnd( temp );
	SetHValueForPanel();

#ifdef WIDE_SCREEN
	Set4WideScreen(GetWideModeEE());
#else
	pres=(DWORD)PVR_;
	scale = (PCMDATA[mode].VAN * 0x10000L) / pres;
	
	if( scale==0x10000 && Flag4Bypass ) 		// Bypass
		BypassZoom();
	else {
		Clear_bypass();
		YScale2(scale);						// save V Scale Up Factor
	}

	if( (PCMDATA[mode].VAN != GetPVR()) || !Flag4Bypass) {
		pres = GetPHR();
		scale = (PCMDATA[mode].HAN * 0x10000L + pres/2) / pres;	// 256*han/phr

		#ifdef DEBUG_EEP
		dPrintf("\r\nXscaleFactor:%04x(%d)", scale, scale);
		#endif

		if( PCMDATA[mode].HAN > 1024 ) {
			scale = (PCMDATA[mode].HAN * 0x80L ) / 1024 + 1;		// (HAN/1024)*256
			XscaleD(scale);
	
			#ifdef DEBUG_EEP
			dPrintf("\r\nXscaleFactorD:%04x(%d)", scale, scale);
			#endif

			scale = (1024 * 0x10000L ) / 1280;						// (1024/PHR)*256
			XscaleU(scale);

			#ifdef DEBUG_EEP
			dPrintf("\r\nXscaleFactorU:%04x(%d)", scale, scale);
			#endif
		}
		else
			XScale2(scale);

	}
#endif	

	AutoPHPCalEnable();

	DisplayResultAndSetActiveRange();
	
}
//=============================================================================
//			Save PC Function Data to EEPROM
//=============================================================================

void SavePCDataEE(BYTE mode)
{
	WORD index;
       BYTE   cTemp = 0;
	   
	index = EE_PCDATA + mode*LEN_PCDATA ;

	#ifdef DEBUG_EEP
	dPrintf("\r\nSave PC DATA mode(%d) index(%04x) IHF(%ld)", (WORD)mode, (WORD)index, IHF );
	dPrintf(" IVF(%d) PPF(%dM)", IVF, (WORD)(GetPPF()/1000000) ); 
	#endif

	cTemp = GetPhaseCurrent();
	cTemp &= 0x1F; // clear bit5-bit7 for mode saved flag
	cTemp |= 0x40; // set mode saved flag;
	WriteEEP( index++, (char)( GetCoarse() - PCMDATA[mode].CLOCK) );
	WriteEEP( index++,         cTemp);
	WriteEEP( index++, (char)( GetVactiveStart() - PCMDATA[mode].Vstart) );
	WriteEEP( index++, (char)( ReadTW88(0xb8) + GetVBackPorch()  - PCMDATA[mode].VBack) );	//VOsync compensation
	WriteEEP( index++, (char)( GetHactiveStart() - PCMDATA[mode].Hstart) );
}

//=============================================================================
void SaveDefaultPCDataEE(void)
{
	WORD	index, i;

	index = EE_PCDATA + PcMode*LEN_PCDATA;

	for(i=0; i<LEN_PCDATA; i++) {
		WriteEEP( index++, 0 );
		delay(1);
	}
}

void SaveDefaultPCDataAllEE(void)
{
	for(PcMode=0; PcMode<EE_PC_MAX; PcMode++)
		SaveDefaultPCDataEE();
}

void SaveCoarseEE(BYTE mode)
{
	WORD	index;

	index = EE_PCDATA + mode*LEN_PCDATA + 0;
	WriteEEP( index, (char)(GetCoarse() - PCMDATA[mode].CLOCK) );
}

void SavePhaseEE(BYTE mode)
{
	WORD	index;
	BYTE       cTemp;

	index = EE_PCDATA + mode*LEN_PCDATA + 1;
	cTemp = ReadEEP(index);
	cTemp &= 0xE0; // clear bit0-bit4 for phase save
	cTemp |= GetPhaseCurrent();
	WriteEEP( index,  cTemp);
}

//=============================================================================

void SaveVactiveEE(BYTE mode)
{
	WORD	index;

	index = EE_PCDATA + mode*LEN_PCDATA + 2;
	WriteEEP( index, (char)(GetVactiveStart() - PCMDATA[mode].Vstart) );
}

void SaveVBackPorchEE(BYTE mode)
{
	WORD	index;

	index = EE_PCDATA + mode*LEN_PCDATA + 3;
	WriteEEP( index, (char)(GetVBackPorch() - PCMDATA[mode].VBack) );

}

void SaveHactiveEE(BYTE mode)
{
	WORD	index;
 
  	index = EE_PCDATA + mode*LEN_PCDATA + 4;
	WriteEEP( index, (char)(GetHactiveStart() - PCMDATA[mode].Hstart));
}

#endif // SUPPORT_PC

⌨️ 快捷键说明

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