📄 mstar.c
字号:
#include <math.h>
#include "types.h"
#include "board.h"
#include "ms_reg.h"
#include "global.h"
#include "panel.h"
#include "adjust.h"
#include "ms_rwreg.h"
#include "debug.h"
#include "misc.h"
#include "ddc.h"
#include "power.h"
#include "detect.h"
#include "msOsd.h"
#include "gamma.h"
//*******************************************************************
//
// Constant Definition
//
//*******************************************************************
#define ADC2Sets 0// 1 for chip with 2 ADC(9x5x & 9x4x)
#define FixDClk 0
#define OutDClk1 108
#define OutDClk2 135
#if PanelLVDS
//14.318 * 15 * 8 / 3.5 = 490.9, 490.9<<19=257374477.16, 490.9<<3=8=3927
#define DClkFactor 257374477ul
//#define DClkFactor 257650102// use 215 as base
#else
//14.318 * 15 * 8 / 4 = 429.54, 429.54<<19=225202667.52, 429.54<<3=8=3436.32
#define DClkFactor 225202667ul
//#define DClkFactor 257650102// use 215 as base
#endif
#define FreeRunDClk (DWORD)DClkFactor/PanelDCLK
#define UseNewPanelTiming 0
#if UseNewPanelTiming
typedef struct
{ BYTE Flags;
WORD expHTotal;
WORD MST_Clock_MHz;
WORD srcHPeriod;
WORD PnlWidth;
WORD PnlHeight;
BYTE PnlMaxDClk;
} OutputFactorType;
extern Bool SetOutputDClk(OutputFactorType *OutputFactor, DWORD *factor);
#endif
//*******************************************************************
//
// local declaration
//
//*******************************************************************
void mStar_SetupInputPort(void);
void mStar_SetupFreeRunMode(void);
void mStar_SetupADC(void);
Bool mStar_SetCaptureWindow(void);
void mStar_SetScalingFactor(void);
void mStar_SetupPattern(void);
Bool mStar_SetPanelTiming(void);
void mStar_InitADC(void);
void mStar_InitTCON(void);
void mStar_SetScalingFilter(BYTE filter);
void mStar_SetUserPref(void);
void mStar_ResetDClkPLL(void);
void CheckLineBuffer(void);
void FixShortLine_LG(void);
void FixShortLine(void);
//jon add
void CheckLineBuffer(void); //ASW 0721 solve dos-mode line-buffer over
//*******************************************************************
//
extern WORD testValue;
//*******************************************************************
// Function Name: mStar_Init(void)
//
// Description: Initialize mStar chip while 1st power on system
//
// Caller: mStar_InitADC(), mStar_InitTCON, mStar_SetupFreeRunMode()
// mStar_SetupInputPort() in mStar.c
// mStar_WriteByte(), mStar_WriteWord() in ms_rwreg.c
// mStar_WriteDDC1(), mStar_WriteDDC2() in ddc.c
// mStar_InitGamma() in gamma.c
// Osd_InitOSD() in osd.c
// Callee: Init_Device() in main.c
//*******************************************************************
void mStar_Init(void)
{
//printMsg("Start : Initial Scaler");
Set_ms_ResetZ(); // reset chipset
Delay1ms(5);
Clr_ms_ResetZ();
// Initialize Scaler block
mStar_WriteByte(REGBK, REGBANKSCALER);
// power down contorl 0xF0~0xF1
mStar_WriteByte(PDMD, 0x00); // power up chip
mStar_WriteByte(TEST, 0x00); // ???? important
mStar_WriteByte(SWRST, 0x3F); // software reset
Delay1ms(1);
mStar_WriteByte(SWRST, 0x00); // software reset
mStar_WriteByte(DBFC, 0);
//=========================================================================
// display timing
// output DE size // 0x10~0x17
mStar_WriteWord(DEVST_H, 0); // Vert. DE start
mStar_WriteWord(DEVEND_H, PanelHeight-1); // Vert. DE end
mStar_WriteWord(DEHST_H, PanelHStart); // Hor. DE start
mStar_WriteWord(DEHEND_H, PanelHStart+PanelWidth-1); // Hor. DE end
// Scaling Image window size 0x18~0x1D
mStar_WriteWord(SIHST_H, PanelHStart);
mStar_WriteWord(SIHEND_H, PanelHStart+PanelWidth-1);
mStar_WriteWord(SIVEND_H, PanelHeight-1);
// Output Sync Timing //0x1E~0x26
mStar_WriteWord(VDTOT_H, PanelVTotal); // output vtotal
mStar_WriteWord(VSST_H, PanelVTotal-PanelVStart); // vsync start
mStar_WriteWord(VSEND_H, PanelVTotal-PanelVSyncBackPorch); //vsync end
mStar_WriteWord(HDTOT_H, PanelHTotal); // output htotal
mStar_WriteByte(HSEND, PanelHSyncWidth-1); //
mStar_WriteByte(OSCCTRL1, LCM_B|HSRM_B|AHRT_B|CTRL_B); // enable auto-htotal
mStar_WriteByte(OSCCTRL2, ATEN2_B); // setup clock mode
// output control // 0x42~0x44
mStar_WriteByte(OCTRL1, (LTIM_B&LVDS_TIMode)|(PanelSwapOddRB&ORBX_B)|(PanelSwapEvenRB&ERBX_B)| // setup output port
(PanelSwapMLSB&MLXT_B)|(PanelSwapOddML&OMLX_B)|(PanelSwapEvenML&EMLX_B)); // setup
#if PanelRSDS
mStar_WriteByte(OCTRL2, TCOP_B | (PanelDualPort&DPO_B)|(PanelSwapPort&DPX_B));
mStar_WriteByte(OCTRL3, 0x1D); // RSDS output with all GPO
#elif PanelLVDS
mStar_WriteByte(OCTRL2, (PanelDualPort&DPO_B)|(PanelSwapPort&DPX_B));
mStar_WriteByte(OCTRL3, ENRT_B); // LVDS output
#elif PanelTTL
mStar_WriteByte(OCTRL2, (PanelDualPort&DPO_B)|(PanelSwapPort&DPX_B));
mStar_WriteByte(OCTRL3, 0); // TTL Output
#endif
// output signal control 0xF2
//mStar_WriteByte(OSCTRL, 0x00); // output signal polarity control
mStar_WriteByte(OSCTRL, (PanelDClkDelay<<4)|(OCLK_B&PanelInvDClk)|(ODE_B&PanelInvDE)|
(OVS_B&PanelInvVSync)|(OHS_B&PanelInvHSync)); // output signal polarity control
// output driving current 0xF5
mStar_WriteByte(ODRV, PanelDCLKCurrent<<6|PanelDECurrent<<4|PanelOddDataCurrent<<2|PanelEvenDataCurrent); // setup output driving current
//=========================================================================
// Clock generator control 0xD0~0xDB
mStar_WriteByte(PLLCTRL1, 0x00); //
#if PanelCPT17EA03R
mStar_WriteByte(PLLCTRL2, 0x80); // Barry1030
mStar_WriteByte(MDCTRL, 0x80); // Barry1030
#else
mStar_WriteByte(PLLCTRL2, 0x00); // setup output pll & master pll
#endif
// Master PLL
mStar_WriteByte(MPLL_M, 0x6F); // set master pll as 215 MHz & drive current
// output dclk setting
mStar_WriteByte(LPLL_M, 0x48);//0x42); // output pll spread spectrum control
#if PanelLVDS
mStar_WriteByte(LPLL_CTL2, 0x1B);//0x0B); // output pll type & divider
#else //select Output PLL type BIT5
mStar_WriteByte(LPLL_CTL2, 0x3B);//0x2B); // output pll type & divider
#endif
#if PanelRSDS
// Spectrum control
mStar_WriteWord(LPLL_STEP_H, 0x151);
mStar_WriteWord(LPLL_SPAN_H, 0x3d);
#else
mStar_WriteWord(LPLL_STEP_H, 0x79);//0x14);
mStar_WriteWord(LPLL_SPAN_H, 0x128);//0x2c);
#endif
// Dither control //0x36~0x38
#if PanelDither==6
#if PanelAURSDS
mStar_WriteByte(DITHCTRL, 0x03);
#elif PanelQDIRSDS
mStar_WriteByte(DITHCTRL, 0x01);
#elif PanelCPTRSDS
//mStar_WriteByte(DITHCTRL, 0x01);
mStar_WriteByte(DITHCTRL, 0x45); //barry1113
#endif
#else
mStar_WriteByte(DITHCTRL, 0x0C); //0x01 sophie 2005.04.25
#endif
mStar_WriteByte(DITHCOEF, 0x2D);//0x22 sophie 2005.04.25
mStar_WriteByte(TRFN, 0x32); // dither method//0x22 sophie 2005.04.25
//barry1113 2->32
//====================================================================
mStar_WriteByte(DDCCTRL, 0x00); // DDC control
// display port
// brightness 0x2A~0x2D
#if !UsePWMBrightness
mStar_WriteByte(BRC, BRC_B); // disable birghtness control
#else
mStar_WriteByte(BRC, BRC_B); // disable birghtness control
#endif
// contrast 0x2E~0x31
mStar_WriteByte(CNTR, CNTR_B); // enable contrast function and set 0 as center
// border color 0x32~0x35
mStar_WriteByte(FWC, 0);//FWC_B); // panel background color
// mStar_SetScalingFilter(2);
#if UsesRGB
mStar_WriteByte(FTAPEN, 0x02); // enable srgb function
#else
// Filter coefficient(sharpness) 0x65~0x69
mStar_WriteByte(FTAPEN, 0x01);//2); // enable srgb function
mStar_WriteByte(FTAPC1, 0x00);
mStar_WriteByte(FTAPC2, 0x40);
mStar_WriteByte(FTAPC3, 0x88);
mStar_WriteByte(FTAPC4, 0x48);
#endif
// Auto Adjustment 0x78~
mStar_WriteByte(ATOCTRL, 0x1); // enable auto position
mStar_WriteByte(ATPCTRL, 0x19); // enable auto phase
mStar_WriteByte(ATGCTRL, 0);//011); // enable auto Gain
#if PanelCPT17EA03R
mStar_WriteByte(ATPTH, 0x10); // enable auto phase
#else
mStar_WriteByte(ATPTH, 0x1C); // enable auto phase
#endif
// VSync Status
mStar_WriteByte(LHMARGIN, 0x30);
mStar_WriteByte(LSMARGIN, 0x20);
// interrupt control
mStar_WriteByte(INTCTRL, 0x20);
mStar_WriteByte(INTPULSE, 0x0F);
mStar_WriteByte(INTENA, 0);
mStar_WriteByte(HSTOL, 1);//10);
mStar_WriteByte(VSTOL, 1);//5);
//========================================================
//=======================================================
mStar_InitADC();
mStar_InitTCON();
mStar_SetupFreeRunMode();
// PWM control 0xC3
mStar_WriteByte(PWM0C, 0x7F);
/*
mStar_AdjustVolume(UserPrefVolume);
if (!AudioMuteOnFlag)
{
hw_ClrMute();
}
else
hw_SetMute();
*/
mStar_SetupInputPort();
mStar_SetUserPref();
Osd_InitOSD();
mStar_AdjustOffset();
mStar_WriteDDC1(); // programming DDC1 inside chip
mStar_WriteDDC2(); // programming DDC2 inside chip
mStar_InitGamma(); // programming gamma table
//printMsg("End : Initial Scaler");
// mStar_SetupPattern();
}
//*******************************************************************
// Function Name: mStar_SetupMode
//
// Decscription: setup registers for input timing,
// return : TRUE,
// caller: mStar_SetupADC(), mStar_SetupCaptureWindow(),
// mStar_SetScalingFactor(), mStar_SetPanelTiming(),
// mStar_SetUserPref() in mstar.c
// mStar_FineTuneDVIPhase(), mStar_ValidTimingDetect() in detect.c
// mSar_WriteByte(), mStar_ReadByte() in ms_rwreg.c
// callee: mStar_ModeHandler() in detect.c
//*******************************************************************
Bool mStar_SetupMode(void)
{
mStar_SetupADC(); // setup ADC block, including polarity & htotal, phase, vco
if (mStar_SetCaptureWindow()==FALSE) // setup capture window
return FALSE;
mStar_SetScalingFactor(); // setup scaling factor
if (mStar_SetPanelTiming()==FALSE) // set output dclk
return TRUE;
if (mStar_ReadWord(SPRHDC_H)==PanelWidth && mStar_ReadWord(SPRVDC_H)==PanelHeight)
mStar_SetScalingFilter(0); // programming sharpness
else
mStar_SetScalingFilter(2);//UserPrefSharpness); // programming sharpness
// fine Tune DVI phase to get more stable DVI
if (SrcInputType==Input_Digital)
{ BYTE dviPhase;
mStar_WriteByte(REGBK, REGBANKADC); // switch to ADC bank
// fine turn DVI phase--Red Channel
dviPhase=mStar_FineTuneDVIPhase(DVI_PHR, RED_CHANNEL);
if (dviPhase<0xFF)
mStar_WriteByte(DVI_PHR, DVIPhaseTbl[dviPhase]);
// fine turn DVI phase--Green Channel
dviPhase=mStar_FineTuneDVIPhase(DVI_PHG, GREEN_CHANNEL);
if (dviPhase<0xFF)
mStar_WriteByte(DVI_PHG, DVIPhaseTbl[dviPhase]);
// fine turn DVI phase--Blue Channel
dviPhase=mStar_FineTuneDVIPhase(DVI_PHB, BLUE_CHANNEL);
if (dviPhase<0xFF)
mStar_WriteByte(DVI_PHB, DVIPhaseTbl[dviPhase]);
mStar_WriteByte(REGBK, REGBANKSCALER); // switch to Scaler bank
mStar_WriteByte(MISCFC, 0x30); // enable vsync glitch & protect to make more DVI stable
}
mStar_WriteWord(VDTOT_H, 0x7FF);
if (mStar_ValidTimingDetect() || InputTimingChangeFlag) // check if input timing has changed
return FALSE;
//jon add
#if Giotto
CheckLineBuffer(); //ASW 0721 solve dos-mode line-buffer over
#endif
#if ChipID==ChipBB
CheckLineBuffer();
#endif
// enable double buffer
mStar_WriteByte(DBFC, 0x05); // enable double bufer.
mStar_WriteByte(REGBK, REGBANKADC);
mStar_WriteByte(DBFC, 0x01); // enable ADC's double bufer.
mStar_WriteByte(REGBK, REGBANKSCALER);
mStar_SetUserPref(); // restore user setting
if (BurninModeFlag) //barry1215 disable burning when singal input
{ Clr_BurninModeFlag();
Clr_DoBurninModeFlag();
mStar_WriteByte(FWC, 0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -