📄 tidtv_tvp5160.c
字号:
/*******************************************************************************
* @ModuleName :: TiDTV_TVP5160.c
*
* @Copyright :: Copyright 2005- Texas Instruments, Inc.
*
* @Description:: Analog Video Decoder (TVP5160) Control Module
*
* @History ::
*---------------------------------------
* 03-13-2005 W.Shi Created
*******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include "ucos_ii.h"
#include "TiDTV_DataType.h"
#include "TiDTV_SysCtrl.h"
#include "TiDTV_UserApi.h"
#include "TVP9K_I2C_Def.h"
#include "TVP9K_NV_Def.h"
#include "TiDTV_GuiApi.h"
//----------------------------------------------------------
// TVP5160EVM Channel selections: I2C_0x00
//
static const UCHAR Tvp5160ChanSel[] = {
#ifdef TVP5160EVM
0x01, // CVBS CH1: TUNER
0x00, // CVBS CH2: CVBS-RCA
0x42, // S-VIDEO
0x95, // Component: YPbPr
// 0xC2, // SCART: RGB, CVBS-RCA
#else // for DTV RefDesign
0x00, // CVBS CH1: TUNER
0x06, // CVBS CH2: CVBS-RCA
0x44, // S-VIDEO
0x92, // Component: YPbPr
#endif /* TVP5160EVM */
};
//----------------------------------------------------------
static void TiDTV_Init5160VDP(void);
static const UCHAR Tvp5160InitData[][2] = {
#if 1
{0xee, 0x01}, // holds processor in reset
{0xea, 0xb0},
{0xe9, 0x00},
{0xe8, 0x63},
{0xe0, 0x01},
{0xee, 0x00}, // release processor reset
{0x04, 0x3f}, // autoswitch mask - interlaced
{0x06, 0x40}, // pedestal off
{0x35, 0x2a}, // GPIO=0, GLCO, AVID and FID enabled
{0x36, 0xaf}, // HS and VS enabled
{0x75, 0x1a}, // F & A bit control
{0x7f, 0x01}, // analog output enabled
{0x59, 0x07}, // enable SDRAM and set SDRAM size
{0x0d, 0x84}, // 3DYC, 3DNR enabled
{0x69, 0x03}, // using TVP5146 compatible mode
{0x01, 0x07}, // set AFE gain control to manual
{0x07, 0x04}, // set luma peaking gain to 0.5
{0x09, 0x69}, // set luma peaking gain brightness to 105
{0x06, 0x03}, // set luma peaking gain 3 pixel clocks delay
{0x5a, 0xff}, // set 3DNR Y sensitivity to 255
{0x5b, 0xff}, // set 3DNR UV sensitivity to 255
{0x5c, 0xff}, // set 3DNR Y coring limit to 255
{0x5d, 0xff}, // set 3DNR UV coring limit to 255
{0x5e, 0xff}, // set 3DNR low noise limit to 255
{0x33, 0x00}, // set YCbCr output code to ITU-R BT 601
{0x0b, 0x96}, // set color saturation to 150
{0xff, 0xff}, // end mark
#else
// Set Internal CPU into Fast mode
{0xea, 0xB0},
{0xe9, 0x00},
{0xe8, 0x60},
{0xe1, 0x01},
{0xe8, 0x63},
{0xe1, 0x01},
{0xea, 0xB0},
{0xe9, 0x00},
{0xe8, 0x60},
{0xe0, 0x00},
// TVP5160 Direct I2C Registers
{0x02, 0x00}, // 0x00 = Auto, 0x01 = Force NTSC
{0x03, 0x00}, // Power Down: Normal Operation
{0x04, 0x03}, // Auto Switch Mask: NTSC and PAL only
{0x30, 0x0F}, // Auto Switch including Progressive mode
{0x06, 0x43}, // Pedestal off: was {0x06, 0x40}
{0x07, 0x08}, // Luma peaking
{0x59, 0x07}, // Enabled SDRAM and set SDRAM size
{0x0D, 0x80}, // Chrominance Processing Ctrl 1 Reg 3DYC Only Enabled
{0x33, 0x40}, // Extended Coding Range, ITU-656 (10-bit)
{0x34, 0x11}, // Outputs Enabled
{0x35, 0xEA}, // GLCO and FID Enabled
{0x36, 0xAF}, // HS and VS Enabled
{0x75, 0x16},
{0xC0, 0x00}, // VBI Data is to 656 port not FIFO (host)
{0xff, 0xff}, // End mark
#endif
};
//----------------------------------------------------------
static const UCHAR Tvp5160InitVdpNTSC[] = {
0xE8,
0x00, 0x06, 0x80,
0xE1,
0x15, 0xC1, // Line-21: CC field-1
0x15, 0xC9, // Line-21: CC field-2
};
/*******************************************************************************
* @RoutineName:: TiDTV_InitVideoDec
*
* @Description:: TVP5160 initializations
*
* @Input :: none
*
* @Output :: none
*
* @Return :: none
*******************************************************************************/
void TiDTV_InitVideoDec(void)
{
UCHAR (*pWorkI2cData)[2] = (UCHAR (*)[2]) Tvp5160InitData;
for (; (*pWorkI2cData)[1] != 0xff; pWorkI2cData++)
TiDTV_I2cWrite(TVP5160_I2C_CHANNEL, 0, TVP5160_I2C_DEVICE_ADDR, 2, &((*pWorkI2cData)[0]), OS_TICKS_PER_SEC / 10);
// TVP5160 VDP (VBI Data Processor) Initializations
TiDTV_Init5160VDP();
// TVP5160 Channel Selection (I2C_0x00: CVBS/S-Video/Component/SCART
TiDTV_VideoDecChanSel();
}
/*******************************************************************************
* @RoutineName:: TiDTV_Init5160VDP
*
* @Description:: TVP5160 VDP (VBI Data Processor) Initializations
*
* @Input :: none
*
* @Output :: none
*
* @Return :: none
*******************************************************************************/
static void TiDTV_Init5160VDP(void)
{
UCHAR FifoCount = 0;
int i;
// Do FIFO Reset untill FIFO COUNT = 0
for (i = 0; i < 10; i++) {
// VDP FIFO Reset
TiDTV_I2cWriteByte(TVP5160_I2C_CHANNEL, 1, TVP5160_I2C_DEVICE_ADDR, 1, 0xBF, 0x01, OS_TICKS_PER_SEC / 2);
TiDTV_I2cRead(TVP5160_I2C_CHANNEL, 1, TVP5160_I2C_DEVICE_ADDR, 1, 0xBC, 1, &FifoCount, OS_TICKS_PER_SEC / 2);
if (FifoCount == 0)
break; // until FIFO COUNT = 0
}
// Init VDP General Control Register
TiDTV_I2cWrite(TVP5160_I2C_CHANNEL, 1, TVP5160_I2C_DEVICE_ADDR, 4, (UCHAR *) &Tvp5160InitVdpNTSC[0], OS_TICKS_PER_SEC);
TiDTV_I2cWrite(TVP5160_I2C_CHANNEL, 1, TVP5160_I2C_DEVICE_ADDR, 5, (UCHAR *) &Tvp5160InitVdpNTSC[4], OS_TICKS_PER_SEC);
}
/*******************************************************************************
* @RoutineName:: TiDTV_VideoDecChanSel
*
* @Description:: TVP5160 Channel selection
*
* @Input :: none
*
* @Output :: none
*
* @Return :: none
*******************************************************************************/
void TiDTV_VideoDecChanSel(void)
{
UCHAR WorkUCHAR = 0xff;
switch (TiDTV_SysCtrl.AvInput) {
case TI_DTV_AV_INPUT_A_VIDEO1: // Analog TV Channels (Tuner)
WorkUCHAR = Tvp5160ChanSel[0];
break;
case TI_DTV_AV_INPUT_A_VIDEO2: // Video (CVBS)
WorkUCHAR = Tvp5160ChanSel[1];
break;
case TI_DTV_AV_INPUT_A_SVIDEO: // S-Video
WorkUCHAR = Tvp5160ChanSel[2];
break;
case TI_DTV_AV_INPUT_YPBPR1: // Component-1
WorkUCHAR = Tvp5160ChanSel[3];
break;
default:
break;
}
if (WorkUCHAR != 0xff) {
// TVP5160 Channel Selection (I2C_0x00: CVBS/S-Video/Component/SCART
TiDTV_I2cWriteByte(TVP5160_I2C_CHANNEL, 0, TVP5160_I2C_DEVICE_ADDR, 1, 0x00, WorkUCHAR, OS_TICKS_PER_SEC / 10);
}
}
/*******************************************************************************
* @RoutineName:: TiDTV_VideoDecGetStandard
*
* @Description:: TVP5160 Get video standard
*
* @Input :: none
*
* @Output :: none
*
* @Return ::
* UCHAR : Video Standard
*******************************************************************************/
UCHAR TiDTV_VideoDecGetStandard(void)
{
// UCHAR TxDataBuf[3] = {0xB8, 0x3F, 0xB9};
UCHAR VideoStandard = 0xff;
// TiDTV_I2cReadAfterWrite(TVP5160_I2C_CHANNEL, 1, 3, TxDataBuf,
// 1, &VideoStandard, OS_TICKS_PER_SEC / 2);
if (TiDTV_I2cRead(TVP5160_I2C_CHANNEL, 1, TVP5160_I2C_DEVICE_ADDR, 1, 0x3F, 1,
&VideoStandard, OS_TICKS_PER_SEC / 2) != TI_DTV_E_NG)
{
switch (VideoStandard & 0x0f) {
case TI_DTV_VIDEO_DEC_NTSC:
VideoStandard = TI_DTV_NV_NTSC;
break;
case TI_DTV_VIDEO_DEC_PAL:
VideoStandard = TI_DTV_NV_PAL;
break;
case TI_DTV_VIDEO_DEC_480P:
VideoStandard = TI_DTV_NV_480P;
break;
case TI_DTV_VIDEO_DEC_576P:
VideoStandard = TI_DTV_NV_576P;
break;
}
}
if (VideoStandard != 0xff && VideoStandard != NvPictureFmtIdx) {
// Video Standard changed
if (VideoStandard == TI_DTV_NV_480P || VideoStandard == TI_DTV_NV_576P) {
// 20-bit 656 output format: I2C_0x33 = 0x44
TiDTV_I2cWriteByte(TVP5160_I2C_CHANNEL, 1, TVP5160_I2C_DEVICE_ADDR, 1, 0x33, 0x44, OS_TICKS_PER_SEC / 2);
} else {
// 10-bit 656 output format: I2C_0x33 = 0x40
TiDTV_I2cWriteByte(TVP5160_I2C_CHANNEL, 1, TVP5160_I2C_DEVICE_ADDR, 1, 0x33, 0x40, OS_TICKS_PER_SEC / 2);
}
}
return VideoStandard;
}
/*******************************************************************************
* @RoutineName:: TiDTV_VideoDecGetLockStatus
*
* @Description:: TVP5160 Get H/V lock status
*
* @Input :: none
*
* @Output :: none
*
* @Return ::
* UCHAR : H/V Lock status
*******************************************************************************/
UCHAR TiDTV_VideoDecGetLockStatus(void)
{
UCHAR HVLockStatus;
TiDTV_I2cRead(TVP5160_I2C_CHANNEL, 0, TVP5160_I2C_DEVICE_ADDR, 1, 0x3A, 1, &HVLockStatus, OS_TICKS_PER_SEC / 2);
return (HVLockStatus & 0x06);
}
/*******************************************************************************
* @RoutineName:: TiDTV_VideoDecGetVTotal
*
* @Description:: TVP5160 Get current signal total lines
*
* @Input :: none
*
* @Output :: none
*
* @Return ::
* USHORT : Video vertical total line numbers
*******************************************************************************/
USHORT TiDTV_VideoDecGetVTotal(void)
{
USHORT VTotalLineNumber = 0;
UCHAR temp8;
// get upper 3 bit
TiDTV_I2cRead(TVP5160_I2C_CHANNEL, 1, TVP5160_I2C_DEVICE_ADDR, 1, 0x43, 1, &temp8, OS_TICKS_PER_SEC / 2);
VTotalLineNumber = (USHORT) temp8;
VTotalLineNumber = VTotalLineNumber << 8;
// get lower 8 bit
TiDTV_I2cRead(TVP5160_I2C_CHANNEL, 1, TVP5160_I2C_DEVICE_ADDR, 1, 0x42, 1, &temp8, OS_TICKS_PER_SEC / 2);
VTotalLineNumber = (USHORT)temp8;
return VTotalLineNumber;
}
/*******************************************************************************
* @RoutineName:: TiDTV_VideoDecAdjBrightness
*
* @Description:: TVP5160 adjust brightness
*
* @Input :: UCHAR Presentage. the Presentage is that:
* Percentage = (float) (Current_Value - Min) / (float)(Max - Min) * 100;
* Current_Value is data stored, min value is current OSD min, max value is current OSD max
*
* @Output :: none
*
* @Return ::
* USHORT : NONE
*******************************************************************************/
USHORT TiDTV_VideoDecAdjBrightness(UCHAR Presentage)
{
UCHAR RealValue;
UCHAR VideoDecBrightnessMin, VideoDecBrightnessMax;
if (Presentage > 100)
return 0;
VideoDecBrightnessMin = 16; // depends on different decoder
VideoDecBrightnessMax = 240; // depends on different decoder
RealValue = (VideoDecBrightnessMax - VideoDecBrightnessMin) * (Presentage / 100);
// write register value
TiDTV_I2cWriteByte(TVP5160_I2C_CHANNEL, 1, TVP5160_I2C_DEVICE_ADDR, 1, 0x09, RealValue, OS_TICKS_PER_SEC / 2);
return 1;
}
/*******************************************************************************
* @RoutineName:: TiDTV_VideoDecAdjSharpness
*
* @Description:: TVP5160 adjust Sharpness
*
* @Input :: UCHAR Presentage. the Presentage is that:
* Percentage = (float) (Current_Value - Min) / (float)(Max - Min) * 100;
* Current_Value is data stored, min value is current OSD min, max value is current OSD max
*
* @Output :: none
*
* @Return ::
* USHORT : NONE
*******************************************************************************/
USHORT TiDTV_VideoDecAdjSharpness(UCHAR Presentage)
{
UCHAR temp8;
if (Presentage > 100)
return 0;
// read peaking register value
TiDTV_I2cRead(TVP5160_I2C_CHANNEL, 1, TVP5160_I2C_DEVICE_ADDR, 1, 0x07,1, &temp8, OS_TICKS_PER_SEC / 2);
// set peaking gains
if (Presentage < 25)
temp8 = temp8 & ( (UCHAR) ~BIT2 & (UCHAR) ~BIT3);
else if((Presentage >= 25) && (Presentage < 50))
temp8 = temp8 & ( (UCHAR) ~BIT2 & (UCHAR) ~BIT3) | (UCHAR) BIT2;
else if((Presentage >= 50) && (Presentage < 75))
temp8 = temp8 & ( (UCHAR) ~BIT2 & (UCHAR) ~BIT3) | (UCHAR) BIT3;
else if(Presentage >= 75)
temp8 = temp8 | (UCHAR) BIT2 | (UCHAR) BIT3;
return 1;
}
/*******************************************************************************
* @RoutineName:: TiDTV_VideoDecAdjNoiseReduction
*
* @Description:: TVP5160 adjust Noise Reduction
*
* @Input :: UCHAR Presentage. the Presentage is that:
* Percentage = (float) (Current_Value - Min) / (float)(Max - Min) * 100;
* Current_Value is data stored, min value is current OSD min, max value is current OSD max
*
* @Output :: none
*
* @Return ::
* USHORT : NONE
*******************************************************************************/
USHORT TiDTV_VideoDecAdjNoiseReduction(UCHAR Presentage)
{
UCHAR NREnable, NRSensitivity, NRCoring;
UCHAR VideoDecNRMin, VideoDecNRMax;
if (Presentage > 100)
return 0;
VideoDecNRMin = 8;
VideoDecNRMax = 128;
NRSensitivity = (VideoDecNRMax - VideoDecNRMin) * (Presentage / 100); // more NR Sensitivity, 3DNR is more
NRCoring = (VideoDecNRMax - VideoDecNRMin) * ((100 - Presentage) / 100); // less NR coring, 3DNR is more
// read noise register Status value
TiDTV_I2cRead(TVP5160_I2C_CHANNEL, 1, TVP5160_I2C_DEVICE_ADDR, 1, 0x0D,1, &NREnable, OS_TICKS_PER_SEC / 2);
if(Presentage == 0) {
// disable NR
NREnable = NREnable & ~BIT2;
TiDTV_I2cWriteByte(TVP5160_I2C_CHANNEL, 1, TVP5160_I2C_DEVICE_ADDR, 1, 0x0D, NREnable, OS_TICKS_PER_SEC / 2);
} else {
if( (NREnable & BIT2) != BIT2) {
NREnable = NREnable | BIT2;
TiDTV_I2cWriteByte(TVP5160_I2C_CHANNEL, 1, TVP5160_I2C_DEVICE_ADDR, 1, 0x0D,NREnable, OS_TICKS_PER_SEC / 2);
}
TiDTV_I2cWriteByte(TVP5160_I2C_CHANNEL, 1, TVP5160_I2C_DEVICE_ADDR, 1, 0x5A,NRSensitivity, OS_TICKS_PER_SEC / 2); // Y Sensitivity
TiDTV_I2cWriteByte(TVP5160_I2C_CHANNEL, 1, TVP5160_I2C_DEVICE_ADDR, 1, 0x5B,NRSensitivity, OS_TICKS_PER_SEC / 2); // C Sensitivity
TiDTV_I2cWriteByte(TVP5160_I2C_CHANNEL, 1, TVP5160_I2C_DEVICE_ADDR, 1, 0x5C,NRCoring, OS_TICKS_PER_SEC / 2); // Y Coring
TiDTV_I2cWriteByte(TVP5160_I2C_CHANNEL, 1, TVP5160_I2C_DEVICE_ADDR, 1, 0x5D,NRCoring, OS_TICKS_PER_SEC / 2); // C Coring
}
return 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -