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

📄 autofunc.c

📁 完整的软件学习--显示器驱动视频软件
💻 C
📖 第 1 页 / 共 2 页
字号:
#include <math.h>
#include "types.h"
#include "board.h"
#include "global.h"
#include "ms_reg.h"
#include "adjust.h"
#include "ms_rwreg.h"
#include "misc.h"
#include "debug.h"
#include "power.h"
#include "debugdef.h"

#define UseWorstPhase	0
#define EvenClock		1
#define QuickAuto		1

#if (PanelHstSX84|PanelAU150XN07|PanelAUEN05)
#define ThresholdLevel 	6
#else
#define ThresholdLevel 	4
#endif

#define OverFlow			BIT7
#define NoneOverFlow	BIT6

#define UnderFlowR		BIT7
#define NoneUnderFlowR	BIT6
#define UnderFlowG		BIT5
#define NoneUnderFlowG	BIT4
#define UnderFlowB		BIT3
#define NoneUnderFlowB	BIT2

extern Bool CheckPowerKeyStatus(void);

//===============================================================
// local declaration
Bool mStar_AutoAdcColor(BYTE vsyncTime);

//===============================================================
// Code
Bool CheckSyncLoss(void)
{
#if UseINT
  if (InputTimingChangeFlag)
    { Power_TurnOffPanel();
      return TRUE;
    }
  else
    return FALSE;
#else
  Bool result=FALSE;

  if (abs(SrcHPeriod-mStar_ReadWord(HSPRD_H))>10)
    result=TRUE;
  else if (abs(SrcVTotal-mStar_ReadWord(VTOTAL_H))>10)
    result=TRUE;
  if (result)
    { Power_TurnOffPanel();
      Set_InputTimingChangeFlag();
    }
  return result;
#endif
}

void WaitAutoStatusReady(BYTE regAddr, BYTE regFlag)
{ BYTE waits=200;
  while (waits-- && !(mStar_ReadByte(regAddr)&regFlag));
}

WORD GetAutoValue(BYTE regAddr)
{ WaitAutoStatusReady(ATOCTRL, ATOR_B);
  return mStar_ReadWord(regAddr);
}

BYTE GetTranstionPosition(BYTE vsyncTime, BYTE regAddr)
{ BYTE retry=6;
  BYTE adjPhase;
  WORD pos;
  BYTE minPhase, maxPhase;

  maxPhase=0x3F;
  minPhase=0x0;
  mStar_AdjustPhase(0);
  Delay1ms(vsyncTime);
  pos=GetAutoValue(regAddr);
  adjPhase=(maxPhase+minPhase)/2;
  while (retry--)
    { mStar_AdjustPhase(adjPhase);
      Delay1ms(vsyncTime);
      if (GetAutoValue(regAddr)!=pos)
      	maxPhase=adjPhase;
      else
      	minPhase=adjPhase;
      adjPhase=(maxPhase+minPhase)/2;
      if (CheckSyncLoss())
       return FALSE;
    }
  //printData("trans phase %d", adjPhase);
  return (adjPhase);
}

#if !QuickAuto
BYTE AutoSetDataThreshold(BYTE vsyncTime)
{ BYTE thr;
  BYTE adjPhase;
  WORD regWord1, regWord2;

  for (thr=ThresholdLevel; thr<0x10; thr++)
    { mStar_WriteByte(AOVDV, thr<<4);
      mStar_AdjustPhase(0);
      Delay1ms(vsyncTime);
      WaitAutoStatusReady(ATOCTRL, ATOR_B);
      regWord1=mStar_ReadWord(AOHST_H);
      for (adjPhase=4; adjPhase<0x40; adjPhase+=4)
      	{ mStar_AdjustPhase(adjPhase);
          Delay1ms(vsyncTime);
          WaitAutoStatusReady(ATOCTRL, ATOR_B);
          regWord2=mStar_ReadWord(AOHST_H);
          if (abs(regWord1-regWord2)>3)
            break;
          if (CheckSyncLoss())
            return FALSE;
      	}
      if (adjPhase>=0x40)
      	break;
    }
  //printData("thr %d", thr);
  return thr;
}
#endif

WORD SearchMaxWidth(BYTE vsyncTime)
{ BYTE startPhase;
  WORD hStart, hEnd;

  vsyncTime*=2; //tony 20040228 
  mStar_AdjustPhase(0);
  Delay1ms(vsyncTime);
  Delay1ms(vsyncTime);
  hStart=GetAutoValue(AOHST_H);
//  printData("hStart %d", hStart);
  startPhase=GetTranstionPosition(vsyncTime, AOHST_H);
  hEnd=GetAutoValue(AOHEND_H);
//  printData("hEnd %d", hEnd);
  hStart=hEnd-hStart+1;

  return hStart;
}

Bool mStar_AutoHTotal(BYTE vsyncTime)
{ WORD tempHTotal;
  WORD autoWidth;
  BYTE result;

  // 1st to coast tune HTotal
  mStar_AdjustPhase(0);
  Delay1ms(vsyncTime);
  autoWidth=GetAutoValue(AOHEND_H)-GetAutoValue(AOHST_H);

  tempHTotal=StandardModeWidth/3;
  if (abs(autoWidth-StandardModeWidth)>tempHTotal)
    return FALSE;

  tempHTotal=UserPrefHTotal;
  if(SrcModeIndex>=6&&SrcModeIndex<=9&&abs(autoWidth-640)>80)
  goto AutoHTotalFailed;
  //printData("1st htotal %d", tempHTotal);
  //printData("1st max width %d", autoWidth);
  if (abs(autoWidth-StandardModeWidth)>1)
    { tempHTotal=(DWORD)UserPrefHTotal*StandardModeWidth/autoWidth;
      if (abs(tempHTotal-StandardModeHTotal)>60)
      	goto AutoHTotalFailed;
      mStar_AdjustHTotal(tempHTotal);
      //printData("2nd htotal %d", tempHTotal);
    }
  autoWidth=SearchMaxWidth(vsyncTime);
  //printData("2nd max width %d", autoWidth);
  // autoWidth=SearchMaxWidth(vsyncTime);
  // 2nd fine tune
  if (autoWidth!=StandardModeWidth)
    { 
      if (CheckPowerKeyStatus())
      	goto AutoHTotalFailed;
      tempHTotal=tempHTotal+(StandardModeWidth-autoWidth);
      mStar_AdjustHTotal(tempHTotal);
      autoWidth=SearchMaxWidth(vsyncTime);
      // printData("3rd htotal %d", tempHTotal);
      // printData("max width %d", autoWidth);
      tempHTotal=tempHTotal+(StandardModeWidth-autoWidth);
    }
  else if (tempHTotal&1)
    { WORD autoWidth2;

      if (CheckPowerKeyStatus())
      	goto AutoHTotalFailed;
      //tempHTotal=tempHTotal-1;
      mStar_AdjustHTotal(tempHTotal-1);
      autoWidth=SearchMaxWidth(vsyncTime);
      mStar_AdjustHTotal(tempHTotal+1);
      autoWidth2=SearchMaxWidth(vsyncTime);
      if (autoWidth2==StandardModeWidth)
        tempHTotal=tempHTotal+1;
      else if (autoWidth==StandardModeWidth)
        tempHTotal=tempHTotal-1;
      //printData("4th htotal %d", tempHTotal);
      //printData("4th max width %d", autoWidth);
      //printData("4th max width2 %d", autoWidth2);
    #if 0
      if (autoWidth!=StandardModeWidth)
        tempHTotal=tempHTotal+(StandardModeWidth-autoWidth);
    #endif
    }

#if EvenClock
 if (tempHTotal%4)
   tempHTotal=((tempHTotal+1)/4)*4;
#endif

AutoHTotalFailed:
  result=FALSE;
  if (abs(tempHTotal-StandardModeHTotal)<60)
    { UserPrefHTotal=tempHTotal;
      result=TRUE;
    }
  mStar_AdjustHTotal(UserPrefHTotal);
  mStar_AdjustPhase(UserPrefPhase);
  #if DEBUG_ENABLE
  printData("final htotal %d", UserPrefHTotal);
  #endif
  return result;
#undef result
}

Bool mStar_AutoPhase(BYTE vsyncTime)
{ BYTE adjPhase, i;
  BYTE bestPhase, bestPhase2;
  DWORD maxcksum, cksum;

  maxcksum=0;

#if 0//MSTMCU
    for (adjPhase=0; adjPhase<0x40; adjPhase+=3)
    { mStar_AdjustPhase(adjPhase);
      Delay1ms(vsyncTime);
      WaitAutoStatusReady(ATPCTRL, ATPR_B);
      cksum=mStar_ReadWord(ATPV4);
      cksum=(cksum<<16)|mStar_ReadWord(ATPV2);
      if (cksum>maxcksum)
      	{ maxcksum=cksum;
      	  bestPhase=adjPhase;
      	}
      if (CheckSyncLoss())//||CheckPowerKeyStatus())
      	return FALSE;
    }
//  printData("coast phase %d", bestPhase);
  // 2nd Search
  if (bestPhase<3)
    bestPhase=(bestPhase+61)%0x40; // 64-3
  else
    bestPhase-=3;
  maxcksum=0;
  for (adjPhase=bestPhase; adjPhase<bestPhase+5; adjPhase++)
    { i=adjPhase%0x40;
      mStar_AdjustPhase(i);
      Delay1ms(vsyncTime);
      WaitAutoStatusReady(ATPCTRL, ATPR_B);
      cksum=mStar_ReadWord(ATPV4);
      cksum=(cksum<<16)|mStar_ReadWord(ATPV2);
      if (cksum>maxcksum)
      	{ maxcksum=cksum;
      	  bestPhase2=i;
      	}
      if (CheckSyncLoss())//||CheckPowerKeyStatus())
      	return FALSE;
    }
  UserPrefPhase=bestPhase2;

#else
  for (adjPhase=0; adjPhase<0x40; adjPhase+=2)
    { mStar_AdjustPhase(adjPhase);
      Delay1ms(vsyncTime);
      WaitAutoStatusReady(ATPCTRL, ATPR_B);
      cksum=mStar_ReadWord(ATPV4);
      cksum=(cksum<<16)|mStar_ReadWord(ATPV2);
      if (cksum>maxcksum)
      	{ maxcksum=cksum;
      	  bestPhase=adjPhase;
      	}
      if (CheckSyncLoss()||CheckPowerKeyStatus())
      	return FALSE;
    }
  //printData("coast phase %d", bestPhase);
  // 2nd Search
  if (bestPhase<2)
    bestPhase=(bestPhase+62)%0x40;
  else
    bestPhase-=2;
  maxcksum=0;
  for (adjPhase=bestPhase; adjPhase<bestPhase+5; adjPhase++)
    { i=adjPhase%0x40;
      mStar_AdjustPhase(i);
      Delay1ms(vsyncTime);
      WaitAutoStatusReady(ATPCTRL, ATPR_B);
      cksum=mStar_ReadWord(ATPV4);
      cksum=(cksum<<16)|mStar_ReadWord(ATPV2);
      if (cksum>maxcksum)
      	{ maxcksum=cksum;
      	  bestPhase2=i;
      	}
      if (CheckSyncLoss()||CheckPowerKeyStatus())
      	return FALSE;
    }
  UserPrefPhase=bestPhase2;
#endif

#if (XGA | PanelAUEN05|PanelAUEG01|PanelAUEG01_v2) //for 256 gray central line 20031226  // add for AUEN05 (sail 200400512)
  if(SrcModeIndex>=17&&SrcModeIndex<=20)
  	{
  		//printData("UserPref1 %d", UserPrefPhase);
  		UserPrefPhase+=64;
		if((mStar_ReadWord(ATPV4)<=0x17)&&(mStar_ReadWord(ATPV4)>=0x11))
		{
		//tony 20040305
    		mStar_WriteByte(REGBK, REGBANKADC);
		mStar_WriteByte(HS_LVL,((mStar_ReadByte(HS_LVL)&0x1f)|0x60));
    		mStar_WriteByte(REGBK, REGBANKSCALER);	
		UserPrefPhase-=10;
		}
		UserPrefPhase=UserPrefPhase%64;
		//printData("UserPref2 %d", UserPrefPhase);		
  	}
#endif

  mStar_AdjustPhase(UserPrefPhase);
#if DEBUG_ENABLE
  printData("final phase %d", UserPrefPhase);
#endif
  return bestPhase;
}

void mStar_AutoPosition(void)
{ WORD height, width;
  WORD actHeight;
  WORD hStart, vStart;

  hStart=GetAutoValue(AOHST_H);
  vStart=GetAutoValue(AOVST_H);
  
  // if No data, we will get 0x7ff hStart position
  if (hStart>StandardModeWidth || vStart>StandardModeHeight)
    return;
  
  width=GetAutoValue(AOHEND_H)-hStart+1;
  height=GetAutoValue(AOVEND_H)-vStart;
  
  actHeight=mStar_ReadWord(SPRVDC_H);
  
  if (UserModeFlag)
    { if (height<(StandardModeHeight*2/3) ||    width<(StandardModeWidth*2/3))
        return;
    }
  else if (height<(StandardModeHeight-80) ||    width<(StandardModeWidth-120))
    { return;
    }

  if (actHeight>height) //if partial expansion, keep the vertical position in center
    { height=(actHeight-height)/2;
      if (vStart>height)
        UserPrefVStart=vStart-height;
      else
      UserPrefVStart=0;
    }

  UserPrefHStart=hStart;
  if (SrcInputType==Input_Digital)
    UserPrefHStart-=0x10;
  
    
  mStar_WriteWord(SPRHST_H, UserPrefHStart);
#if WidePanel      // sail add
  	mStar_WriteWord(SPRVST_H, UserPrefVStart-BlackVstartOffset);
#else  	
  	 mStar_WriteWord(SPRVST_H, UserPrefVStart);
#endif  
}
//=================================================================================
//=================================================================================
// Auto Color Setting
Bool mStar_AutoAdjustAdcGain(BYTE vsyncTime)
{ BYTE rGain, gGain, bGain;
  BYTE maxRGain, maxGGain, maxBGain;
  BYTE minRGain, minGGain, minBGain;

⌨️ 快捷键说明

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