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

📄 mode.c

📁 RTD2662板卡源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
//----------------------------------------------------------------------------------------------------
// ID Code  	: Mode.c No.0002
// Update Note  :
//
//----------------------------------------------------------------------------------------------------

#define __MODE__

#include "Core\Header\Include.h"




unsigned char code HDMI_ModeMap[] =
{
	0,  1,  2,  2,  3,  4,  
	1,  1,  1,  1,  1,  1,  
	1,  1,  2,  2,  5,  2,  
	2,  3,  4,  1,  1,  1,  
	1,  1,  1,  1,  1,  2,	 
	2,  5,  5,  5,  5
};

//--------------------------------------------------
// Description  : Mode handler, the main control flow
// Input Value  : None
// Output Value : None
//--------------------------------------------------
void CModeHandler(void)
{
	if (CPowerHandler()) 
	{
		ucCurrState = GET_POWERSTATUS() ? _INITIAL_STATE : _PWOFF_STATE;
	}
	switch (ucCurrState)
	{
		case _PWOFF_STATE:
			ucCurrState = GET_POWERSTATUS() ? _INITIAL_STATE : _PWOFF_STATE;
			break;

#if(_OSD_TYPE == _OSD007)
        case _SOURCE_CHANGE_STATE:
#if(_CHANGE_SOURCE_METHOD == _CHANGE_SOURCE_METHOD_0)
            CTimerDelayXms(20);
#endif
            break;
#endif

		case _INITIAL_STATE:
			if (bSourceVideo())
            {
               CVideoInitial();
            }

            SET_FIRST_SHOW_NOTE();
			ucCurrState = _SEARCH_STATE;

/*
#if(_LOGO_ENABLE
#if(_OSD_TYPE == _OSD003)
            CModeSetFreeRun();
            CDrawLogo(0x03);
            CPowerPanelOn();
            CPowerLightPowerOn();
            CPattenChange();
#endif
#endif
*/


            if (_GET_INPUT_SOURCE() == _SOURCE_DVI || _GET_INPUT_SOURCE() == _SOURCE_HDMI)
            {
                 CShowNote();//ucOsdEventMsg = _DO_SHOW_NOTE;
                CPowerPanelOn();
    			if (GET_LIGHTPOWERSTATUS() == _OFF) 
    			{
                    CPowerLightPowerOn();
    			}
            }

            if(GET_FIRST_LOADFONT() == _TRUE)
            {
                CLR_FIRST_LOADFONT();
                COsdDispFirstTimeLoadFont();
			    #if(LNG_CHI_S_EN)
			    	if(GET_LANGUAGE() == LNG_CHI_S)
			    		COsdLoad1BitFontWidth12(FntCH_S,0x80,48);      
				#endif
				#if(LNG_CHI_T_EN)
			    	if(GET_LANGUAGE() == LNG_CHI_T)
			    		COsdLoad1BitFontWidth12(FntCH_T,0x80,48);      
				#endif
#if(_OSD_TYPE == _OSD002)
                g_ucMenuItemIndex = _MENU_NONE;
#endif
            }
			break;
					
        case _SEARCH_STATE:
        case _ACTIVE_STATE:
        case _NOSIGNAL_STATE:
		case _NOSUPPORT_STATE:
		case _SLEEP_STATE:
			switch (_GET_INPUT_SOURCE()) 
			{
				case _SOURCE_YPBPR:
				case _SOURCE_VGA:
				case _SOURCE_DVI:
	            case _SOURCE_HDMI:
					CSyncProcess();
				break;
			#if(_VIDEO_SUPPORT == _ON)
				case _SOURCE_VIDEO_AV:
				case _SOURCE_VIDEO_SV:
				case _SOURCE_VIDEO_TV:
					CVideoProcess();
				break;
			#endif
				case _SOURCE_NONE:   // Don't need to do anything
				break;
				
			default:
				break;
    		}
    		break;
    				
    	default:
    		while(_TRUE);
	}
}
//--------------------------------------------------
// Description  : Check measure ready process
// Input Value  : None
// Output Value : Return _TRUE if measure finished, _FALSE if timeout
//--------------------------------------------------
bit CModeMeasureReady(void)
{
	CScalerSetBit(_SYNC_SELECT_47, ~_BIT0, 0x00);
	CAdjustSyncProcessorMeasureStart();
	if (CTimerPollingEventProc(60, CMiscModeMeasurePollingEvent)) 
	{
		return _TRUE;
	} 
	else
	{
		CScalerSetBit(_MEAS_HS_PERIOD_H_52, ~_BIT5, 0x00);
		return _FALSE;
	}
}

/**
* CSyncMeasureSyncType
* Get measure data and convert into system information
* @param <none>
* @return {_TRUE if success, _FALSE if the measurement result is out of range}
*
*/
bit CModeMeasureData(void)
{

	if(_GET_INPUT_SOURCE() == _SOURCE_DVI || _GET_INPUT_SOURCE() == _SOURCE_HDMI)
    {
		CScalerSetBit(_SYNC_SELECT_47, ~_BIT6, _BIT6);	
		CScalerSetBit(_SYNC_CTRL_49, ~_BIT2, _BIT2);
	}
	
	// Read measurement status bit
	CScalerRead(_MEAS_HS_PERIOD_H_52, 3, &pData[8], _AUTOINC);// 
	if((bit)(pData[8] & _BIT4) || (bit)(pData[10] & _BIT4) || (bit)(pData[10] & _BIT5))
    {
		// Hsync period overflow ,  Vsync period timeout       ,  Vsync period timeout
		//DebugPrintf("\n CModeMeasureData.0.%c",0x20);		
		return _FALSE;
	}			
	
	// Pop up measurement result
	CScalerSetBit(_MEAS_HS_PERIOD_H_52, ~_BIT6, _BIT6);
	CScalerSetBit(_MEAS_HS_VS_HI_SEL_58, ~_BIT0, 0x00);
	CScalerRead(_MEAS_HS_PERIOD_H_52, 6, &pData[8], _AUTOINC);
	
	// Calculate measurement result
	((WORD *)pData)[0] = ((pData[8] & 0x1f) << 8) | pData[9];
	((WORD *)pData)[1] = ((pData[10] & 0x1f) << 8) | pData[11];
	((WORD *)pData)[2] = ((pData[12] & 0xf0) << 4) | pData[13];
	
	if((((WORD *)pData)[0] >=  0x07ff) || (((WORD *)pData)[1] >= 0x07ff) || (((WORD *)pData)[0] == 0) || (((WORD *)pData)[1] == 0))
	{
		// The measurement result is out of range
		//DebugPrintf("\n CModeMeasureData.1.%c",0x20);
		return _FALSE;
	}
	else
	{
		// Store measurement results in global system variable
		stModeInfo.Polarity = (pData[10] & 0xc0) >> 6;
		stModeInfo.IHCount = ((WORD *) pData)[0];
		stModeInfo.IHFreq = (WORD) ((DWORD) _RTD_XTAL * 10 * 2 / stModeInfo.IHCount);
		stModeInfo.IHFreq = (stModeInfo.IHFreq >> 1) + (stModeInfo.IHFreq & 0x01);
		stModeInfo.IVTotal = ((WORD *) pData)[1];
		stModeInfo.IVFreq = (WORD)((DWORD) (stModeInfo.IHFreq) * 1000 * 2 / stModeInfo.IVTotal);
		stModeInfo.IVFreq = (stModeInfo.IVFreq >> 1) + (stModeInfo.IVFreq & 0x01);
		stModeInfo.IHSyncPulseCount = ((WORD *) pData)[2];
		
		if((_GET_INPUT_SOURCE()==_SOURCE_DVI || _GET_INPUT_SOURCE() == _SOURCE_HDMI) && (ucCurrState==_SEARCH_STATE))	//for philips dvd player(dvp5965k) hdmi timing
			CTimerDelayXms(40);
		//DebugPrintf("\n stModeInfo.IHFreq=%x",(BYTE)(stModeInfo.IHFreq>>8));	
		//DebugPrintf(",%x",(BYTE)(stModeInfo.IHFreq));	
		//DebugPrintf("\n stModeInfo.IVFreq=%x",(BYTE)(stModeInfo.IVFreq>>8));	
		//DebugPrintf(",%x",(BYTE)(stModeInfo.IVFreq));	
		return _TRUE;
	}
}

//----------------------------------------------------------------------------------------------------
// Mode Detect Functions
//----------------------------------------------------------------------------------------------------
/**
* CModeDetect
* mode detect according to the input port
* @param <none>
* @return {TRUE if sync type is identified;FALSE if no sync}
*
*/
//--------------------------------------------------
// Description  : Mode detect process
// Input Value  : None
// Output Value : Return _TRUE if we get a stable mode
//--------------------------------------------------
bit CModeDetect(void)
{
	switch (_GET_INPUT_SOURCE()) 
	{
	case _SOURCE_VGA:
#if(_TMDS_SUPPORT == _ON)
	case _SOURCE_DVI:
#endif
#if(_YPBPR_SUPPORT == _ON)
	case _SOURCE_YPBPR:
#endif
    case _SOURCE_HDMI:
		if (CModeDetectCommon())
			return _TRUE;
		break;
	}
	return _FALSE;
}

/**
* CModeDetect
* Mode detect process for VGA and DVI
* first decide if mode is exist,then decide if the signal is stable
* if there is nosignal but it is stable,also return TRUE
* @param <none>
* @return {_TRUE if there is a stable mode;_FALSE if not}
*
*/
//--------------------------------------------------
// Description  : Mode detect process for VGA and DVI
// Input Value  : None
// Output Value : Return _TRUE if we get a stable mode
//--------------------------------------------------
bit CModeDetectCommon(void)
{
	BYTE modetemp = _MODE_NOSIGNAL;
	BYTE polaritytemp;
	WORD hcount, vtotal;
	
	if (CModeMeasureReady()) 
	{
		polaritytemp = stModeInfo.Polarity;
		hcount = stModeInfo.IHCount;
		vtotal = stModeInfo.IVTotal;
		
		// Get measure results and decide " modetemp = _MODE_NOSIGNAL/_MODE_NOSUPPORT/_MODE_EXIST "
		
		if (CModeMeasureData()) 
		{
            CSyncModifyPolarityVGA();
			stModeInfo.ModeCurr = _MODE_NOSIGNAL;
			
			if (abs(stModeInfo.IHCount - hcount) <= 1)
				stModeInfo.IHCount = hcount;
			
			if (abs(stModeInfo.IVTotal - vtotal) <= 2)
				stModeInfo.IVTotal = vtotal;
			
			if ((stModeInfo.IHCount != hcount) ||(stModeInfo.IVTotal != vtotal) ||	(stModeInfo.Polarity != polaritytemp))
			{
				modetemp = _MODE_NOSIGNAL;
			}
			else 
			{
				if ((stModeInfo.IHFreq < Panel[ucPanelSelect]->HSyncMinFreq) ||(stModeInfo.IHFreq > Panel[ucPanelSelect]->HSyncMaxFreq) ||
					(stModeInfo.IVFreq < Panel[ucPanelSelect]->VSyncMinFreq) ||(stModeInfo.IVFreq > Panel[ucPanelSelect]->VSyncMaxFreq)) 
				{
					modetemp = _MODE_NOSUPPORT;
				}
				else 
				{
					modetemp = _MODE_EXIST;
				}
			}
		}
		else 
		{
			modetemp = _MODE_NOSIGNAL;
		}
		// Wait mode stable and decide the mode type for current source
		if (modetemp != ucModeFound) 
		{
			ucModeFound = modetemp;
			ucEvent1 = _INACTIVE_COUNTDOWN_EVENT;
			CLR_MODESTABLE();
			CTimerCountDownEventProc(&ucEvent1, 3, CModeStableCountDownEvent);
			return _FALSE;
		}
		else 
		{
			CTimerCountDownEventProc(&ucEvent1, 3, CModeStableCountDownEvent);
			if (GET_MODESTABLE()) 
			{
				if (ucModeFound == _MODE_EXIST)
				{
					CModeInterlaceCheck();//v003_interlace_check
					stModeInfo.ModeCurr = CModeSearchDisplayMode();
				}
				else 
				{
					stModeInfo.ModeCurr = ucModeFound;
				}
				return _TRUE;
			}
			else 
			{
				return _FALSE;
			}
		}
	}
	else 
	{
		return _FALSE;
	}
}

/**
* CModeIsChange
* Check if mode is changed
* check the current mode compare with the previous mode
* @param <none>
* @return {_TRUE if mode is changed;_FALSE if not}
*
*/
bit CModeIsChange(void)
{
	BYTE polaritytemp;
	WORD hcount, vtotal;
	
	polaritytemp = stModeInfo.Polarity;
	hcount = stModeInfo.IHCount;
	vtotal = stModeInfo.IVTotal;
	
	if(_GET_INPUT_SOURCE() == _SOURCE_VGA)
	{
		if(CScalerGetBit(_HSYNC_TYPE_DETECTION_FLAG_4E, _BIT6 | _BIT5))
			return _TRUE;
	}
	//DebugPrintf("\nMMD.1.%c",0x20);	
	if(CModeMeasureData())
	{
		if(abs(stModeInfo.IHCount - hcount) <= 1)
			stModeInfo.IHCount = hcount;
       	if(abs(stModeInfo.IVTotal - vtotal) <= 2)
			stModeInfo.IVTotal = vtotal;
		
       	if((stModeInfo.IHCount != hcount) || (stModeInfo.IVTotal != vtotal) || (stModeInfo.Polarity != polaritytemp))
			return _TRUE;
		else
			return _FALSE;
	}
	else
		return _TRUE;
}

/**
* CModeSearchDisplayMode
* Search display mode according to the input source
* called only by CModeDetectCommon
* @param <none>
* @return {_TRUE if there is a stable mode;_FALSE if not}
*
*/
//--------------------------------------------------
// Description  : Search display mode process
// Input Value  : None
// Output Value : Mode number
//--------------------------------------------------
BYTE CModeSearchDisplayMode(void)
{
	BYTE modetemp;

	switch (_GET_INPUT_SOURCE())
	{
	case _SOURCE_VGA:
		modetemp = CModeSearchModeVGA();
		break;
		
#if(_YPBPR_SUPPORT == _ON)
	case _SOURCE_YPBPR:
		modetemp = CYPbPrSearchMode();
		break;
#endif
		
#if((_TMDS_SUPPORT == _ON) || (_HDMI_SUPPORT == _ON))
	case _SOURCE_DVI:
    case _SOURCE_HDMI:
		modetemp = CModeSearchModeDVI();
		break;
#endif
	}
	return modetemp;
}

⌨️ 快捷键说明

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