⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tvp5150a.cpp

📁 视频芯片TVP5150驱动的
💻 CPP
字号:
//------------------------------------------------------------------------------
//
//	Copyright (C) 2006 MagicEyes co., Ltd All Rights Reserved
//	MagicEyes Proprietary & Confidential
//
//	Module     : TVP5150A(Video decoder) source file
//	File       : TVP5150A.h
//	Description:
//	Author     : rohan
//	History    : 
//		2006.08.0x first implementation
//------------------------------------------------------------------------------

#include "config.h"
#include "vidsrcif.h"
#include "mutexi2c.h"
#include "TVP5150A.h"


#if __cplusplus
extern "C" 
#if (BSP_IN_VIDEO_DECODER_TVP5150A == 1)

void  *GetVideoSourceHnd(void)
{
	DEBUGMSG(ZONE_VIDDEC,(TEXT(" TVP5150A: Create TVP5150A video source instance. \r\n")));
	CVIDSource *pVIDEO = new TVP5150A();
	if(pVIDEO == NULL)	
		return NULL;		
	return pVIDEO;
}
#endif	// BSP_IN_VIDEO_DECODER_TVP5150A
#endif	// __cplusplus

// Constructor
TVP5150A::TVP5150A(void)
{
	DEBUGMSG(ZONE_VIDDEC,(TEXT(" TVP5150A::TVP5150A \r\n")));
	m_pi2c = new MutexI2C(TVP5150A_I2C_ADDR, 1000, MutexI2C::MES_I2C0);	
	m_pi2c->Init(MES_I2C03::TXCLKSRC_PCLK256, 0, 10);
}  

// Destructor
TVP5150A::~TVP5150A(void)
{  
	DEBUGMSG(ZONE_VIDDEC,(TEXT(" TVP5150A::~TVP5150A \r\n")));
	DeInitDevice();
	if(m_pi2c) delete m_pi2c;	}  
BOOL 
TVP5150A::Identify(void)
{
	// Check Device ID
	U8  id[2]={0,}; 
	m_pi2c->Read(0x80, &id[0], 1);
	m_pi2c->Read(0x81, &id[1], 1);

	if(((id[1]<<8) | id[0]) != TVP5150A_IDENTYFY)
	{	
		ERRORMSG(ZONE_ERROR,(TEXT(" Fail: TVP5150A access failed. \r\n")));
		return FALSE;
	}
	DEBUGMSG(1,(TEXT(" TVP5150A Identify code: (0x%X)\r\n"), ((id[1]<<8) | id[0])));
	return TRUE;
}

BOOL
TVP5150A::InitDevice(void)
{ 
	U8 tmp;	
	// Operation Mode Control Register : Disable Power-down
	tmp = 0x00;	m_pi2c->Write(0x02, &tmp, 1);	
	for( volatile U32 i=0 ; i<0xFFFFFF ; i++ );	// some delay

	tmp = 0x01; m_pi2c->Write(0x05, &tmp, 1);		// software reset, all default set
	tmp = 0x02; m_pi2c->Write(0x0F, &tmp, 1);		// Select FID, GPCL
	tmp = 0x00; m_pi2c->Write(0x00, &tmp, 1);		// Composite = AIP1A

	// Analog channle control register : Automatic offset control = disabled, Automatic gain control = AGC enabled.
//	tmp = 0x11; m_pi2c->Write(0x01, &tmp, 1);
//	tmp = 0x04; m_pi2c->Write(0xC2, &tmp, 1);		// YCbCr Enable
	
	// Misc Control Register : GPCL Output Enable & Low, YCbCr & Clock Enable
	tmp = 0x29; m_pi2c->Write(0x03, &tmp, 1);
//	tmp = 0x2D; m_pi2c->Write(0x03, &tmp, 1);		// HSYNC, VSYNC, AVID, FID are active
	
	return CTRUE;	
}

BOOL 
TVP5150A::DeInitDevice(void)
{
	// Misc Control Register
//	m_pi2c->Read (0x03, &temp, 1);		
//	temp &= ~0x29;	// YCbCr & Clock Disable & GPCL Output Disable.
//	m_pi2c->Write(0x03, &temp, 1);	
	
	return TRUE;
}

BOOL	
TVP5150A::GetStatus(U32 Addr, U32 *pStatus)
{ 
	m_pi2c->Read((U8)Addr, (U8 *)pStatus, 1);

	*pStatus &= 0xff;
	
	return S_OK; 
}

HRESULT
TVP5150A::GetVideoSyncInfo(int SyncNum, LPVIP_SYNCINFO pSync)
{	
	U32 status;	
	m_nSyncInfoNum = SyncNum;
	
	GetStatus(&status);
	
	if(0 == (status & DECODERSTATUS_MASK_READYFORCAPURE))
		DEBUGMSG(ZONE_VIDDEC,(TEXT(" TVP5150A - No signal(0x%02X) \n"), status));
	
	if( status & DECODERSTATUS_MASK_60HZ )	
	{
		pSync->ExternalSync = CFALSE;			
		pSync->HorActive     = 720; // Active width                  
		pSync->HorFrontPorch =   8; // Horizontal Blank : Front porch
		pSync->HorSyncWidth  =  64; // Horizontal Blank : Sync width 
		pSync->HorBackPorch  =  66; // Horizontal Blank : Back porch 
		pSync->VerActive     = 240; // Active height                 
		pSync->VerFrontPorch =   4; // Vertical Blank : Front porch  
		pSync->VerSyncWidth  =   6; // Vertical Blank : Sync width   
		pSync->VerBackPorch  =  12; // Vertical Blank : Back proch   
	}
	else
	{
		pSync->ExternalSync = CFALSE;			
		pSync->HorActive     = 720;	// Active width                  
		pSync->HorFrontPorch =  10;	// Horizontal Blank : Front porch
		pSync->HorSyncWidth  =  64;	// Horizontal Blank : Sync width 
		pSync->HorBackPorch  =  70;	// Horizontal Blank : Back porch 
		pSync->VerActive     = 288;	// Active height                 
		pSync->VerFrontPorch =   2;	// Vertical Blank : Front porch  
		pSync->VerSyncWidth  =   6;	// Vertical Blank : Sync width   
		pSync->VerBackPorch  =  16;	// Vertical Blank : Back proch   
	}

	if( status & DECODERSTATUS_MASK_INTERLACE )
		pSync->IsInterlaced = CTRUE;		
	else
		pSync->IsInterlaced = CFALSE;
	
	return S_OK;
}

HRESULT	
TVP5150A::SetVideoPort(VIPSRC_PORT Port)	
{
	U8	tmp = 0xFF;				
	U8	ch  = 0;
	m_pi2c->Write(0x1C, &tmp, 1); 	// Interrupt Reset Register B : Reset status B
	m_pi2c->Write(0xC0, &tmp, 1);	// Interrupt Status Register A : Reset status A
	
	m_pi2c->Read (0x03, &tmp, 1);	// read decoder pin status		
	switch(Port)
	{
		case COMPOSITE_PORT: 	tmp &= ~0x40, ch = 0;	break;
		case S_VIDEO_PORT  :	tmp |=  0x40, ch = 1;	break;		
		default:				return E_FAIL;				
	}
	tmp |= 0x09;
	m_pi2c->Write(0x03, &tmp, 1);
	m_pi2c->Write(0x0, &ch, 1);
	
	return S_OK;
}	

HRESULT	
TVP5150A::SetVideoChannel(U8 Ch)
{
	return E_FAIL;
}


BOOL
TVP5150A::GetStatus(U32 *pStatus)	
{
	U8 status[7]= {0,};
	U8 temp = 0;
	
	m_pi2c->Read(0x88, &status[0], 1);		// Status #1
	m_pi2c->Read(0x89, &status[1], 1);		// Status #2
//	m_pi2c->Read(0x8A, &status[2], 1);		// Status #3
//	m_pi2c->Read(0x8B, &status[3], 1);		// Status #4
//	m_pi2c->Read(0x8C, &status[4], 1);		// Status #5
//	m_pi2c->Read(0x86, &status[5], 1);		// Status B
	m_pi2c->Read(0xC0, &status[6], 1);		// Status A
	
	for(int i=0; i < 7; i++)
		DEBUGMSG(0,(TEXT(" TVP5150A: status[%d]:0x%02X\r\n"), i, status[i]));	
		
	temp = (DECODERSTATUS_MASK_60HZ | DECODERSTATUS_MASK_INTERLACE);	
	
	if( status[6] & (1<<7))		temp |= DECODERSTATUS_MASK_READYFORCAPURE;	// |= 0x01 (ready)	
	if( status[1] & 0x07)		temp |= DECODERSTATUS_MASK_COPYPROTECTION;	// |= 0x07 (macrovision)
	if( status[0] & (1<<5))		temp &= ~DECODERSTATUS_MASK_60HZ;			// &= 0xdf (50hz)
	if((status[0] & 0x06)==6)	temp |= DECODERSTATUS_MASK_LOOPLOCK;		// |= 0x40
	if( status[0] & (1<<6))		temp &= ~DECODERSTATUS_MASK_INTERLACE; 		// &= 0x7f (Non Interlace)

	*pStatus = temp;	
	DEBUGMSG(ZONE_VIDDEC,(TEXT(" TVP5150A: GetStatus = 0x%02X\r\n"), *pStatus));
	return TRUE;
}

HRESULT 
TVP5150A::SetFramePerSecond(U32 FPS)
{ 
	return E_FAIL; 
}

//------------------------------------------------------------------------------
// 	Color Control Interface functions
//------------------------------------------------------------------------------
HRESULT	
TVP5150A::SetHueValue(U8 Value)
{ 
	// 1000 0000 : -128 (-180 phase)
	// 1000 0000 :    0 (default)
	// 1111 1111 : +127 (+180 phase)
	m_pi2c->Write(0x0B, &Value, 1);
	DEBUGMSG(ZONE_VIDDEC,(TEXT(" TVP5150A: Hue Reg[0x%02X]=%d\r\n"), 0x0B, (char)Value));
		
	return S_OK; 
};

HRESULT	
TVP5150A::SetContrastValue(U8 Value)
{ 
	// 0000 0000 :   0 - min contrast(no dark color)
	// 1000 0000 : 128 - default
	// 1111 1111 : 255 - max contrast
	m_pi2c->Write(0x0C, &Value, 1);
	DEBUGMSG(ZONE_VIDDEC,(TEXT(" TVP5150A: Contrast Reg[0x%02X]=%d\r\n"), 0x0C, Value));
	
	return S_OK; 	
};

HRESULT	
TVP5150A::SetSaturationValue(U8 Value)
{ 
	// 0000 0000 :   0 - min (no color)
	// 1000 0000 : 128 - default
	// 1111 1111 : 255 - max 
	m_pi2c->Write(0x0A, &Value, 1);
	DEBUGMSG(ZONE_VIDDEC,(TEXT(" TVP5150A: Saturation Reg[0x%02X]=%d\r\n"), 0x0A, Value));
	
	return S_OK; 
};

HRESULT	
TVP5150A::SetBrightValue(U8 Value)
{ 
	// 0000 0000 :   0 - dark
	// 1000 0000 : 128 - default
	// 1111 1111 : 255 - white(bright)
	m_pi2c->Write(0x09, &Value, 1);
	DEBUGMSG(ZONE_VIDDEC,(TEXT(" TVP5150A: Brightness Reg[0x%02X]=%d\r\n"), 0x09, Value));
	
	return S_OK; 
};

HRESULT	
TVP5150A::SetSharpValue (U8 Value)
{ 
	return E_FAIL; 
}

HRESULT	
TVP5150A::SetMiscConfig(LPVID_MISC pMisc)
{ 
	return E_FAIL; 
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -