📄 auto.c
字号:
/********************************************************************************/
/* The Software is proprietary, confidential, and valuable to Realtek */
/* Semiconductor Corporation ("Realtek"). All rights, including but not */
/* limited to copyrights, patents, trademarks, trade secrets, mask work */
/* rights, and other similar rights and interests, are reserved to Realtek. */
/* Without prior written consent from Realtek, copying, reproduction, */
/* modification, distribution, or otherwise is strictly prohibited. The */
/* Software shall be kept strictly in confidence, and shall not be */
/* disclosed to or otherwise accessed by any third party. */
/* c<2003> - <2008> */
/* The Software is provided "AS IS" without any warranty of any kind, */
/* express, implied, statutory or otherwise. */
/********************************************************************************/
//----------------------------------------------------------------------------------------------------
// ID Code : Auto.c No.0000
// Update Note :
//----------------------------------------------------------------------------------------------------
#define __AUTO__
#include "Common\Header\Include.h"
#if(_SCALER_SERIES_TYPE == _RTD2472D_SERIES)
void CAutoPositionFail(void)
{
stModeUserData.Clock = stModeUserData.CenterClock;
#if(_NEW_ADC == _FALSE)
CAdjustAdcClock(stModeUserData.Clock, 1);
CAdjustAdcClock(stModeUserData.Clock, 2);
#else
CAdjustAdcClock(stModeUserData.Clock);
#endif
stModeUserData.HPosition = stModeUserData.CenterHPos;
stModeUserData.VPosition = stModeUserData.CenterVPos;
CAdjustHPosition();
CAdjustVPosition();
}
// V010 Patch Note (2) : Auto Function Modify
//--------------------------------------------------
// Description : Auto clock, phase and H,V position
// Input Value : None
// Output Value : _ERROR_SUCCESS if succeed
//--------------------------------------------------
BYTE CAutoDoAutoConfig(void)
{
bit autoposition = _SUCCESS;
bit autoclock = _SUCCESS;
bit autophase = _SUCCESS;
// Clear the HW auto status to prevent some un-expected event happened
CScalerSetByte(_AUTO_ADJ_CTRL1_7D, 0x00);
CMiscClearStatusRegister();
// Check Input Active Region
if(CAutoCheckActiveRegion())
{
// Do Auto Phase (if active region has been captured, we only do Auto Phase.)
if(CAutoDoAutoPhase() != _ERROR_SUCCESS)
{
//stModeUserData.Phase = stModeUserCenterData.CenterPhase;
CAdjustPhase(stModeUserData.Phase);
return _ERROR_ABORT;
}
else
{
return _ERROR_SUCCESS;
}
}
// Do Auto Position
if(CAutoDoAutoPosition() != _ERROR_SUCCESS)
{
CAutoPositionFail();
autoposition = _FAIL;
}
// Do Auto Clock
if(CAutoDoAutoClock() != _ERROR_SUCCESS)
{
CAutoPositionFail();
autoclock = _FAIL;
}
// Do Auto Phase
if(CAutoDoAutoPhase() != _ERROR_SUCCESS)
{
CAutoPositionFail();
autophase = _FAIL;
}
// Do Auto Position
if(CAutoDoAutoPosition() != _ERROR_SUCCESS)
{
CAutoPositionFail();
autoposition = _FAIL;
}
// Set First Auto Flag
if((stModeUserData.FirstAuto == 0) && (autoposition == _SUCCESS) && ((autoclock == _SUCCESS) || (stModeInfo.IHWidth <= 720)))
{
stModeUserData.FirstAuto = 1;
}
// Save auto result after checking frame-sync status.
CScalerSetByte(_STATUS0_02, 0x00);
CTimerWaitForEvent(_EVENT_DVS);
CTimerWaitForEvent(_EVENT_DVS);
CScalerRead(_STATUS0_02, 1, pData, _NON_AUTOINC);
if((pData[0] & 0x63) == 0x00)
{
CAdjustUpdateCenterData();
CEepromSaveNewModeData();
#if(_NEW_AUTO == _TRUE)
CEepromSaveSystemData();
#endif
CMiscClearStatusRegister();
}
#if(_OSD_TYPE == _BENQ_OSD)
ucDdcciVPositionRatio=AlignMapToPercent(stModeUserData.VPosition,COsdFxGetVPositionRangeBenq(_MAX),COsdFxGetVPositionRangeBenq(_MIN));
#else
ucDdcciVPositionRatio=AlignMapToPercent(stModeUserData.VPosition,COsdFxGetVPositionRangeGeneric(_MAX),COsdFxGetVPositionRangeGeneric(_MIN));
#endif
return _ERROR_SUCCESS;
}
//--------------------------------------------------
// Description : Check active region which should be under the capture window.
// Input Value : None
// Output Value : Return _TRUE if active region has been captured, we only do Auto Phase.
//--------------------------------------------------
bit CAutoCheckActiveRegion(void)
{
if(_ERROR_SUCCESS != CAutoMeasurePositionH(_MIN_NOISE_MARGIN))
{
return _FALSE;
}
if((g_usHStartPos > (ucHStartBias + stModeUserData.HPosition + 8)) && (g_usHEndPos < (ucHStartBias + stModeUserData.HPosition + stModeInfo.IHWidth - 8)))
{
return _TRUE;
}
else
{
return _FALSE;
}
}
//--------------------------------------------------
// Description : Auto color ( white balance )
// Input Value : None
// Output Value : _ERROR_SUCCESS if succeed
//--------------------------------------------------
BYTE CAutoDoWhiteBalance(void)
{
BYTE result = 0;
result = CAutoTuneBalance();
if(result == _ERROR_SUCCESS)
{
CEepromSaveAdcData();
bWBA_OK = _TRUE;
}
else
{
CEepromLoadAdcDataDefault();
bWBA_OK = _FALSE;
}
return result;
}
//--------------------------------------------------
// Description : Wait auto measure process completed
// Input Value : None
// Output Value : Return result _ERROR_INPUT, _ERROR_SUCCESS
//--------------------------------------------------
BYTE CAutoWaitFinish(void)
{
BYTE timeoutcnt=0, ivsevent=0;
CMiscClearStatusRegister();
// Auto timeout
timeoutcnt = (CScalerGetBit(_AUTO_ADJ_CTRL0_7A, _BIT1 | _BIT0) == 0x03) ? 150 : 50;
// IVS timeout
ivsevent = 25;
#if(_PARTIAL_DISPLAY == _ON)
if (stModeInfo.ModeCurr == _MODE_720x400_70HZ || stModeInfo.ModeCurr == _MODE_640x350_70HZ)
{
timeoutcnt *= 2;
ivsevent *= 2;
}
#endif
do
{
CTimerDelayXms(1);
CScalerRead(_STATUS1_03, 1, pData, _NON_AUTOINC);
#if(_MODE_COMPARE_BY_SOD==_TRUE)
//Issac-03-13
//if((GET_INPUTSYNC_TYPE() == _CS_STATE)||(GET_INPUTSYNC_TYPE() == _SOG_STATE))
{
if (ucNoCheckFS==_TRUE)
pData[0] = 0x00;
}
#endif
if(pData[0] & _EVENT_IVS)
{
CScalerSetByte(_STATUS1_03, 0x00);
ivsevent = 25;
#if(_PARTIAL_DISPLAY == _ON)
if (stModeInfo.ModeCurr == _MODE_720x400_70HZ || stModeInfo.ModeCurr == _MODE_640x350_70HZ)
{
ivsevent *= 2;
}
#endif
}
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);
#if(_MODE_COMPARE_BY_SOD==_TRUE)
//if((GET_INPUTSYNC_TYPE() == _CS_STATE)||(GET_INPUTSYNC_TYPE() == _SOG_STATE))
{
if (ucNoCheckFS) pData[0] = 0x00; //Issac-03-13
}
#endif
// 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 = 25;
CScalerSetByte(_STATUS1_03, 0x00);
do
{
CTimerDelayXms(1);
CScalerRead(_STATUS1_03, 1, pData, _NON_AUTOINC);
pData[0] &= (_EVENT_IVS | _EVENT_UNDERFLOW | _EVENT_OVERFLOW);
#if(_MODE_COMPARE_BY_SOD==_TRUE)
//Issac-03-13
//if((GET_INPUTSYNC_TYPE() == _CS_STATE)||(GET_INPUTSYNC_TYPE() == _SOG_STATE)) // 20070509
{
if (ucNoCheckFS) pData[0] = pData[0] & (~(_EVENT_UNDERFLOW | _EVENT_OVERFLOW));
}
#endif
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=0, rbound=0;
CScalerSetBit(_VGIP_HV_DELAY_1E, 0x0f, 0x50);
lbound = (WORD)((DWORD)stModeInfo.IHStartPos * (100 - _H_BOUND_RANGE_L) / 100);
rbound = (WORD)((DWORD)(stModeUserData.Clock - stModeInfo.IHStartPos - stModeInfo.IHWidth) * (100 - _H_BOUND_RANGE_R) / 100);
rbound = stModeInfo.IHStartPos + stModeInfo.IHWidth + rbound;
ucNoiseMarginH &= 0xfc;
CScalerSetBit(_AUTO_ADJ_CTRL1_7D, ~_BIT0, 0x00);
#if(_SCALER_TYPE == _RTD2472D)
pData[0] = ((lbound >> 4) & 0x70) | (HIBYTE(rbound) & 0x0f);
#elif((_SCALER_TYPE == _RTD2545LR) || (_SCALER_TYPE == _RTD247xRD) || (_SCALER_TYPE == _RTD248xRD))
pData[0] = ((lbound >> 4) & 0xF0) | (HIBYTE(rbound) & 0x0f);
#else
No Setting !!
#endif //End of #if(_SCALER_TYPE == _RTD2472D)
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);
g_usHStartPos = (((WORD)(pData[8] & 0xf0 ) << 4) | (WORD)pData[9]) + 32;
g_usHEndPos = (((WORD)(pData[8] & 0x0f ) << 8) | (WORD)pData[10]) + 32;
if(g_usHEndPos < g_usHStartPos)
{
g_usHStartPos = 0;
g_usHEndPos = 0;
}
return _ERROR_SUCCESS;
}
//--------------------------------------------------
// Description : Measure position V
// Input Value : ucNoiseMarginV --> Noise margin for V
// Output Value : Measure status
//--------------------------------------------------
BYTE CAutoMeasurePositionV(BYTE ucNoiseMarginV)
{
WORD lbound=0, rbound=0;
CScalerSetBit(_VGIP_HV_DELAY_1E, 0x0f, 0x50);
lbound = (WORD)((DWORD)stModeInfo.IHStartPos * (100 - _H_BOUND_RANGE_L) / 100);
rbound = (WORD)((DWORD)(stModeUserData.Clock - stModeInfo.IHStartPos - stModeInfo.IHWidth) * (100 - _H_BOUND_RANGE_R) / 100);
rbound = stModeInfo.IHStartPos + stModeInfo.IHWidth + rbound;
ucNoiseMarginV &= 0xfc;
CScalerSetBit(_AUTO_ADJ_CTRL1_7D, ~_BIT0, 0x00);
#if(_SCALER_TYPE == _RTD2472D)
pData[0] = ((lbound >> 4) & 0x70) | (HIBYTE(rbound) & 0x0f);
#elif((_SCALER_TYPE == _RTD2545LR) || (_SCALER_TYPE == _RTD247xRD) || (_SCALER_TYPE == _RTD248xRD))
pData[0] = ((lbound >> 4) & 0xF0) | (HIBYTE(rbound) & 0x0f);
#else
No Setting !!
#endif //End of #if(_SCALER_TYPE == _RTD2472D)
pData[1] = (LOBYTE(lbound));
pData[2] = (LOBYTE(rbound));
pData[3] = (HIBYTE(stModeInfo.IVTotal - 1 + 3) & 0x0f);
pData[4] = (0x02);
pData[5] = (LOBYTE(stModeInfo.IVTotal - 1 + 3));
CScalerWrite(_H_BOUNDARY_H_70, 6, pData, _AUTOINC);
pData[0] = ucNoiseMarginV;
pData[1] = ucNoiseMarginV;
pData[2] = ucNoiseMarginV;
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(_V_START_END_H_7E, 3, &pData[8], _AUTOINC);
g_usVStartPos = (((WORD)(pData[8] & 0xf0 ) << 4) | (WORD)pData[9]) + 3;
g_usVEndPos = (((WORD)(pData[8] & 0x0f ) << 8) | (WORD)pData[10]) + 3;
// Check all black
if(g_usVEndPos == 0x0000)
{
return _ERROR_ABORT;
}
// Update auto-tracking window vertical range
#if(_SCALER_TYPE == _RTD2472D)
pData[0] = (pData[8] & 0x7f);
#elif((_SCALER_TYPE == _RTD2545LR) || (_SCALER_TYPE == _RTD247xRD) || (_SCALER_TYPE == _RTD248xRD))
pData[0] = (pData[8] & 0xff);
#else
No Setting !!
#endif //End of #if(_SCALER_TYPE == _RTD2472D)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -