📄 osdtune.02
字号:
/************************************************
* *
* OSDTUNE.C: Auto tuning From David *
* *
*************************************************/
#include <reg51.h>
#include <math.h>
#include "MOSAIC.h"
#include "busio.h"
#include "OSD.h"
extern unsigned char idata buff[];
extern unsigned int idata ival,ival1,ival2;
extern EepData idata eepData;
extern EepModeData idata eepModeData;
extern MODETBL code ModeTbl[];
extern EepData code defeepData;
extern bit CalibSuccess;
extern bit PresetModeFlag;
extern unsigned int idata DefaultPitch;
extern unsigned char idata DefaultPhase;
extern unsigned char data CurrentMode; // current mode #
extern unsigned int idata HsyncCnt, VsyncCnt;
bit autoTuningFlag = 0;
unsigned int hTotal;
unsigned char phaseError;
unsigned char phaseHwStart;
unsigned char phaseHwEnd;
char calibStatus;
void initCalibration(void);
void hvCalibration(unsigned char);
char pitchCalibration(bit);
void phaseHWCalibration(void);
char phaseCalibration(unsigned char);
void phaseMaxCalibration(unsigned char);
char waitCalibReady(unsigned char);
char waitCalibReady1(unsigned char);
void checkPowerOffButton(void);
void pitchPatch(void);
/******************************************
* Auto Tuning Adjustment *
*******************************************/
void autoTune(unsigned char options)
{
#if DEBUGMSG
printf("AutoTune\n");
#endif
setColorRGB(); //def
RegByteOut(0xB0, 0x00); // Disable calibration
CalibSuccess = 1;
if (options & OPTIONPITCH) {
miscSetADCPitch(DefaultPitch); //+40
}
if (options & OPTIONPHASE) {
miscSetADCPhase(DefaultPhase);
}
autoTuningFlag = 1;
// tune HV
if (options & OPTIONCENTER) {
initCalibration();
hvCalibration(options);
}
checkPowerOffButton();
if (!(eepData.MascotFlag & FLAG_POWERSTATUS)) return;
// tune pitch and phaseHW
if (options & OPTIONPITCH) {
pitchCalibration(DEF_DATA); // tune pitch
if (!(eepData.MascotFlag & FLAG_POWERSTATUS)) return;
phaseHWCalibration(); // tune phase
if (!(eepData.MascotFlag & FLAG_POWERSTATUS)) return;
if(pitchCalibration(EEP_DATA)) // tune pitch
{
if (!(eepData.MascotFlag & FLAG_POWERSTATUS)) return;
phaseHWCalibration(); // tune phase
if(pitchCalibration(EEP_DATA)) // tune pitch
{
if (!(eepData.MascotFlag & FLAG_POWERSTATUS)) return;
phaseHWCalibration(); // tune phase
}
}
}
checkPowerOffButton();
if (!(eepData.MascotFlag & FLAG_POWERSTATUS)) return;
// tune phase
#if DETAIL_AUTOTUNE
if ((options & OPTIONPHASE)&&(!(options & OPTIONFAST))) {
phaseError = 8;
phaseCalibration(0x07);
}
checkPowerOffButton();
if (!(eepData.MascotFlag & FLAG_POWERSTATUS)) return;
#endif
// tune HV
if (options & OPTIONCENTER) {
initCalibration();
hvCalibration(options);
}
autoTuningFlag = 0;
checkPowerOffButton();
if (!(eepData.MascotFlag & FLAG_POWERSTATUS)) return;
/* enable mode table adjustment flag */
updateModeData();
setColorRGB(); //eep // restore ADC setting
#if DEBUGMSG
printf("AutoTune %s\n", CalibSuccess?"DONE":"FAIL");
#endif
}
/************************************************
* initial Calibration setting *
*************************************************/
#define VCALSTART 3
#define HCALSTART (4*8+4)
#define HLIMIT 100 //(CurrentWidth>>4)
#define VLIMIT 100 //(CurrentHeight>>3)
void initCalibration(void)
{
unsigned int vTotal;
unsigned char *regtbl;
// set start position to default
regtbl = (ModeTbl[CurrentMode&0x7f].modeptr) + MODEHSTART;
RegDataOut(0x34, regtbl, 4);
// RegBitOut(0x32,0x04,0x06);
// Get H/V total
#if (DEBUGMSG>=2)
printf("\n -------- Total Calib,\n");
#endif
//resetting:
RegByteOut(0xB1, 0x00);
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);
hTotal = ((unsigned int)(buff[10]&0x70)<<4) +buff[9];
vTotal = ((unsigned int)(buff[10]&0x07)<<8) +buff[8];
}
/*
if (hTotal < CurrentWidth)
{
RegByteOut(0x32,(RegByteIn(0x32)^0x02));
#if (DEBUGMSG>=2)
printf("resetting hTotal\n");
#endif
goto resetting;
}
if (vTotal < CurrentHeight)
{
RegByteOut(0x32,(RegByteIn(0x32)^0x04));
#if (DEBUGMSG>=2)
printf("resetting vTotal\n");
#endif
goto resetting;
}
*/
#if (DEBUGMSG>=2)
printf("hTotal=%04X/%d vTotal=%04X/%d\n", hTotal,hTotal,vTotal,vTotal);
#endif
// Set cal area
buff[8] = HCALSTART; // Cal H Start [7:0]
buff[9] = hTotal; // Cal H End [7:0]
buff[10] = ((hTotal>>4)&0xF0)+((HCALSTART>>8)&0x0F);//Cal H Start/End [10:8]
buff[11] = VCALSTART; // Cal V Start [7:0]
buff[12] = vTotal; // Cal V End [7:0]
buff[13] = ((vTotal>>4)&0xF0)+((VCALSTART>>8)&0x0F);//Cal V Start/End [10:8]
RegDataOut(0xB3, buff+8, 6);
}
/************************************************
* Vertical Calibration *
*************************************************/
#define VCALSTART 3
#define HCALSTART (4*8+4)
#define HLIMIT 100 //(CurrentWidth>>4)
#define VLIMIT 100 //(CurrentHeight>>3)
#define hStart ival1
#define hWidth ival2
void hvCalibration(unsigned char options)
{
unsigned int vStart,vHeight;
RegByteOut(0xB0, 0x02); // Enable vertical calibration
RegByteOut(0x00, 0x00); // Clear the calibration status reg
if (!waitCalibReady(0x02))
{
CalibSuccess = 0;
goto hvcalib_ret;
}
RegByteOut(0xB0, 0x04);
RegByteOut(0x00, 0x00); // Clear the calibration status reg
if (!waitCalibReady(0x04))
if (!waitCalibReady(0x02))
{
CalibSuccess = 0;
goto hvcalib_ret;
}
RegDataIn(0xD3, buff, 5);
RegDataIn(0xF9, buff+5, 5);
hStart = ((unsigned int)(buff[2]&0x07)<<8) + buff[0];
hWidth = ((unsigned int)(buff[7]&0x70)<<4) + buff[6] - hStart + 1;
vStart = ((unsigned int)(buff[4]&0x07)<<8) + buff[3];
vHeight= ((unsigned int)(buff[9]&0x07)<<8) + buff[8] - vStart + 1;
#if (DEBUGMSG>=3)
printf(" hStart = %d, hWidth = %d, vStart = %d, vHeight = %d\n",hStart,hWidth,vStart,vHeight);
#endif
// Vertical calibration
if (!(options & OPTIONVERT))
goto hcalib;
#if (DEBUGMSG>=2)
printf(" V Calib, ");
#endif
if (vStart < VCALSTART) {
#if DEBUGMSG
printf(" Error: vStart < VCALSTART ");
#endif
goto vcal_fail;
}
#if 0
if ( vHeight < CurrentHeight - VLIMIT) {
#if DEBUGMSG
printf(" Error:vHeight out of VLIMIT");
#endif
goto vcal_fail;
}
#endif
if (vStart <= MIN_vstart && vStart>=MAX_vstart ) {
#if DEBUGMSG
printf(" Error:vStart out of range ");
#endif
goto vcal_fail;
}
#if MASCOT2_R3
if (RegByteIn(0x24) & 0x02) vStart -= 1; //USE_MINIFY
#endif
if ((CurrentMode == 0x00)||(CurrentMode == 0x1a)||(CurrentMode == 0x80)||(CurrentMode == 0x9a))
vStart -= 24; //640x350
eepModeData.setData.vstart = vStart;
eepModeData.setData.def_vstart = vStart;
goto vcal_done;
vcal_fail:
CalibSuccess = 0;
vcal_done:
RegByteOut(0x36, eepModeData.setData.vstart);
RegByteOut(0x37, 0);
#if (DEBUGMSG>=2)
printf("VS=%04X\n", eepModeData.setData.vstart);
#endif
// Horizontal calibration
hcalib:
if (!(options & OPTIONHORT))
goto hvcalib_ret;
#if (DEBUGMSG>=2)
printf(" H Calib, ");
#endif
if (hStart < HCALSTART) {
#if DEBUGMSG
printf(" Error: hStart < HCALSTART ");
#endif
goto hcal_fail;
}
if (hWidth < CurrentWidth - HLIMIT) {
#if DEBUGMSG
printf(" Error:hWidth out of HLIMIT");
#endif
goto hcal_fail;
}
if (hStart <= MIN_hstart && hStart>=MAX_hstart ) {
#if DEBUGMSG
printf(" Error:hStart out of range ");
#endif
goto hcal_fail;
}
eepModeData.setData.hstart = hStart;
eepModeData.setData.def_hstart = hStart;
goto hcal_done;
hcal_fail:
CalibSuccess = 0;
hcal_done:
RegByteOut(0x34, (unsigned char)eepModeData.setData.hstart);
RegByteOut(0x35, (unsigned char)(eepModeData.setData.hstart>>8));
#if (DEBUGMSG>=2)
printf("HS=%04X HW=%d\n", eepModeData.setData.hstart, hWidth);
#endif
hvcalib_ret:
/* Disable vertical calibration */
RegByteOut(0xB0, 0x00);
}
#undef hStart
#undef hWidth
/************************************************
* Pitch Calibration *
*************************************************/
#define hStart ival1
#define hWidth ival2
#define adjust_limit buff[12]
#define CHANGE 1
#define NOCHANGE 0
char pitchCalibration(bit flag)
{
unsigned int pitch,tpitch0;
bit up = 0,dn = 0;
#if (DEBUGMSG>=2)
printf("\n--------------- Pitch Calib\n");
#endif
if ( !CalibSuccess ) return NOCHANGE;
adjust_limit = (unsigned char)((CurrentWidth >> 4)+10);
#if MRT_VITESSE2
pitch = (flag == EEP_DATA) ? eepModeData.setData.pitch : DefaultPitch;
tpitch0 = pitch;
#endif
#if DO_COMPSYNC
if(RegByteIn(0x07)& 0x01)
RegByteOut(0xB2, 0x80); // Set color compare mask 0x80
else
#endif
RegByteOut(0xB2,COLORCMPMASK); // Set color compare mask 0xc0
RegByteOut(0xB0, 0x04); // Enable vertical calibration
miscSetADCPitch(pitch);
pitchcal0:
if (adjust_limit-- == 0) {
#if DEBUGMSG
printf(" ERROR: over limit\n");
#endif
goto pitchcal_fail;
}
miscSetADCPitch(pitch);
pitchcal1:
checkPowerOffButton(); //in pitchCalib
if (!(eepData.MascotFlag & FLAG_POWERSTATUS)) goto pitchcal_fail;
RegByteOut(0xB0, 0x02); // Enable vertical calibration
RegByteOut(0x00, 0x00); // Clear the calibration status reg
if (!waitCalibReady(0x02)) goto pitchcal_fail;
RegByteOut(0xB0, 0x04);
RegByteOut(0x00, 0x00); // Clear the calibration status reg
if (!waitCalibReady(0x04)) goto pitchcal_fail;
RegDataIn(0xD3, buff, 5);
RegDataIn(0xF9, buff+5, 5);
hStart = ((unsigned int)(buff[2]&0x07)<<8) + buff[0];
hWidth = ((unsigned int)(buff[7]&0x70)<<4) + buff[6] - hStart + 1;
#if 1
#if (DEBUGMSG>=3)
printf(" hStart = %d , hWidth = %d \n",hStart,hWidth);
#endif
#else
#if (DEBUGMSG>=3)
printf(" (%04X %04X)-(%04X %04X)",
((unsigned int)(buff[2]&0x07)<<8)+buff[0],
((unsigned int)(buff[4]&0x07)<<8)+buff[3],
((unsigned int)(buff[2]&0x70)<<4)+buff[1],
((unsigned int)(buff[4]&0x07)<<8)+buff[3]);
printf(" (%04X %04X)-(%04X %04X)\n",
((unsigned int)(buff[7]&0x07)<<8)+buff[5],
((unsigned int)(buff[9]&0x07)<<8)+buff[8],
((unsigned int)(buff[7]&0x70)<<4)+buff[6],
((unsigned int)(buff[9]&0x07)<<8)+buff[8]);
printf(" hS=%04X hW=%d\n", hStart, hWidth);
#endif
#endif
ival = ((unsigned int)(buff[7]&0x70)<<4) + buff[6];
if ((ival >= hTotal) && (hWidth <= CurrentWidth))
{
#if (DEBUGMSG>=3)
printf(" (hStart+hWidth-1) = hRE = %d , hTotal = %d \n",ival,hTotal);
#endif
pitch += 8;
miscSetADCPitch(pitch);
initCalibration();
goto pitchcal1;
}
if (hWidth == CurrentWidth)
goto pitchcal_done;
if (hWidth > CurrentWidth)
goto pitchcal_down;
// pitch up
pitch += 1;
if (dn) {
#if DEBUGMSG
printf(" pitch up-----ERROR: back loop, abort pitchCal!\n");
#endif
goto pitchcal_done;
}
up = 1; dn = 0;
if (tpitch0 == pitch)
goto pitchcal_done; // stop if back to old value
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -