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

📄 auto.c

📁 realtek LCD monitor, TV开发源代码
💻 C
📖 第 1 页 / 共 4 页
字号:

//--------------------------------------------------
// Description  : Auto phase process
// Input Value  : None
// Output Value : Measure status
//--------------------------------------------------
BYTE CAutoDoAutoPhase(void)
{

    BYTE  result=0, phase=0, best=0;
    DWORD maxsum=0, temp0=0, temp1=0, temp2=0;

    result = CAutoMeasurePositionH(_MIN_NOISE_MARGIN);
    if(_ERROR_SUCCESS != result)  return result;

    // Set threshold 0xA0 for Phase Search
    CScalerSetByte(_DIFF_THRESHOLD_79, 0xA0);

    temp0 = 0;
    maxsum = CAutoPhaseSearch(_COLOR_SELECT, _HWAUTO_STEP_4, HWAUTOSTEPNUM(16), HWAUTOSTEPSTART(0), &result);

    if(maxsum == 0xffffffffL)
    {
        return _ERROR_INPUT;
    }

    if(maxsum == 0)
    {
        return _ERROR_ABORT;
    }

    if(maxsum < ((DWORD)stModeInfo.IVHeight * 1024 * 3 / 4))
    {
        // Decrease threshold to 0x40 for Phase Search
        CScalerSetByte(_DIFF_THRESHOLD_79, 0x30);

//        maxsum  = CAutoPhaseSearch(_COLOR_SELECT, _HWAUTO_STEP_4, HWAUTOSTEPNUM(16), HWAUTOSTEPSTART(0), &result);
        maxsum  = CAutoPhaseSearch(_COLOR_SELECT, _HWAUTO_STEP_4, HWAUTOSTEPNUM(16), HWAUTOSTEPSTART(0), &result);

        if(maxsum == 0xffffffffL)
        {
            return _ERROR_INPUT;
        }

        if(maxsum == 0)
        {
            return _ERROR_ABORT;
        }

        if(maxsum < ((DWORD)stModeInfo.IVHeight * 1024 * 3 / 4))
        {
            return _ERROR_PHASE;
        }
    }

    // Issac:
    // Please do not delete these backup code below.
/*
    if(((DWORD)stModeInfo.IHFreq * stModeInfo.IHTotal / 1000) < 530)
    {
        BYTE  count, ucSelStep, ucSelColor;

        CScalerSetByte(_AUTO_ADJ_CTRL1_7D, 0x00);

        ucSelStep   = (0x01 << _HWAUTO_STEP_2);
        count       = ((result - 8) & 0x3f);
        ucSelColor  = count + (8 * ucSelStep);
        maxsum      = 0;
        best        = 0;

        do
        {
            CAdjustPhase(count);

            if(_ERROR_SUCCESS != CAutoReadPhaseInfo(_COLOR_SELECT))   return _ERROR_INPUT;

            if(((DWORD *)pData)[0] > maxsum)
            {
                maxsum  = ((DWORD *)pData)[0];
                best    = count;
            }

            count += ucSelStep;
        }
        while(count < ucSelColor);

        CScalerSetByte(_AUTO_ADJ_CTRL1_7D, 0x00);

        result = best & 0x3f;
    }
    else
    {
        maxsum  = CAutoPhaseSearch(_COLOR_SELECT, _HWAUTO_STEP_2, HWAUTOSTEPNUM(8), HWAUTOSTEPSTART((result - 8) & 0x3f), &result);

        if(maxsum == 0xffffffffL)
        {
            return _ERROR_INPUT;
    }

        if(maxsum == 0)
        {
            return _ERROR_ABORT;
        }
    }
*/
    // Search phase by weighting SOD
    phase = (result - 8) & 0x3f;

    CAdjustPhase(phase);

    if(_ERROR_SUCCESS != CAutoReadPhaseInfo(_COLOR_SELECT))
    {
        return _ERROR_INPUT;
    }

    temp0   = ((DWORD *)pData)[0];
    phase = phase + 1;
    CAdjustPhase(phase);

    if(_ERROR_SUCCESS != CAutoReadPhaseInfo(_COLOR_SELECT))
    {
        return _ERROR_INPUT;
    }

    temp1   = ((DWORD *)pData)[0];
    result = (result + 8) & 0x3f;
    maxsum = 0;

    do
    {
        phase   = (phase + 1) & 0x3f;
        CAdjustPhase(phase);

        if(_ERROR_SUCCESS != CAutoReadPhaseInfo(_COLOR_SELECT))
        {
            return _ERROR_INPUT;
        }

        temp2   = ((DWORD *)pData)[0];

        // Search phase by weighting SOD
        ((DWORD *)pData)[0] = temp2 + temp1 + temp0
                              - ((temp1 > temp0 ? temp1 - temp0 : temp0 - temp1) / 2)
                              - ((temp1 > temp2 ? temp1 - temp2 : temp2 - temp1) / 2);

        if(((DWORD *)pData)[0] > maxsum)
        {
            maxsum  = ((DWORD *)pData)[0];
            best    = (phase - 1) & 0x3f;
        }

        temp0   = temp1;
        temp1   = temp2;
    }
    while(phase != result);

    stModeUserData.Phase    = best;
    CAdjustPhase(stModeUserData.Phase);

    return _ERROR_SUCCESS;
}

//--------------------------------------------------
// Description  : Auto position process
// Input Value  : None
// Output Value : Measure status
//--------------------------------------------------
#if(_NEW_AUTO == _OFF)
BYTE CAutoDoAutoPosition(void)
{
    BYTE result;
    SWORD dtemp, ctemp, atemp;

    result  = CAutoMeasurePositionV(_MIN_NOISE_MARGIN);
    if(_ERROR_SUCCESS != result)    return result;

    result  = CAutoMeasurePositionH(_MIN_NOISE_MARGIN);
    if(_ERROR_SUCCESS != result)    return result;

    /////////////////////////////////
    // Calculate Vertical Position //
    /////////////////////////////////
    CScalerRead(_IPV_ACT_STA_H_18, 2, pData, _AUTOINC);

#if(_SCALER_TYPE == _RTD2472D)
    ctemp = (((WORD)(pData[0] & 0x07)) << 8) | pData[1];
#elif((_SCALER_TYPE == _RTD2545LR) || (_SCALER_TYPE == _RTD247xRD) || (_SCALER_TYPE == _RTD248xRD))
    ctemp = (((WORD)(pData[0] & 0x0F)) << 8) | pData[1];
#else
    No Setting !!
#endif //End of #if(_SCALER_TYPE == _RTD2472D)

    CScalerRead(_IVS_DELAY_1C, 1, pData, _AUTOINC);
    CScalerRead(_VGIP_HV_DELAY_1E, 1, &pData[1], _AUTOINC);
    dtemp = (((WORD)(pData[1] & _BIT1)) << 8) | pData[0];

    dtemp = g_usVStartPos - dtemp;

    atemp = (stModeInfo.IVHeight - (g_usVEndPos - g_usVStartPos + 1));

    if(atemp > 3)
        atemp = abs(g_usVEndPos - g_usVStartPos + 1 - stModeInfo.IVHeight) / 2;
    else
        atemp = 0;

    while(_TRUE)
    {
#if(_V_POSITION_DIRECTION == _V_POSITION_METHOD_0)
        if(abs(stModeUserData.VPosition + (ctemp - dtemp) - stModeInfo.IVStartPos + atemp) <= ucVStartBias)
        {
            stModeUserData.VPosition += ctemp - dtemp + atemp;
            break;
        }
        else if (abs(stModeUserData.VPosition + (ctemp - dtemp) - stModeInfo.IVStartPos + 0) <= ucVStartBias)
        {
            stModeUserData.VPosition += ctemp - dtemp + 0;
#endif

#if(_V_POSITION_DIRECTION == _V_POSITION_METHOD_1)
        if(abs(stModeUserData.VPosition - (ctemp - dtemp) - stModeInfo.IVStartPos - atemp) <= ucVStartBias)
        {
            stModeUserData.VPosition -= ctemp - dtemp + atemp;
#endif
            break;
        }

        else if(abs(stModeUserData.VPosition - (ctemp - dtemp) - stModeInfo.IVStartPos + 0) <= ucVStartBias)
        {
            stModeUserData.VPosition -= ctemp - dtemp + 0;
            break;
        }
        else
        {
            stModeUserData.VPosition = stModeInfo.IVStartPos;
            break;
        }
    }

#if(_PARTIAL_DISPLAY == _ON)
    if (stModeInfo.ModeCurr == _MODE_720x400_70HZ || stModeInfo.ModeCurr == _MODE_640x350_70HZ)
    {
        stModeUserData.VPosition = stModeInfo.IVStartPos - ucVStartBias;
    }
#endif

    CAdjustVPosition();

    ///////////////////////////////////
    // Calculate Horizontal Position //
    ///////////////////////////////////
    CScalerRead(_IPH_ACT_STA_H_14, 2, pData, _AUTOINC);

#if(_SCALER_TYPE == _RTD2472D)
    ctemp = (((WORD)(pData[0] & 0x07)) << 8) | pData[1];
#elif((_SCALER_TYPE == _RTD2545LR) || (_SCALER_TYPE == _RTD247xRD) || (_SCALER_TYPE == _RTD248xRD))
    ctemp = (((WORD)(pData[0] & 0x0F)) << 8) | pData[1];
#else
    No Setting !!
#endif //End of #if(_SCALER_TYPE == _RTD2472D)

    CScalerRead(_IHS_DELAY_1D, 2, pData, _AUTOINC);
    dtemp = (((WORD)(pData[1] & _BIT0)) << 8) | pData[0];

    dtemp = g_usHStartPos - dtemp - 2;

    while(_TRUE)
    {
        if(abs(stModeUserData.HPosition + (ctemp - dtemp) - stModeInfo.IHStartPos) <= ucHStartBias)
        {
            stModeUserData.HPosition += ctemp - dtemp;
            break;
        }
        else
        {
            stModeUserData.HPosition = stModeInfo.IHStartPos;
            break;
        }
    }

    CAdjustHPosition();

    return _ERROR_SUCCESS;
}

#else//#if(_NEW_AUTO == _ON)

BYTE CAutoDoAutoPosition(void)
{
    BYTE result=0;
    SWORD dtemp=0, ctemp=0;

    result  = CAutoMeasurePositionV(_MIN_NOISE_MARGIN);
    if(_ERROR_SUCCESS != result)    return result;

    result  = CAutoMeasurePositionH(_MIN_NOISE_MARGIN);
    if(_ERROR_SUCCESS != result)    return result;

    /////////////////////////////////
    // Calculate Vertical Position //
    /////////////////////////////////
    CScalerRead(_IPV_ACT_STA_H_18, 2, pData, _AUTOINC);

#if(_SCALER_TYPE == _RTD2472D)
    ctemp = (((WORD)(pData[0] & 0x07)) << 8) | pData[1];
#elif((_SCALER_TYPE == _RTD2545LR) || (_SCALER_TYPE == _RTD247xRD) || (_SCALER_TYPE == _RTD248xRD))
    ctemp = (((WORD)(pData[0] & 0x0F)) << 8) | pData[1];
#else
    No Setting !!
#endif //End of #if(_SCALER_TYPE == _RTD2472D)

    CScalerRead(_IVS_DELAY_1C, 1, pData, _AUTOINC);
    CScalerRead(_VGIP_HV_DELAY_1E, 1, &pData[1], _AUTOINC);
    dtemp = (((WORD)(pData[1] & _BIT1)) << 8) | pData[0];

    if(g_usVStartPos <= (tINPUTMODE_PRESET_TABLE[stModeInfo.ModeCurr].IVStartPos * (100 + _V_POSITION_RANGE) / 100))
    {
        dtemp = g_usVStartPos - dtemp;
        result = _ERROR_SUCCESS;
    }
    else if((stModeInfo.IVTotal - g_usVEndPos) <= ((stModeInfo.IVTotal - stModeInfo.IVHeight - tINPUTMODE_PRESET_TABLE[stModeInfo.ModeCurr].IVStartPos) * (100 + _V_POSITION_RANGE) / 100))
    {
        dtemp = (g_usVEndPos - stModeInfo.IVHeight + 1) - dtemp;
        result = _ERROR_SUCCESS;
    }
    else
    {
        stModeUserData.VPosition = stModeUserData.CenterVPos;
        dtemp = stModeUserData.VPosition - stModeUserData.CenterVPos - dtemp;
        result = _ERROR_FINISH;
    }

    if(result == _ERROR_SUCCESS)
    {
        if(abs(stModeUserData.VPosition - (ctemp - dtemp) - stModeInfo.IVStartPos + 0) <= ucVStartBias)
        {
            stModeUserData.VPosition -= ctemp - dtemp + 0;
        }
        else
        {
            stModeUserData.VPosition = stModeInfo.IVStartPos;
        }

#if(_PARTIAL_DISPLAY == _ON)
        if (stModeInfo.ModeCurr == _MODE_720x400_70HZ || stModeInfo.ModeCurr == _MODE_640x350_70HZ)
        {
            stModeUserData.VPosition = stModeInfo.IVStartPos - ucVStartBias;
        }
#endif

    }

    CAdjustVPosition();


    ///////////////////////////////////
    // Calculate Horizontal Position //
    ///////////////////////////////////
    CScalerRead(_IPH_ACT_STA_H_14, 2, pData, _AUTOINC);

#if(_SCALER_TYPE == _RTD2472D)
    ctemp = (((WORD)(pData[0] & 0x07)) << 8) | pData[1];
#elif((_SCALER_TYPE == _RTD2545LR) || (_SCALER_TYPE == _RTD247xRD) || (_SCALER_TYPE == _RTD248xRD))
    ctemp = (((WORD)(pData[0] & 0x0F)) << 8) | pData[1];
#else
    No Setting !!
#endif //End of #if(_SCALER_TYPE == _RTD2472D)

    CScalerRead(_IHS_DELAY_1D, 2, pData, _AUTOINC);
    dtemp = (((WORD)(pData[1] & _BIT0)) << 8) | pData[0];

    if(g_usHStartPos <= ((DWORD)tINPUTMODE_PRESET_TABLE[stModeInfo.ModeCurr].IHStartPos * (100 + _H_POSITION_RANGE) / 100))
    {
        if(g_usHStartPos <= (_IHS_DELAY_LIMIT + _H_POSITION_ADJUST_LIMIT + 2))
        {
            ucHStartBias = _IHS_DELAY_LIMIT;
            stModeUserData.HPosition = _H_POSITION_ADJUST_LIMIT + 2;
        }
        else if(g_usHStartPos <= (_IHS_START_BIAS * 2 + 4))
        {
            ucHStartBias = g_usHStartPos / 2 - 2;
            stModeUserData.HPosition = g_usHStartPos / 2 + (g_usHStartPos & _BIT0);
        }
        else
        {
            ucHStartBias = _IHS_START_BIAS;
            stModeUserData.HPosition = g_usHStartPos - ucHStartBias - 2;
        }

        result = _ERROR_SUCCESS;
    }
    else if((stModeInfo.IHTotal - g_usHEndPos) <= (((DWORD)stModeInfo.IHTotal - stModeInfo.IHWidth - tINPUTMODE_PRESET_TABLE[stModeInfo.ModeCurr].IHStartPos) * (100 + _H_POSITION_RANGE) / 100))
    {
        if((g_usHEndPos - stModeInfo.IHWidth) <= (_IHS_DELAY_LIMIT + _H_POSITION_ADJUST_LIMIT + 2))
        {
            ucHStartBias = _IHS_DELAY_LIMIT;
            stModeUserData.HPosition = _H_POSITION_ADJUST_LIMIT + 2;
        }
        else if((g_usHEndPos - stModeInfo.IHWidth) <= (_IHS_START_BIAS * 2 + 4))
        {
            ucHStartBias = (g_usHEndPos - stModeInfo.IHWidth) / 2 - 1;
            stModeUserData.HPosition = (g_usHEndPos - stModeInfo.IHWidth) / 2 + ((g_usHEndPos - stModeInfo.IHWidth) & _BIT0);
        }
        else
        {
            ucHStartBias = _IHS_START_BIAS;
            stModeUserData.HPosition = (g_usHEndPos - stModeInfo.IHWidth) - ucHStartBias - 1;
        }

        result = _ERROR_SUCCESS;
    }
    else
    {
        ucHStartBias = stSystemData.HStartBias;
        stModeUserData.HPosition = stModeUserData.CenterHPos;
        result = _ERROR_FINISH;
    }

    if(stModeUserData.HPosition < 2)
    {
        stModeUserData.HPosition = _H_POSITION_ADJUST_LIMIT;
    }

    CAdjustHPosition();

    return _ERROR_SUCCESS;
}

#endif//End of #if(_NEW_AUTO == _OFF)
//--------------------------------------------------
// Description  : Tune ADC gain and offset
// Input Value  : None
// Output Value : Measure status
//--------------------------------------------------
BYTE CAutoTuneBalance(void)
{
    BYTE rev=0, result0=0, result1=0, color=0, count=0;
    bit flag = 1;

    for(count=0;count<3;count++)
    {
        stAdcData.AdcGain[count] = 0x80;

⌨️ 快捷键说明

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