measure.c

来自「显示屏驱动源代码」· C语言 代码 · 共 1,866 行 · 第 1/3 页

C
1,866
字号

	//------- Display the Result ---------------------
	#ifdef DEBUG_PC
	dPuts  ("\r\n-------------------------------------------");
	dPrintf("\r\n   Resolution    = %d x %d (%s)", PCMDATA[PcMode].HAN, PCMDATA[PcMode].VAN, PcModeStr[PcMode]);
	dPrintf("\r\n   IVF(Refresh)  = (%d)", IVF);
	dPrintf("\r\n   IHF           = %08lx (%ld)", IHF, IHF);
	dPuts  ("\r\n-------------------------------------------");
	#endif

	//----- calculate H Pos Range
	HPosCurr = GetHactiveStart();
	cRang = PCMDATA[PcMode].HAN / 20;
	HPosMax = PCMDATA[PcMode].Hstart + cRang;
	#ifdef DEBUG_PC
	dPrintf("\r\n HPosCurr  = %d,  HPosMax = %d, HRang = %d ", (WORD)HPosCurr, (WORD)HPosMax, (WORD)cRang);
	#endif
	
	//----- calculate V Pos Range
	VPosCurr = GetVactiveStart();
	cRang = PCMDATA[PcMode].VAN / 40;
	VPosMax = PCMDATA[PcMode].Vstart + cRang;
	#ifdef DEBUG_PC
	dPrintf("\r\n VPosCurr  = %d,  VPosMax = %d, VRang = %d ", (WORD)VPosCurr, (WORD)VPosMax, (WORD)cRang);
	#endif

}
/*===========================================================================*/
/*						  Real Measurement routine				             */
/*===========================================================================*/
BYTE DoMeasurement(void)
{
/*	WORD coarse;

	//------------------------ Clock Tuning -------------------------------
	#ifdef DEBUG_PAUSE
	Pause("coarse = AutoTuneClock()");
	#endif

	coarse = AutoTuneClock();			// plldiv
	if( coarse == 0 ) {
		ePuts("\r\nToo big IPF");
		MeasureAndWait(3);
		return FALSE;
	}
*/
	//-------------------------- Fine Tuning ------------------------------

#ifdef AUTOTUNEPHASE
	AutoTunePhase();
#endif
	
	//-------------------------- Get Active Region ------------------------
	if( !GetActiveRegion() ) {

		GetPCDataEE(PcMode);

		MeasureAndWait(3);
		return FALSE;
	}

	//-------------------------- Display Result ---------------------------
	DisplayResultAndSetActiveRange();

	return TRUE;
}

//#ifdef SUPPORT_DTV
void RGBModeFieldDetect(BYTE flag)
{
	BYTE val;

	val = ReadTW88(0x42);
	if( flag ) val = val | 0x80;
	else       val = val & 0x7f;
	WriteTW88( 0x42, val);
}
//#endif

/*===========================================================================*/
/*                                                                           */
/*===========================================================================*/
BYTE SetADCandInputRegisterByMode(BYTE mode)
{

	BYTE fielddetect=0, ret;

	SetCoarse( PCMDATA[mode].CLOCK );
//	ret = SetVCORange(IHF * PCMDATA[mode].CLOCK);	
	ret = SetVCORange(PCMDATA[mode].IPF * 100000L);	

	{
		switch (mode) {
		case EE_RGB_480I:		
		case EE_RGB_576I:		
		case EE_RGB_1080I:		
		case EE_RGB_1080I50A:
			fielddetect = 1;	
			break;

		default:
			fielddetect = 0;	
			break;
		}
		
	}

	RGBModeFieldDetect(fielddetect);

	return ret;

}

CODE_P BYTE *GetPCInputSourceName(void)
{
	BYTE *ptr;

	if( PcMode<EE_PC_MAX ) ptr = PcModeStr[PcMode];
	else                   ptr = (CODE_P BYTE *)"";

	#ifdef DEBUG
	dPrintf("\r\n++(GetPCInputSourceName)=<%s>", ptr);
	#endif

	return ptr;
}

BYTE AutoAdjust(void)
{
	BYTE ret=0;

	ClearOSDInfo();
	DisplayAutoAdjust();

	SaveDefaultPCDataEE(); // reset position/phase/pll of PC

       MeasureSetup();
	delay(2);   
	PcMode = DecideVGAInputSource(GetHpnVpn(1), IVF);
       ret = DoMeasurement();	
//       WriteTW88( 0x44, (ReadTW88(0x44)&0xf3)|0x0c );		// set mode to RGB

	ClearAutoAdjust();
	LCDPowerON(0);	//HHY 1.63
	WriteTW88( STATUS0, 0xff );
	WriteTW88( STATUS1, 0xff );

	return ret;
}						
#endif

// Hans
BYTE DetectComponentInputMode(void)
{
	BYTE mode, pcmodetemp;

	mode = ((ReadDecoder(CVFMT) & 0x70) >> 4);
	ComponentMode = mode;
#ifdef DEBUG
	dPrintf("\n\r component Mode: %2x-> %2x (%s)", (WORD)mode, (WORD)mode,COMPONENT_STR[mode]);
#endif	

	switch (mode)
	{
	case YPBPR_480i:	
		pcmodetemp = EE_YPbPr_480I;	
		break;
	case YPBPR_576i:	
		pcmodetemp = EE_YPbPr_576I;	
		break;
	case YPBPR_480p:
		pcmodetemp = EE_YPbPr_480P;	
		break;
	case YPBPR_576p:
		pcmodetemp = EE_YPbPr_576P;	
		break;
	case YPBPR_720p:	
		pcmodetemp = EE_YPbPr_720P;	
		break;
	case YPBPR_1080i:
		pcmodetemp = EE_YPbPr_1080I;	
		break;
	default:
		pcmodetemp = EE_PC_UNKNOWN;	
		break;
	}

	return pcmodetemp;
}

// Hans
BYTE ModeDetect(void)
{
	BYTE i = 0;
#if (defined SUPPORT_PC) || (defined SUPPORT_DTV)
	WORD vpn, ivf;
#endif

	#ifdef DEBUG
	dPrintf("\r\n ModeDetect ==========");
	#endif
	bPanelMute = 0; // clear panel mute flag
	cCounter = 0; // clear monitor
       PcMode = EE_PC_NO_SIGNAL; // clear PcMode

       WriteTW88(0xff, 0); // page 0

       // make sure syncs were detected
#if (defined SUPPORT_PC) || (defined SUPPORT_DTV)
	if ((InputSelection == PC) || (InputSelection == DTV))
	{
		if (( ReadTW88(STATUS0) & 0x01 ) == 0) { // no sync input
			#ifdef DEBUG_PC
			dPuts("\r\nCheck PC/DTV Cable.....");
			#endif
			return FALSE;
		}
	}
	else
#else
	if (IsNoInput()) // no decoder input
	{
#ifdef SUPPORT_TV
       	if (InputSelection != TV)
#endif
		{
			#ifdef DEBUG_PC
			dPuts("\r\nCheck CVBS/SVIDEO/COMPONENT Cable.....");
			#endif
			return FALSE;
		}
	}
#endif	


#if (defined SUPPORT_PC) || (defined SUPPORT_DTV)
	if ((InputSelection == PC) || (InputSelection == DTV))
	{
		PcMode = DetectDTVInputSource();
		if (PcMode != EE_PC_UNKNOWN) // already got the format from register
			return TRUE;
		// else continue detect mode table
	}
	else
#endif
#ifdef SUPPORT_COMPONENT
	if( InputSelection == COMPONENT )
	{
		PcMode = DetectComponentInputMode();
		if (PcMode ==  EE_PC_UNKNOWN)
			return FALSE;
		else 
			return TRUE;
	}
	else
#endif
	{ // video/svideo/tv
           WriteTW88(0xff, 0); // page 0
	    VInputStd = DetectDecoderInput();
           switch (VInputStd)
           {
		case PAL:	
		case SECAM:	
		case PALN:	
			PcMode = EE_YPbPr_576I;	
			break;
		case NTSC:	
		case NTSC4:	
		case PALM:
		case PAL60:
		default:	
			PcMode = EE_YPbPr_480I;	
			break;

           }
	    return TRUE; // video/svideo/tv  don't need to detect mode table
	}
       
#if (defined SUPPORT_PC) || (defined SUPPORT_DTV)
       do{
		vpn = GetHpnVpn(1);					// VPN, IVF 
		ivf = IVF;

		#ifdef DEBUG_PC
		dPrintf("\r\n======================== LOOP:%d", (WORD)i);
		#endif
		PcMode = DecideVGAInputSource(vpn, IVF);

		// Check SYNC Loss	// HHY 1.47
		if( PcMode == EE_PC_UNKNOWN ) {
			if(! (ReadTW88(STATUS0) & 0x01) )  {
				PcMode = EE_PC_NO_SIGNAL;
				#ifdef DEBUG_PC
				ePuts("\r\n-----> Sync Loss");
				#endif
				break;
			}
		}
		i++;
       } while ( (PcMode == EE_PC_UNKNOWN) && i<3 ); // max try 3 times

	#ifdef DEBUG_PC
	if (PcMode < EE_PC_NO_SIGNAL)
		dPrintf("\r\n PcMode = %d(%s)", (WORD)PcMode, PcModeStr[PcMode] );
	#endif

	if( !(ReadTW88(STATUS0) & 0x01) ) {
		PcMode = EE_PC_NO_SIGNAL;

		#ifdef DEBUG_PC
		ePuts("\r\n-----> finished, but Sync Loss");
		#endif
	}

	if ((PcMode != EE_PC_UNKNOWN) && (PcMode != EE_PC_NO_SIGNAL))
	{
		SetADCandInputRegisterByMode(PcMode);		
		return TRUE;
	}
	else
	{
		return FALSE;
	}
#endif
}

// Hans
BYTE SourceMonitor(void)
{
	static bit AUTO_STATUS=0;
	BYTE std, cMode, cRet = TRUE;
#if defined( SUPPORT_PC ) || defined( SUPPORT_DTV )
	BYTE statusD0, statusD1;
#endif
       if( ( GetDisplayedOSD() & MENU )  )  return TRUE;

	if (AutoDetect)
	{
		WriteTW88(0xff, 0); // page 0	

		if( AUTO_STATUS == 0 ){
			AUTO_STATUS = 1;
			Printf("\r\nAuto detection Enable");
		}

		switch ( GetInputSelection() ) {

		case COMPOSITE:
#ifdef SUPPORT_SVIDEO
		case SVIDEO:
#endif
#ifdef SUPPORT_TV
		case TV:
#endif
			//----- Check Decoder ----------------
                     std = DetectDecoderInput();
			if (std == NOINPUT) // sync loss
			{
				cRet = 2; // go to "NoSignal" state
			}
			else
			{
	                     if ( std!=UNKNOWN && std!= VInputStd )
	                     	cCounter++;
	                     else
	                     	cCounter = 0;
				if (cCounter > 5)
				{
					cCounter = 0;
					VInputStd = std;
					cRet = FALSE; // refresh signal setting
				}
			}
			break;

#ifdef SUPPORT_COMPONENT
		case COMPONENT:
#endif
			//----- Check No Input
			if(IsNoInput()) {	// no decoder input
				#ifdef DEBUG
				dPrintf("\r\n ModeDetect ==========component sync loss");
				#endif
				cRet = 2; // go to "NoSignal" state
			}
			else
			{
				cMode = ((ReadDecoder(CVFMT) & 0x70) >> 4);
	                     if (cMode != ComponentMode )
	                     	cCounter++;
	                     else
	                     	cCounter = 0;
				if (cCounter > 5)
				{
					#ifdef DEBUG
					dPrintf("\r\n ModeDetect ==========component sync changed");
					#endif
					cCounter = 0;
					ComponentMode = cMode;
					cRet = FALSE; // refresh signal setting
				}
			}
			break;

#if defined( SUPPORT_PC ) || defined( SUPPORT_DTV )
		case PC:
		case DTV:
       		statusD0 = ReadTW88(STATUS0);
			statusD1 = ReadTW88(STATUS1);   
			ResetStatusRegs();

			if (!( statusD0 & 0x01 )) //means sync loss
			{
				cRet = 2; // go to "NoSignal" state
			}
			else
			{
				if ( (statusD1 & 0x30) == 0x30) // means VSYNC & HSYNC changed
	                     	cCounter++;
	                     else
	                     	cCounter = 0;
				if (cCounter > 5)
				{
					cCounter = 0;
					cRet = FALSE; // refresh signal setting
				}	
			}
			break;
#endif
		default:
			cRet = TRUE;
			break;
		}
	}
	else
	{
			if( AUTO_STATUS == 1 ){
				AUTO_STATUS = 0;
				Printf("\r\nAuto detection Disable");
			}
	}

	return cRet;
}

// Hans
BYTE NoSignal(void)
{
	BYTE cRet = FALSE;
#if (defined SUPPORT_PC) || (defined SUPPORT_DTV)
       BYTE statusD0, statusD1;	
#endif

       if( ( GetDisplayedOSD() & MENU )  )  return FALSE;

       if (AutoDetect == 0) 
	   	return FALSE;
	   
#if (defined SUPPORT_PC) || (defined SUPPORT_DTV)
       WriteTW88(0xff, 0); // page 0	
       statusD0 = ReadTW88(STATUS0);
	statusD1 = ReadTW88(STATUS1);   
       if ((InputSelection == PC)  || (InputSelection == DTV) )
       {
              if ((statusD0 & 0x01 ) == 1) // sync detected
              {
		       if (PcMode == EE_PC_UNKNOWN)
		       {
				if ((statusD1 & 0x30) == 0x30) // means Hsync or VSync were changed
				{
#ifdef DEBUG
					dPrintf("\r\n NoSignal ========== Signal timing changed++D1: %d", (WORD)statusD1);
#endif
					bPanelMute = 0;
					cRet = TRUE;
				}
				else
				{
					if (bPanelMute == 0)
					{
#ifdef DEBUG
						dPrintf("\r\n  NoSignal ========== Signal out of rang");
#endif
						bPanelMute = 1;
                                          AudioOff();
						PanelMute(1);
	              			DisplayPCInfo(OutOfRangeStr[GetOSDLang()]);		
					}	
					cRet = FALSE;
				}
		       }
			else // ee_pc_no_signal
			{
#ifdef DEBUG
				dPrintf("\r\n NoSignal ========== Syncs was detected++D0: %d", (WORD)statusD0);			
#endif
				bPanelMute = 0;
				DisplayInputHold = 0;
				cRet = TRUE;
			}
              }
		else // sync loss
		{
			PcMode = EE_PC_NO_SIGNAL;
			if (bPanelMute == 0)
			{
#ifdef DEBUG
				dPrintf("\r\n NoSignal ========== PC/DTV  Sync loss++D0: %d", (WORD)statusD0);			
#endif
				bPanelMute = 1;
				AudioOff();
				PanelMute(1);

				DisplayInputHold = 1;		// Hold  Input Information in no signal.
				ClearOSDInfo();
				DisplayInput();
			}
			cRet = FALSE;
		}              	
        }
	else
#endif
	{
	       if(IsNoInput() ) // no decoder input
	       {
			if (bPanelMute == 0)
			{
#ifdef DEBUG
				dPrintf("\r\n NoSignal ========== Sync loss");
#endif
				bPanelMute = 1;
				AudioOff();
#ifdef SUPPORT_TV
				if (InputSelection != TV) 
#endif					
				PanelMute(1);

				DisplayInputHold = 1;		// Hold  Input Information in no signal.
				ClearOSDInfo();
				DisplayInput();
			}
			cRet = FALSE;
	       }
		else
		{
			bPanelMute = 0;
			DisplayInputHold = 0;
			cRet = TRUE;
		}
	}	      

#if (defined SUPPORT_PC) || (defined SUPPORT_DTV)
       ResetStatusRegs();
#endif

	return cRet;
}

// Hans
void SourceProcess(void)
{
	BYTE cRet = FALSE;
	
	switch(cSourceState)
	{
	case ssInputSetup:
		InputSetup();
		cSourceState = ssMeasureSetup;
		break;

	case ssMeasureSetup:
              PanelMute(1);
		MeasureSetup();
		SetDelayCount(100); // 100 * 10ms delay
		cSourceState = ssModeDetect;
		break;

	case ssModeDetect:
		if (GetDelayCount()) return; // ensure delay enough time for signal detection
		cRet = ModeDetect();
		if (cRet == TRUE)
			cSourceState = ssSourceConfigAndDisplay;
		else
			cSourceState = ssNoSignal;			
		break;

	case ssSourceConfigAndDisplay:
		cRet = SourceConfigAndDisplay();
		if (cRet == TRUE)
			cSourceState = ssSourceMonitor;
		else
			cSourceState = ssNoSignal;			
		break;

	case ssSourceMonitor:
		cRet = SourceMonitor();
		if (cRet == FALSE)
			cSourceState = ssMeasureSetup;
		else if  (cRet == 2) 
			cSourceState = ssNoSignal;
		// else keep monitor state
		break;

	case ssNoSignal:
		cRet = NoSignal();
		if (cRet == TRUE)
			cSourceState = ssMeasureSetup;
		break;

	case ssIDLE:
	default:
		break;
	}
}







⌨️ 快捷键说明

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