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

📄 mode.c

📁 车载 液晶显示器的主控程序(主要使用芯片为 MYSON MTV512 单片机、RealTek 2323 Scare 芯片、TVP5147(视频解码)。配Sharp 8寸液晶显示器 )。
💻 C
📖 第 1 页 / 共 5 页
字号:
        	return _FALSE;
    	}
}

//--------------------------------------------------
// 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)
{
    	// Pop up measurement result
    	CScalerSetBit(_MEAS_HS_PERIOD_H_52, ~_BIT6, _BIT6);
    	CScalerRead(_MEAS_HS_PERIOD_H_52, 7, &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] & 0x0f) << 8) | pData[13];
    	((WORD *)pData)[3] = ((pData[12] & 0xf0) << 4) | pData[14];

    	if((((WORD *)pData)[0] >=  0x07ff) || (((WORD *)pData)[1] >= 0x07ff) || (((WORD *)pData)[0] == 0) || (((WORD *)pData)[1] == 0) || (bit)(pData[10] & _BIT5))
    	{
        	// 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)((LWORD)_RTD_XTAL * 10 * 2 / stModeInfo.IHCount);
        	stModeInfo.IHFreq = (stModeInfo.IHFreq >> 1) + (stModeInfo.IHFreq & 0x01);
        	stModeInfo.IVTotal = ((WORD *)pData)[1];
        	stModeInfo.IVFreq = (WORD)((LWORD)(stModeInfo.IHFreq) * 1000 * 2 / stModeInfo.IVTotal);
        	stModeInfo.IVFreq = (stModeInfo.IVFreq >> 1) + (stModeInfo.IVFreq & 0x01);
        	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(_TMDS_SUPPORT == _ON)
        	case _SOURCE_DVI:
#endif

#if(_YPBPR_SUPPORT == _ON)
        	case _SOURCE_YPBPR:
#endif
            		if(CModeDetectCommon())	//get current mode . note by zhang_dc
                		return _TRUE;
            		break;

#if(_VIDEO_SUPPORT == _ON)

        	case _SOURCE_VIDEO8:
            		stModeInfo.ModeCurr = _MODE_EXIST;
            		//CModeDisplayActiveMode();	//show video. Note and Disabled by zhang_dc
            		return _TRUE;

#endif
    	}

    	return _FALSE;
}
*/


//version 200D
//----------------------------------------------------------------------------------------------------
// 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(_TMDS_SUPPORT == _ON)
        case _SOURCE_DVI:
#endif

#if(_YPBPR_SUPPORT == _ON)
        case _SOURCE_YPBPR:
#endif
            if(CModeDetectCommon())
                return _TRUE;
            break;

#if(_VIDEO_SUPPORT == _ON)

        case _SOURCE_VIDEO8:
            stModeInfo.ModeCurr = _MODE_EXIST;
            //CModeDisplayActiveMode();
            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)	//Update by Realtek at 20050617
{
    	BYTE modetemp = _MODE_NOSIGNAL;
    	BYTE polaritytemp;
    	WORD hcount, vtotal;

    	if(CModeMeasureReady())
    	{
    		//save pre information. note by zhang_dc
        	polaritytemp    = stModeInfo.Polarity;
        	hcount          = stModeInfo.IHCount;
        	vtotal          = stModeInfo.IVTotal;

        	// Get measure results and decide " modetemp = _MODE_NOSIGNAL/_MODE_NOSUPPORT/_MODE_EXIST "
        	if(CModeMeasureData())		//if sync is normal. note by zhang_dc
        	{
            		stModeInfo.ModeCurr = _MODE_NOSIGNAL;

            		if(abs(stModeInfo.IHCount - hcount) <= 1)
                		stModeInfo.IHCount = hcount;

            		//if(abs(stModeInfo.IVTotal - vtotal) <= 1)
                	//	stModeInfo.IVTotal = vtotal;
					if(abs(stModeInfo.IVTotal - vtotal) <= 2)	//x.hu, note 20050715: update by realtek
                		stModeInfo.IVTotal = vtotal;


            		if((stModeInfo.IHCount != hcount) || (stModeInfo.IVTotal != vtotal) || (stModeInfo.Polarity != polaritytemp))
            		{
                		modetemp    = _MODE_NOSIGNAL;
            		}
            		else
            		{
                		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
                		{
                    if(((GET_INPUTPORT_TYPE(stSystemData.InputSource) == _YPBPR_A0_PORT) || (GET_INPUTPORT_TYPE(stSystemData.InputSource) == _YPBPR_A1_PORT)) && ((bit)CScalerGetBit(_SYNC_SELECT_47, _BIT6)))
                        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;	//sync do not stable. note by zhang_dc
        	}
        	else
        	{
            		CTimerCountDownEventProc(&ucEvent1, 3, CModeStableCountDownEvent);	//sync stable, set stable flag. note by zhang_dc

            		if(GET_MODESTABLE())
            		{
                		if(ucModeFound == _MODE_EXIST)
                		{
                    			stModeInfo.ModeCurr = CModeSearchDisplayMode();
                		}
                		else
                		{
                    			stModeInfo.ModeCurr = ucModeFound;
                		}

                		return _TRUE;
            		}
            		else
            		{
                		return _FALSE;
            		}
        	}
    	}
    	else
    	{
        	return _FALSE;
    	}
}
*/

//version 200D
//--------------------------------------------------
// 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())
        {
            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 < _H_FREQ_MIN) || (stModeInfo.IHFreq > _H_FREQ_MAX) || (stModeInfo.IVFreq < _V_FREQ_MIN) || (stModeInfo.IVFreq > _V_FREQ_MAX))
                {
                    modetemp    = _MODE_NOSUPPORT;
                }
                else
                {
//                    if(((GET_INPUTPORT_TYPE(stSystemData.InputSource) == _YPBPR_A0_PORT) || (GET_INPUTPORT_TYPE(stSystemData.InputSource) == _YPBPR_A1_PORT)) && ((bit)CScalerGetBit(_SYNC_SELECT_47, _BIT6)))
//                        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)
                {
                    stModeInfo.ModeCurr = CModeSearchDisplayMode();
                }
                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) {	//x.hu; 20050625, test
		if(CVideoIsChange())						
			return _TRUE;
		else 
			return _FALSE;
	}
	*/
	if (GET_INPUTPORT_TYPE(stSystemData.InputSource) == _VIDEO_AV_PORT || \
		GET_INPUTPORT_TYPE(stSystemData.InputSource) == _VIDEO_AV2_PORT ) {	//x.hu; 20050625, test
		if(CVideoIsChange()==_TRUE)						
			return _TRUE;
		else 
			return _FALSE;
	}
	#endif

	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;	//mode changed. zhang_dc
		}
		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:
            		modetemp    = CModeSearchModeDVI();
            		break;

#endif

⌨️ 快捷键说明

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