📄 tw88.c
字号:
#include "Config.h"
#include "reg.h"
#include "typedefs.h"
#include "i2c.h"
#include "main.h"
#include "tw88.h"
#include "etc_eep.h"
#include "pc_eep.h"
#include "measure.h"
#include "adc.h"
#include "CPU.h"
#include "Printf.h"
#include "rgbmix.h" // for TW8801
#include "panel.h"
#include "osdmenu.h"
#include "osdbasic.h"
#include "Dispinfo.h"
#include "Tuner.h"
#include "Audio.h"
///extern IDATA BYTE adc_i2c_address, CurrentADC;
extern BYTE CheckBuf;
extern CODE struct _PANELDATA PanelData; // Hans
extern BYTE VInputStdDetectMode; // Hans
extern BYTE DebugLevel;
extern IDATA BYTE PcMode;
extern CODE struct _PCMDATA PCMDATA[];
extern IDATA BYTE InputSelection;
CODE BYTE cModeIndex[] =
{
EE_YPbPr_480I,
EE_YPbPr_576I,
EE_YPbPr_480P,
EE_YPbPr_576P,
};
// UNKNOWN 0
// COMPOSITE 1
// SVIDEO 2
// COMPONENT 3
// DTV 4
// TV 5
// SCART 6
// PC 7
// DIGITALVGA 8
CODE struct _INPUT_MATRIX InputMatrix[] =
{
// cYSEL, cCSEL, cVSEL, cIFSEL, cDataOrder, cDataFormat, cInputRoute
{ YIN0, NOTUSE, NOTUSE, D_VIDEO, ORDER_RGB_YPbPr, IF_YUV_444, IS_DECODER}, // unknown default to COMPOSITE
{ YIN0, NOTUSE, NOTUSE, D_VIDEO, ORDER_RGB_YPbPr, IF_YUV_444, IS_DECODER}, // COMPOSITE
{ YIN1, CIN0, NOTUSE, D_SVIDEO, ORDER_RGB_YPbPr, IF_YUV_444, IS_DECODER}, // SVIDEO
{ YIN2, CIN1, VIN0, D_COMPONENT_P, ORDER_RGB_YPbPr, IF_YUV_444, IS_DECODER}, // COMPONENT
{ NOTUSE, NOTUSE, NOTUSE, D_UNUSED, ORDER_GBR_PbPrY, IF_ITU656, IS_DTV}, // DTV
{ YIN1, NOTUSE, NOTUSE, D_VIDEO, ORDER_RGB_YPbPr, IF_YUV_444, IS_DECODER}, // TV
{ NOTUSE, NOTUSE, NOTUSE, D_VIDEO, ORDER_RGB_YPbPr, IF_YUV_444, IS_DECODER}, // SCART //not used
{ YIN3, CIN2, VIN1, D_UNUSED, ORDER_RGB_YPbPr, IF_RGB_444, IS_ADC}, // PC
{ NOTUSE, NOTUSE, NOTUSE, D_UNUSED, ORDER_GBR_PbPrY, IF_RGB_444, IS_DTV}, // DIGITALVGA //not used
};
CODE struct _DECODER_FORMAT DecoderFormat[] = {
//ScaleWidth, ScaleHeight, HActive, VActive, HDelay, VDelay
{ 690, 228, 720, 240, 0x16, 0x15}, // 480i
{ 690, 278, 720, 288, 0x16, 0x16}, // 576i
{ 622, 460, 720, 480, 0x40, 0x2A}, // 480P
{ 630, 538, 720, 576, 0x3f, 0x31}, // 576P
};
BYTE IsDecoderSource(void)
{
BYTE Temp = ReadTW88(0x44);
if ((Temp & 0x03) == 0)
return TRUE; //Internal analog video decoder
else
return FALSE;
}
//=============================================================================
// Auto Detect
//=============================================================================
void SetAutoDetectStd(void)
{
BYTE val;
// if( GetInputSelection()==COMPONENT ) return;
dPuts("\r\nSetAutoDetectStd");
val = 0x80 | GetPossibleAutoDetectStdEE(); //AutoDetectStd
WriteDecoder(SDTR, val); // SDTR
val = ReadDecoder(SDT); // SDT
WriteDecoder(SDT, val | 0x07); // SDT
}
#ifdef SUPPORT_TV
void ClearAutoDetectStd(BYTE std)
{
BYTE val;
// if( GetInputSelection()==COMPONENT ) return;
dPuts("\r\nClearAutoDetectStd");
val = ReadDecoder(SDT); // SDT
val = (val & 0xf8) | std;
WriteDecoder(SDT, val );
}
#endif
//=============================================================================
// Auto Panel H Period Control
//=============================================================================
void AutoPHPCalEnable(void)
{
dPuts("\r\n +++++++++++++++++=>Auto PHP Enable");
WriteDecoder( 0xb6, (ReadDecoder(0xb6) & 0x7f) ); // Auto PHP Enable
WriteDecoder( 0xb2, ReadDecoder(0xb2) );
}
void AutoPHPCalDisable(void)
{
#if 1
BYTE cTemp = ReadDecoder(0xb6);
dPuts("\r\n +++++++++++++++++=>Auto PHP Disable");
cTemp |= 0x80; // Auto PHP Disable
cTemp &= 0xf0; // clear High four bits of hperiod
cTemp |= (BYTE)((PanelData.HPeriod & 0xf00) >> 8);
WriteTW88(0xb6, cTemp);
WriteTW88(0xb2, (PanelData.HPeriod & 0xff));
#else
dPuts("\r\n +++++++++++++++++=>Auto PHP Disable");
WriteDecoder( 0xb6, (ReadDecoder(0xb6) | 0x80) ); // Auto PHP Disable
WriteDecoder( 0xb2, (ReadDecoder(0xb2)));
#endif
}
//=============================================================================
// Video Input Functions
//=============================================================================
#ifdef SUPPORT_TV
BYTE IsVideoInput(void)
{
if( ( ReadDecoder(CSTATUS) & 0xc0 )==0x40 )
return 1;
return 0;
}
#endif
//=============================================================================
// Detect Video System by Decoder
//=============================================================================
#ifndef ID_CHECK_BY_FW
BYTE DetectDecoderInput(void)
{
BYTE std;
BYTE val;
//----- Check No Input
val = ReadDecoder(CSTATUS); // Decoder status Register
if( (val & 0xc0) != 0x40 ) { // no decoder input
std = NOINPUT;
return std;
}
//----- Check Color System by decoder
val = ReadDecoder(SDT); // SDT
if( val & 0x80 ) { // Detection in proress
std = UNKNOWN;
}
else {
val >>= 4;
if( val==0x07 ) std = UNKNOWN;
else std = val + 1;
}
return std;
}
#endif // ID_CHECK_BY_FW
//=============================================================================
// Power Functions
//=============================================================================
BYTE GetLCDPowerState(void)
{
BYTE val;
val = ReadDecoder(0xd5);
val &= 0x30;
val >>= 4;
return val;
}
void PanelFreeRun(BYTE on)
{
BYTE val;
#ifndef QVGA
if( on ) AutoPHPCalDisable();
else AutoPHPCalEnable();
#endif
val = ReadDecoder(0xbe);
if( on ) val |= 0x04;
else val &= 0xfb;
WriteDecoder(0xbe, val);
}
void PanelBlack(BYTE on)
{
BYTE val, tmp;
tmp = ReadDecoder(0xff);
WriteDecoder(0xff, 0x01);
val = ReadDecoder(0xf3);
// val = ReadDecoder(0xB4);
if( on ) val |= 0x20;
else val &= 0xdf;
WaitEndofDisplayArea();
WriteDecoder(0xf3, val);
// WriteDecoder(0xB4, val);
WriteDecoder(0xff, tmp);
}
void PanelMute(BYTE on)
{
if( on ){ // Mute
PanelBlack(on);
PanelFreeRun(on);
}
else
{ // Recover
PanelFreeRun(on);
PanelBlack(on);
}
}
void ON_LVDS(void)
{
#ifdef TICONLESS
#else
BYTE val;
val = ReadDecoder(0x4e);
WriteDecoder(0x4e, val|0x10); // GPIO0 En
val = ReadDecoder(0x4f) & 0xf9;
WriteDecoder(0x4f, val | 0x08); // GPIO0 = 1
#ifdef INTERNAL_MCU
P2_0 = 1;
#endif
dPuts("\r\n--ON_LVDS");
#endif
}
void OFF_LVDS(void)
{
#ifdef TICONLESS
#else
BYTE val;
val = ReadDecoder(0x4e);
WriteDecoder(0x4e, val&~(0x10)); // GPIO0 En
val = ReadDecoder(0x4f) & 0xf0;//0xf9;
WriteDecoder(0x4f, val | 0x09); // GPIO0 = 0
#ifdef INTERNAL_MCU
P2_0 = 0;
#endif
dPuts("\r\n--OFF_LVDS");
#endif
}
void LCDPowerON(BYTE mute)
{
dPuts("\r\n------> LCD on");
PowerLED(ON);
WriteTW88(0xff, 0); // Page 0
if( GetLCDPowerState()!=POWER_ON ) {
PanelMute(mute);
ON_LVDS();
#if 0 // removed for CCFL control //Hans
delay(1);
WriteDecoder(0xd5, 0x09); // Standby Panel:1 Signal:0 Back:0
delay(1);
WriteDecoder(0xd5, 0x0b); // Suspend Panel:1 Signal:1 Back:0
// delay(1);
// ON_LVDS();
// PanelMute(mute);
delay(10);
#endif
WriteDecoder(0xd5, 0x0f); // On Panel:1 Signal:1 Back:1
delay(5);
}
else
PanelMute(mute);
}
/*
void LCDPowerOFF(void)
{
dPuts("\r\n------> LCD off");
PanelMute(1);
// OFF_LVDS();
SetLCDPowerState(POWER_OFF);
OFF_LVDS();
delay(10);
}
*/
void LCDPowerOFF(void)
{
// if( GetLCDPowerState()==POWER_OFF ) return;
dPuts("\r\n------> LCD off");
PanelMute(1);
#if 0 // removed for CCFL control //Hans
WriteDecoder(0xd5, 0x0b); // Suspend Panel:1 Signal:1 Back:0
delay(1);
WriteDecoder(0xd5, 0x09); // Standby Panel:1 Signal:0 Back:0
delay(1);
#endif
WriteDecoder(0xd5, 0x08); // Off Panel:0 Signal:0 Back:0
OFF_LVDS();
// delay(10);
}
#ifdef SERIAL
void LCDPower(void)
{
static BYTE state=0;
//state = GetLCDPowerState();
if( state==POWER_ON ){
state = POWER_OFF;
LCDPowerOFF();
PowerDown_XTAL(1);
Printf("\nPower Off!!");
}
else //if( state==POWER_OFF )
{
// reset = 0;
PowerDown_XTAL(0);
delay(10);
/* reset = 1;
delay(10);
InputSelection = 0xff;
ChangeInput( GetInputSelectionEE() );
LCDPowerON(0);
*/
state = POWER_ON;
LCDPowerON(0);
Printf("\nPower On!!");
}
}
#endif // SERIAL
//=============================================================================
// Measurement Functions
//=============================================================================
#if defined( SUPPORT_PC ) || defined( SUPPORT_DTV ) || defined( DEBUG_SETPANEL)
BYTE MeasureAndWait(BYTE field)
{
BYTE val;
BYTE i;
// StartMeasurement
val = ( (field & 0x03) << 2 ) | 0x01; // flag : choose field for measurement
WriteDecoder(0x5b, val);
// WaitMeasurementDataReady
for(i=0; i<50; i++) { // make more delay
delay(1);
val = ReadDecoder(0x5b);
val &= 0x01;
if( val == 0 ) return 1;
}
#ifdef DEBUG_PC
dPrintf("\r\n ReadDecoder(0x5b) = %2x", ReadDecoder(0x5b));
#endif
// ClearMeasurement
WriteDecoder(0x5b, 0);
wPuts(" ? ");
return 0;
}
#endif
//=================================================================================================
//
//=================================================================================================
#if defined( SUPPORT_PC ) || defined( SUPPORT_DTV ) || defined( DEBUG_SETPANEL)
void SetEnDet(void)
{
BYTE val;
val = ReadDecoder(0x5c);
val |= 0x01; //Enable Input HSYNC/VSYNC period change/loss detection.
WriteDecoder(0x5c, val);
val = ReadDecoder(0x5c);
}
void ClearEnDet(void)
{
BYTE val;
val = ReadDecoder(0x5c);
val &= 0xfe; //Disable Input HSYNC/VSYNC period change/loss detection.
WriteDecoder(0x5c, val);
val = ReadDecoder(0x5c);
}
#endif // SUPPORT_PC || SUPPORT_DTV || DEBUG_SETPANEL
//=============================================================================
// Panel Setting
//=============================================================================
#if defined( SUPPORT_PC ) || defined( SUPPORT_DTV )
BYTE IsBypassmode(void)
{
BYTE dat;
dat = ReadDecoder(TW88_XYSCALEHI) & 0x10; // Zoom by-pass
return dat;
}
/*
BYTE IsInteraced(void)
{
if( ReadDecoder(0x42) & 0x80 ) return 1;
return 0;
}
*/
WORD GetHstart(void)
{
WORD hstart;
WriteDecoder(0x5b, 0x80);
hstart = (WORD)ReadDecoder(0x58) << 8;
hstart += ReadDecoder(0x57);
#ifdef DEBUG_PC
dPrintf("\r\n === GetHstart(%d)", hstart);
#endif
return hstart;
}
#ifdef AUTO_TUNE_CLOCK
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;
}
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);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -