📄 tvp5150.c
字号:
/*
* Copyright 2006 by VisionMagic Ltd.
* All rights reserved. Property of VisionMagic Ltd.
* Restricted rights to use, duplicate or disclose this code are
* granted through contract.
*
*/
/**************************************************************************/
/* tvp5150.c file */
/**************************************************************************/
#include <std.h>
#include <csl_i2c.h>
#include <csl_gpio.h>
#include <csl_stdinc.h>
#include <edc.h>
#include "tvp5150.h"
#include "_iic.h"
#include "_tvp5150.h"
typedef enum {INTERLACED = TRUE, PROGRESSIVE = FALSE} FrameType ;
static void initI2CHandle(I2C_Handle handle);
static Uint8 setTargetTVP5150(Int channel);
static void simpConfigTVP5150(Int channel, TVP5150_ConfParams *pConfParams);
static void powerdownTVP5150(Int channel, Bool powerDownEnable);
static void resetTVP5150(Int channel);
static void scalerReset(Uns channel);
static Int TVP5150_ctrl(EDC_Handle handle, TVP5150_Cmd cmd, Arg arg);
static Int TVP5150_close(EDC_Handle handle);
static EDC_Handle TVP5150_open(String devName, Arg optArg);
EDC_Fxns TVP5150_Fxns = {
TVP5150_open,
TVP5150_close,
TVP5150_ctrl
};
static I2C_Handle g_hI2C = INV;
/*-------------------------------------------------------
* This function switches the I2C bus if necessary.
*-------------------------------------------------------*/
static void initI2CHandle(I2C_Handle handle)
{
static Int hI2C_inited = 0;
if ( !hI2C_inited )
{
g_hI2C = handle;
hI2C_inited = 1;
/* init the gpio0 for iic, gpen for gpio0 is enabled by default, so omit it. */
GPIO_RSET(GPGC,0x0); /*将GPIO0不做为GPINT使用*/
GPIO_RSET(GPDIR,0x1); /*将GPIO0做为输出*/
}
}
/*-------------------------------------------------------
* This function switches the I2C bus if necessary.
*-------------------------------------------------------*/
static Uint8 setTargetTVP5150(Int channel)
{
static Int curI2CBusID = -1;
Int busid = -1;
Uint8 addrI2C = 0;
if (channel == 0 || channel == 1)
busid = 0;
else if (channel == 2 || channel == 3)
busid = 1;
else
{
/* error channel number, go to error process. */
return addrI2C;
}
addrI2C = (channel == 0 || channel == 2) ? _TVP5150_IIC_ADDR0 : _TVP5150_IIC_ADDR1;
if (busid == curI2CBusID)
return addrI2C;
curI2CBusID = busid;
GPIO_RSET(GPVAL, curI2CBusID); /* select the IIC bus */
return addrI2C;
}
/*-------------------------------------------------------
* This function configs the tvp5150 in the simple way.
*-------------------------------------------------------*/
static void simpConfigTVP5150(Int channel, TVP5150_ConfParams *pConfParams)
{
Uint8 addrI2C, data;
addrI2C = setTargetTVP5150(channel);
if (addrI2C == 0) /* if not valid address, return */
return;
data = 0x00;
/*0x00 below repesents the video input source selection #1 register, see 5150.pdf*/
_IIC_write(g_hI2C, addrI2C, 0x00, &data, 1); /* default */
data = 0x42;
_IIC_write(g_hI2C, addrI2C, 0x02, &data, 1);
/* vbko:gpcl, gpcl output 1, gpcl is output, YCbCr enable,
hsync,vsync,avid enable, vertical blank off, clock output enable */
data = 0x6D;//0x6F;
/*0x03 below repesents the miscellaneous control register, see 5150.pdf*/
_IIC_write(g_hI2C, addrI2C, 0x03, &data, 1);
/* YCbCr code range: extended range;
CbCr code format: Offset binary code (2s complement + 128)
YCbCr data path bypass: Normal operation.
YCbCr output format: 8-bit ITU-R BT.656 interface with embedded sync output
*/
data = 0x07;/*0x47;*/
_IIC_write(g_hI2C, addrI2C, 0x0D, &data, 1); /* default */
/* INTREQ/GPCL/VBLK (pin 27) function select: 1 = GPCL or VBLK depending on bit 7 of register 03h */
data = 0x02;//0x06;
_IIC_write(g_hI2C, addrI2C, 0x0F, &data, 1);
/* chromance control filter: enabled */
data = 0x14;
_IIC_write(g_hI2C, addrI2C, 0x1B, &data, 1); /* default */
data = 0x0c;
_IIC_write(g_hI2C, addrI2C, 0x08, &data, 1);
data = 0x77;
_IIC_write(g_hI2C, addrI2C, 0x07, &data, 1);
if (pConfParams->inMode == TVP5150_MODE_PAL720 || pConfParams->inMode == TVP5150_MODE_PAL768)
{/* set it to PAL mode forcibly */
data = 0x04;
_IIC_write(g_hI2C, addrI2C, 0x28, &data, 1);
}
}
/*
* ======== powerdownTVP5150 ========
*/
static void powerdownTVP5150(Int channel, Bool powerDownEnable)
{
Uint8 addrI2C;
Uint8 powerdownSettings = 0x0d;
/*Put _TVP5150 in power down mode */
if(!powerDownEnable) {
powerdownSettings = 0xf0;
}
addrI2C = (channel == 0) ? _TVP5150_IIC_ADDR0 : _TVP5150_IIC_ADDR1;
_IIC_write(g_hI2C, addrI2C,0x88,&powerdownSettings,1);
}
/*
* ======== resetTVP5150 ========
*/
static void resetTVP5150(Int channel)
{
scalerReset(channel);
powerdownTVP5150(channel, FALSE);
}
/*
* ======== scalerReset ========
*/
static void scalerReset(Uns channel)
{
#if 0
_TVP5150_Globals *globalPtr;
Uint8 addrI2C;
addrI2C = (channel == 0) ? _TVP5150_IIC_ADDR0 : _TVP5150_IIC_ADDR1;
globalPtr = &_TVP5150_settingsDef[channel].globals;
/* reset */
globalPtr->resetScaler = 0;
_IIC_write( hI2C, addrI2C, 0x88, (Uint8 *)globalPtr + 8, 1 );
/* unreset */
globalPtr->resetScaler = 1;
_IIC_write( hI2C, addrI2C, 0x88, (Uint8 *)globalPtr + 8, 1 );
#endif
}
/*
* ======== TVP5150_close ========
*/
static Int TVP5150_close(EDC_Handle handle)
{
Int devId = (int)handle;
/*First Check if the Handle is correct */
if(devId == 0 || devId == 1) {
/*Put _TVP5150 in power down mode */
powerdownTVP5150(devId, TRUE);
return EDC_SUCCESS;
} else {
return EDC_FAILED;
}
}
/*
* ======== TVP5150_ctrl ========
*/
static Int TVP5150_ctrl(EDC_Handle handle, TVP5150_Cmd cmd, Arg arg)
{
Int devId = (int)handle;
/*First Check if the Handle is correct */
if(devId != 0 && devId != 1) {
return EDC_FAILED;
}
switch(cmd) {
case EDC_CONFIG: {
TVP5150_ConfParams *tvp5150Params = (TVP5150_ConfParams *)arg;
initI2CHandle(tvp5150Params->hI2C);
simpConfigTVP5150(devId, tvp5150Params);
}
break;
case EDC_RESET:
resetTVP5150(devId);
break;
case TVP5150_POWERDOWN:
powerdownTVP5150(devId, TRUE);
break;
case TVP5150_POWERUP:
powerdownTVP5150(devId, FALSE);
break;
case TVP5150_SET_AMUXMODE:
break;
}
return EDC_SUCCESS;
}
/*
* ======== TVP5150_open ========
*/
static EDC_Handle TVP5150_open(String devName, Arg optArg)
{
Int devId;
/* Check if the addresse is correct */
if(devName[0] != '/') {
devId = -1;
} else if(devName[1] == '0') {
devId = 0;
} else if(devName[1] == '1'){
devId = 1;
} else if(devName[1] == '2') {
devId = 2;
} else if(devName[1] == '3'){
devId = 3;
} else {
devId = -1;
}
return (EDC_Handle)devId;
}
/**************************************************************************/
/* End of file */
/**************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -