📄 vdc_tvp5147.c
字号:
{
BYTE temp;
BYTE i;
//reset whole chip...
//bVIDEOPOWER = _LOW; //power up(low active.)
CVIDEO_POWER_ON(); //power up(low active.)
bVIDEORESET = _HIGH; //pull up reset pin, prepare for reset.
CTimerDelayXms(10); //delay 10ms for power stable. min is 1ms according to spec.
bVIDEORESET = _LOW;
CTimerDelayXms(100); //delay 100ms for reset finish. min is 200ns according to spec.
bVIDEORESET = _HIGH; //normal operation.
CVideoPowerState(_VIDEO_NORMAL);
// 1. User must write the following value to TVP5147.
for(i=0; i<4; i++)
{
temp = tVIDEO_TABLE_VBUS_INIT[i][3];
CI2cWrite(_VIDEO_DEVICE, ADDRESS(0xE8), LENGTH(3), tVIDEO_TABLE_VBUS_INIT[i]);
CI2cWrite(_VIDEO_DEVICE, ADDRESS(0xE0), LENGTH(1), &temp);
}
// 2. delay 20ms
CTimerDelayXms(20);
//Update firmware
// ...
//write unused register:
temp = 0x00;
CI2cWrite(_VIDEO_DEVICE, ADDRESS(0x35), LENGTH(1), &temp);
CI2cWrite(_VIDEO_DEVICE, ADDRESS(0x36), LENGTH(1), &temp);
CI2cWrite(_VIDEO_DEVICE, ADDRESS(0x37), LENGTH(1), &temp);
CI2cWrite(_VIDEO_DEVICE, ADDRESS(0x38), LENGTH(1), &temp);
temp = 0x01;
CI2cWrite(_VIDEO_DEVICE, ADDRESS(0x39), LENGTH(1), &temp);
CTimerDelayXms(1);
CVideoDataEnable(_OFF);
CVideoPowerState(_VIDEO_POWER_SAVING);
//x.hu, request to set scaler in CVideoExist()
SET_VIDEO_TABLE_SET_SCALER();
}
//--------------------------------------------------
// Description : Check if color locked
// Input Value : ucColorStandard --> Color standard
// Output Value : Return _TRUE if color is locked, otherwise _FALSE
//--------------------------------------------------
bit CVideoIsColorLocked(BYTE ucColorStandard)
{
BYTE temp;
//set color standard
temp = ucColorStandard & 0x07;
CI2cWrite(_VIDEO_DEVICE, ADDRESS(0x02), LENGTH(1), &temp);
CTimerDelayXms(100); // must longer than 40ms.
//get lock information
CI2cRead(_VIDEO_DEVICE, ADDRESS(0x3A), LENGTH(1), &temp);
if((temp & _BIT3) == _BIT3)
return _TRUE;
else
return _FALSE;
}
//--------------------------------------------------
// Description : Polling to get a locked color standard
// Input Value : None
// Output Value : Return _TRUE if color locked
//--------------------------------------------------
bit CVideoColorFormatProc(void)
{
BYTE temp;
BYTE i;
if(CVideoIsColorLocked(_AUTO_MODE)) //set to auto detection mode and then check color is lock or not.
{
CI2cRead(_VIDEO_DEVICE, ADDRESS(0x3F), LENGTH(1), &temp);
//Here we can get color mode information.
temp &= 0x07;
CI2cWrite(_VIDEO_DEVICE, ADDRESS(0x02), LENGTH(1), &temp); //set to designate color mode.
ucModeFound = temp; //get current color mode information.
if (temp == _PAL_BGDHI || temp==_PAL_M || temp==_PAL_N|| temp==_PAL_60)
{
for(i=0; i<54; i++)
{
temp = tVIDEO_TABLE_PAL_COMB_OPTIMIZE[i][3];
CI2cWrite(_VIDEO_DEVICE, ADDRESS(0xE8), LENGTH(3), tVIDEO_TABLE_PAL_COMB_OPTIMIZE[i]);
CI2cWrite(_VIDEO_DEVICE, ADDRESS(0xE0), LENGTH(1), &temp);
}
CTimerDelayXms(20);
}
else if (temp == _NTSC_M|| temp==_NTSC_443)
{
for(i=0; i<2; i++)
{
temp = tVIDEO_TABLE_NTSC_COMB_OPTIMIZE[i][3];
CI2cWrite(_VIDEO_DEVICE, ADDRESS(0xE8), LENGTH(3), tVIDEO_TABLE_NTSC_COMB_OPTIMIZE[i]);
CI2cWrite(_VIDEO_DEVICE, ADDRESS(0xE0), LENGTH(1), &temp);
}
CTimerDelayXms(20);
}
return _TRUE;
}
else
{
return _FALSE;
}
}
//--------------------------------------------------
// Description : Set to designate mode according to current channel
// Input Value : ucInputChannel --> choose input channel, like AV or SV channels
// Output Value : None
//--------------------------------------------------
void CVideoModeProc(BYTE ucInputChannel)
{
BYTE temp;
if(ucInputChannel == _AV_CHANNEL)
temp = _AV_PORT;
if(ucInputChannel == _AV2_CHANNEL)
temp = _AV2_PORT;
else if(ucInputChannel == _SV_CHANNEL)
temp = _SV_PORT;
//First, set channel.
CI2cWrite(_VIDEO_DEVICE, ADDRESS(0x00), LENGTH(1), &temp);
//set color mode to auto for detection.
temp = _AUTO_MODE;
CI2cWrite(_VIDEO_DEVICE, ADDRESS(0x02), LENGTH(1), &temp);
//Second, set general setting...
switch(ucInputChannel)
{
case _AV_CHANNEL:
case _AV2_CHANNEL:
//Optimizes the trap filter selection for NTSC and PAL
temp = 0x00;
CI2cWrite(_VIDEO_DEVICE, ADDRESS(0x08), LENGTH(1), &temp);
//Optimizes the chrominance filter selection for NTSC and PAL
//temp = 0x04;
temp = 0x0c; //x.hu, 20051026, for PAL compensation
CI2cWrite(_VIDEO_DEVICE, ADDRESS(0x0e), LENGTH(1), &temp);
//Enable YCbCr output and the clock output
temp = 0x11;
CI2cWrite(_VIDEO_DEVICE, ADDRESS(0x34), LENGTH(1), &temp);
break;
case _SV_CHANNEL:
break;
default:
break;
}
}
//--------------------------------------------------
// Description : Check Video Channel if Signal Exist
// Input Value : ucInputChannel --> choose input channel, like AV or SV channels
// Output Value : Return _TRUE if video signal exist, otherwise _FALSE
//--------------------------------------------------
bit CVideoIsExist(BYTE ucInputChannel)
{
BYTE temp;
//////////////////////////////////////
if (GET_VIDEO_TABLE_SET_SCALER()) {
CScalerCodeW(tVIDEO_TABLE_SET_SCALER);
CLR_VIDEO_TABLE_SET_SCALER();
CVideoModeProc(ucInputChannel);
CTimerDelayXms(100); //for signal switch finish.
}
//////////////////////////////////////
//CScalerCodeW(tVIDEO_TABLE_SET_SCALER);
//CVideoModeProc(ucInputChannel);
//CTimerDelayXms(100); //for signal switch finish.
///////////////////////////////////////
CTimerDelayXms(1);
CI2cRead(_VIDEO_DEVICE, ADDRESS(0x3A), LENGTH(1), &temp); //get signal information.
if((temp & _BIT5) == _BIT5) //field rate.
{
SET50HZ();
}
else
{
SET60HZ();
}
if((temp & (_BIT1 | _BIT2)) == (_BIT1 | _BIT2)) //H/V sync lock.
{
if(CVideoColorFormatProc()) //if color lock.
{
if(CModeMeasureReady()) //Measure H/V sync.
{
if(CModeMeasureData())
{
stModeInfo.ModeCurr = _VIDEO_EXIST;
return _TRUE;
}
else
{
return _FALSE; //Measure failed.
}
}
else
{
return _FALSE;
}
}
else
return _FALSE; //color lock failed.
}
else
{
return _FALSE; //Sync lock failed.
}
}
//--------------------------------------------------
// Description : Check if video signal is changed
// Input Value : None
// Output Value : Return _TRUE if video signal is changed
//--------------------------------------------------
bit CVideoIsChange(void)
{
BYTE temp;
CI2cRead(_VIDEO_DEVICE, ADDRESS(0x3A), LENGTH(1), &temp);
////////////////////////
// x.hu, 20050804, update, detect whether the video is changed btween PAL and NTSC
/*if ((temp & (_BIT1|_BIT2)) != (_BIT1 | _BIT2)) // H/V sync state
{
return _TRUE;
}*/
if ((temp & (_BIT1|_BIT2)) != (_BIT1 | _BIT2)) // H/V sync state
{
#if (_CUSTOM_TYPE == _CUSTOM_HAOZHEN)
// 20051027, for HaoZhen, Do not shutdown while PAL/NTSC alternate
SET_VIDEO_PN_ACTION();
#endif
return _TRUE;
}
////////////////////////
if(CHECK50HZ() && ((temp & _BIT5)==0x00)) // 50Hz-->60Hz
{
return _TRUE;
}
else if(CHECK60HZ() && ((temp & _BIT5)==_BIT5)) // 60Hz-->50Hz
{
return _TRUE;
}
else
{
return _FALSE;
}
}
//---------------------------------------
// Description : power save Video Decoder
// Input Value: None
// Output Value: None
//---------------------------------------
void CVideoPowerState(BYTE state)
{
state &= 0x03;
CI2cWrite(_VIDEO_DEVICE, ADDRESS(0x03), LENGTH(1), &state);
CTimerDelayXms(20);
}
//----------------------------------------
// Description : Enable Video Data Output or not
// Input Value: None
// Output Value: None
//----------------------------------------
void CVideoDataEnable(BIT bEnable)
{
BYTE temp;
CI2cRead(_VIDEO_DEVICE, ADDRESS(0x34), 1, &temp);
if(bEnable)
{
//Enable data output and enable data clock
temp &= 0x11;
}
else
{
//Disable data & clock output
temp |= (~0x11);
}
CI2cWrite(_VIDEO_DEVICE, ADDRESS(0x34), 1, &temp);
}
#endif
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -