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

📄 tw88.c

📁 此程序为twell8806驱动程序
💻 C
📖 第 1 页 / 共 3 页
字号:
{
/*	WORD	pvr;
	BYTE	val;
	
	val = ReadDecoder(0xbb);
	pvr = (val & 0x70) << 4;		// pppp xxxx -> pppp 0000 0000
	pvr |= ReadDecoder(0xba);

	return pvr;*/
	return PVR_;
}

//----- Panel H Resolution
WORD GetPHR(void)
{
/*	WORD	phr;
	BYTE	val;

	val = ReadDecoder(0xb6);
	phr = (val & 0x70) << 4;		// pppp xxxx -> pppp 0000 0000
	phr |= ReadDecoder(0xb5);

	return phr;*/
	return PHR_;
}

WORD GetHPN(void)
{
	WORD buf;

	ClearEnDet();			// HHY 05.29.03 protect changing during read out

	WriteDecoder(0x5b, 0x50);	// HSYNC period and VSYNC period

	buf = ReadDecoder(0x58);	// from MSB
	buf = buf << 8;
	buf = buf | ReadDecoder(0x57);

	SetEnDet();				// HHY 05.29.03 release protection

	return buf;


}
/*
WORD GetHPN(void)
{
	WORD buf, sum;
	BYTE i;

	//Get HPN 
	WriteDecoder(0x5b, 0x50);	// HSYNC period and VSYNC period

	//HPN

	for(i=0, sum=0; i<5; i++) {		// HHY 1.45 take average 
		buf = (WORD)ReadDecoder(0x58) << 8;// from MSB
		buf |= ReadDecoder(0x57);
		sum += buf;
	}

	buf = (sum+5)/5;

	return buf;
}
*/
WORD GetVPN(void)
{
	WORD buf;

	WriteDecoder(0x5b, 0x50);	// HSYNC period and VSYNC period

	buf = (WORD)ReadDecoder(0x5a);
	buf = buf << 8;
	buf = buf | ReadDecoder(0x59);
	return buf;
}

/*
WORD GetPVP(void)
{
	WORD pvp;

	pvp = ReadDecoder(0xbb);					// pvp = Panel Vsync Period
	pvp = (pvp & 0x0f) << 8;				//
	pvp |= ReadDecoder(0xb7);					//

	return pvp;
}
*/

BYTE GetVBackPorch(void)
{
	return ReadDecoder(0xb9);
}

#endif // SUPPORT_PC

#if defined SUPPORT_PC || defined SUPPORT_DTV
void SetVBackPorch(BYTE val)
{
	WriteDecoder(0xb9, val);
}

void SetPVP(WORD period )
{
	BYTE val;

	// TW8804 write LSByte first
	val = ReadDecoder(0xbb);
	val = val & 0xf0;
	val = val | (BYTE)(period>>8);
	WriteDecoder(0xbb, val);
	WriteDecoder(0xb7, (BYTE)period);	// A4, A8 = Panel Vsync Period
}

void SetPHP(WORD php)
{
	BYTE val;

	// TW8804 write LSByte first
	val = ReadDecoder(0xb6);
	val &= 0xf0;				//0xf8; cut D
	val |= (BYTE)(php>>8);
	WriteDecoder(0xb6, val);
	WriteDecoder(0xb2, php);		// A9, AD = Panel Hsync Cycle
}

#endif //#if defined SUPPORT_PC || defined SUPPORT_DTV

/*WORD GetPHP(void)
{
	WORD php;

	php = ((WORD)ReadDecoder(0xb6) & 0x0f) << 8;
	php += ReadDecoder(0xb2);

	return php;
}

*/


//#if (defined SERIAL) || (defined WIDE_SCREEN)
/*#if (defined WIDE_SCREEN)
WORD GetVactive(void)  // Input V active length
{
	WORD actv;

	actv =   ReadDecoder(CROP_HI) & 0x30;
	actv <<= 4;
	actv |=  ReadDecoder(VACTIVE_LO);

	return actv;
}
#endif // WIDE_SCREEN


WORD GetHCounter1(BYTE field )
{
	WORD counter;

	MeasureAndWait(field);

	WriteDecoder(0x5b, 0xc0);
	counter = (WORD)ReadDecoder(0x58) << 8;
	counter += ReadDecoder(0x57);

	return counter;
}

void SetHInitial(BYTE field, WORD counter)
{
	BYTE val;
	
	if( field==0 ) {	// odd
		val = ReadDecoder( 0xc2 );
		val = ( val & 0xf0 ) |  ( ( counter>>8 ) & 0x0f );
		WriteDecoder(0xc2, val);
		WriteDecoder(0xc0, (BYTE)counter);
	}
	
	else {				// even
		val = ReadDecoder( 0xc2 );
		val = ( val & 0x0f ) |  ( ( counter>>4 ) & 0xf0 );
		WriteDecoder(0xc2, val);
		WriteDecoder(0xc1, (BYTE)counter);
	}
}
*/
//=============================================================================
//
//=============================================================================
//
/*
void TuneLineBuffer(BYTE field)
{
	WORD php, hcounter;
	int initial=0;
	BYTE freerun;

	extern IDATA BYTE  PcMode;


	#if defined (DEBUG_PC) || defined (DEBUG_DECODER)
	dPrintf("\r\n----- TuneLineBuffer:%d -----", (WORD)field);
	#endif

	#ifdef SUPPORT_PC
	if( IsBypassmode() ) return;
	#endif

	//#ifdef SUPPORT_DTV
	//if( IsDTVInput() ) return;
	//#endif

	// disable free run
	freerun = IsFreeRun();
	PanelFreeRun(0);

	php = GetPHP();

	initial = 0;
	SetHInitial(field, initial);

	hcounter = GetHCounter1(field);
	#if defined (DEBUG_PC) || defined (DEBUG_DECODER)
	dPrintf("\r\nInitial=%4x  Hcounter=%4x  PHP=%4x (%2d%%)", initial, hcounter, php, (WORD)((DWORD)hcounter*100/php) );
	#endif
	
	if( (hcounter < ((DWORD)php*78/100)) || (hcounter > ((DWORD)php*82/100)) ) {
		
		initial = php*4/5 - hcounter + initial;
		if( initial>=0 ) {
			SetHInitial(field, initial/2);
			dPuts(" + ");
		}
		else {
			SetHInitial(field, 0x1000 + initial/2);
			dPuts(" - ");
		}
		
//		WriteDecoder(0xb1, ReadDecoder(0xb1)&0x08);
//		WriteDecoder(0xb0, 0xff);
//		WriteDecoder(0xb1, 0xff);
		
	}
	

	PanelFreeRun(freerun);
}
*/

//=============================================================================
//
//=============================================================================
/*
WORD GetAveHCVWRS(BYTE field)
{
	WORD hcounter, ave=0;
	BYTE i;


	#ifdef DEBUG_TW88
	dPuts("\r\n------ Get Average of HCVWRS ------");
	#endif

	for(i=0; i<5; i++) {
	
		hcounter = GetHCounter1(field);

		#ifdef DEBUG_TW88
		dPrintf("\r\n[%2d] HCVWRS=%4d", i, hcounter);
		#endif
		if( i==0 )
			ave = hcounter;
		else
			ave = ( ave + hcounter ) / 2;
	}
	#ifdef DEBUG_TW88
	dPrintf("\r\n----------- Average:%d -------------", ave);
	#endif

	return ave;
}
*/


#if 0 //SERIAL
void TestHCVWRS(BYTE field, WORD initial)
{
	WORD /*php,*/ hcounter, min=0, max=0;
	BYTE i;


	#ifdef DEBUG_TW88
	dPuts("\r\n------ Get HCVWRS ------");
	#endif

//	php = GetPHP();
	
	SetHInitial(field, initial);

	for(i=0; i<30; i++) {
	
		hcounter = GetHCounter1(field);
		Printf("\r\n[%2d] HInitial:%d  HCVWRS=%4d  PHP=%4d", i, initial, hcounter, GetPHP());
		Printf(" : %d%% of PHP ", hcounter*10/(GetPHP()/10));
		if( i==0 )
			min = hcounter;
		if( min > hcounter )
			min = hcounter;
		if( max < hcounter )
			max = hcounter;
	}
	Printf("\r\n------ Min:%d     Max:%d  ---(Field:%d)--", min, max, field);
}
#endif // SERIAL

//#endif

/***
WORD GetHPN1(void)
{
	WORD buf;
	BYTE val;

	//Get HPN 
	WriteDecoder(0x5b, 0x50);	// HSYNC period and VSYNC period

	//HPN

	val = ReadDecoder(0x58);	// from MSB
	buf = (WORD)val << 8;
	val = ReadDecoder(0x57);
	buf |= val;

	return buf;
}
***/

/****
#if (defined SERIAL) || (defined WIDE_SCREEN)
WORD CalcVBackPorch4DecoderInput( void )
{
	WORD		back_porch, vsud;
	DWORD		realv;

	vsud = GetVSUD();
	back_porch = ( ReadDecoder(VDELAY_LO) - ReadDecoder( 0xbd ) + 2 ) * 0x100L ;	
											// input vdelay - diff_in_out_vsync + 2 
	back_porch += (vsud-1);					// for getting rounded up result
	back_porch /=  vsud ;					// convert to value based on output
	back_porch -= ReadDecoder( 0xb8 );			// - Pandel Vertical Pulse Width

	realv =  ( GetVactive() * (DWORD)0x100 / vsud - GetPVR() ) / 2 ;
											// because of overscan.
	Printf("\r\n(CalcVBack...) min back proch:0x%x  add:0x%lx", back_porch, realv);
	back_porch +=  realv;

	SetVBackPorch( (BYTE) back_porch );
	return back_porch;
}
#endif // SERIAL || WIDE_SCREEN
****/

/******
WORD GetVSUD(void)
{
	WORD		vsud;
	BYTE        scale;

	scale = ReadDecoder( TW88_XYSCALEHI );
	vsud = (WORD)(scale & 0x0c) << 8;
	vsud |= ReadDecoder( TW88_YUSCALELO );

	#ifdef DEBUG_TW88
	dPrintf("\r\n(GetVSDU) :0x%x", vsud);
	#endif
	return vsud;
}
******/

/////////////////////////////////////////////////////////////////////////////
// Mapping( int fromValue, CRegInfo fromRange,
//                                           int * toValue, CRegInfo toRange )
// Purpose: Map a value in certain range to a value in another range
// Input:   int fromValue - value to be mapped from
//          CRegInfo fromRange - range of value mapping from
//          CRegInfo toRange   - range of value mapping to
// Output:  int * toValue - mapped value
// Return:  Fail if error in parameter, else Success
// Comment: No range checking is performed here. Assume parameters are in
//          valid ranges.
//          The mapping function does not assume default is always the mid
//          point of the whole range. It only assumes default values of the
//          two ranges correspond to each other.
//          
//          The mapping formula is:
//
//            For fromRange.Min() <= fromValue <= fromRange.Default():
//
//				(fromValue -fromRange.Min())* (toRange.Default() - toRange.Min())
//				-------------------------------------------------------------------- + toRange.Min()
//					fromRange.Default() - fromRange.Min()
//
//			  For fromRange.Default() < fromValue <= fromRange.Max():
//
//				(fromValue - fromRange.Default()) * (toRange.Max() - toRange.Default())
//				--------------------------------------------------------------------- + toRange.Default()
//		             fromRange.Max() - fromRange.Default()
////
////////////////////////////////////////////////////////////////////////////
BYTE Mapping1( int fromValue, CODE_P struct RegisterInfo *fromRange,
                                 int * toValue, CODE_P struct RegisterInfo *toRange )
{

	// calculate intermediate values
	int a;
	int b;

	// perform mapping
	if ( fromValue <= fromRange->Default ) 
	{
		a = toRange->Default - toRange->Min;
		b = fromRange->Default - fromRange->Min;
		// prevent divide by zero
		if( b==0 )		return (FALSE);
		*toValue = (int) ( (DWORD)fromValue- (DWORD)fromRange->Min ) * a / b 
						+(DWORD)toRange->Min;
	}
	else 
	{
		a = toRange->Max - toRange->Default;
		b = fromRange->Max - fromRange->Default;
		// prevent divide by zero
		if( b==0 )		return (FALSE);
        *toValue = (int) ( (DWORD)fromValue - (DWORD)fromRange->Default ) * a / b
                       + (DWORD)toRange->Default;
	}
	return ( TRUE );
   
}



#ifndef KEILC
#ifdef SUPPORT_PC
BYTE Mapping2( int fromValue, IDATA_P struct RegisterInfo *fromRange,
                                 int * toValue, CODE_P struct RegisterInfo *toRange ){

	// calculate intermediate values
	int a;
	int b;


	// perform mapping
	if ( fromValue <= fromRange->Default ) {
		a = toRange->Default - toRange->Min;
		b = fromRange->Default - fromRange->Min;
		// prevent divide by zero
		if( b==0 )		return (FALSE);
		*toValue = (int) ( (DWORD)fromValue- (DWORD)fromRange->Min ) * a / b 
						+(DWORD)toRange->Min;
	}
	else {
		a = toRange->Max - toRange->Default;
		b = fromRange->Max - fromRange->Default;
		// prevent divide by zero
		if( b==0 )		return (FALSE);
      *toValue = (int) ( (DWORD)fromValue - (DWORD)fromRange->Default ) * a / b
                       + (DWORD)toRange->Default;
	}

	#ifdef DEBUG_OSD
	dPrintf("\r\n++(Mapping2)%d(%d-%d-%d)", (WORD)fromValue, (WORD)fromRange->Min, (WORD)fromRange->Default, 
		(WORD)fromRange->Max );
	dPrintf("->%d(%d-%d)", (WORD)*toValue, (WORD)toRange->Min, (WORD)toRange->Max);
	#endif
	
	return ( TRUE );
   
}
#endif

BYTE Mapping3( int fromValue, CODE_P struct RegisterInfo *fromRange,
                                 int * toValue, IDATA_P struct RegisterInfo *toRange ){

	// calculate intermediate values
	int a;
	int b;


	// perform mapping
	if ( fromValue <= fromRange->Default ) {
		a = toRange->Default - toRange->Min;
		b = fromRange->Default - fromRange->Min;
		// prevent divide by zero
		if( b==0 )		return (FALSE);
		*toValue = (int) ( (DWORD)fromValue- (DWORD)fromRange->Min ) * a / b 
						+(DWORD)toRange->Min;
	}
	else {
		a = toRange->Max - toRange->Default;
		b = fromRange->Max - fromRange->Default;
		// prevent divide by zero
		if( b==0 )		return (FALSE);
      *toValue = (int) ( (DWORD)fromValue - (DWORD)fromRange->Default ) * a / b
                       + (DWORD)toRange->Default;
	}

	#ifdef DEBUG_OSD
	dPrintf("\r\n++(Mapping3)%d(%d-%d-%d)", (WORD)fromValue, (WORD)fromRange->Min, (WORD)fromRange->Default, 
		(WORD)fromRange->Max );
	dPrintf("->%d(%d-%d)", (WORD)*toValue, (WORD)toRange->Min, (WORD)toRange->Max);
	#endif
	
	return ( TRUE );
   
}
#endif

//---------------------------------------------------------------------------------
extern	CODE BYTE NTSC_Regs[];
#ifdef ADD_ANALOGPANEL
extern CODE BYTE NTSC_Regs_Analog[];
#endif

BYTE GetDataFromTxtFile(BYTE index)
{
	BYTE cnt;
	CODE_P BYTE *RegSet;

	#ifdef ADD_ANALOGPANEL
	if(IsAnalogOn())
		RegSet = NTSC_Regs_Analog;
	else
	#endif	
	RegSet = NTSC_Regs;

	cnt = 0;
	CheckBuf = 0;
	while ( *RegSet != 0xFF ) {

		if( cnt==0 ) {
			//first 2 bytes are I2C address and count of register
			if( (*RegSet) ==TW88I2CAddress ) {
				cnt = *(RegSet+1);
				RegSet+=2;
				for(; cnt>0; cnt--) {
					if((*RegSet)==index ) {

						#ifdef DEBUG_TW88
						dPrintf("--%02x", (WORD)*(RegSet+1));
						#endif

						CheckBuf = (*(RegSet+1));
						return 1;
					}
					RegSet+=2;
				}
				break;
			}
			else
				RegSet += ( (*(RegSet+1)+1)*2 );	// HHY 2.04
		}
	}

	return 0;
}


BYTE GetAttributesFromNTSCSettings(BYTE index)
{

	#ifdef DEBUG_TW88
	dPuts("\r\n++(GetAttributesFromNTSCSettings)");
	#endif

	#ifdef DEBUG_TW88
	dPrintf("\r\nindex:%02x", (WORD)index);
	#endif

	if(GetDataFromTxtFile(index)) return CheckBuf;

	//in case of failing to find that register value in default setting

	switch( index ) {
	case 0x70:	return 0x20;
	case 0x71:
	case 0x72:
	case 0x73:
	case 0x74:	
	case 0x75:
	case 0x76:		return 0x80;
	case 0x77:		return 0;

	case BRIGHT:	return 0x00;
	case CONTRAST:	return 0x60;
	case SHARPNESS:	return 0x10;
	case PNLSHARPNESS: return 0x03;
	case SAT_U:		return 0x7f;
	case SAT_V:		return 0x5a;
	case HUE:		return 0x00;

	case SHUE:		return 0x0;
	case SCONTRAST:	return 0x60;
	case SBRIGHT:	return 0x0;
	case SCbGAIN:	return 0x40;
	case SCrGAIN:	return 0x40;
	default:	return 0xff;
	}
	
}

⌨️ 快捷键说明

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