//----------------------------------------------------------------------------------------------------
// 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;
case _INITIAL_STATE:
if (bSourceVideo())
{
CVideoInitial();
}
SET_FIRST_SHOW_NOTE();
ucCurrState = _SEARCH_STATE;
#if(_LOGO_ENABLE)
CModeSetFreeRun();
CDrawLogo();
#endif
if(1)//GET_FIRST_LOADFONT() == _TRUE)
{
CLR_FIRST_LOADFONT();
COsdDispFirstTimeLoadFont();
}
if (_GET_INPUT_SOURCE() == _SOURCE_DVI || _GET_INPUT_SOURCE() == _SOURCE_HDMI || _GET_INPUT_SOURCE() == _SOURCE_YPBPR||_GET_INPUT_SOURCE() == _SOURCE_YPBPR1)
{
CShowNote();//ucOsdEventMsg = _DO_SHOW_NOTE;
CPowerPanelOn();
if (GET_LIGHTPOWERSTATUS() == _OFF)
{
CPowerLightPowerOn();
}
}
break;
case _SEARCH_STATE:
#if(AUDIO_TYPE == _AUDIO_SC7313 || AUDIO_TYPE == _AUDIO_PWM)
CInitSoundChannel(_GET_INPUT_SOURCE());
#endif
case _ACTIVE_STATE:
case _NOSIGNAL_STATE:
case _NOSUPPORT_STATE:
case _SLEEP_STATE:
switch (_GET_INPUT_SOURCE())
{
case _SOURCE_YPBPR:
case _SOURCE_YPBPR1:
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))
{
return _FALSE;
}
// Pop up measurement result
CScalerSetBit(_MEAS_HS_PERIOD_H_52, ~_BIT6, _BIT6);
if(CTimerPollingEventProc(60, CMiscMeasureResultPOPPollingEvent))
{
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
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);
return _TRUE;
}
}
else
return _FALSE;
}
//----------------------------------------------------------------------------------------------------
// 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
#if(_YPBPR1_SUPPORT == _ON)
case _SOURCE_YPBPR1:
#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_NOSIGNA