tw88.c
来自「显示屏驱动源代码」· C语言 代码 · 共 2,093 行 · 第 1/4 页
C
2,093 行
WORD GetHend(void)
{
WORD hend;
WriteDecoder(0x5b, 0x98);
hend = (WORD)ReadDecoder(0x58) << 8;
hend += ReadDecoder(0x57);
#ifdef DEBUG_PC
dPrintf("\r\n === GetHend(%d)", hend);
#endif
return hend;
}
#endif
WORD GetVstart(void)
{
WORD vstart;
WriteDecoder(0x5b, 0xa0);
vstart = (WORD)ReadDecoder(0x58) << 8;
vstart += ReadDecoder(0x57);
#ifdef DEBUG_PC
dPrintf("\r\n === GetVstart(%d)", vstart);
#endif
return vstart;
}
WORD GetVend(void)
{
WORD vend;
WriteDecoder(0x5b, 0xb0);
vend = (WORD)ReadDecoder(0x5a) << 8;
vend += ReadDecoder(0x59);
#ifdef DEBUG_PC
dPrintf("\r\n === GetVend(%d)", vend);
#endif
return vend;
}
/**** Not used
void MaskOnSYNCInt()
{
BYTE val;
val = 0xfc;
WriteDecoder(0xb2, val); //IRQ mask
dPrintf("\r\nDisableSYNCint:->%02x", val);
}
****/
/*
void MaskOffSYNCInt()
{
BYTE val;
val = 0xfc;
WriteDecoder(0xd2, val); //IRQ mask
#ifdef DEBUG_TW88
dPrintf("\r\nEnableSYNCint:->%02x", (WORD)val);
#endif
WriteDecoder(0xd2, 0xcc);
#ifdef DEBUG_TW88
dPrintf("\r\nEnableSYNCint:->%02x", (WORD)0xcc);
#endif
}
/*
void MakeStartInt(void)
{
MaskOffSYNCInt();
WriteDecoder(0xd3, 0x02); // IRQ mask 2
WriteDecoder(0x4e, ReadDecoder(0x4e) | 0x08); // IRQ pin, active low
WriteDecoder(0x5b, 0x01); // Start measure
//WriteDecoder(0x5b, 0x00); // clear measure self cleared bit
WriteDecoder(0x5c, 0x07); // change error tolerance and enable V/HSYNC change/loss detection
SetEnDet(); // Set enable-detection
}
*/
void Clear_bypass()
{
BYTE dat;
dat = ReadDecoder(TW88_XYSCALEHI);
WriteDecoder(TW88_XYSCALEHI, dat & 0xef); // xxx0 xxxx
}
WORD GetHactiveStart(void)
{
WORD buf;
BYTE val;
val = ReadDecoder(0x49);
buf = (WORD)(val & 0x07) << 8;
buf += ReadDecoder(0x47);
return buf;
}
/**** Not used */
WORD GetHactiveEnd(void)
{
WORD buf;
BYTE val;
val = ReadDecoder(0x49);
buf = (WORD)(val & 0xf0) << 4;
buf += ReadDecoder(0x48);
return buf;
}
/****/
//#ifdef DEBUG_TW88
WORD GetVactiveStart(void)
{
WORD buf;
BYTE val;
val = ReadDecoder(0x4d); // high 2 bits
buf = (WORD)(val & 0x03) << 8;
buf |= ReadDecoder(0x4a); // Vactive Odd field Line start position
return buf;
}
//#endif
#include "osdmenu.h"
extern CODE struct RegisterInfo UserRange;
extern CODE struct RegisterInfo PanelContrastRange;
extern CODE struct RegisterInfo PanelBrightnessRange;
extern CODE struct RegisterInfo PanelSharpnessRange;
extern CODE struct RegisterInfo PanelHueRange;
extern CODE struct RegisterInfo PanelSaturationRange;
void GetInitPanelAttribute1(void)
{
BYTE rdata;
int regv;
rdata = GetPanelContrastEE();
Mapping1( rdata, &UserRange ,®v, &PanelContrastRange);
SetRGBContrast( GetPCColorTempModeEE(), (BYTE)regv );
rdata = GetPanelBrightnessEE() ;
Mapping1( rdata, &UserRange , ®v, &PanelBrightnessRange );
SelectPanelAttrRegGroup(GROUP_RGB); // Need to refresh "INDX_CB" bit // Hans
SetPanelBrightnessReg(RED, (BYTE)regv);
SetPanelBrightnessReg(GREEN, (BYTE)regv);
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;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?