📄 mode.c
字号:
startValue = madj_cnt;
#if DEBUGMSG
printf(" up, startValue = %d \n",(unsigned int)startValue);
#endif
}
#if DEBUGMSG
printf(" +1 ");
#endif
miscDClkUp(1);
madj_cnt++;
goto madj_next;
}
else
{
#if DEBUGMSG
printf(" -5 ");
#endif
findflag = 1;
miscDClkDown(5);
madj_cnt -= 5;
goto madj_next;
}
//down
madj_down:
#if DEBUGMSG
printf(" DClk- : ");
#endif
if(madj_cnt-- < -MADJ_LIMIT) {
goto madj_fail;
}
if (startValue != -128)
{
temp = madj_cnt;
#if DEBUGMSG
printf(" endValue = %d \n",(unsigned int)temp);
#endif
#if CHIMEI_M150X3
if (!(eepData.MascotFlag & FLAG_PORTB))
{
if((temp - startValue) < 2)
{
RegByteOut(0x41,RegByteIn(0x41)+1);
#if DEBUGMSG
printf("Htotal++ redo_madj\n");
#endif
goto redo_madj;
}
}
#endif
temp = (1+temp-startValue)/2 + 1;
#if DEBUGMSG
printf("ok -%d ",(unsigned int)temp);
#endif
miscDClkDown(temp);
RegByteOut(0xB0, 0x00);
return 1;
}
else
{
if(up && (step > 1))
step /=2;
#if DEBUGMSG
printf(" -%d ",(unsigned int)step);
#endif
madj_cnt -= step;
miscDClkDown(step);
}
up = 0;
down = 1;
miscDelay(1);
goto madj_next;
madj_fail:
#if DEBUGMSG
printf(" Fail: overlimit ");
#endif
RegByteOut(0xB0, 0x00);
return 0;
//up
madj_up:
#if DEBUGMSG
printf(" DClk+ : ");
#endif
if (madj_cnt > MADJ_LIMIT) {
goto madj_fail;
}
if (findflag)
{
madj_cnt += 1;
miscDClkUp(1);
}
else
{
if(down && (step > 1))
step /=2;
#if DEBUGMSG
printf(" +%d ",(unsigned int)step);
#endif
madj_cnt += step;
miscDClkUp(step);
}
up = 1;
down = 0;
miscDelay(1);
goto madj_next;
}
#endif //(!MODE_ADJ_BY_CALCULATE)
#if USE_TCON
#define DEF_FDE 3
#define CPV_VS 0x00
#define CPV_VE 0x02
#define POL_VS 0x58
#define POL_VE 0x5A
#define LP_VS 0x64
#define LP_VE 0x66
#define STV1_VS 0x08
#define STV1_VE 0x0A
#define STH1_VS 0x48
#define STH1_VE 0x4A
#define STV2_VS 0x10
#define STV2_VE 0x12
#define STV3_VS 0x18
#define STV3_VE 0x1A
#define STH8_VS 0x50
#define STH8_VE 0x52
#define OE1_VS 0x20
#define OE1_VE 0x22
#define OE2_VS 0x28
#define OE2_VE 0x2A
#define OE3_VS 0x30
#define OE3_VE 0x32
bit modeAdjustMVz(void)
{
extern unsigned char code initTCON[];
unsigned char data mjz_cnt, mjz_buff;
unsigned char data temp;
// Adjust DCLK in MV mode
#define FDE buff[0]
temp = CurrentMode & 0x7f;
//Adjust DCLK in MVZ mode
#if 1 //MVXPRL
RegBitOut(0x24, 0x80, 0xC0);
#else
RegBitOut(0x24, 0x00, 0xC0);
#endif
TconByteOut(0x6C, 0x83);
if (temp <= 12 )
TconByteOut(0x6C, 0x84);
#if (!USE_RSDS) //20030307
RegByteOut(0x46, 0x00);
RegByteOut(0x47,0xB0+(RegByteIn(0x47)&0x0F)) ;
RegWordOut(0x48, 0x0001);
RegByteOut(0x4A, 0x04);
#endif
miscDelay(30);
#if MODE_ADJ_BY_CALCULATE
if ( !fine() )
#else
if ( !modeAdjust() )
#endif
goto mjz_fail;
if (temp <= 12 )
{
FDE = 4;
goto mjz_done;
}
else
FDE = 3;
//mjz_retry:
for (mjz_cnt = 0; mjz_cnt < 10; mjz_cnt++)
{
TconByteOut(0x6C, FDE+0x80);
// miscDelay(50);
mjz_buff = checkFifoState();
if (mjz_buff == 0x01)
{
if (FDE > 7)
goto mjz_done;
FDE++;
}
else if (mjz_buff == 0x02)
{
if (FDE <= 2)
goto mjz_done;
FDE--;
}
else
goto mjz_done;
}
// goto mjz_retry;
mjz_done:
TconByteOut(0x6C, FDE+0x80);
PatchTconTable(FDE-DEF_FDE);
return 1;
mjz_fail:
return 0;
#undef FDE
}
void PatchTconTable(char delta)
{
extern unsigned char code initTCON[];
miscSwitchTCONReg(1);
ival = ((unsigned int)initTCON[STV1_VS+1]<<8) + initTCON[STV1_VS];
#if CPT_S15
RegWordOut(STV1_VS, ival+delta+1);
#else
RegWordOut(STV1_VS, ival+delta);
#endif
ival = ((unsigned int)initTCON[STV2_VS+1]<<8) + initTCON[STV2_VS];
RegWordOut(STV2_VS, ival+delta);
ival = ((unsigned int)initTCON[STV3_VS+1]<<8) + initTCON[STV3_VS];
RegWordOut(STV3_VS, ival+delta);
/*
ival = ((unsigned int)initTCON[CPV_VS+1]<<8) + initTCON[CPV_VS];
RegWordOut(CPV_VS, ival+delta);
ival = ((unsigned int)initTCON[OE1_VS+1]<<8) + initTCON[OE1_VS];
RegWordOut(OE1_VS, ival+delta);
ival = ((unsigned int)initTCON[OE2_VS+1]<<8) + initTCON[OE2_VS];
RegWordOut(OE2_VS, ival+delta);
ival = ((unsigned int)initTCON[OE3_VS+1]<<8) + initTCON[OE3_VS];
RegWordOut(OE3_VS, ival+delta);
ival = ((unsigned int)initTCON[CPH1_VS+1]<<8) + initTCON[CPH1_VS];
RegWordOut(CPH1_VS, ival+delta);
ival = ((unsigned int)initTCON[CPH2_VS+1]<<8) + initTCON[CPH2_VS];
RegWordOut(CPH2_VS, ival+delta);
ival = ((unsigned int)initTCON[STH1_VS+1]<<8) + initTCON[STH1_VS];
RegWordOut(STH1_VS, ival+delta);
ival = ((unsigned int)initTCON[STH8_VS+1]<<8) + initTCON[STH8_VS];
RegWordOut(STH8_VS, ival+delta);
ival = ((unsigned int)initTCON[POL_VS+1]<<8) + initTCON[POL_VS];
RegWordOut(POL_VS, ival+delta);
ival = ((unsigned int)initTCON[SHC_VS+1]<<8) + initTCON[SHC_VS];
RegWordOut(SHC_VS, ival+delta);
ival = ((unsigned int)initTCON[LP_VS+1]<<8) + initTCON[LP_VS];
RegWordOut(LP_VS, ival+delta);
*/
miscSwitchTCONReg(0);
}
unsigned char checkFifoState()
{
unsigned char i;
RegByteOut(0x02, 0x00);
RegByteOut(0xB0, 0x81);
for (i = 0; i < 200; i++) {
if (!(RegByteIn(0xB0)&0x80)) {
return (RegByteIn(0x02)&0x03);
}
}
return 0;
}
#endif
/*********************************************
* get default mode table *
**********************************************/
void getDefModeData(void)
{
unsigned char *regtbl;
regtbl = (ModeTbl[CurrentMode&0x7f].modeptr) + MODEHSTART;
eepModeData.def_hstart = eepModeData.hstart = ((unsigned int)*(regtbl+1)<<8) + *regtbl;
eepModeData.def_vstart = eepModeData.vstart = *(regtbl+2);
regtbl = ModeTbl[CurrentMode&0x7f].tdaptr;
eepModeData.def_pitch = eepModeData.pitch = ((*(regtbl+TDA_DIVH_OFF)&0x07)<<8) + *(regtbl+TDA_DIVL_OFF);
eepModeData.pitch_val = DEF_pitchval;
eepModeData.def_phase = eepModeData.phase = *(regtbl+TDA_PHASE_OFF);
eepModeData.auto_counter = 0;
eepModeData.dummy = 0xff;
#if (DEBUGMSG >= 2)
printf(" getDefModeData pitch=%x phase=%x\n",eepModeData.pitch,(unsigned int)eepModeData.phase);
#endif
}
/*
void freeRunMode(void)
{
freeRunFlag = 1;
#if PANEL_1280
TDADataTableOut(Mode48Tda);
RegDataTableOut(Mode1024Tbl);
#else
TDADataTableOut(Mode27Tda);
RegDataTableOut(Mode768Tbl);
#endif
RegBitOut(0x1b,0x40,0x40);
RegByteOut(0x40,0x60);
}
*/
void checkVtotal(void) //20030219
{
unsigned int vTotal;
if ((RegByteIn(0x0f)&0x03)!= 0x02)
return;
#if (DEBUGMSG>=2)
printf("\n checkVtotal --------------->");
#endif
RegByteOut(0xB1, 0x80); // use threshold
RegByteOut(0xB9, 0x30); // threshold value
RegByteOut(0xB2, COLORCMPMASK); // Set color compare mask
RegByteOut(0xB0, 0x01); // Enable total calibration
RegByteOut(0x00, 0x00); // Clear the calibration status reg
if ( waitCalibReady(0x01) )
{
RegDataIn(0xD0, buff+8, 3);
vTotal = ((unsigned int)(buff[10]&0x07)<<8) +buff[8];
}
#if (DEBUGMSG>=2)
printf(" vTotal = %d\n",vTotal);
#endif
RegByteOut(0xB0, 0x00); // Disable total calibration
RegByteOut(0x00, 0x00); // Clear the calibration status reg
if (vTotal < 30)
{
InputPolarity = 0x02;
RegBitOut(0x32,0x00,0x04);
RegBitOut(0x18,0x00,0x80);
}
}
#if CALCULATE_DCLK
void calculateDCLK(void)
{
unsigned long Fout;
unsigned char i;
buff[10] = EA;
EA = 0;
RegByteOut(0x09,1); //CR09, Vsync error
RegByteOut(0x0A,1); //CR0A, Hsync error
RegByteOut(0x01, 0x00);
miscDelay(60);
for (i = 0;i < 100; i++)
{
miscDelay(2);
if((RegByteIn(0x01)& 0x02))
break;
}
RegDataIn(0x0B, buff, 5);
VsyncCnt = buff[1]*0x100 + buff[0];
HsyncCnt = buff[3]*0x100 + buff[2];
RegByteOut(0x09,VERRORRANGE); //CR09, Vsync error
RegByteOut(0x0A,HERRORRANGE); //CR0A, Hsync error
EA = buff[10];
redo_DCLK:
checkModeChange(); // by seven 030718 for calculateDCLK()
if (modechangeflag) // by seven 030718 for calculateDCLK()
return;
Fout = HsyncCnt * 22.88853;
ival = ((unsigned int)RegByteIn(0x41) + 1) * 8;
#if DEBUGMSG
printf(" Hsync(i) = %ld, Htotal(o) = %d\n",Fout,ival);
#endif
Fout = Fout * ival / 1000;
ival = (unsigned int)(RegByteIn(0x3B) << 8) + RegByteIn(0x3A) + 1;
Fout *= PANEL_HEIGHT;
Fout /= ival;
#if DEBUGMSG
printf(" DCLK(o) ------------------> %ld\n",Fout);
#endif
ival = Fout % 6000;
if (ival > 5400 || ival < 600)
{
RegByteOut(0x41,RegByteIn(0x41)+1);
#if DEBUGMSG
printf(" redo DCLK\n");
#endif
goto redo_DCLK;
}
ival1 = Fout*0.021; //value of N
ival2 = ival1>>8;
RegByteOut(0x2B, 252);
RegByteOut(0x2C, (unsigned char)ival1);
RegByteOut(0x2D, (unsigned char)ival2);
RegByteOut(0x2E, 0x32);
RegByteOut(0x2F, 0x80);
}
#endif //CALCULATE_DCLK
#if MODE_ADJ_BY_CALCULATE
#define mt ival
#define nt ival1
#define NMUL 12 //12
#define MINM 0x4 //4
#define MAXM 0xFF //0xFF
#define STEPM 2
#define MAXN 0x7FF //0xFFF
#if PANEL_1280
#define ONELINEPIXELS 1314
#define ONELINEERROR 10
#else
#define ONELINEPIXELS 1072
#define ONELINEERROR 15
#endif
bit fineCalculateDCLK(void)
{
unsigned long F, fs, ft;
unsigned char M;
unsigned int N;
unsigned char i;
// return 1;
redo_fineDCLK:
checkModeChange(); // by seven 030718 for fineCalculateDCLK()
if (modechangeflag) // by seven 030718 for fineCalculateDCLK()
return 1;
//Read VsyncCnt and HsyncCnt
buff[10] = EA;
EA = 0;
RegByteOut(0x09,1); //CR09, Vsync error
RegByteOut(0x0A,1); //CR0A, Hsync error
RegByteOut(0x01, 0x00);
miscDelay(60);
for (i = 0;i < 100; i++)
{
miscDelay(2);
if((RegByteIn(0x01)& 0x02))
break;
}
RegDataIn(0x0B, buff, 5);
VsyncCnt = buff[1]*0x100 + buff[0];
HsyncCnt = buff[3]*0x100 + buff[2];
RegByteOut(0x09,VERRORRANGE); //CR09, Vsync error
RegByteOut(0x0A,HERRORRANGE); //CR0A, Hsync error
EA = buff[10];
//calculate Vtotal(i) and Vtotal(o)
ival1 = (((unsigned long)HsyncCnt * VsyncCnt) >> 13);
ival = (((unsigned long)HsyncCnt * VsyncCnt) % 8192);
if (ival > 4096) ival1++; // ival1 = Vtotal(i)
ival2 = (unsigned long)ival1 * PANEL_HEIGHT / CurrentHeight; // ival2 = Vtotal(o)
#if (DEBUGMSG >= 5)
printf(" Vtotal(i) = %d, Vtotal(o) = %d \n", ival1, ival2);
#endif
//get Vcount & Hcount
#if (USE_TCON + USE_RSDS)
RegBitOut(0x24,0xc0,0xc0);
miscDelay(100);
#endif
RegByteOut(0xb1,0x40);
miscDelay(100);
RegDataIn(0xf9,buff,3);
ival = (buff[0]<< 3) + (buff[2] & 0x07);
ival1 = (buff[1]<< 3) + ((buff[2]>>4) & 0x07);
RegByteOut(0xb1,0x00);
#if (USE_TCON + USE_RSDS)
#if 1 //MVXPRL
RegBitOut(0x24, 0x80, 0xC0);
#else
RegBitOut(0x24, 0x00, 0xC0);
#endif
#endif
#if (DEBUGMSG >= 5)
printf(" Vcount = %d, Hcount = %d ", ival, ival1);
#endif
if (ival1 >= ONELINEPIXELS+ONELINEERROR) ival--;
else if (ival1 >= ONELINEPIXELS-ONELINEERROR)
{
//-------------------------------------------------------------------------------------------
//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -