📄 tw88.c
字号:
#include "Config.h"
#include "reg.h"
#include "typedefs.h"
#include "i2c.h"
#include "main.h"
#include "tw88.h"
#include "cc.h"
#include "debug.h"
#include "etc_eep.h"
#include "pc_eep.h"
#include "measure.h"
#include "adc.h"
#include "Printf.h"
#include "rgbmix.h" // for TW8801
#include "panel.h"
#include "osdmenu.h"
#include "osdbasic.h"
///extern IDATA BYTE adc_i2c_address, CurrentADC;
extern BYTE CheckBuf;
//=============================================================================
// 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
}
void ClearAutoDetectStd(BYTE std)
{
BYTE val;
// if( GetInputSelection()==COMPONENT ) return;
dPuts("\r\nClearAutoDetectStd");
val = ReadDecoder(SDT); // SDT
val = (val & 0xf8) | std;
WriteDecoder(SDT, val );
}
//=============================================================================
// 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)
{
dPuts("\r\n +++++++++++++++++=>Auto PHP Disable");
WriteDecoder( 0xb6, (ReadDecoder(0xb6) | 0x80) ); // Auto PHP Disable
WriteDecoder( 0xb2, (ReadDecoder(0xb2)));
}
//=============================================================================
// 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
//=============================================================================
// Change Input
//=============================================================================
#ifdef TW8804
#define REG06 0x00
#elif defined TW9908
#define REG06 0x40
#endif
void COMPOSITEInput(void)
{
WriteDecoder(0x38, 0x8e); // Test for new chip
WriteDecoder(INFORM, 0x40); // 01 00 00 x x 27M, COMPOSITE, Y0, C-, V-
WriteDecoder(ACNTL, REG06|0x03); // CLK-on, Y-on, C-off, V(FB)-off
}
#ifdef SUPPORT_SVIDEO
void SVIDEOInput(void)
{
WriteDecoder(0x38, 0x8e); // Test for new chip
WriteDecoder(INFORM, 0x54); // 01 01 01 0 x 27M, S-VIDEO, Y1, C0, --
WriteDecoder(ACNTL, REG06|0x01); // CLK-on, Y-on, C-on, V(FB)-off
}
#endif
#ifdef SUPPORT_COMPONENT
void COMPONENTInput(void)
{
WriteDecoder(0x38, 0x8e); // Test for new chip
WriteDecoder(INFORM, 0x7a); // 0 1 11 10 1 0 27M, COMPONENT, Y2, C1, V0
WriteDecoder(ACNTL, REG06|0x00); // CLK-on, Y-on, C-on, V(FB)-on
// WriteDecoder(0x35, 0x00); // V clamp Enable
// WriteDecoder(SDTR, 0x03);
}
#endif
#ifdef SUPPORT_TV
void TVInput(void)
{
BYTE val;
WriteDecoder(0x38, 0x8e); // Test for new chip
WriteDecoder(INFORM, 0x48); // 01 00 11 x x 27M, COMPOSITE, Y2, C-, V-
WriteDecoder(ACNTL, REG06|0x03); // CLK-on, Y-on, C-off, V(FB)-off
val = ReadDecoder(MISC3); // clear blue screen
val &= 0xf9; // xxxx x00x
WriteDecoder(MISC3, val);
//WriteDecoder(RGBMISC, 0x05 ); // 39: 0000 0101 Select RGB, FB control
//WriteDecoder(FBCONTRL, 0x00); // FB Type: Analog
}
#endif // SUPPORT_TV
#ifdef SUPPORT_PC
void AVGAInput(void)
{
MakeStartInt();
WriteDecoder(ACNTL, REG06|0x00); // CLK-on, Y-on, C-on, V(FB)-on
WriteDecoder(INFORM, 0xed); // Y3,C2,V1
SetADCMode(PC); // Load Inital Data
//GetADCGainOffsetEE(); // ADC gain & offset
GetInitPanelAttribute1(); // Panel Brightness / Contrast
SelectPanelAttrRegGroup(GROUP_RGB);
WriteDecoder(0x77, 0x00); // Panel sharpness=0
WriteDecoder(0x78, 0x00); //
WriteDecoder(0x86, 0x00); // Black/White stretsh Disable
WriteDecoder(0x87, 0xff); //
//SelectADCmux(PC);
}
#endif // SUPPORT_PC
#ifdef SUPPORT_DTV
void DTVInput(void)
{
MakeStartInt();
WriteDecoder(ACNTL, REG06|0x00); // CLK-on, Y-on, C-on, V(FB)-on
WriteDecoder(INFORM, 0xed); // Y3,C2,V1
SetADCMode(DTV);
//GetADCGainOffsetForDTVEE(); // ADC gain & offset
//GetInitPanelAttribute1(); // Panel Brightness / Contrast
//GetInitPanelAttribute2(); // Panel Hue / Sharpness / Saturation
SelectPanelAttrRegGroup(GROUP_YCbCr);
//WriteDecoder(0x77, 0x30); // Panel sharpness=0
SetVideoMode( GetVideoModeEE());
//SelectADCmux(DTV);
}
#endif // SUPPORT_DTV
//=============================================================================
// Power Functions
//=============================================================================
BYTE GetLCDPowerState(void)
{
BYTE val;
val = ReadDecoder(0xd5);
val &= 0x30;
val >>= 4;
return val;
}
void SetLCDPowerState(BYTE dat)
{
WriteDecoder( 0xd4, 0x01 ); // timer prescaler
WriteDecoder( 0xd6, 0x11 ); // suspend->standby on->suspend
WriteDecoder( 0xd7, 0x11 ); // off->standby(!) standby->off
WriteDecoder( 0xd8, 0x11 ); // standby->suspend(*) suspend->on
WriteDecoder( 0xd5, dat ); // Auto Power
}
/*
BYTE IsFreeRun(void)
{
BYTE val;
val = ReadDecoder(0xbe);
if( val & 0x04 ) return 1;
else return 0;
}
*/
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);
if( on ) val |= 0x20;
else val &= 0xdf;
WaitEndofDisplayArea();
WriteDecoder(0xf3, val);
WriteDecoder(0xff, tmp);
}
void PanelMute(BYTE on)
{
if( on ){ // Mute
PanelBlack(on);
PanelFreeRun(on);
}
else
{ // Recover
PanelFreeRun(on);
PanelBlack(on);
}
}
// TW8806 Board : Control LVDS En by GPIO2.
// TW8806B Board : Control LVDS En by GPIO0.
void ON_LVDS(void)
{
#if (defined WVGA) || (defined WQVGA)
#else
BYTE val;
val = ReadDecoder(0x4e);
WriteDecoder(0x4e, val|0x10); // GPIO0 En
val = ReadDecoder(0x4f) & 0xf9;
WriteDecoder(0x4f, val | 0x08); // GPIO0 = 1
dPuts("\r\n--ON_LVDS");
#endif
}
void OFF_LVDS(void)
{
#if (defined WVGA) || (defined WQVGA)
#else
BYTE val;
val = ReadDecoder(0x4e);
WriteDecoder(0x4e, val&0x10); // GPIO0 En
val = ReadDecoder(0x4f) & 0xf9;
WriteDecoder(0x4f, val & 0xf7); // GPIO1 = 0
dPuts("\r\n--OFF_LVDS");
#endif
}
void LCDPowerON(BYTE mute)
{
dPuts("\r\n------> LCD on");
PowerLED(ON);
if( GetLCDPowerState()!=POWER_ON )
{
PanelMute(mute);
ON_LVDS();
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);
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;
PanelMute(1);
WriteDecoder(0xd5, 0x0b); // Suspend Panel:1 Signal:1 Back:0
delay(1);
WriteDecoder(0xd5, 0x09); // Standby Panel:1 Signal:0 Back:0
delay(1);
WriteDecoder(0xd5, 0x08); // Off Panel:0 Signal:0 Back:0
OFF_LVDS();
// delay(10);
}
#ifdef SERIAL
void LCDPower(void)
{
BYTE state;
state = GetLCDPowerState();
if( state==POWER_ON )
{
LCDPowerOFF();
// PowerDown_XTAL(1);
}
else if( state==POWER_OFF )
{
// PowerDown_XTAL(1);
// delay(10);
LCDPowerON(0);
}
}
#endif // SERIAL
#if defined( SUPPORT_PC ) || defined( SUPPORT_DTV )
void DPMSmodeOFF(void)
{
//WriteDecoder(ACNTL, ReadDecoder(ACNTL) | 0x0f); // HHY 1.44 power down 27M clock, ADC
}
void DPMSmodeON(void)
{
WriteDecoder(ACNTL, ReadDecoder(ACNTL) & 0xf0); // HHY 1.44 power on 27M clock, ADC
delay(5);
}
#endif // SUPPORT_PC
/***
void SetPanelBitOrder(BYTE swap)
{
BYTE val;
val = ReadDecoder(0xf7);
if( swap ) val = val | 0x01;
else val = val & 0xfe;
WriteDecoder(0xf7, val);
}
***/
/***
void SetPanelSingleDouble(BYTE single)
{
BYTE val;
val = ReadDecoder(0xb0);
if( single ) val = val & 0x7f;
else val = val | 0x80;
WriteDecoder(0xb0, val);
}
***/
//=============================================================================
// Measurement Functions
//=============================================================================
BYTE MeasureAndWait(BYTE flag)
{
BYTE val;
WORD i;
// StartMeasurement
val = ( (flag & 0x03) << 2 ) | 0x01; //flag : choose field for measurement
WriteDecoder(0x5b, val);
// WaitMeasurementDataReady
for(i=0; i<200; i++) {
val = ReadDecoder(0x5b) & 0x01;
if( !val ) return 1;
//delay(1);
}
// ClearMeasurement
WriteDecoder(0x5b, 0);
wPuts(" ? ");
return 0;
}
//=============================================================================
// Interrupt / SW Reset Control Functions
//=============================================================================
/**** Not used
void SetInt(void)
{
WriteDecoder(0xb2, 0xec); //IRQ mask, MASK OFF all
}
****/
//void ClearInt(void)
//{
// dPuts("\r\nClear Int(b2:0xff)");
// WriteDecoder(0xb2, 0xff);
//}
/*
//#ifdef SUPPORT_TV
void SWReset(void)
{
BYTE val;
BYTE state;
state = GetLCDPowerState();
if( state==POWER_ON )
OFF_LVDS();
val = ReadDecoder(ACNTL);
val |= 0x80; // Software Reset
WriteDecoder(ACNTL, val);
if( state==POWER_ON ) {
while( GetLCDPowerState()!=POWER_ON )
;
ON_LVDS();
}
}
#endif
//=============================================================================
// MISC2 for decoder
//=============================================================================
#ifdef SUPPORT_CCD_VCHIP
void ForceDecoderOutput(BYTE color)
{
color = BLACK_DECODER;
PanelBlack(1);
return 1;
}
void ClearForcedDecoderOutput(void)
{
PanelBlack(0);
}
#endif
*/
//=============================================================================
// CC and EDS
//=============================================================================
#ifdef SUPPORT_TW88_CC_DECODER
BYTE GetCCStatus()
{
return ReadDecoder(CC_STATUS);
}
void DisableCC()
{
BYTE ccs;
ccs = ReadDecoder(CC_STATUS);
ccs &= 0xdf;
WriteDecoder(CC_STATUS, ccs);
}
void EnableCC()
{
BYTE ccs;
ccs = ReadDecoder(CC_STATUS);
ccs |= 0x20;
WriteDecoder(CC_STATUS, ccs);
}
BYTE GetCCData()
{
return ReadDecoder(CC_DATA);
}
void EnableEDS(void)
{
BYTE ccs;
ccs = ReadDecoder(CC_STATUS);
ccs |= 0x40;
WriteDecoder(CC_STATUS, ccs);
}
void DisableEDS(void)
{
BYTE ccs;
ccs = ReadDecoder(CC_STATUS);
ccs &= 0xbf;
WriteDecoder(CC_STATUS,ccs);
}
void RecoverCCOverflow(void)
{
BYTE ccs, i;
ccs = ReadDecoder(CC_STATUS);
WriteDecoder(CC_STATUS,ccs & 0x9f); //clear bit6:5
for(i=0; i<16; i++) GetCCData();
WriteDecoder(CC_STATUS,ccs); //reset bit6:5
}
#endif // SUPPORT_TW88_CC_DECODER
//=================================================================================================
//
//=================================================================================================
#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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -