📄 osdtune.c
字号:
/************************************************
* *
* OSDTUNE.C: Auto tuning From David *
* *
*************************************************/
#include <reg51.h>
#include <math.h>
#include "mascot.h"
#include "OSD.h"
#include "global.h"
/******************************************
* Auto Tuning Adjustment *
*******************************************/
void autoTune(unsigned char options)
{
#if DEBUGMSG
printf("AutoTune\n");
#endif
RegByteOut(0xB0, 0x00); // Disable calibration
CalibSuccess = 1;
disableDigitalFilter();
// tune HV
if (options & OPTIONCENTER)
{
initCalibration();
hvCalibration(options);
}
// checkPowerOffButton(); // auto powerkey disable by seven 030619
// if (!(eepData.MascotFlag & FLAG_POWERSTATUS)) return;
// tune pitch and phaseHW
if (options & OPTIONPITCH)
{
pitchCalibration(); // tune pitch
if (!(eepData.MascotFlag & FLAG_POWERSTATUS))
return;
phaseHWCalibration(); // tune phase
if (!(eepData.MascotFlag & FLAG_POWERSTATUS))
return;
if(pitchCalibration()) // tune pitch
{
if (!(eepData.MascotFlag & FLAG_POWERSTATUS))
return;
phaseHWCalibration(); // tune phase
if(pitchCalibration()) // tune pitch
{
if (!(eepData.MascotFlag & FLAG_POWERSTATUS))
return;
phaseHWCalibration(); // tune phase
}
}
}
// checkPowerOffButton(); // auto powerkey disable by seven 030619
// if (!(eepData.MascotFlag & FLAG_POWERSTATUS)) return;
tunePhaseFlag = 0;
#if TUNE_PITCH_WITH_PHASE
if ((options & OPTIONPITCH)&&(eepModeData.pitch % 8))
{
tunePhaseFlag = 1;
pitchCalibwithPhase();
}
#endif
// tune phase
if (options & OPTIONPHASE)
{
if (CurrentWidth >= 1024) // by seven 030424
phaseCalibration(0x07); // by seven 030718
else if (tunePhaseFlag)
phaseHWCalibration();
}
// checkPowerOffButton(); // auto powerkey disable by seven 030619
// if (!(eepData.MascotFlag & FLAG_POWERSTATUS)) return;
enableDigitalFilter();
// tune HV
if (options & OPTIONCENTER)
{
initCalibration();
hvCalibration(options);
}
// checkPowerOffButton(); // auto powerkey disable by seven 030619
// if (!(eepData.MascotFlag & FLAG_POWERSTATUS)) return;
#if DEBUGMSG
printf("AutoTune %s\n", CalibSuccess?"DONE":"FAIL");
#endif
}
/************************************************
* initial Calibration setting *
*************************************************/
void initCalibration(void)
{
unsigned int vTotal;
#if (DEBUGMSG>=2)
printf("\n ### Total Calib,\n");
#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);
hTotal = ((unsigned int)(buff[10]&0x70)<<4) +buff[9];
vTotal = ((unsigned int)(buff[10]&0x07)<<8) +buff[8];
}
#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);
RegByteOut(0xB0, 0x00); // Disable total calibration
RegByteOut(0x00, 0x00); // Clear the calibration status reg
}
/************************************************
* Vertical Calibration *
*************************************************/
#define hStart ival1
#define hWidth ival2
void hvCalibration(unsigned char options)
{
unsigned int vStart,vHeight;
#if (DEBUGMSG>=2)
printf("\n ### HV Calib,\n");
#endif
RegByteOut(0xB0, 0x02); // Enable vertical calibration
RegByteOut(0x00, 0x00); // Clear the calibration status reg
if (!waitCalibReady(0x02))
{
CalibSuccess = 0;
goto hvcal_fail;
}
miscDelay(30);
RegDataIn(0xD8, buff+7, 3);
RegByteOut(0xB0, 0x04);
RegByteOut(0x00, 0x00); // Clear the calibration status reg
if (!waitCalibReady(0x04))
if (!waitCalibReady(0x02))
{
CalibSuccess = 0;
goto hvcal_fail;
}
RegDataIn(0xD3, buff, 5);
RegDataIn(0xFA, buff+5, 2);
hStart = ((unsigned int)(buff[2]&0x07)<<8) + buff[0]-2;
hWidth = ((unsigned int)(buff[6]&0x70)<<4) + buff[5] - hStart + 1;
vStart = ((unsigned int)(buff[4]&0x07)<<8) + buff[3];
vHeight= ((unsigned int)(buff[9]&0x07)<<8) + buff[7] - vStart + 1;
#if (DEBUGMSG>=3)
printf("hStart = %d, hWidth = %d, vStart = %d, vHeight = %d\n",hStart,hWidth,vStart,vHeight);
#endif
// Horizontal calibration
//hcalib:
if (!(options & OPTIONHORT))
goto vcalib;
#if (DEBUGMSG>=2)
printf("H Calib, ");
#endif
if (hStart < HCALSTART) {
#if DEBUGMSG
printf(" Error: hStart < HCALSTART ");
#endif
goto hvcal_fail;
}
if (hWidth < CurrentWidth - HLIMIT) {
#if DEBUGMSG
printf(" Error:hWidth out of HLIMIT");
#endif
goto hvcal_fail;
}
if (hStart <= MIN_hstart && hStart>=MAX_hstart ) {
#if DEBUGMSG
printf(" Error:hStart out of range ");
#endif
hvcal_fail:
CalibSuccess = 0;
RegByteOut(0x34, (unsigned char)eepModeData.hstart);
RegByteOut(0x35, (unsigned char)(eepModeData.hstart>>8));
RegByteOut(0x36, eepModeData.vstart);
RegByteOut(0x37, 0);
RegByteOut(0xB0, 0x00);
return;
}
eepModeData.hstart = hStart;
eepModeData.def_hstart = hStart;
RegByteOut(0x34, (unsigned char)eepModeData.hstart);
RegByteOut(0x35, (unsigned char)(eepModeData.hstart>>8));
#if (DEBUGMSG>=2)
printf("HS=%d HW=%d", eepModeData.hstart, hWidth);
#endif
// Vertical calibration
vcalib:
if (!(options & OPTIONVERT))
goto hvcal_fail;
#if (DEBUGMSG>=2)
printf(" V Calib, ");
#endif
if (vStart < VCALSTART) {
#if DEBUGMSG
printf(" Error: vStart < VCALSTART ");
#endif
goto hvcal_fail;
}
if ( vHeight < CurrentHeight - VLIMIT) {
#if DEBUGMSG
printf(" Error:vHeight out of VLIMIT");
#endif
goto hvcal_fail;
}
if (vStart <= MIN_vstart && vStart>=MAX_vstart ) {
#if DEBUGMSG
printf(" Error:vStart out of range ");
#endif
goto hvcal_fail;
}
if (RegByteIn(0x24) & 0x02) vStart -= 1; //USE_MINIFY
if ((CurrentMode&0x7f) == 5) //640x350 84
vStart -= 24;
eepModeData.vstart = vStart;
eepModeData.def_vstart = vStart;
RegByteOut(0x36, eepModeData.vstart);
RegByteOut(0x37, 0);
#if (DEBUGMSG>=2)
printf(" VS=%d\n\n", (unsigned int)eepModeData.vstart);
#endif
/* Disable vertical calibration */
RegByteOut(0xB0, 0x00);
}
#undef hStart
#undef hWidth
/************************************************
* Pitch Calibration *
*************************************************/
#define hStart ival1
#define hWidth ival2
#define adjust_limit buff[14] // 12 to 14 by seven 030630
#define CHANGE 1
#define NOCHANGE 0
bit pitchCalibration(void)
{
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);
adjust_limit = 120; // 2003/7/22 06:14
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -