📄 mode.c
字号:
// Description : Get measure data and convert into system information
// Input Value : None
// Output Value : Return _TRUE if success, _FALSE if the measurement result is wrong
//--------------------------------------------------
bit CModeMeasureData(void)
{
BYTE cnt;//1231 sephinroth for single read/write
//1231 sephinroth for single read/write
// Read measurement status bit
for(cnt=0;cnt<3;cnt++)
{
CScalerRead((_MEAS_HS_PERIOD_H_52+cnt), 1, &pData[8+cnt], _NON_AUTOINC);
}
if((bit)(pData[8] & _BIT4) || (bit)(pData[10] & _BIT4) || ((bit)(pData[10] & _BIT5) && (~((ucCurrState == _SLEEP_STATE) && (bSleepByOverRange)))))//1212 sephinroth
{
if((GET_INPUTSOURCE_TYPE() == _SOURCE_DVI) || (GET_INPUTSOURCE_TYPE() == _SOURCE_HDMI)) //cyyeh V008_20080806
SET_INPUTSOURCE_TYPE(_SOURCE_NONE);
return _FALSE;
}
// Pop up measurement result
CScalerSetBit(_MEAS_HS_PERIOD_H_52, ~_BIT6, _BIT6);
CScalerSetBit(_MEAS_HS_VS_HI_SEL_58, ~_BIT0, 0x00);
//1231 sephinroth for single read/write
for(cnt=0;cnt<6;cnt++)
{
CScalerRead((_MEAS_HS_PERIOD_H_52+cnt), 1, &pData[8+cnt], _NON_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
return _FALSE;
}
else
{
// Store measurement results in global system variable
stModeInfo.Polarity = (pData[10] & 0xc0) >> 6;
// V010 Patch Note (14) : To get exact result of measurement of input H/V frequency.
stModeInfo.IHCount = ((WORD *)pData)[0] + 1;
stModeInfo.IHFreq = (WORD)((DWORD)_RTD_XTAL * 10 * 2 / stModeInfo.IHCount);
stModeInfo.IHFreq = (stModeInfo.IHFreq >> 1) + (stModeInfo.IHFreq & 0x01);
stModeInfo.IVTotal = ((WORD *)pData)[1] + 1;
stModeInfo.IVFreq = (WORD)((DWORD)_RTD_XTAL * 10 * 1000 / ((DWORD)stModeInfo.IHCount * stModeInfo.IVTotal));
stModeInfo.IHSyncPulseCount = ((WORD *)pData)[2];
return _TRUE;
}
}
//----------------------------------------------------------------------------------------------------
// Mode Detect Functions
//----------------------------------------------------------------------------------------------------
//--------------------------------------------------
// Description : Mode detect process
// Input Value : None
// Output Value : Return _TRUE if we get a stable mode
//--------------------------------------------------
bit CModeDetect(void)
{
switch(GET_INPUTSOURCE_TYPE())
{
case _SOURCE_VGA:
#if(_DP_SUPPORT == _ON)
case _SOURCE_DP:
#endif
#if(_YPBPR_SUPPORT == _ON)
case _SOURCE_YPBPR:
#endif
if(CModeDetectCommon())
return _TRUE;
break;
#if(_TMDS_SUPPORT == _ON)
case _SOURCE_DVI:
#endif
#if( _HDMI_SUPPORT == _ON)
case _SOURCE_HDMI:
#endif
//CTimerDelayXms(100);
//if(CModeMeasureReady())//0828 sephinroth
// CModeMeasureData();
if(CModeDetectCommon())
return _TRUE;
break;
#if(_VIDEO_SUPPORT == _ON)
case _SOURCE_VIDEO8:
stModeInfo.ModeCurr = _MODE_EXIST;
return _TRUE;
#endif
}
return _FALSE;
}
//--------------------------------------------------
// 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;
/*
// V010 Patch Note (18) : Solve the measure time-out issue caused by low frame rate of input signal.
if((bit)CScalerGetBit(_MEAS_VS_PERIOD_H_54, _BIT5))
{
#if((_SCALER_TYPE ==_RTD2545LR)||(_SCALER_TYPE ==_RTD247xRD) || (_SCALER_TYPE ==_RTD248xRD))
CScalerPageSelect(_PAGE1);
CScalerSetByte(_P1_M2PLL_M_E0, 0x59);
CScalerSetByte(_P1_M2PLL_N_E1, 0x13);
CScalerSetBit(_FIFO_FREQUENCY_22, ~_BIT2, _BIT2);
#elif(_SCALER_TYPE == _RTD2472D)
CScalerSetBit(_FIFO_FREQUENCY_22, ~_BIT2, _BIT2);
#endif
}
*/
// Get measure results and decide " modetemp = _MODE_NOSIGNAL/_MODE_NOSUPPORT/_MODE_EXIST "
if(CModeMeasureData())
{
CSyncModifyPolarity();
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
{
//CModeInterlaceCheck();//0828 sephinroth//by marco for VGA/DVI interlace mode show out of range 20080806
if((stModeInfo.IHFreq < _H_FREQ_MIN) || (stModeInfo.IHFreq > _H_FREQ_MAX) || (stModeInfo.IVFreq < _V_FREQ_MIN) || (stModeInfo.IVFreq > _V_FREQ_MAX))
{
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();
stModeInfo.ModeCurr = CModeSearchDisplayMode();
//V404 modify Start
// Issac-0129-Fixed
if (GET_INPUTSOURCE_TYPE() == _SOURCE_DVI || GET_INPUTSOURCE_TYPE() == _SOURCE_HDMI)
{
//if (stModeInfo.IHWidth == 0 || stModeInfo.IVHeight == 0)
if((stModeInfo.IHWidth == 0 || stModeInfo.IVHeight == 0) || ((((stModeInfo.IHWidth / stModeInfo.IVHeight) < 1) || ((stModeInfo.IHWidth / stModeInfo.IVHeight) > 2)) && (!GET_INTERLACE_MODE())) || ((((stModeInfo.IHWidth / stModeInfo.IVHeight) < 2) || ((stModeInfo.IHWidth / stModeInfo.IVHeight) > 4)) && (GET_INTERLACE_MODE())))//0530 sephinroth
{
ucModeFound = _MODE_NOSIGNAL;
ucEvent1 = _INACTIVE_COUNTDOWN_EVENT;
CLR_MODESTABLE();
CTimerCountDownEventProc(&ucEvent1, 3, CModeStableCountDownEvent);
return _FALSE;
}
}
//V404 modify End
}
else
{
stModeInfo.ModeCurr = ucModeFound;
}
return _TRUE;
}
else
{
return _FALSE;
}
}
}
else
{
return _FALSE;
}
}
//--------------------------------------------------
// Description : Check if mode is changed
// Input Value : None
// Output Value : Return _TRUE if mode is changed
//--------------------------------------------------
bit CModeIsChange(void)
{
BYTE polaritytemp;
WORD hcount, vtotal;
polaritytemp = stModeInfo.Polarity;
hcount = stModeInfo.IHCount;
vtotal = stModeInfo.IVTotal;
#if(_VIDEO_SUPPORT == _ON)
if(GET_INPUTSOURCE_TYPE() == _SOURCE_VIDEO8)
{
if(CVideoIsChange())
return _TRUE;
}
#endif
//cyyeh 20080124 for hdmi deep color mode Interoperability with DVI issue !!
if((GET_DEEPCOLORMODE()) && (GET_INPUTSOURCE_TYPE() == _SOURCE_HDMI))//sephinroth 20080710
{
CScalerPageSelect(_PAGE2);
CScalerRead( _P2_TMDS_DPC0_B4 , 1 , pData , _NON_AUTOINC);
if( (pData[0] & 0x07) == 0x00)
{
return _TRUE;
}
}
if(GET_INPUTSOURCE_TYPE() == _SOURCE_VGA)
{
if(CScalerGetBit(_HSYNC_TYPE_DETECTION_FLAG_4E, _BIT6 | _BIT5))
return _TRUE;
}
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;
}
}
//--------------------------------------------------
// Description : Search display mode process
// Input Value : None
// Output Value : Mode number
//--------------------------------------------------
BYTE CModeSearchDisplayMode(void)
{
BYTE modetemp;
switch(GET_INPUTSOURCE_TYPE())
{
case _SOURCE_VGA:
modetemp = CModeSearchModeVGA();
break;
#if(_YPBPR_SUPPORT == _ON)
case _SOURCE_YPBPR:
modetemp = CYPbPrSearchMode();
break;
#endif
#if(_TMDS_SUPPORT == _ON)
case _SOURCE_DVI:
case _SOURCE_HDMI:
case _SOURCE_DP:
modetemp = CModeSearchModeDVI();
break;
#endif
case _SOURCE_VIDEO8:
break;
case _SOURCE_VIDEO16:
break;
}
return modetemp;
}
//--------------------------------------------------
// Description : Search mode for VGA
// Input Value : None
// Output Value : Mode number
//--------------------------------------------------
BYTE CModeSearchModeVGA(void)
{
BYTE modecnt;
SET_MODE_SEARCH_TYPE(_PRESET_MODE_TYPE);
for(modecnt=0;modecnt<_MAX_PRESET_MODE;modecnt++)
{
if(CModeComparePresetModeVGA(modecnt))
{
if(modecnt==_MODE_1280x768_70HZ)
{
if(stModeInfo.IHSyncPulseCount > 45)
modecnt=_MODE_1024x768_70HZ;
}
//*********************ryan 081209 change 1600*900 to 1440*900**********************
#if(1)
if(((stModeInfo.Polarity&_SYNC_HP_VN)==_SYNC_HP_VN)&&((modecnt == _MODE_1440x900_60HZ)||(modecnt == _MODE_1440x900_60HZ_RB)))
{
if(stModeInfo.IVTotal > 930)
modecnt = _MODE_1440x900_60HZ; // ATI card
else
modecnt = _MODE_1440x900_60HZ_RB;
}
#else
if(((stModeInfo.Polarity&_SYNC_HP_VN)==_SYNC_HP_VN)&&((modecnt == _MODE_1600x900_60HZ)||(modecnt == _MODE_1600x900_60HZ_RB)))
{
if(stModeInfo.IVTotal > 930)
modecnt = _MODE_1600x900_60HZ; // ATI card
else
modecnt = _MODE_1600x900_60HZ_RB;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -