📄 detect.c
字号:
#include <math.h>
#include "types.h"
#include "board.h"
#include "global.h"
#include "ms_reg.h"
#include "ms_rwreg.h"
#include "power.h"
#include "debug.h"
#include "misc.h"
#include "menu.h"
#include "UserPref.h"
#include "msOSD.h"
#include "mStar.h"
#if Dual_Input_Icon_Enable
#include "Menudef.h"
#include "Menu.h"
#include "Adjust.h"
extern Bool ExecuteKeyEvent(MenuItemActionType menuAction);
#endif
#define HPeriod_Torlance 10 // for mode change
#define VTotal_Torlance 10 // for mode change
#define VideoVTotal_Torlance 80//for mode change
// time of one loop is 34 when no input
#define ValidTimingStableCount 8 // 10 // 20 // 15
#define SyncLossStableCount 8 // 10 // 20 // 30 fendy
#define SwitchInputPortCount 15 // 10 // 30 // half or SyncLossStableCount to disable osd while switch input port
//#define SwitchAnalogCount 10 // 15 // 7 // switch SOG/CSync-Separate by 4 times on switch input port
#if WidePanel // sail add
#define HFreq_Torlance 10 // 1.5 KHz
#else
#define HFreq_Torlance 15 // 1.5 KHz
#endif
#define VFreq_Torlance 15 // 1.5 Hz
#define VTotal_Delta 50
#if XGA
#define MaxInputHFreq 700 //855 // 80.0 KHz
#define MinInputHFreq 285 //285 // 28.5 KHz
#define MaxInputVFreq 770 //865 // 76.5 Hz
#define MinInputVFreq 480 // 50.0 Hz
#elif WidePanel
#define MaxInputHFreq 575
#define MinInputHFreq 285
#define MaxInputVFreq 730//disble 75Hz timing
#define MinInputVFreq 580
#elif WidePanel_16_9
#define MaxInputHFreq 650//610
#define MinInputHFreq 285
#define MaxInputVFreq 770// 76.5 Hz
#define MinInputVFreq 480
#else
#define MaxInputHFreq 830 //805 //1000//855 // 80.0 KHz //for the require of QE in ProView //mode change use some type of chroma
#define MinInputHFreq 285 //100//285 // 28.5 KHz
#define MaxInputVFreq 770 //900//865 // 76.5 Hz
#define MinInputVFreq 480 //400 // 50.0 Hz
#endif
extern InputModeType code StandardMode[];
extern BYTE InputTimingStableCounter;
extern BYTE TimingChangeDebunce;
BYTE code DVIPhaseTbl[];
BYTE mStar_FineTuneDVIPhase(BYTE channelReg,BYTE channel);
Bool mStar_FindMode(void);
BYTE mStar_GetInputStatus(void);
#if NoCable_Detect_Enable
Bool IsCableNotConnected(void);
#endif
Bool mStar_SyncLossStateDetect(void);
Bool mStar_ValidTimingDetect(void);
void mStar_AutoDVI(void);
#if (NEWIC_18A||NEWIC_18B)
void CheckADC(void);
#endif
//*******************************************************************
// Function Name: mStar_MonitorInputTiming
//
// Decscription: Detect input timing
//
// callee: mStar_SyncLossStateDetect(), mStar_ValidTimingDetect(), mStar_AutoDVI() in detect.c
// mStar_SetInputPort(), mStar_SetAnalogInputPort() in mstar.c
//
// caller: main() in main.c
//*******************************************************************
void mStar_MonitorInputTiming(void)
{ if (!PowerOnFlag)
return;
#if DISPLAYLOGO
if(DoDisplayLogoFlag)
return;
#endif
// detect whether input signal is changing
if (!InputTimingChangeFlag)
{ if (SyncLossState())
{ if (!FreeRunModeFlag)
Set_InputTimingChangeFlag();
else if (mStar_SyncLossStateDetect()) // detect mode while no Sync/suspend/standby/disconnect
Set_InputTimingChangeFlag();
else if (InputTimingStableCounter)
{ // input timing is stable
if (InputTimingStableCounter%SwitchInputPortCount==0)
{ // switch input port while current port has no input.
// detection time for each port is programmable according to requirement
#if Dual_Input_Icon_Enable
if(!SwitchDelay)
{
SrcInputType= (SrcInputType+1)%Input_Nums;// timg MODIFY
mStar_SetupInputPort();
if (SrcInputType==Input_Digital)
mStar_AutoDVI(); //do auto tracking DVI
Set_DrawSourceTypeFlag();
}
SwitchDelay=0;
#endif
}
}
}
else // valid timing
{ // check if input timing is changing
if (mStar_ValidTimingDetect())
{ SrcFlags|=SyncLoss;
Set_InputTimingChangeFlag();
//printMsg("sail debug1!");
}
}
}
//=============================================================================
//=============================================================================
if (InputTimingChangeFlag) // input timing is unstable
{ Clr_InputTimingChangeFlag();
Clr_UnsupportedModeFreerunFlag();
Clr_DoModeSettingFlag();
TimingChangeDebunce++;
if (!SyncLossState())// && !InputTimingStableFlag) // prevent from SOG
{ if (TimingChangeDebunce<=6)
{ SrcFlags|=SyncLoss;
return;
}
}
mStar_PrepareForTimingChange();
// Power_TurnOffGreenLed(); // turn off green led
// Power_TurnOnAmberLed(); // turn on amber led
}
else // input timing is stable
{ TimingChangeDebunce=0;
InputTimingStableCounter++; // counter timing stable times
if (InputTimingStableCounter==0)
InputTimingStableCounter=1;
if (!InputTimingStableFlag)
{ if ((!SyncLossState() && InputTimingStableCounter>=ValidTimingStableCount) || // set timing stable flag
(SyncLossState() && InputTimingStableCounter>=SyncLossStableCount))
{ Set_InputTimingStableFlag();// set flag to search for input mode
Set_DoModeSettingFlag();
//printData("input timing stable %d", SrcInputType);
}
}
}
}
//*******************************************************************
// Function Name: mStar_ModeHandler
//
// Decscription: Programming scaler while input timing is changing
//
// callee: mStar_SyncLossStateDetect(), mStar_ValidTimingDetect(), mStar_AutoDVI() in detect.c
// mStar_SetInputPort(), mStar_SetAnalogInputPort() in mstar.c
//
// caller: main() in main.c
//*******************************************************************
void mStar_ModeHandler(void)
{
if (!DoModeSettingFlag) // while timing change & stable
return;
#if DISPLAYLOGO
if(DoDisplayLogoFlag)
return;
#endif
Clr_DoModeSettingFlag();
if (!SyncLossState()) // no sync
{
#if (NEWIC_18A||NEWIC_18B)//zwtan for tsu56ak
if (SrcInputType==Input_Digital)
{
CheckADC();
}
#endif
if (!mStar_FindMode()) // search mode index
{ Set_InputTimingChangeFlag(); // search mode faile
return;
}
if (!UnsupportedModeFlag) //supported mode
{
#if DEBUG_ENABLE
printData("input timing index = %d", SrcModeIndex);
#endif
ReadModeSetting(); // restore user's settings from NVRAM for each mode
if (mStar_SetupMode()==FALSE) // setup scaler
{ Set_InputTimingChangeFlag(); // setup mode failed
mStar_SetupFreeRunMode(); // setup freerun mode
#if DEBUG_ENABLE
printMsg("Failed to setup mode");
#endif
return;
}
if (UnsupportedModeFlag)
{
#if DEBUG_ENABLE
printMsg("Failed: Out of panel spec");
#endif
}
}
else
{
#if DEBUG_ENABLE
printMsg("unsupported mode");
#endif
}
}
if (SyncLossState() || UnsupportedModeFlag)
{
#if 0//OutRange_Display // if unsupport must to display sail modify 20040715
#if EnableVideo656Port
if((SrcInputType==Input_656Video) )
{
mStar_SetupFreeRunMode(); // setup freerun mode
// Power_TurnOffGreenLed(); // turn off green led
Power_TurnOnGreenLed(); // turn on green led
Power_TurnOnAmberLed(); // turn on amber led
}
else
#endif
{
if(UnsupportedModeFlag && VFreq(HFreq(SrcHPeriod), SrcVTotal)<865)
{
Init_ModeSetting();
if(HFreq(SrcHPeriod)>830 ||SrcModeIndex==36||(SrcModeIndex>39 && SrcModeIndex<44))
mStar_SetupFreeRunMode(); // setup freerun mode
else if (mStar_SetupMode()==FALSE) // setup scaler
{ Set_InputTimingChangeFlag(); // setup mode failed
mStar_SetupFreeRunMode(); // setup freerun mode
#if DEBUG_ENABLE
printMsg("Failed to setup mode");
#endif
return;
}
}
}
else
#endif
#if 0//(WidePanel||WidePanel_16_9)
if(UnsupportedModeFlag&&!UnsupportedModeFreerunFlag)
{
ReadModeSetting();
if (mStar_SetupMode()==FALSE)
{ Set_InputTimingChangeFlag();
mStar_SetupFreeRunMode();
return;
}
}
else
#endif
mStar_SetupFreeRunMode(); // setup freerun mode
if(UnsupportedModeFlag) //tony 20040113
{
Power_TurnOnGreenLed(); // turn off green led
Power_TurnOffAmberLed(); // turn on amber led
}
}
else
{ Power_TurnOnGreenLed(); // turn on green led
Power_TurnOffAmberLed(); // turn off amber led
}
if (!SyncLossState())
{
if (DoBurninModeFlag)
{ Clr_DoBurninModeFlag();
mStar_WriteByte(FWC, 0); // disable background color function.
}
}
else
{
if(FactoryModeFlag)
Set_DoBurninModeFlag();
}
Power_TurnOnPanel(); // turn on panel
Menu_InitAction(); // initial menu osd state
}
void mStar_PrepareForTimingChange(void)
{ Clr_ForcePowerSavingFlag();
PowerDownCounter=0;
if (PowerSavingFlag)
Power_PowerOnSystem();
else
#if (PanelAUEN05|PanelAUEG01|PanelAUEG01_v2) //xxxx 1204
{
hw_ClrBackLit();
Osd_Hide();
}
#else
Power_TurnOffPanel();
#endif
mStar_SetupFreeRunMode();
Osd_Hide();
#if UseINT
mStar_WriteByte(INTENA, 0);
#endif
if (InputTimingStableFlag)
{ mStar_WriteByte(SWRST, GPR_B);// Reset Graphic port to re-counter input hfreq & vtotal
Delay1ms(3);
mStar_WriteByte(SWRST, 0);
Delay1ms(20);
if (SrcInputType==Input_Digital)
{
#if NEWIC_18A
mStar_WriteByte(MISCFC, 0x28);
#else
mStar_WriteByte(MISCFC, 0x20);
#endif
mStar_AutoDVI();
}
}
Clr_InputTimingStableFlag(); // reset input timing stable and wait for timing stable
InputTimingStableCounter=0;
SrcFlags&=~(bUnsupportMode|bUserMode|bNativeMode);
mStar_WriteByte(DBFC, 0x00); // enable double bufer.
mStar_WriteByte(REGBK, REGBANKADC);
mStar_WriteByte(DBFC, 0x00); // enable ADC's double bufer.
mStar_WriteByte(REGBK, REGBANKSCALER);
}
//==========================================================
BYTE GetBestBandwidth(BYTE channel, BYTE *errA)
{ BYTE errB;
mStar_WriteByte(TESTEN, channel|ERRD_B); // set test channed
mStar_WriteByte(TESTEN, channel|TSTEN_B); // set test channed
mStar_WriteByte(TESTA0, 0x20); // set high bandwidth
mStar_WriteByte(TESTEN, channel); // set test channed
Delay1ms(1);
mStar_WriteByte(TESTEN, channel|ERRD_B); // set test channed
*errA=mStar_ReadByte(DVI_ERST);
mStar_WriteByte(TESTEN, channel|TSTEN_B); // set test channed
#if ChipID>=ChipAD
mStar_WriteByte(TESTA0, 0x08); // set medium bandwidth
#else
mStar_WriteByte(TESTA0, 0x00); // set medium bandwidth
#endif
mStar_WriteByte(TESTEN, channel); // set test channed
Delay1ms(1);
mStar_WriteByte(TESTEN, channel|ERRD_B); // set test channed
errB=mStar_ReadByte(DVI_ERST);
mStar_WriteByte(TESTEN, channel); // set test channed
#if ChipID>=ChipAD
if (*errA>errB)
{ *errA=errB;
return 0x8;
}
#else
if (*errA>errB)
{ *errA=errB;
return 0x0;
}
#endif
return 0x20;
}
BYTE mStar_FineTuneBandwidth(void)
{ BYTE errRed, bwRed;
BYTE errGreen, bwGreen;
BYTE errBlue, bwBlue;
bwRed=GetBestBandwidth(RED_CHANNEL, &errRed);
bwGreen=GetBestBandwidth(GREEN_CHANNEL, &errGreen);
bwBlue=GetBestBandwidth(BLUE_CHANNEL, &errBlue);
if (errRed>errGreen)
{ if (errGreen>errBlue)
return bwBlue;
else
return bwGreen;
}
else
{ if (errRed>errBlue)
return bwBlue;
else
return bwRed;
}
}
BYTE code DVIPhaseTbl[]=
{// 0 1 2 3 4 5 6 7 8 9
0x40, 0x01, 0x03, 0x07, 0x0F, 0x17, 0x13, 0x11, 0x10, 0x31,
0x33, 0x37, 0x3F, 0x27, 0x23, 0x21, 0x20, 0x61, 0x63, 0x67,
0x6F, 0x77, 0x73, 0x71, 0x70, 0x51, 0x53, 0x57, 0x5F, 0x47,
0x43, 0x41
};
BYTE code DVIPhaseTbl2[]=
{// 0 4 8 12 16 20 24 28
0x00, 0x1F, 0x30, 0x2F, 0x60, 0x7F, 0x50, 0x4F
};
BYTE GetLinearPhaseValue(BYTE value)
{ BYTE i;
for (i=0; i<0x20; i++)
if (DVIPhaseTbl[i]==value)
break;
if (i>=0x20)
{ for (i=0; i<8; i++)
if (DVIPhaseTbl2[i]==value)
break;
if (i>=8)
i=0;
else
i=i*4;
}
return i;
}
BYTE mStar_FineTuneDVIPhase(BYTE channelReg,BYTE channel)
{ BYTE phX, phY, phZ;
BYTE errX, errY, errZ;
mStar_WriteByte(TESTEN, channel|ERRD_B); // set test channed
mStar_WriteByte(TESTEN, channel); // set test channed
Delay1ms(1);
mStar_WriteByte(TESTEN, channel|ERRD_B); // set test channed
errX=mStar_ReadByte(DVI_ERST); // read error status X
if (errX==0)
return 0xFF;
phX=mStar_ReadByte(channelReg); // read phase X
phX=GetLinearPhaseValue(phX); // convert to linear Phase;
mStar_WriteByte(channelReg, DVIPhaseTbl[(phX+8)%0x20]); // write linear phase
mStar_WriteByte(TESTEN, channel); // set test channed
Delay1ms(1);
mStar_WriteByte(TESTEN, channel|ERRD_B); // set test channed
errY=mStar_ReadByte(DVI_ERST); // read error status X
if (errY==0)
return 0xFF;
phY=mStar_ReadByte(channelReg); // read phase X
phY=GetLinearPhaseValue(phY); // convert to linear Phase;
mStar_WriteByte(channelReg, DVIPhaseTbl[(phY+8)%0x20]); // write linear phase
mStar_WriteByte(TESTEN, channel); // set test channed
Delay1ms(1);
mStar_WriteByte(TESTEN, channel|ERRD_B); // set test channed
errZ=mStar_ReadByte(DVI_ERST); // read error status X
phZ=mStar_ReadByte(channelReg); // read phase X
phZ=GetLinearPhaseValue(phZ); // convert to linear Phase;
mStar_WriteByte(TESTEN, channel); // set test channed
if (errX>errY)
{ if (errY>errZ)
return phZ;
else
return phY;
}
else // X<Y
{ if (errX>errZ)
return phZ;
else
return phX;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -