📄 tw88.c
字号:
SetPanelBrightnessReg(BLUE, (BYTE)regv);
SelectPanelAttrRegGroup(GROUP_YCbCr);
SetDTVBrightnessReg(0x80);
SetDTVContrastReg(0x80);
SetPanelSaturationReg(U_SAT, 0x80);
SetPanelSaturationReg(V_SAT, 0x80);
}
#endif // SUPPORT_PC
//-------------------------------------------------------------------
// Set Active Region Functions
//-------------------------------------------------------------------
void SetHactiveStart(WORD hstart)
{
BYTE val;
#ifdef DEBUG_PC
dPrintf("\r\n === SetHactiveStart(%d)", hstart);
#endif
// TW8804 write LSByte first
val = ReadDecoder(0x49);
val = val & 0xf8;
val = val | (hstart>>8);
WriteDecoder(0x49, val);
WriteDecoder(0x47, (BYTE)hstart);
}
void SetHactiveEnd(WORD hend)
{
BYTE val, buf;
#ifdef DEBUG_PC
dPrintf("\r\n === SetHactiveEnd(%d)", hend);
#endif
// TW8804 write LSByte first
buf = (BYTE)(hend>>8)<<4;
val = ReadDecoder(0x49);
val = val & 0x0f;
val = val | buf;
WriteDecoder(0x49, val);
WriteDecoder(0x48, (BYTE)hend);
}
void SetVactiveStart(WORD vstart)
{
BYTE val, v_h, v_l;
#ifdef DEBUG_PC
dPrintf("\r\n === SetVactiveStart(%d)", vstart);
#endif
// TW8804 write LSByte first
v_l = (BYTE)vstart;
v_h = (BYTE)(vstart>>8);
val = ReadDecoder(0x4d); // high 2 bits
val = (val & 0xf0);
val = val | (v_h<<2);
val = val | v_h;
WriteDecoder(0x4d, val);
WriteDecoder(0x4a, v_l); // Vactive Odd field Line start position
WriteDecoder(0x4b, v_l); // Vactive Even field Line start position
}
void SetVactiveLen(WORD van)
{
// WORD vstop;
BYTE val, buf;
van += 1; // HHY add 1, because of bottom line garbage
#ifdef DEBUG_PC
dPrintf("\r\n === SetVactiveLen(%d)", van);
#endif
// TW8804 write LSByte first
buf = (BYTE)(van>>8) << 4;
val = ReadDecoder(0x4d);
val = val & 0x8f;
val = val | buf;
WriteDecoder(0x4d, val);
WriteDecoder(0x4c, (BYTE)van);
}
void DefaultPanelAttributeForVideo(void)
{
SelectPanelAttrRegGroup(GROUP_RGB);
SetPanelContrastReg(RED, 0x80);
SetPanelContrastReg(GREEN,0x80);
SetPanelContrastReg(BLUE, 0x80);
SetPanelBrightnessReg(RED, 0x80);
SetPanelBrightnessReg(GREEN,0x80);
SetPanelBrightnessReg(BLUE, 0x80);
SelectPanelAttrRegGroup(GROUP_YCbCr);
SetDTVBrightnessReg(0x70); // 0x80
SetDTVContrastReg(0x80);
SetPanelSaturationReg(U_SAT, 0xB0); // 0x80
SetPanelSaturationReg(V_SAT, 0xB0); // 0x80
}
#ifdef SUPPORT_PC
//=============================================================================
// Invert Polarity Functions
//=============================================================================
/*
void InvertHSYNCPolarity(void)
{
BYTE val;
val = ReadDecoder(0x40);
if( val & 0x04 ) {
val &= 0xfb;
#ifdef DEBUG_PC
dPuts("\r\nInvert H Pol: N->P ");
#endif
}
else {
val |= 0x04;
#ifdef DEBUG_PC
dPuts("\r\nInvert H Pol: P->N ");
#endif
}
WriteDecoder(0x40, val);
}
*/
void InvertVSYNCPolarity(void)
{
BYTE val;
val = ReadDecoder(0x40);
if( val & 0x02 ) {
val &= 0xfd;
#ifdef DEBUG_PC
dPuts("\r\nInvert V Pol: N->P ");
#endif
}
else {
val |= 0x02;
#ifdef DEBUG_PC
dPuts("\r\nInvert V Pol: P->N ");
#endif
}
WriteDecoder(0x40, val);
}
//=============================================================================
// get sync pulse Functions
//=============================================================================
WORD GetVSYNCPulse(void)
{
WORD buf;
WriteDecoder(0x5b, 0x70); // VSYNC
delay(10);
buf = (WORD)ReadDecoder(0x58) << 8;
buf |= ReadDecoder(0x57);
#ifdef DEBUG_PC
dPrintf("\r\nGetVSYNCPulse():%d ", buf);
#endif
return buf;
}
/* Not used right now!!
WORD GetRelativePosition(void)
{
WORD buf;
WriteDecoder(0x5b, 0x70); // VSYNC
buf = (WORD)ReadDecoder(0x5a) << 8;
buf |= ReadDecoder(0x59);
return buf;
}
//*/
WORD GetHSYNCPulse(void)
{
WORD buf;
WriteDecoder(0x5b, 0x60); // HSYNC
buf = (WORD)ReadDecoder(0x58) << 8; // from MSB
buf |= ReadDecoder(0x57);
return buf;
}
#endif // SUPPORT_PC
//=============================================================================
// Internal PLL
//=============================================================================
#if defined SUPPORT_PC || defined SUPPORT_DTV
BYTE GetPOST(void)
{
BYTE post;
post = ReadDecoder(TW88_PLL_DIV);
return ((post>>6) & 0x03); // change register position
}
DWORD GetPPF(void)
{
DWORD ppf, Freq;
BYTE i;
Freq = ReadDecoder(TW88_FPLL0);
Freq &= 0x0f;
Freq <<= 8;
Freq |= ReadDecoder(TW88_FPLL1);
Freq <<= 8;
Freq |= ReadDecoder(TW88_FPLL2);
#ifdef DEBUG_PC
dPrintf("\r\n(GetFBDN) :%ld", Freq);
#endif
// 27000000 * 4 * FREQ / 2^17 / 2^POST
ppf = 824L * ( Freq );
// ppf = 412L * ( GetFBDN() );
i= GetPOST();
for(; i>0; i-- ) ppf /= 2;
#ifdef DEBUG_PC
dPrintf("\r\n(GetPPF) :%ld", ppf);
#endif
return ppf;
}
#endif
#if defined SUPPORT_PC || defined SUPPORT_DTV
//=============================================================================
// Set Measurement Window Functions
//=============================================================================
void SetMeasureWindowH(WORD start, WORD stop)
{
BYTE val;
#ifdef DEBUG_PC
dPrintf("\r\nSetWindow H. Range(%04x, %04x)", start, stop);
#endif
// TW8804 write LSByte first
val = (BYTE)((stop >> 4) & 0xf0);
val |= (BYTE)((start>>8) & 0x07);
WriteDecoder(0x53, val); // H-start and H-stop
WriteDecoder(0x51, (BYTE)start); // H-start
WriteDecoder(0x52, (BYTE)stop); // H-stop
}
void SetMeasureWindowV(WORD start, WORD stop)
{
BYTE val;
#ifdef DEBUG_PC
dPrintf("\r\nSetWindow V. Range(%04x, %04x)", start, stop);
#endif
// TW8804 write LSByte first
val = (BYTE)((stop>>4) & 0x70);
val |= (BYTE)((start>>8) & 0x07);
WriteDecoder(0x56, val); // V-start & V-stop
WriteDecoder(0x54, (BYTE)start); // V-start
WriteDecoder(0x55, (BYTE)stop); // V-stop
}
#endif // SUPPORT_PC || defined SUPPORT_DTV
//=============================================================================
// ZoomControl
//=============================================================================
#ifndef WIDE_SCREEN
#if defined(SUPPORT_PC) || defined(SUPPORT_DTV)
void BypassZoom()
{
#ifdef WXGA
WriteDecoder(TW88_XUSCALELO, 0xcd);
WriteDecoder(TW88_YUSCALELO, 0x80);
WriteDecoder(TW88_XDSCALELO, 0x00);
WriteDecoder(TW88_XYSCALEHI, 0x06);
#else
//SetBypassmode=1;
WriteDecoder(TW88_XUSCALELO, 0x00);
WriteDecoder(TW88_XDSCALELO, 0x80);
WriteDecoder(TW88_YUSCALELO, 0x00);
WriteDecoder(TW88_XYSCALEHI, 0x15); //Set bit 4 to 1
#endif
}
#endif
#endif
void XscaleU(DWORD scale)
{
BYTE val;
WriteDecoder( TW88_XUSCALEFINE, (BYTE)scale);
scale >>= 8;
WriteDecoder( TW88_XUSCALELO, (BYTE)scale);
scale >>= 8;
val = ReadDecoder(TW88_XYSCALEHI);
val &= 0xfe;
val |= (BYTE)scale;
WriteDecoder( TW88_XYSCALEHI, val );
}
void XscaleD(DWORD scale)
{
BYTE val;
WriteDecoder( TW88_XDSCALELO, (BYTE)scale);
scale >>= 8;
scale <<= 1;
val = ReadDecoder(TW88_XYSCALEHI);
val &= 0xfd;
val |= (BYTE)scale;
WriteDecoder( TW88_XYSCALEHI, val );
}
void XScale2(DWORD scale)
{
if( scale==0x10000 ) { // No Scale
XscaleU(0x10000);
XscaleD(0x80);
}
else if( scale<0x10000 ) { // Up Scale
XscaleU(scale);
XscaleD(0x80);
}
else { // Down Scale
XscaleU(0x10000);
XscaleD(scale/2/256);
}
}
void YScale2(DWORD scale)
{
BYTE val;
// max down scale rate is 1/2. Hans
if (scale > 0x1ff00) scale = 0x1ff00;
WriteDecoder( TW88_YUSCALEFINE, (BYTE)(scale));
scale >>= 8;
WriteDecoder( TW88_YUSCALELO, (BYTE)(scale));
scale >>= 8;
scale <<= 2;
val = ReadDecoder(TW88_XYSCALEHI) & 0xf3;
val |= (BYTE)scale;
WriteDecoder( TW88_XYSCALEHI, val );
}
// PLL = 108MHz *FPLL / 2^17
// FPLL = PLL * 2^17 / 108MHz
void ChangeInternPLL(DWORD _PPF)
{
BYTE ppf, CURR, VCO, POST, i;
DWORD FPLL;
#ifdef DEBUG_PC
dPrintf("\r\n++ ChangeInternPLL ++_PPF:%08lx(%ld) ", _PPF, _PPF);
#endif
ppf = _PPF/1000000;
//----- Frequency Range --------------------
if ( ppf < 27 ) { VCO=0; CURR=0; POST=0; } // step = 0.5MHz
else if( ppf < 54 ) { VCO=1; CURR=0; POST=1; } // step = 1.0MHz
else if( ppf < 108 ) { VCO=2; CURR=0; POST=2; } // step = 1.0MHz
else { VCO=3; CURR=0; POST=2; } // step = 1.0MHz
//----- Get FBDN
FPLL = (_PPF/100000L)*2427L;
i = POST;
for(; i>0; i-- )
FPLL *= 2;
FPLL = FPLL / 20L;
//----- Setting Registers : below is different with 8806
WriteDecoder( TW88_FPLL0, (FPLL>>16));
WriteDecoder( TW88_FPLL1, (BYTE)(FPLL>>8));
WriteDecoder( TW88_FPLL2, (BYTE)FPLL );
WriteDecoder( TW88_PLL_DIV, (VCO<<4) | (POST<<6) |CURR );
}
/**
#if defined(SUPPORT_PC) || defined(SUPPORT_DTV)
WORD GetYScale(void)
{
WORD scale;
BYTE val;
scale = ReadDecoder(TW88_YUSCALELO);
val = ReadDecoder(TW88_XYSCALEHI);
val = (val >> 2) & 0x03;
scale = scale + val*0x100;
return scale;
}
#endif // SUPPORT_PC || SUPPORT_DTV
**/
//=============================================================================
// Panel related..
//=============================================================================
/***
#if (defined SERIAL) || (defined WIDE_SCREEN)
void SetPVR(WORD pvr)
{
BYTE buf;
// TW8804 write LSByte first
buf = ReadDecoder(0xbb) & 0x0f;
buf = buf | ( (pvr>>4) & 0xf0 );
WriteDecoder( 0xbb, buf );
WriteDecoder( 0xba, (BYTE)pvr );
}
void SetPHR(WORD phr)
{
BYTE buf;
// TW8804 write LSByte first
buf = ReadDecoder(0xb6) & 0x0f;
buf = buf | ( (phr>>4) & 0xf0 );
WriteDecoder( 0xb6, buf );
WriteDecoder( 0xb5, (BYTE)phr );
}
#endif // SERIAL || WIDE_SCREEN
***/
#if defined( SUPPORT_PC ) || defined( SUPPORT_DTV ) || defined( DEBUG_SETPANEL)
//----- Panel V Resolution
WORD GetPVR(void)
{
/* WORD pvr;
BYTE val;
val = ReadDecoder(0xbb);
pvr = (val & 0x70) << 4; // pppp xxxx -> pppp 0000 0000
pvr |= ReadDecoder(0xba);
return pvr;*/
return PVR_;
}
//----- Panel H Resolution
WORD GetPHR(void)
{
/* WORD phr;
BYTE val;
val = ReadDecoder(0xb6);
phr = (val & 0x70) << 4; // pppp xxxx -> pppp 0000 0000
phr |= ReadDecoder(0xb5);
return phr;*/
return PHR_;
}
WORD GetHPN(void)
{
WORD buf;
ClearEnDet(); // HHY 05.29.03 protect changing during read out
WriteDecoder(0x5b, 0x50); // HSYNC period and VSYNC period
buf = ReadDecoder(0x58); // from MSB
buf = buf << 8;
buf = buf | ReadDecoder(0x57);
SetEnDet(); // HHY 05.29.03 release protection
return buf;
}
/*
WORD GetHPN(void)
{
WORD buf, sum;
BYTE i;
//Get HPN
WriteDecoder(0x5b, 0x50); // HSYNC period and VSYNC period
//HPN
for(i=0, sum=0; i<5; i++) { // HHY 1.45 take average
buf = (WORD)ReadDecoder(0x58) << 8;// from MSB
buf |= ReadDecoder(0x57);
sum += buf;
}
buf = (sum+5)/5;
return buf;
}
*/
WORD GetVPN(void)
{
WORD buf;
WriteDecoder(0x5b, 0x50); // HSYNC period and VSYNC period
buf = (WORD)ReadDecoder(0x5a);
buf = buf << 8;
buf = buf | ReadDecoder(0x59);
return buf;
}
/*
WORD GetPVP(void)
{
WORD pvp;
pvp = ReadDecoder(0xbb); // pvp = Panel Vsync Period
pvp = (pvp & 0x0f) << 8; //
pvp |= ReadDecoder(0xb7); //
return pvp;
}
*/
BYTE GetVBackPorch(void)
{
return ReadDecoder(0xb9);
}
#endif // SUPPORT_PC
#if defined SUPPORT_PC || defined SUPPORT_DTV
void SetVBackPorch(BYTE val)
{
#ifdef DEBUG_PC
dPrintf("\r\n === SetVBackPorch(%d)", (WORD)val);
#endif
WriteDecoder(0xb9, val);
}
void SetPVP(WORD period )
{
BYTE val;
// TW8804 write LSByte first
val = ReadDecoder(0xbb);
val = val & 0xf0;
val = val | (BYTE)(period>>8);
WriteDecoder(0xbb, val);
WriteDecoder(0xb7, (BYTE)period); // A4, A8 = Panel Vsync Period
}
void SetPHP(WORD php)
{
BYTE val;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -