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

📄 auto.c

📁 realtek LCD monitor, TV开发源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
        stAdcData.AdcOffset[count] = 0x80;
    }

    CAdjustAdcGainOffset();

    rev = CAutoMeasurePositionV(_MIN_NOISE_MARGIN);
    if(rev != _ERROR_SUCCESS)
    {
        return rev;
    }

    rev = CAutoMeasurePositionH(_MIN_NOISE_MARGIN);
    if(rev != _ERROR_SUCCESS)
    {
        return rev;
    }

    if(CAutoMeasureColor(_BLUE, _MEASURE_COLORS_MAX, &rev) != _ERROR_SUCCESS)
    {
        return _ERROR_ABORT;
    }

    if(rev < 0x60)
    {
        return _ERROR_ABORT;
    }

    if(CAutoMeasureColor(_GREEN, _MEASURE_COLORS_MAX, &rev) != _ERROR_SUCCESS)
    {
        return _ERROR_ABORT;
    }

    if(rev < 0x60)
    {
        return _ERROR_ABORT;
    }

    if(CAutoMeasureColor(_RED, _MEASURE_COLORS_MAX, &rev) != _ERROR_SUCCESS)
    {
        return _ERROR_ABORT;
    }

    if(rev < 0x60)
    {
        return _ERROR_ABORT;
    }

    g_ucAdcPGA = 8;

    CScalerPageSelect(_PAGE0);
    CScalerSetBit(_P0_ADC_RGB_CTRL_CE, 0x0F, (g_ucAdcPGA << 4) & 0xF0);
    CTimerDelayXms(1);

    color = _BLUE;
    while(flag)
    {
        count = 0x30;

        do
        {
            /*
            // Power off while auto config--------
            CKeyCheckPowerKey();

            if(GET_POWERSWITCH())
                return _ERROR_ABORT;
            //------------------------------------
            */

            rev = CAutoTuneAdcGain(color, &result0);

            if(rev == _ERROR_ABORT)
            {
                return rev;
            }

            if(rev == _ERROR_FINISH)
            {
                break;
            }

            rev = CAutoTuneAdcOffset(color, &result1);

            if(rev == _ERROR_ABORT)
            {
                return rev;
            }

            //YPbPr Auto Color Start
            if((GET_INPUTSOURCE_TYPE() == _SOURCE_YPBPR) && (color != _GREEN))
            {
                rev = _WHITEBALANCE_BR_MIN_LEVEL;
            }
            else
            {
                rev = _WHITEBALANCE_MIN_LEVEL;
            }

            if((result0 == _WHITEBALANCE_MAX_LEVEL) && (result1 == rev))
            {
                break;
            }

            if((count > 8) && (result0 <= (_WHITEBALANCE_MAX_LEVEL + 1)) && (result0 >= (_WHITEBALANCE_MAX_LEVEL - 1))
                && (result1 <= (rev + 1)) && (result1 >= (rev - 1)))
            {
                count = 8;
            }
            //YPbPr Auto Color End
        }
        while(--count);

        if(stAdcData.AdcGain[color] > 240)
        {
            if(g_ucAdcPGA == 7)
            {
                if(color == _BLUE)
                {
                    color = _GREEN;
                }
                else if(color == _GREEN)
                {
                    color = _RED;
                }
                else
                {
                    flag = 0;
                }
            }
            else
            {
                color = _BLUE;
                g_ucAdcPGA = g_ucAdcPGA + 1;
            }

            CScalerPageSelect(_PAGE0);
            CScalerSetBit(_P0_ADC_RGB_CTRL_CE, 0x0F, (g_ucAdcPGA << 4) & 0xF0);
            CTimerDelayXms(1);
        }
        else if(stAdcData.AdcGain[color] < 30)
        {
            if(g_ucAdcPGA == 4)
            {
                if(color == _BLUE)
                {
                    color = _GREEN;
                }
                else if(color == _GREEN)
                {
                    color = _RED;
                }
                else
                {
                    flag = 0;
                }
            }
            else
            {
                color = _BLUE;
                g_ucAdcPGA = g_ucAdcPGA - 1;
            }

            CScalerPageSelect(_PAGE0);
            CScalerSetBit(_P0_ADC_RGB_CTRL_CE, 0x0F, (g_ucAdcPGA << 4) & 0xF0);
            CTimerDelayXms(1);
        }
        else
        {
            if(color == _BLUE)
            {
                color = _GREEN;
            }
            else if(color == _GREEN)
            {
                color = _RED;
            }
            else
            {
                flag = 0;
            }
        }
    }

    if((stAdcData.AdcGain[_RED] == 0x00) || (stAdcData.AdcGain[_GREEN] == 0x00) || (stAdcData.AdcGain[_BLUE] == 0x00))
    {
        return _ERROR_ABORT;
    }
    else
    {
        for(rev=0;rev<3;rev++)
        {
            stAdcData.AdcOffset[rev]+=5;
        }
        CAdjustAdcGainOffset();


        return _ERROR_SUCCESS;
    }
}

//--------------------------------------------------
// Description  : Get max or min color value
// Input Value  : Measure information
// Output Value : Measure status
//--------------------------------------------------
BYTE CAutoMeasureColor(BYTE ucColor, BYTE ucPar, BYTE *pMargin)
{
    CScalerSetBit(_AUTO_ADJ_CTRL0_7A, ~(_BIT2 | _BIT1 | _BIT0), (ucColor == 3) ? ucColor : ( 2 - ucColor));
    CScalerSetBit(_AUTO_ADJ_CTRL1_7D, ~_BIT0, 0x00);

    if(ucPar == _MEASURE_COLORS_MIN)
    {
        pData[0] = 0x12;
        pData[1] = 0x80;
        pData[2] = 0x00;
        pData[3] = 0x00;
        pData[4] = (g_usVStartPos > 9) ? 9 : (g_usVStartPos - 1);
        pData[5] = pData[4] + 1;
    }
    else
    {
#if(_SCALER_TYPE == _RTD2472D)
        pData[0] = ((g_usHStartPos >> 4) & 0x70) | (HIBYTE(g_usHEndPos) & 0x0f);
#elif((_SCALER_TYPE == _RTD2545LR) || (_SCALER_TYPE == _RTD247xRD) || (_SCALER_TYPE == _RTD248xRD))
        pData[0] = ((g_usHStartPos >> 4) & 0xf0) | (HIBYTE(g_usHEndPos) & 0x0f);
#else
    No Setting !!
#endif //End of #if(_SCALER_TYPE == _RTD2472D)

        pData[1] = (LOBYTE(g_usHStartPos));
        pData[2] = (LOBYTE(g_usHEndPos));
        pData[3] = ((g_usVStartPos >> 4) & 0x70) | (HIBYTE(g_usVEndPos) & 0x0f);
        pData[4] = (LOBYTE(g_usVStartPos));
        pData[5] = (LOBYTE(g_usVEndPos));
    }

    CScalerWrite(_H_BOUNDARY_H_70, 6, pData, _AUTOINC);
    CScalerSetByte(_AUTO_ADJ_CTRL1_7D, 0x01 | ((ucPar & 0x01) << 5));

    pData[0] = CAutoWaitFinish();

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

    CScalerRead(_AUTO_PHASE_0_87, 1, pMargin, _AUTOINC);

    if(ucPar == _MEASURE_COLORS_MIN)
    {
        *pMargin ^= 0xff;
    }

    return _ERROR_SUCCESS;
}

//--------------------------------------------------
// Description  : Adjust ADC gain
// Input Value  : Adjusting setting
// Output Value : Measure status
//--------------------------------------------------
BYTE CAutoTuneAdcGain(BYTE ucColor, BYTE *pMargin)
{
    BYTE temp=0;

    if(CAutoMeasureColor(ucColor, _MEASURE_COLORS_MAX, pMargin) != _ERROR_SUCCESS)
    {
        return _ERROR_ABORT;
    }

    if(*pMargin > _WHITEBALANCE_MAX_LEVEL)
    {
        temp  = *pMargin - _WHITEBALANCE_MAX_LEVEL;
        temp = (temp * 7 + 3) / 10; // make auto more precisely.

        // Non-zero return value of Change_ADC_Gain() means ADC gain reaches maximum.
        if(CAutoChangeAdcGain(ucColor, temp, 0))                  // Increase Gain; Decrease Contrast
        {
            if(CAutoChangeAdcOffset(ucColor, 4, 0))               // Increase Offset; Decrease Brightness
            {
                return _ERROR_FINISH;
            }
        }
    }
    else if(*pMargin < _WHITEBALANCE_MAX_LEVEL)
    {
        temp  = _WHITEBALANCE_MAX_LEVEL - *pMargin;

        // for ADC Input Range 0.25 ~ 1.25V Start Need to Confrim
        temp = (temp * 7 + 3) / 10; // make auto more precisely.

        // Non-zero return value of Change_ADC_Gain() means ADC gain reaches minimum.
        if(CAutoChangeAdcGain(ucColor, temp, 1))                  // Decrease Gain; Increase Contrast
        {
            if(CAutoChangeAdcOffset(ucColor, 4, 1))               // Decrease Offset; Increase Brightness
            {
                return _ERROR_FINISH;
            }
        }
    }

    return _ERROR_SUCCESS;
}

//--------------------------------------------------
// Description  : Adjust ADC offset
// Input Value  : Adjusting setting
// Output Value : Measure status
//--------------------------------------------------
BYTE CAutoTuneAdcOffset(BYTE ucColor, BYTE *pMargin)
{
    BYTE temp=0, level=0;

    if((GET_INPUTSOURCE_TYPE() == _SOURCE_YPBPR) && (ucColor != _GREEN))
    {
        level = _WHITEBALANCE_BR_MIN_LEVEL;
    }
    else
    {
        level = _WHITEBALANCE_MIN_LEVEL;
    }

    if(CAutoMeasureColor(ucColor, _MEASURE_COLORS_MIN, pMargin) != _ERROR_SUCCESS)
    {
        return _ERROR_ABORT;
    }

    if(*pMargin > level)
    {
        temp = *pMargin - level;
        CAutoChangeAdcOffset(ucColor, ((temp > 8) ? 8 : temp), 0);     // Increase Offset; Decrease Brightness
    }
    else if(*pMargin < level)
    {
        temp = level - *pMargin;

        if((GET_INPUTSOURCE_TYPE() == _SOURCE_YPBPR) && (ucColor != _GREEN))
        {
            CAutoChangeAdcOffset(ucColor, ((temp > 8) ? 8 : temp), 1);
        }
        else
        {
            if(*pMargin == 0)
            {
                CAutoChangeAdcOffset(ucColor, temp + 4, 1);       // Decrease Offset; Increase Brightness
            }
            else
            {
                CAutoChangeAdcOffset(ucColor, temp, 1);           // Decrease Offset; Increase Brightness
            }
        }
    }

    return _ERROR_SUCCESS;
}

//--------------------------------------------------
// Description  : Change ADC gain
// Input Value  : Input information
// Output Value : Return 1 if overrange
//--------------------------------------------------
BYTE CAutoChangeAdcGain(BYTE ucColor, BYTE ucDelta, BYTE ucInc)
{
    BYTE overrange = 0;

    if(ucInc)
    {
        if(stAdcData.AdcGain[ucColor] >= ucDelta)
        {
            stAdcData.AdcGain[ucColor] -= ucDelta;
        }
        else
        {
            stAdcData.AdcGain[ucColor] = 0;
            overrange = 1;
        }
    }
    else
    {
        if ((0xff - ucDelta) >= stAdcData.AdcGain[ucColor])
        {
            stAdcData.AdcGain[ucColor] += ucDelta;
        }
        else
        {
            stAdcData.AdcGain[ucColor] = 0xff;
            overrange = 1;
        }
    }

    CAdjustAdcGain();

    return overrange;
}

//--------------------------------------------------
// Description  : Change ADC offset
// Input Value  : Input information
// Output Value : Return 1 if overrange
//--------------------------------------------------
BYTE CAutoChangeAdcOffset(BYTE ucColor, BYTE ucDelta, BYTE ucInc)
{
    BYTE overrange = 0;

    if(ucInc)
    {
        if(stAdcData.AdcOffset[ucColor] >= ucDelta)
        {
            stAdcData.AdcOffset[ucColor] -= ucDelta;
        }
        else
        {
            stAdcData.AdcOffset[ucColor] = 0;
            overrange = 1;
        }
    }
    else
    {
        if ((0xff - ucDelta) >= stAdcData.AdcOffset[ucColor])
        {
            stAdcData.AdcOffset[ucColor] += ucDelta;
        }
        else
        {
            stAdcData.AdcOffset[ucColor] = 0xff;
            overrange = 1;
        }
    }

    CAdjustAdcOffset();

    return overrange;
}


#endif  // End of #if(_SCALER_SERIES_TYPE == _RTD2472D_SERIES)

⌨️ 快捷键说明

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