📄 t103_util.c
字号:
/****************************************************************************
* File: T803_Util.c *
* Description: Define T803 chip control policy *
* History: 2005/08/12 *
* *
* Copyright 2005 (c) Terawins Inc. *
****************************************************************************/
/****************************************************************************
* Include File *
****************************************************************************/
#include "reg51.h"
#include "math.h"
#include "common.h"
#include "struct.h"
#include "system.h"
#include "panel.h"
#include "Resolution.h"
#include "SRC_ctrl.h"
#include "twowire.h"
#include "filter.h"
#include "keypad.h"
#include "Nvram.h"
//#include "Video.h"
#include "T803_Util.h"
#include "TW803Reg.h"
#include "remote.h"
#include "osddraw.h"
#include "tuner.h"
#include "timer0.h"
#include "T515.h"
#include "ModeCtrl.h"
#include "Global.h"
#include "display.h"
#include "cfgdsply.h"
#include "keypad.h"
#include "Gamma.h"
#include "INIT.h"
#include "VBI_Parser.h" // kenny 20060403
#include "SRC_565.h"
#include "RGB565.h"
static uCHAR cSVideo=0;
//static uCHAR cYPbPr=0; // add by Sherman 06'01'12
/****************************************************************************
* Public Global Variable *
****************************************************************************/
uDWORD m_dwTemp[2];
uWORD m_wDWHSZ=DWHSZ;
uCHAR NoSignal=0;
#ifdef ROTATE
uCHAR Dis_Mode=TOP_LEFT;
#endif
/****************************************************************************
* Public Function *
****************************************************************************/
void InitT803(void)
{
uCHAR RegIndex,RegAdr;
RegIndex=0;
RegAdr=stInitT10xP0[0].ucRegAdr;
while (RegAdr != 0xFF) // bruce, 2006/01/09
{
if(RegAdr==0x30){
I2CWriteByte(TW803_P0,RegAdr,(I2CReadByte(TW803_P0,0x30)|0x01)); // enable Shadow
I2CWriteByte(TW803_P0,RegAdr,(I2CReadByte(TW803_P0,0x30)&(~0x02))| DEINTERLACE); //Bruce, 2006/01/10
}
else{
I2CWriteByte(TW803_P0,RegAdr,stInitT10xP0[RegIndex].ucRegVal);
}
RegAdr=stInitT10xP0[++RegIndex].ucRegAdr;
}
RegIndex=0;
RegAdr=stInitT10xP2[0].ucRegAdr;
while (RegAdr != 0xFF) // bruce, 2006/01/09
{
if(RegAdr==0x01)
I2CWriteByte(TW803_P2,RegAdr,(I2CReadByte(TW803_P2,0x01)|0x01));// enable black level correction for 10 blank-to-black pedestal
else
I2CWriteByte(TW803_P2,RegAdr,stInitT10xP2[RegIndex].ucRegVal);
RegAdr=stInitT10xP2[++RegIndex].ucRegAdr;
}
//=========================================================================
// Panel specified register settings
//=========================================================================
//#if (EMPTY_ARRAY)
for(RegIndex=0;RegIndex < PanelSpecP0Cnt;RegIndex++)
{
I2CWriteByte(TW803_P0,ucaPanelSpecAdrP0[RegIndex],ucaPanelSpecDataP0[RegIndex]);
}
//#endif
for(RegIndex=0;RegIndex < PanelSpecP2Cnt;RegIndex++)
{
I2CWriteByte(TW803_P2,ucaPanelSpecAdrP2[RegIndex],ucaPanelSpecDataP2[RegIndex]);
}
#ifdef ROTATE
SET_Dismod();
#endif
//kenny 20060403
#ifdef VBI_CC
VBI_Init();
#endif
//kenny 20060403
}
#ifdef TCON
void TconInit(void)
{
uCHAR TconIndex;
for(TconIndex=0;TconIndex < P1TconCnt;TconIndex++)
I2CWriteByte(TW803_P1, TconAddress+TconIndex, TconP1Data[TconIndex]);
}
#endif
#ifdef ROTATE
void SET_Dismod(void)
{
switch (Dis_Mode){
case TOP_LEFT: //Start from top-left
#ifdef ANALOG_PANEL
I2CWriteByte(TW803_P0,0xE1, ScanMode[0]);
#else
UP_DOWN = DigiPanlScanMode[0]>>1;
LEFT_RIGHT = DigiPanlScanMode[0]&0x01;
I2CWriteByte(TW803_P0,0xE1, ScanMode[0]&0xF0);
#endif
break;
case TOP_RIGHT: //Start from top-right
#ifdef ANALOG_PANEL
I2CWriteByte(TW803_P0,0xE1, ScanMode[1]);
#else
UP_DOWN = DigiPanlScanMode[1]>>1;
LEFT_RIGHT = DigiPanlScanMode[1]&0x01;
I2CWriteByte(TW803_P0,0xE1, ScanMode[1]&0xF0);
#endif
break;
case BOTTOM_RIGHT: //Start from bottom-right
#ifdef ANALOG_PANEL
I2CWriteByte(TW803_P0,0xE1, ScanMode[2]);
#else
UP_DOWN = DigiPanlScanMode[2]>>1;
LEFT_RIGHT = DigiPanlScanMode[2]&0x01;
I2CWriteByte(TW803_P0,0xE1, ScanMode[2]&0xF0);
#endif
break;
case BOTTOM_LEFT: //Start from bottom-left
#ifdef ANALOG_PANEL
I2CWriteByte(TW803_P0,0xE1, ScanMode[3]);
#else
UP_DOWN = DigiPanlScanMode[3]>>1;
LEFT_RIGHT = DigiPanlScanMode[3]&0x01;
I2CWriteByte(TW803_P0,0xE1, ScanMode[3]&0xF0);
#endif
break;
}
#ifdef OUT_PIN_CONF
I2CWriteByte(TW803_P0,0xE1, OUT_PIN_CONF);
#endif
return;
}
#endif
void SourceSelect(void)
{
if(m_cSource==isrccRGB565)
{
SetSignalStd();
SetOPTiming();
}
I2CWriteByte(TW803_P0, 0xC2, I2CReadByte(TW803_P0, 0xC2)|(PSYNC_STR|IGNORE_VSYNC));
I2CWriteByte(TW803_P0, 0x9d, 0x10);
I2CWriteByte(TW803_P0, 0x9e, 0xff);
I2CWriteByte(TW803_P0, 0x9f, 0x40);
I2CWriteByte(TW803_P0, PATTERN_CTRL, 0x87);
I2CWriteByte(TW803_P0,0x0f,0x70); //2005-03030 for position shift
I2CWriteByte(TW803_P0,0x0f,0x00); //2005-03030 for position shift
I2CWriteByte(TW803_P0,0x31,0x00);
I2CWriteByte(TW803_P0,0x1a, 0x87);
I2CWriteByte(TW803_P0,0x18, uiaSrcMux[(m_cSource&0x0F)*2]>>8); // cMux1);
I2CWriteByte(TW803_P0,0x19, uiaSrcMux[(m_cSource&0x0F)*2]&0xFF); // cMux2);
if(uiaSrcMux[(m_cSource&0x0F)*2+1]==itypeSVIDEO)
{
#ifdef T112
I2CWriteByte(TW803_P0,0x11, 0x22);
#else
I2CWriteByte(TW803_P0,0x11, 0x05);
#endif
I2CWriteByte(TW803_P2,0x07, /*0x24*/0x27);//0x05|0x22); //lucy
I2CWriteByte(TW803_P2,0x00, I2CReadByte(TW803_P2,0x00)|0x01);
I2CWriteByte(TW803_P2,0x01, I2CReadByte(TW803_P2,0x01)&~ENYPbPr);
I2CWriteByte(TW803_P2,0x03, I2CReadByte(TW803_P2,0x03)|0x03);
I2CWriteByte(TW803_P0,0x16, 0xD3); //lucy for begin source is SVIDEO
I2CWriteByte(TW803_P0,0x40, 0xC2); //lucy for begin source is SVIDEO
I2CWriteByte(TW803_P0,0x17, 0xC8); //lucy for begin source is SVIDEO
}
else if (uiaSrcMux[(m_cSource&0x0F)*2+1]==itypeCVBS)
{
I2CWriteByte(TW803_P0,0x11, 0x00);
I2CWriteByte(TW803_P2,0x07, 0x20);//0x05|0x22);
I2CWriteByte(TW803_P2,0x00, I2CReadByte(TW803_P2,0x00)&0xfe);
// I2CWriteByte(TW803_P2,0x01, I2CReadByte(TW803_P2,0x01)&~ENYPbPr);
// I2CWriteByte(TW803_P0,0x16, 0xD3);
if(m_cChroma==S_NTSC_4) // temporarily add by Sherman 06'01'27
I2CWriteByte(TW803_P2,0x03, 3);
else
I2CWriteByte(TW803_P2,0x03, 0);
//I2CWriteByte(TW803_P0,0x11, 0x00);
//I2CWriteByte(TW803_P2,0x07, 0x21);//0x05|0x22);
//I2CWriteByte(TW803_P2,0x00, I2CReadByte(TW803_P2,0x00)&0xfe);
//I2CWriteByte(TW803_P2,0x01, I2CReadByte(TW803_P2,0x01)&~ENYPbPr);
//I2CWriteByte(TW803_P0,0x16, 0xD3);
//if(m_cChroma==S_NTSC_4) // temporarily add by Sherman 06'01'27
// I2CWriteByte(TW803_P2,0x03, I2CReadByte(TW803_P2,0x03)&0xf8|0x03);
//else
// I2CWriteByte(TW803_P2,0x03, I2CReadByte(TW803_P2,0x03)&0xfc);
}
else if (uiaSrcMux[(m_cSource&0x0F)*2+1]==itypeYPBPR)
{
I2CWriteByte(TW803_P0,0x11, 0x55);
I2CWriteByte(TW803_P2,0x07, 0x20);
I2CWriteByte(TW803_P2,0x01, I2CReadByte(TW803_P2,0x01)|ENYPbPr);
}
else if (uiaSrcMux[(m_cSource&0x0F)*2+1]==itypeRGB)
{
I2CWriteByte(TW803_P0,0x16, 0x00);
I2CWriteByte(TW803_P0,0x31, 0x40);
I2CWriteByte(TW803_P0,0x40, 0xC2);
I2CWriteByte(TW803_P0,0x17, 0xC8);
I2CWriteByte(TW803_P0,0x1A, I2CReadByte(TW803_P0,0x1A)&0xF8);
//~ Enable Interrupt ~//
//I2CWriteByte(TW803_P0,0x33, 0xB0);
I2CWriteByte(TW803_P0,0x33, 0x0C);
I2CWriteByte(TW803_P0,0x32, 0xFF);
I2CWriteByte(TW803_P0,0x37, 0x40);
I2CWriteByte(TW803_P0,0x39, 0x10);
}
else if (uiaSrcMux[(m_cSource&0x0F)*2+1]==itypeRGB565)
{
I2CWriteByte(TW803_P0,0x16, 0xD3);
I2CWriteByte(TW803_P0,0x40, 0xC2);
I2CWriteByte(TW803_P0,0x17, 0xC8);
SRC_565();
}
if (uiaSrcMux[(m_cSource&0x0F)*2+1]==itypeITU656)
{
I2CWriteByte(TW803_P0,0x31, 0x10);
}
#ifdef T515
if ( (m_cSource&0x0F)< isrc_T515_CVIDEO1){
if(cSVideo)
I2CWriteByte(TW803_P2,0x07, 0x06|0x02);//|0x22
else
I2CWriteByte(TW803_P2,0x07, 0x02);// 930729//|0x20
}else{
DetectSignalStd(); // add by Sherman 06'01'03
SRC_656();
}
if((m_cSource&0x0F)>=isrcSVIDEO){
I2CWriteByte(TW803_P2,0x02, 0x4B);
I2CWriteByte(TW803_P0,0x1a, 0x87);
}
twdDelay(300);
if((m_cSource&0x0F)>=isrc_T515_CVIDEO1){
NoSignal=0;
I2CWriteByte(TW803_P0, 0xC2, I2CReadByte(TW803_P0, 0xC2)&~(PSYNC_STR|IGNORE_VSYNC));
I2CWriteByte(TW803_P0, PATTERN_CTRL, 0x00);
}else{
if(I2CReadByte(TW803_P2, 0x3A)&0x06){
NoSignal=0;
I2CWriteByte(TW803_P0, 0xC2, I2CReadByte(TW803_P0, 0xC2)&~(PSYNC_STR|IGNORE_VSYNC));
I2CWriteByte(TW803_P0, PATTERN_CTRL, 0x00);
}
}
#else
twdDelay(500);
if((I2CReadByte(TW803_P2, 0x3A)&0x06)){
NoSignal=0;
I2CWriteByte(TW803_P0, 0xC2, I2CReadByte(TW803_P0, 0xC2)&~(PSYNC_STR|IGNORE_VSYNC));
I2CWriteByte(TW803_P0, PATTERN_CTRL, 0x00);
}
#endif
I2CWriteByte(TW803_P0, 0xE2, 0x11);
}
void DetectSignalStd(void)
{
uCHAR index=0,SlaveAddr,RegAddrShift;//,tmp;
#ifdef T515
if(m_cSource >= isrc_T515_CVIDEO1){
SlaveAddr=0xb8;
RegAddrShift=0x20;
}else{
SlaveAddr=TW803_P2;
RegAddrShift=0x00;
}
#else
SlaveAddr=TW803_P2;
RegAddrShift=0x00;
#endif
m_cBuff[0]=m_cStandard;
m_cBuff[1]=I2CReadByte(SlaveAddr, 0x3A+RegAddrShift);
if(I2CReadByte(SlaveAddr, 0x3A+RegAddrShift)&0x06) // Judge vlock and hlock
{
//if(I2CReadByte(SlaveAddr, 0x7B+RegAddrShift)>0x10){// For no chroma case
//twdDelay1(50);
//~~~~~~~ set OPTiming ~~~~~~~~~~~~~~~~~~~//
if(I2CReadByte(TW803_P0,0x59) <= 0xd6)
m_cBuff[0]=S_NTSC;
else
m_cBuff[0]=S_PAL;
#ifdef T515
if((m_cSource&0x0f) >= isrc_T515_CVIDEO1){
m_cBuff[0] = I2CReadByte(TW515, 0x5c)&0x04;
if((I2CReadByte(TW515, 0x5c)&0x07)==0)
m_cBuff[0]=S_NTSC;
else if(I2CReadByte(TW515, 0x5c)&0x02)
m_cBuff[0]=S_SECAM;
else if(I2CReadByte(TW515, 0x5c)&0x04)
m_cBuff[0]=S_PAL;
else
m_cBuff[0]=0xff;
}
#endif
if((m_cStandard!=m_cBuff[0])){ // signal std was changed,and output timing must be set again
m_cStandard=m_cBuff[0];
SetOPTiming();
}
//~~~~~~~ End of set OPTiming ~~~~~~~~~~~~~~~~~~~//
//~~~~~~~ set Chroma ~~~~~~~~~~~~~~~~~~~//
m_cBuff[4]=m_cChroma;
#ifdef T515
if((m_cSource&0x0f) >= isrc_T515_CVIDEO1){
m_cBuff[4] = I2CReadByte(TW515, 0x5c)&0x04;
//else if((m_cSource&0x0f) >= isrc_T515_CVIDEO1){
if((I2CReadByte(TW515, 0x5c)&0x07)==0)
m_cBuff[4]=S_NTSC;
else if(I2CReadByte(TW515, 0x5c)&0x02)
m_cBuff[4]=S_SECAM;
else if(I2CReadByte(TW515, 0x5c)&0x04)
m_cBuff[4]=S_PAL;
else
m_cBuff[4]=0xff;
}
#endif
twdDelay1(25);
// Set Chroma lock configration
if(I2CReadByte(TW803_P0,0x59) <= 0xd6)
I2CWriteByte(SlaveAddr, 0x83+RegAddrShift, 0x39);//6f); // NTSC // change by Sherman 06'02'07
else
I2CWriteByte(SlaveAddr, 0x83+RegAddrShift, 0x39); // PAL
twdDelay1(50);
if(I2CReadByte(TW803_P0,0x59) <= 0xd6) { // NTSC-M,NTSC-4,PAL-M
m_wBuff[2]=0;
m_cBuff[1]=m_cChroma; // Preserve previous status for signal std
twdDelay1(150); // add by Sherman 06'01'16
while (1){ // NTSC-M=1,NTSC-4=4,PAL-M=5
if (m_cChroma == S_NTSC_4){
if ((I2CReadByte(SlaveAddr, 0x3a+RegAddrShift)&0x08)&&(I2CReadByte(SlaveAddr, 0x7a+RegAddrShift)<0x80))
break;
}
if ((m_cChroma == S_NTSC)|(m_cChroma == S_PAL_M)){
if ((I2CReadByte(SlaveAddr, 0x3a+RegAddrShift)&0x08))
break;
}
if (m_cChroma == S_NTSC)
#ifndef Signal_NTSC_4
#ifndef Signal_PAL_M
m_cChroma=S_NTSC;
#else
m_cChroma=S_PAL_M;
#endif
#else
m_cChroma=S_NTSC_4;
#endif
else if (m_cChroma == S_NTSC_4)
#ifndef Signal_PAL_M
m_cChroma=S_NTSC;
#else
m_cChroma=S_PAL_M;
#endif
else //if (m_cChroma == S_PAL_M)
m_cChroma=S_NTSC;
SetSignalStd(); // Set Signal flag and DTO
twdDelay1(50);
if ((++m_wBuff[2]) >4) break; // Avoid while setting, input switch to NTSC
}
}else{ // PAL-BD,PAL-CN,SECAM
#if (defined YPbPr)
if(m_cSource == isrYPbPr)
m_cBuff[4]=S_PAL;
else {
#endif
m_wBuff[2]=0;
m_cBuff[1]=m_cChroma; // Preserve previous status for signal std
twdDelay1(150); // add by Sherman 06'01'16
while (1){ // PAL-BD=2,PAL-CN=6,SECAM=3
if ((m_cChroma == S_PAL)|(m_cChroma == S_PAL_CN)){
if ((I2CReadByte(SlaveAddr, 0x3a+RegAddrShift)&0x08) && (I2CReadByte(SlaveAddr, 0x3c+RegAddrShift)&0x01==1))//&& (I2CReadByte(SlaveAddr, 0x7d+RegAddrShift)>0xf0))
break;
}
if (m_cChroma == S_SECAM){
if ((I2CReadByte(SlaveAddr, 0x3a+RegAddrShift)&0x08) && (I2CReadByte(SlaveAddr, 0x7d+RegAddrShift)>0xf0))
break;
}
if (m_cChroma == S_PAL)
#ifndef Signal_SECAM
#ifndef Signal_PAL_CN
m_cChroma=S_PAL;
#else
m_cChroma=S_PAL_CN;
#endif
#else
m_cChroma=S_SECAM;
#endif
else if (m_cChroma == S_SECAM)
#ifndef Signal_PAL_CN
m_cChroma=S_PAL;
#else
m_cChroma=S_PAL_CN;
#endif
else //if (m_cChroma == S_PAL_CN)
m_cChroma=S_PAL;
SetSignalStd(); // Set Signal flag and DTO
twdDelay1(50);
if ((++m_wBuff[2]) >4) break; // Avoid while setting, input switch to NTSC
}
#if (defined YPbPr)
}
#endif
}
if (m_cBuff[1] != m_cChroma){
if ((I2CReadByte(SlaveAddr, 0x3a+RegAddrShift)&0x08))
m_cBuff[4] = m_cChroma;
m_cChroma=m_cBuff[1] ;
}
if((m_cChroma!=m_cBuff[4])){
m_cChroma=m_cBuff[4];
}
}// 癹伴い
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -