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

📄 auto.c

📁 车载 液晶显示器的主控程序(主要使用芯片为 MYSON MTV512 单片机、RealTek 2323 Scare 芯片、TVP5147(视频解码)。配Sharp 8寸液晶显示器 )。
💻 C
📖 第 1 页 / 共 4 页
字号:
//----------------------------------------------------------------------------------------------------
// ID Code      : Auto.c No.0001
// Update Note  : 
//
//----------------------------------------------------------------------------------------------------

#define __AUTO__

#include "..\Header\Include.h"


//--------------------------------------------------
// Description  : Auto clock, phase and H,V position
// Input Value  : None
// Output Value : _ERROR_SUCCESS if succeed
//--------------------------------------------------
BYTE CAutoDoAutoConfig(void)
{
/*
    BYTE result, phasetemp;

    // Save current phase
    phasetemp = stModeUserData.Phase;

    stModeUserData.VPosition = stModeInfo.IVStartPos;
    CAdjustVPosition();

    // Clear the HW auto status to prevent some un-expected event happened
    CScalerSetByte(_AUTO_ADJ_CTRL1_7D, 0x00);

    CMiscClearStatusRegister();

    result  = CAutoDoAutoClock();

    if(result == _ERROR_SUCCESS)
    {
        result  = CAutoDoAutoPhase();

        if((result == _ERROR_SUCCESS) || (result == _ERROR_PHASE))
        {
            if(result == _ERROR_PHASE)
            {
                stModeUserData.Phase = phasetemp;
                CAdjustPhase(stModeUserData.Phase);
            }

            result  = CAutoDoAutoPosition();

            if(result != _ERROR_SUCCESS)
            {
                stModeUserData.HPosition = stModeInfo.IHStartPos;
                stModeUserData.VPosition = stModeInfo.IVStartPos;
                CAdjustHPosition();
                CAdjustVPosition();
            }
        }
        else
        {
            // If auto phase is failed, load phase setting before auto config
            stModeUserData.Phase = phasetemp;
            CAdjustPhase(stModeUserData.Phase);
        }
    }
    else
    {
        // If auto clock is failed, load default clock setting
        stModeUserData.Clock = stModeInfo.IHTotal;
        CAdjustAdcClock(stModeUserData.Clock);
    }

    if((result == _ERROR_SUCCESS) || (result == _ERROR_ABORT))
    {
        // Save auto result
        CEepromSaveModeData(stModeInfo.ModeCurr);
    }

    CMiscClearStatusRegister();

    return result;
    */
    //version 200D
        BYTE result, phasetemp;

    // Save current phase
    phasetemp = stModeUserData.Phase;

    // Clear the HW auto status to prevent some un-expected event happened
    CScalerSetByte(_AUTO_ADJ_CTRL1_7D, 0x00);

    CMiscClearStatusRegister();

    result  = CAutoDoAutoPosition();

    if(result == _ERROR_SUCCESS)
    {
        result  = CAutoDoAutoClock();

        if(result == _ERROR_SUCCESS)
        {
            result  = CAutoDoAutoPhase();

            if((result == _ERROR_SUCCESS) || (result == _ERROR_PHASE))
            {
                if(result == _ERROR_PHASE)
                {
                    stModeUserData.Phase = phasetemp;
                    CAdjustPhase(stModeUserData.Phase);
                }

                result  = CAutoDoAutoPosition();

                if(result != _ERROR_SUCCESS)
                {
                    stModeUserData.HPosition = stModeInfo.IHStartPos;
                    stModeUserData.VPosition = stModeInfo.IVStartPos;
                    CAdjustHPosition();
                    CAdjustVPosition();
                }
            }
            else
            {
                // If auto phase is failed, load phase setting before auto config
                stModeUserData.Phase = phasetemp;
                CAdjustPhase(stModeUserData.Phase);
            }
        }
        else
        {
            // If auto clock is failed, load default clock setting
            stModeUserData.Clock = stModeInfo.IHTotal;
            CAdjustAdcClock(stModeUserData.Clock);
        }
    }

		#if (_PANEL_TYPE == _PANEL_LQ104V1DG51 ||_PANEL_TYPE==_PANEL_JIALUHUA)
		if ( stModeInfo.ModeCurr == _MODE_640x480_60HZ)
		{
			stModeUserData.HPosition = 143;
			stModeUserData.VPosition = 30;//34;
		}
		if (	stModeInfo.ModeCurr == _MODE_640x480_72HZ)
		{
			stModeUserData.HPosition = 168;
			stModeUserData.VPosition = 34;
		}
		if ( stModeInfo.ModeCurr == _MODE_640x480_75HZ)
		{
			//stModeUserData.HPosition = 200;
			//stModeUserData.VPosition = 34;
		}
		CAdjustHPosition();
		CAdjustVPosition();
		#endif



    if((result == _ERROR_SUCCESS) || (result == _ERROR_ABORT))
    {
        // Save auto result
        CEepromSaveModeData(stModeInfo.ModeCurr);
    }

    CMiscClearStatusRegister();

    return result;

}

//--------------------------------------------------
// Description  : Auto color ( white balance )
// Input Value  : None
// Output Value : _ERROR_SUCCESS if succeed
//--------------------------------------------------
BYTE CAutoDoWhiteBalance(void)
{
    BYTE result;

    result = CAutoTuneBalance();

    if(result == _ERROR_SUCCESS)
    {
        CEepromSaveAdcData();
    }
    else
    {
        CEepromLoadAdcDataDefault();
    }

    return result;
}

//--------------------------------------------------
// Description  : Wait auto measure process completed
// Input Value  : None
// Output Value : Return result _ERROR_INPUT, _ERROR_SUCCESS
//--------------------------------------------------
BYTE CAutoWaitFinish(void)
{
    BYTE timeoutcnt, ivsevent;

    CMiscClearStatusRegister();

    // Auto timeout
    timeoutcnt   = (CScalerGetBit(_AUTO_ADJ_CTRL0_7A, _BIT1 | _BIT0) == 0x03) ? 150 : 50;

    // IVS timeout
    ivsevent     = 25;

    do
    {
        CTimerDelayXms(1);

        CScalerRead(_STATUS1_03, 1, pData, _NON_AUTOINC);

        if(pData[0] & _EVENT_IVS)
        {
            CScalerSetByte(_STATUS1_03, 0x00);
            ivsevent = 25;
        }
        else
        {
            ivsevent = ivsevent - 1;
        }

        if((ivsevent == 0) || (pData[0] & (_EVENT_UNDERFLOW | _EVENT_OVERFLOW)))
        {
            return _ERROR_INPUT;
        }

        // Power off while auto config--------
        CKeyCheckPowerKey();

        if(GET_POWERSWITCH())
            return _ERROR_INPUT;
        //------------------------------------

        CScalerRead(_AUTO_ADJ_CTRL1_7D, 1, pData, _NON_AUTOINC);
    }
    while((pData[0] & 0x01) && (--timeoutcnt));

    CScalerRead(_STATUS0_02, 1, pData, _NON_AUTOINC);
    CScalerSetByte(_STATUS0_02, 0x00);

    // Return non-zero value in Data[0] if :
    // 1. IVS or IHS changed
    // 2. Auto-Phase Tracking timeout
    return ((pData[0] & 0x63) || (0 == timeoutcnt)) ? _ERROR_INPUT : _ERROR_SUCCESS;
}

//--------------------------------------------------
// Description  : Wait for IVS process
// Input Value  : ucTimes   --> frames
// Output Value : Return underflow/overflow status
//--------------------------------------------------
BYTE CAutoWaitForIVS(BYTE ucTimes)
{
    BYTE timeoutcnt;

    timeoutcnt = 25;

    CScalerSetByte(_STATUS1_03, 0x00);
   	do
    {
        CTimerDelayXms(1);

        CScalerRead(_STATUS1_03, 1, pData, _NON_AUTOINC);        

        pData[0] &= (_EVENT_IVS | _EVENT_UNDERFLOW | _EVENT_OVERFLOW);

        if(((pData[0] & _EVENT_IVS) == _EVENT_IVS) && (ucTimes != 0))
        {
            CScalerSetByte(_STATUS1_03, 0x00);
            ucTimes--;
            timeoutcnt = 25;
        }
   	}
    while((ucTimes != 0) && (--timeoutcnt) && ((pData[0] & (_EVENT_UNDERFLOW | _EVENT_OVERFLOW)) == 0));

    return pData[0];
}
/*
//--------------------------------------------------
// Description  : Measure position H
// Input Value  : ucNoiseMarginH    --> Noise margin for H
// Output Value : Measure status
//--------------------------------------------------
BYTE CAutoMeasurePositionH(BYTE ucNoiseMarginH)
{
    WORD lbound, rbound;

    rbound  = stModeInfo.IHTotal;                                                 // Totol Clock Number
    lbound  = (LWORD)rbound * stModeInfo.IHSyncPulseCount / stModeInfo.IHCount;   // Clock number in HSYNC pulse

    CScalerSetBit(_VGIP_HV_DELAY_13, 0x0f, 0x50);

    rbound  = (rbound + _MEASURE_HDEALY) - 2;

    rbound  = rbound - 32;

    lbound  = (lbound + 20 + _MEASURE_HDEALY) < stModeInfo.IHStartPos ? (lbound + 20 + _MEASURE_HDEALY) : 0x0001;

    lbound  = (lbound > 32) ? (lbound - 32) : 0x0001;

    ucNoiseMarginH  &= 0xfc;

    pData[0]    = ((lbound >> 4) & 0x70) | (HIBYTE(rbound) & 0x0f);
    pData[1]    = (LOBYTE(lbound));
    pData[2]    = (LOBYTE(rbound));
    CScalerWrite(_H_BOUNDARY_H_70, 3, pData, _AUTOINC);

    pData[0]    = ucNoiseMarginH;
    pData[1]    = ucNoiseMarginH;
    pData[2]    = ucNoiseMarginH;
    pData[3]    = 0x00;
    pData[4]    = 0x00;
    pData[5]    = 0x00;
    pData[6]    = 0x00;
    pData[7]    = 0x01;
    CScalerWrite(_RED_NOISE_MARGIN_76, 8, pData, _AUTOINC);

    pData[0]    = CAutoWaitFinish();

    if(pData[0] != _ERROR_SUCCESS)       return pData[0];

    CScalerRead(_H_START_END_H_81, 3, &pData[8], _AUTOINC);

    usHStartPos = (((WORD)(pData[8] & 0xf0 ) << 4) | (WORD)pData[9]) + 32;
    usHEndPos   = (((WORD)(pData[8] & 0x0f ) << 8) | (WORD)pData[10]) + 32;

    return _ERROR_SUCCESS;
}
*/
//version 200D
//--------------------------------------------------
// Description  : Measure position H
// Input Value  : ucNoiseMarginH    --> Noise margin for H
// Output Value : Measure status
//--------------------------------------------------
BYTE CAutoMeasurePositionH(BYTE ucNoiseMarginH)
{
    WORD lbound, rbound;

    rbound  = stModeUserData.Clock;                                               // Totol Clock Number
    lbound  = (LWORD)rbound * stModeInfo.IHSyncPulseCount / stModeInfo.IHCount;   // Clock number in HSYNC pulse

    CScalerSetBit(_VGIP_HV_DELAY_13, 0x0f, 0x50);

    rbound  = (rbound + _MEASURE_HDEALY) - 2;

    rbound  = rbound - 32;

    lbound  = (lbound + 20 + _MEASURE_HDEALY) < stModeInfo.IHStartPos ? (lbound + 20 + _MEASURE_HDEALY) : 0x0001;

    lbound  = (lbound > 32) ? (lbound - 32) : 0x0001;

    ucNoiseMarginH  &= 0xfc;

    pData[0]    = ((lbound >> 4) & 0x70) | (HIBYTE(rbound) & 0x0f);
    pData[1]    = (LOBYTE(lbound));
    pData[2]    = (LOBYTE(rbound));
    CScalerWrite(_H_BOUNDARY_H_70, 3, pData, _AUTOINC);

    pData[0]    = ucNoiseMarginH;
    pData[1]    = ucNoiseMarginH;
    pData[2]    = ucNoiseMarginH;
    pData[3]    = 0x00;
    pData[4]    = 0x00;
    pData[5]    = 0x00;
    pData[6]    = 0x00;
    pData[7]    = 0x01;
    CScalerWrite(_RED_NOISE_MARGIN_76, 8, pData, _AUTOINC);

    pData[0]    = CAutoWaitFinish();

    if(pData[0] != _ERROR_SUCCESS)       return pData[0];

    CScalerRead(_H_START_END_H_81, 3, &pData[8], _AUTOINC);

    usHStartPos = (((WORD)(pData[8] & 0xf0 ) << 4) | (WORD)pData[9]) + 32;
    usHEndPos   = (((WORD)(pData[8] & 0x0f ) << 8) | (WORD)pData[10]) + 32;

    return _ERROR_SUCCESS;
}
/*

⌨️ 快捷键说明

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