/*************** MTK CONFIDENTIAL & COPYRIGHTED ****************/
/*************** ****************/
/*************** $Modtime:: 04/10/06 5:30p $ ****************/
/*************** $Revision:: 2 $ ****************/
/*************** ****************/
/*************** Description : TV Encoder Module ****************/
/*************** ****************/
/*************** Company : MediaTek Inc. ****************/
/*************** Programmer : Alan Hsu ****************/
/**********************************************************************/
#define _C_TVE_
#include "general.h"
#pragma NOAREGS
#ifndef MTK_TVE /* for external TVE only */
#if (defined(_CS4954_) || defined(_CS4955_))
/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
x CS4954 NTSC/PAL Digital Video Encoder x
x--------------------------------------------------------------------x
x Device Addr = 0x00 x
x--------------------------------------------------------------------x
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
// *********************************************************************
// Define TV Multi-Standard Output Format Configuration
// *********************************************************************
BYTE code NTSC[7] = {0x01, 0x02, 0x1C, 0x3E, 0xF8, 0xE0, 0x43};
BYTE code NTSCJ_BT601[7] = {0x01, 0x00, 0x1C, 0x3E, 0xF8, 0xE0, 0x43};
BYTE code NTSCM_RS170[7] = {0x21, 0x06, 0x1C, 0x3E, 0xF8, 0xE0, 0x43};
BYTE code PAL[7] = {0x41, 0x00, 0x15, 0x96, 0x15, 0x13, 0x54};
BYTE code PAL_M[7] = {0x61, 0x02, 0x15, 0xC7, 0xDF, 0xCD, 0x43};
BYTE code PAL_N[7] = {0xA1, 0x00, 0x15, 0x96, 0x15, 0x13, 0x54};
BYTE code PAL_NC[7] = {0x81, 0x00, 0x15, 0x8C, 0x28, 0xED, 0x43};
/************************************************************************
Function : BOOL fgTvI2CDataWrite(BYTE bData_Addr, BYTE *prData)
Description : ByteWrite Routine
Parameter : bData_Addr -> Data Address
*prData -> Data Content Pointer
Return : TRUE : successful with ACK from slave
FALSE : bus (SCL = 0) or ACK failure
************************************************************************/
BOOL fgTvI2CDataWrite(BYTE bData_Addr, BYTE bData) large
{
#ifdef USE_3W_SIF
return (fgI2CByteWrite(0x00, bData_Addr, bData));
#else
BYTE bDevice = 0x00;
bDevice = bDevice << 1; // Shift the 7-bit address to 7+1 format
if(!fgI2CStart(bDevice)) // Write Command
{
return(FALSE); // Device Address exceeds the range
}
if(!fgI2CSend(bData_Addr)) // Word Address
{
return(FALSE); // Device Address exceeds the range
}
if(!fgI2CSend(bData)) // Data Content Write
{
return(FALSE); // Device Address exceeds the range
}
vI2CStop();
return(TRUE);
#endif /* USE_3W_SIF */
}
/************************************************************************
Function : BOOL fgTvI2C_DataRead(BYTE bData_Addr, BYTE *prData)
Description : DataRead Routine
Parameter : bDevice -> Device Address
bData_Addr -> Data Address
bDataCount -> Data Content Cont
*prData -> Data Content Pointer
Return : TRUE : successful with ACK from slave
FALSE : bus (SCL = 0) or ACK failure
************************************************************************/
BOOL fgTvI2CDataRead(BYTE bData_Addr, BYTE *prData) large
{
#ifdef USE_3W_SIF
return (fgI2CByteRead(0x00, bData_Addr, prData));
#else
BYTE bDevice = 0x00;
bDevice = bDevice << 1; // Shift the 7-bit address to 7+1 format
if(!fgI2CStart(bDevice)) // Write Command
{
return(FALSE); // Start fail
}
if(!fgI2CSend(bData_Addr))// Word Address
{
return(FALSE); // Data Address Fail
}
// Step 2 : Real Read
bDevice = bDevice + 1; // Shift the 7-bit address to 7+1 format
if(!fgI2CStart(bDevice)) // Read Command
{
return(FALSE); // Start fail
}
vI2CRead(prData, FG_RANDREAD); // Data Content Read
// Step 3 : Stop
vI2CStop();
return (TRUE);
#endif /* USE_3W_SIF */
}
/************************************************************************
Function : void vTvSetFormat(BYTE *pbFormat)
Description : Setting Output Format
Parameter : 0->NTSC, 1->PAL, 2->NTSCJ_BT601, 3->NTSCM_RS170
4->PAL_M, 5->PAL_N, 6->PAL_NC, default->NTSC
Return : NONE
************************************************************************/
void vTvSetFormat(BYTE bTvType) large
{
BYTE code *pbFmt;
BYTE bData, bType;
switch(bTvType)
{
case TV_PAL:
pbFmt = PAL;
break;
case TV_NTSCJ_BT601:
pbFmt = NTSCJ_BT601;
break;
case TV_NTSCM_RS170:
pbFmt = NTSCM_RS170;
break;
case TV_PAL_M:
pbFmt = PAL_M;
break;
case TV_PAL_N:
pbFmt = PAL_N;
break;
case TV_PAL_NC:
pbFmt = PAL_NC;
break;
case TV_NTSC:
default:
pbFmt = NTSC;
break;
}
fgTvI2CDataRead(0x00, &bData);
#ifdef ENCODER_MASTER
bData = (bData & 0x02) + pbFmt[0] + 0x10;
#else
bData = (bData & 0x02) + pbFmt[0];
#endif
fgTvI2CDataWrite(0x00, bData);
fgTvI2CDataRead(0x01, &bData);
bData = (bData & 0xF8) + pbFmt[1];
#ifdef NO_PEDESTAL_OFFSET
if(pbFmt[1] & 0x02)
{
bData = bData - 0x02;
}
#endif
fgTvI2CDataWrite(0x01, bData);
fgTvI2CDataWrite(0x10, pbFmt[2]);
fgTvI2CDataWrite(0x11, pbFmt[3]);
fgTvI2CDataWrite(0x12, pbFmt[4]);
fgTvI2CDataWrite(0x13, pbFmt[5]);
fgTvI2CDataWrite(0x14, pbFmt[6]);
bType = bSharedInfo(SI_TVE_MVTYPE);
if (bType != 0x00)
{
if (bTvType != TV_NTSC)
{
bType = 4;
}
}
MVisionChangeType(bType);
}
/************************************************************************
Function : void vTvAmpAdjust(BYTE bType, BYTE bData)
Description : Write Amplitude Adjust Register(0x22 ~ 0x28)
Parameter : bType : 0->U/Cb, 1->V/Cr, 2->Y/Luma,
3->Red, 4->Green,5->Blue, 6->Bright
bData : Amplitude coefficient
Return : NONE
************************************************************************/
void vTvAmpAdjust(BYTE bType, BYTE bData) large
{
switch(bType)
{
case 0:
fgTvI2CDataWrite(0x22, bData);
break;
case 1:
fgTvI2CDataWrite(0x23, bData);
break;
case 2:
fgTvI2CDataWrite(0x24, bData);
break;
case 3:
fgTvI2CDataWrite(0x25, bData);
break;
case 4:
fgTvI2CDataWrite(0x26, bData);
break;
case 5:
fgTvI2CDataWrite(0x27, bData);
break;
case 6:
fgTvI2CDataWrite(0x28, bData);
break;
}
}
/************************************************************************
Function : void vTvDacEnable(BYTE bType, BYTE bEnable)
Description : Enable or Disable DACWrite(0x05)
Parameter : bType : 0->Blue, 1->Green, 2->Red, 0x20->B/G/R
3->Chroma, 4->Luma, 0x40-> C/L, 5->Composite 0
0xFF -> All
bEnable : 0->Disable, 1->Enable, 0xF0-> High-I, 0x0F->L-I
Return : NONE
************************************************************************/
void vTvDacEnable(BYTE bType, BYTE bEnable) large
{
BYTE bData;
fgTvI2CDataRead(0x05, &bData);
if(bEnable == 0xF0) //High-Impedance
{
bData = (bData & 0xBF) + 0x40;
}
else if(bEnable == 0x0F) //Low-Impedance
{
bData = bData & 0