measure.c

来自「车载DVD osdIC TW8816原厂代码」· C语言 代码 · 共 1,877 行 · 第 1/4 页

C
1,877
字号
#include "Config.h"


#include "typedefs.h"

#include "main.h"
#include "tw88.h"
#include "measure.h"
#include "adc.h"
#include "i2c.h"
#include "dispinfo.h"
#include "pc_eep.h"
#include "etc_eep.h"
#include "printf.h"
#include "osdmenu.h"
#include "RegMap.h"
#include "panel.h"
#include "CPU.h"
#include "Audio.h"

//================== Input Measurement ====================================

// Hans
IDATA BYTE    cSourceState = ssSourceMonitor;

WORD	VPosMax, VPosCurr, HPosMax, HPosCurr;

DWORD 	RGBPeak, PhaseRGB;

#ifdef WIDE_SCREEN
extern BYTE WideScreenMode;
#endif

bit bPanelMute;
bit bBlueScreenOn = TRUE;
static BYTE cCounter;	

CODE BYTE PcModeStr[][15] = {
    "720x400 70Hz",	// 0

    "640x400 80Hz",	// 1
    "640x350 85Hz",	// 2
    "720x400 85Hz",	// 3

    "640x480 60Hz",	// 4
    "640x480 66Hz",	// 5
    "640x480 70Hz",	// 6
    "640x480 72Hz",	// 7
    "640x480 75Hz",	// 8
    "640x480 85Hz",	// 9

    "800x600 56Hz",	// 10
    "800x600 60Hz",	// 11
    "800x600 70Hz",	// 12
    "800x600 72Hz",	// 13
    "800x600 75Hz",	// 14
    "800x600 85Hz",	// 15
    
    "832x624 75Hz",	// 16

    "1024x768 60Hz",	// 17
    "1024x768 70Hz",	// 18
    "1024x768 72Hz",	// 19
    "1024x768 75Hz",	// 20
    "1024x768 85Hz",	// 21

    "1152x864 60Hz",	// 22
    "1152x864 70Hz",	// 23
    "1152x864 75Hz",	// 24
    
	"1280x1024 60Hz",	// 25
    "1280x1024 70Hz",	// 26
    "1280x1024 75Hz",	// 27

    "RGB 480p 60Hz",	// 28
    "RGB 720p 60Hz",	// 29
    "RGB 720p 50Hz",	// 30
    "RGB 1080i 60Hz",	// 31
    "RGB 1080i 50Hz",	// 32
    "RGB 1080i 50Hz",	// 33
    "RGB 480i 60Hz",	// 34
    "RGB 576i 50Hz",	// 35
    "RGB 576p 50Hz",	// 36

    "YPbPr 480p",	// 37
    "YPbPr 720p",	// 38
    "YPbPr 720p50",	// 39
    "YPbPr 1080i",	// 40
    "YPbPr 1080i50",	// 41
    "YPbPr 1080i50",	// 42
    "YPbPr 480i",	// 43
    "YPbPr 576i",	// 44
    "YPbPr 576p",	// 45

	""
};

//-------------------------------------------------------------------------
extern CODE struct RegisterInfo UserRange;

extern	IDATA WORD  IVF;
extern	IDATA DWORD	IHF;
extern	 	  BYTE	DebugLevel;
extern	      bit   Range4Coarse;
extern	DATA  WORD  tm01, tm001;
extern	DATA  BYTE  tic01;
extern  DATA  WORD  tic_pc;

		IDATA BYTE PcMode;

#if defined WVGA || defined WSVGA || defined WXGA || defined VGA_PRIMEVIEW
		bit   Flag4Bypass=0;	    // 0:non-bypass
#else
		bit   Flag4Bypass=0;//1;		// 1:bypass 
#endif

//-----------------------------------------------------------------------------
extern	CODE struct _PCMDATA  PCMDATA[];

extern CODE BYTE *CheckPCCableStr[];
extern CODE BYTE *CheckDTVCableStr[];
extern CODE BYTE *OutOfRangeStr[] ;
#ifdef SUPPORT_COMPONENT
extern IDATA BYTE  ComponentMode;
#endif
extern IDATA BYTE  VInputStd;
extern bit AutoDetect;
extern IDATA BYTE InputSelection;
extern CODE BYTE COMPONENT_STR[][15] ;
extern  bit		DisplayInputHold;
extern     CODE struct _PANELDATA PanelData; // Hans

CODE BYTE DTVMode[] = {	EE_YPbPr_480I, EE_YPbPr_576I, EE_YPbPr_480P, EE_YPbPr_576P,
						EE_YPbPr_1080I,	EE_YPbPr_720P, EE_PC_UNKNOWN, EE_PC_UNKNOWN };
#define DetectDTVInputSource()	DTVMode[ReadADC(0xC1)& 0x07]

#if defined( SUPPORT_PC ) || defined( SUPPORT_DTV )
//=============================================================================
/*BYTE Measure_VPN_IHF( WORD *p_vpn, DWORD *p_ihf)
{
	DWORD ppf;
	WORD  hpn;


	if( !MeasureAndWait(3) ) {
	
		#ifdef DEBUG_PC
		dPuts("\r\n  ** Error at Get_VPN_IHF");
		#endif
		return 0;
	}

	ppf    = GetPPF();			//
	*p_vpn = GetVPN();			//
	hpn    = GetHPN();			// HPN = H Period Num

	*p_ihf = (ppf + hpn/2) / hpn;			// IHF = PPF / HPN 

	#ifdef DEBUG_PC
	dPrintf("\r\n  *** PPF=%ld   HPN=%4d", ppf, hpn);
	dPrintf("  --> VPN=%4d   IHF=%ld ", *p_vpn, *p_ihf);
	dPrintf("  IVF=%d", (WORD)((*p_ihf + *p_vpn/2) / *p_vpn) );

//	dPrintf(" [%d, %ld]", LastVPN, LastIHF);

	#endif

	return 1;
}
*/
void ResetPCValue(void)
{
	SaveDefaultPCDataEE();
	GetPCDataEE(PcMode);
}

void StartNewDetect(void)
{
	ClearEnDet();
	MeasureAndWait(3);
	SetEnDet();

	WriteTW88(STATUS0, 0xff);
	WriteTW88(STATUS1, 0xff);
}

WORD GetCoarseValue(void)
{
	return GetCoarse();
}

WORD SetPCCoarseValue(BYTE val)		//1:Up	2:Dn
{
	WORD	coarse;

//	WriteADC(0xc1, 0x30);
	WriteADC(0xc0, 0x30);

	coarse = GetCoarse();
	if( val==UP ) coarse++;
	else coarse--;

	SetCoarse(coarse);
	SaveCoarseEE(PcMode);	// HHY 1.33

	StartNewDetect();

//	WriteADC(0xc1, 0x20);
	WriteADC(0xc0, 0x20);
	return coarse;
}


BYTE SetPhaseValue(BYTE val)
{
	BYTE	phase;

	phase = GetPhaseCurrent();

	if( val==UP ) {
		if( phase>=31 ) return phase;
		else phase++;
	}
	else {
		if( phase==0 ) return phase;
		else phase--;
	}

	SetPhase(phase);
	SavePhaseEE(PcMode);	// HHY 1.33

	return phase;
}

BYTE IsDTVInput(void)
{
	if( GetInputSelection()==DTV || GetInputSelection()==PC ) {
		if( PcMode>=EE_RGB_480P && PcMode<=EE_YPbPr_576P ) return 1;
	}
	return 0;
}

//IDATA struct RegisterInfo VPositionRange={0,100, 50};

//=============================================================================
//                    PC Screen Position Move Functions
//=============================================================================
BYTE GetVPosition(void)
{
	int newv;
	struct RegisterInfo VPositionRange;
	
	VPositionRange.Min =  PCMDATA[PcMode].Vstart * 2 - VPosMax; // Rang : from (vstart - front)   to  (hvstart + front)
	VPositionRange.Max = VPosMax;
	VPositionRange.Default = PCMDATA[PcMode].Vstart ;
	
	Mapping2( VPosCurr, &VPositionRange, &newv, &UserRange );

	return newv;
}

BYTE SetVPosition(BYTE val)		//0:UP, 1:DOWN
{
	int newv;
	struct RegisterInfo VPositionRange;
	char add;

	VPositionRange.Min =  PCMDATA[PcMode].Vstart * 2 - VPosMax; // Rang : from (vstart - front)   to  (vstart + front)
	VPositionRange.Max = VPosMax;
	VPositionRange.Default = PCMDATA[PcMode].Vstart ;

#ifdef DEBUG
	dPrintf("\r\n vpos min: %d, max: %d, cur: %d", VPositionRange.Min, VPositionRange.Max, (WORD)VPosCurr);
#endif

	add = ( val==UP  ? 1  :  -1  );
	if( (VPosCurr + add) < VPositionRange.Min || (VPosCurr + add)  > VPositionRange.Max )
	{
       	Mapping2( VPosCurr, &VPositionRange, &newv, &UserRange );
		return newv;
	}

	VPosCurr += add;
       Mapping2( VPosCurr, &VPositionRange, &newv, &UserRange );

	if( IsBypassmode() ) {
		SetVactiveStart( VPosCurr );
		SaveVactiveEE(PcMode);						// HHY 1.33
	}
	else {
		SetVactiveStart( VPosCurr );
		SaveVactiveEE(PcMode);						// HHY 1.33
		SetVBackPorch( GetVBackPorch()+add );		// A6
		SaveVBackPorchEE(PcMode);					// HHY 1.33
	}
	
	return newv;
}

BYTE GetHPosition(void)
{
	int newv;
	struct RegisterInfo HPositionRange;
	
	HPositionRange.Min =  PCMDATA[PcMode].Hstart * 2 - HPosMax; // Rang : from (Hstart - front)   to  (hstart + front)
	HPositionRange.Max = HPosMax;
	HPositionRange.Default = PCMDATA[PcMode].Hstart ;
	
	Mapping2( HPosCurr, &HPositionRange, &newv, &UserRange );

	return newv;
}

BYTE SetHPosition(BYTE val)
{
	int newv;

	char add;
	WORD hend;
	struct RegisterInfo HPositionRange;
	
	HPositionRange.Min =  PCMDATA[PcMode].Hstart * 2 - HPosMax; // Rang : from (Hstart - front)   to  (hstart + front)
	HPositionRange.Max = HPosMax;
	HPositionRange.Default = PCMDATA[PcMode].Hstart ;

#ifdef DEBUG
	dPrintf("\r\n hpos min: %d, max: %d, cur: %d", HPositionRange.Min, HPositionRange.Max, (WORD)HPosCurr);
#endif

	add = ( val==UP  ? 1  :  -1  );
	if( (HPosCurr + add) < HPositionRange.Min || (HPosCurr + add) > HPositionRange.Max )
	{
       	Mapping2( HPosCurr, &HPositionRange, &newv, &UserRange );
		return newv;
	}

	HPosCurr += add;
       Mapping2( HPosCurr, &HPositionRange, &newv, &UserRange );

	hend   = GetHactiveEnd();

	hend   += add;
	SetHactiveStart(HPosCurr);
	SetHactiveEnd(hend);

	SaveHactiveEE(PcMode);		// HHY 1.33

	return newv;
}
//=============================================================================
//		Phase Measurement
//			Return : PhaseBlue, PhaseGreen, PhaseRed										   
//=============================================================================
DWORD ReadOut4(void)
{
	BYTE	i;
	DWORD	dat=0;

	for(i=0; i<4; i++) {
		dat <<= 8;
		dat |= (DWORD)ReadTW88(0x5a-i);
	}
	return dat;
}

BYTE GetPhaseRGB(void)		// HHY 1.10 BYTE return 
{
	static bit flag=0;
	DWORD _RGB;

	#ifdef DEBUG_PC
	BYTE sign;
	#endif

	_RGB = PhaseRGB;

	if( !MeasureAndWait(3) ) {
		#ifdef DEBUG_PC
		dPuts("\r\n  Error at GetPhaseRGB");
		#endif
		return 0;		//LJY001219
	}

	WriteTW88(0x5b, 0x00);			// Read Phase B
	PhaseRGB  = ReadOut4();

	WriteTW88(0x5b, 0x10);			// Read Phase G
	PhaseRGB += ReadOut4();

	WriteTW88(0x5b, 0x20);			// Read Phase R
	PhaseRGB += ReadOut4();

	#ifdef DEBUG_PC
	if( PhaseRGB  >= _RGB ) sign = '+'; else sign = '-';
	dPrintf("(%c%08lx)", (WORD)sign, PhaseRGB);
	#endif

	if( PhaseRGB==_RGB ) {			// NO INPUT ???
		dPuts("\r\n??? SYNC loss...");
		if(flag) {
			flag = 0;
			return 0;
		}
		else flag = 1;
	}
	else flag = 0;

	return 1;
}


//============================================================================
//			Determine InputSource Format based on VPN
//============================================================================
//	Input	VPN
//	Return	PcMode
//			InputSource (PC_XGA, PC_SVGA, PC_VGA)

BYTE DecideVGAInputSource(WORD vpn, WORD ivf)
{
	BYTE _PcMode;

	#ifdef DEBUG_PC
	dPrintf("\r\n-----> DecideVGAInputSource: vpn:%4xh, ivf:%4xh", vpn, ivf);
	#endif


	_PcMode     = EE_PC_UNKNOWN;

	//====================== PC DOS ================================
	if( vpn >= 440  && vpn <= 460 ) { 
		#ifdef DEBUG_PC
		dPrintf("\r\n========= PC DOS ==================: vpn:%4d, ivf:%4d", (WORD)vpn, (WORD)ivf);
		#endif
		//InputSource = PC_DOS1;  
		switch( ivf ) {
		case 69: case 70: case 71:	_PcMode = EE_DOS;			break;
		
		case 84: case 85: case 86: case 87:
			GetHpnVpn(1);
			if( ReadTW88(0x40) & 0x02 ) 
				_PcMode = EE_SP1;			
			else
				_PcMode = EE_SP2;			
			break;

		default:					_PcMode = EE_PC_UNKNOWN;	break;

		}
	}
	//====================== PC VGA, DTV 480P ======================
	else if( vpn>=490  && vpn<=540 ) { 

		#ifdef DEBUG_PC
		dPrintf("\r\n============ PC VGA, DTV 480P ============: vpn:%4d, ivf:%4d", (WORD)vpn, (WORD)ivf);
		#endif
		switch( ivf ) {
			case 59: case 60: case 61:
				_PcMode = EE_VGA_60;	break;
			case 65: case 66: case 67:	_PcMode = EE_VGA_66;		break;
			case 69: case 70: case 71:	_PcMode = EE_VGA_70;		break;
	        case 72: case 73:			_PcMode = EE_VGA_72;		break;
			case 74: case 75: case 76:	_PcMode = EE_VGA_75;		break;
			case 83:
		 	case 84: case 85: case 86:	_PcMode = EE_VGA_85;		break;
			default:					_PcMode = EE_PC_UNKNOWN;	break;
		}
	}
	//====================== PC SVGA ===============================
	else if( vpn>=610 && vpn<=680+30 ) {

⌨️ 快捷键说明

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