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

📄 chipdefbase.cpp

📁 用C语言设计的EPSON LCD控制器S1D13700驱动。
💻 CPP
📖 第 1 页 / 共 5 页
字号:
//============================================================================
//
//  CHIPDEFBASE.CPP
//
//  Copyright (c) 2003 Epson Research and Development, Inc. 
//  All rights reserved.
//
//	The tabs in the file is formatted at 4.
//
//============================================================================

#ifdef _WIN32
#pragma warning( disable : 4100 )	// Disable "unreferenced formal parameter" warning.
#endif

#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "chipdefbase.h"
#include "datatype.h"
#include "expat.h"
#include "hal.h"


//=============================PUBLIC=AREA====================================

ChipDefBase::ChipDefBase( ) :
	m_DebugMode( false ),
	m_fAcquiredChip( false ),
	m_fChipInitialized( false ),
	m_fHotHotHot( false ),
	m_fShowTestPattern( false ),
	m_nTimerTick( 0 ),
	m_CurProduct( 0 ),
	m_SummaryMargin( NULL ),
	m_NumSummaryMarginLines( 0 )
{
	HelperInit( );
	m_SP = CreateCircularStrPool( 24, 1024 );

#if defined(_DEBUG)
	m_DebugMode = true;
#endif

	// Invalidate these member variables.
	m_LastRegisterIndex = 0xFFFFFFFF;
	m_LastRegisterRegIndex = 0xFFFFFFFF;
	m_LastFeatureIndex = 0xFFFFFFFF;
	strcpy( m_LastFeatureKeyname, "invalid" );
}




ChipDefBase::~ChipDefBase( )
{
	UInt32 i;

	if ( m_Products )
	{
		for ( i=0; i<m_NumProducts; i++ )
		{
			if ( m_Products[i].Keyname )	delete [] m_Products[i].Keyname;
			if ( m_Products[i].Prefix )		delete [] m_Products[i].Prefix;
			if ( m_Products[i].Name )		delete [] m_Products[i].Name;
			if ( m_Products[i].Suffix )		delete [] m_Products[i].Suffix;
			if ( m_Products[i].Desc )		delete [] m_Products[i].Desc;
			if ( m_Products[i].VariantOf )	delete [] m_Products[i].VariantOf;
		}
		delete [] m_Products;
		m_Products = NULL;
	}
	if ( m_Categories )
	{
		for ( i=0; i<m_NumCategories; i++ )
		{
			if ( m_Categories[i].Keyname )	delete [] m_Categories[i].Keyname;
			if ( m_Categories[i].Name )		delete [] m_Categories[i].Name;
		}
		delete [] m_Categories;
		m_Categories = NULL;
	}
	if ( m_Registers )
	{
		for ( i=0; i<m_NumRegisters; i++ )
		{
			if ( m_Registers[i].Keyname )	delete [] m_Registers[i].Keyname;
			if ( m_Registers[i].Name )		delete [] m_Registers[i].Name;
			if ( m_Registers[i].Desc )		delete [] m_Registers[i].Desc;
			if ( m_Registers[i].Category )	delete [] m_Registers[i].Category;
			if ( m_Registers[i].Reserved )	delete [] m_Registers[i].Reserved;
			if ( m_Registers[i].Product )	delete [] m_Registers[i].Product;
		}
		delete [] m_Registers;
		m_Registers = NULL;
	}
	if ( m_Features )
	{
		for ( i=0; i<m_NumFeatures; i++ )
		{
			if ( m_Features[i].Keyname )	delete [] m_Features[i].Keyname;
			if ( m_Features[i].Name )		delete [] m_Features[i].Name;
			if ( m_Features[i].Desc )		delete [] m_Features[i].Desc;
			if ( m_Features[i].Unit )		delete [] m_Features[i].Unit;
			if ( m_Features[i].Op1 )		delete [] m_Features[i].Op1;
			if ( m_Features[i].Op2 )		delete [] m_Features[i].Op2;
			if ( m_Features[i].Reserved )	delete [] m_Features[i].Reserved;
			if ( m_Features[i].Product )	delete [] m_Features[i].Product;
			if ( m_Features[i].Influences )	delete [] m_Features[i].Influences;
			if ( m_Features[i].Values )
			{
				for ( UInt32 j=0; j<m_Features[i].NumValues; j++ )
				{
					if ( m_Features[i].Values[j].ValueName )		delete [] m_Features[i].Values[j].ValueName;
					if ( m_Features[i].Values[j].ReadValueName )	delete [] m_Features[i].Values[j].ReadValueName;
					if ( m_Features[i].Values[j].WriteValueName )	delete [] m_Features[i].Values[j].WriteValueName;
					if ( m_Features[i].Values[j].Reserved )			delete [] m_Features[i].Values[j].Reserved;
					if ( m_Features[i].Values[j].Product )			delete [] m_Features[i].Values[j].Product;
				}
				delete [] m_Features[i].Values;
			}
		}
		delete [] m_Features;
		m_Features = NULL;
	}

	if ( m_SummaryMargin != NULL )
	{
		delete [] m_SummaryMargin;
		m_SummaryMargin = NULL;
	}
}




bool ChipDefBase::GetDebugMode( void )
{
	return m_DebugMode;
}




void ChipDefBase::SetDebugMode( in bool Enable )
{
	m_DebugMode = Enable;
}




const char*	ChipDefBase::GetProduct( void )
{
	return m_Products[m_CurProduct].Keyname;
}




const char* ChipDefBase::GetProductName( in const char* Keyname, in int Flags )
{
	UInt32		iProduct;
	const char* ProductKeyname;
	char*		Name = GetCircularStr( m_SP );

	if ( Keyname == NULL )
		ProductKeyname = m_Products[m_CurProduct].Keyname;
	else
		ProductKeyname = Keyname;
	
	if ( !LookupProduct(ProductKeyname,&iProduct) )
		assert( false ); // ERROR: user must test IsProductValid first!

	if ( ( Flags & GN_PREFIX ) && m_Products[iProduct].Prefix )
		strcat( Name, m_Products[iProduct].Prefix );

	if ( Flags & GN_NAME )
		strcat( Name, m_Products[iProduct].Name );

	if ( ( Flags & GN_SUFFIX ) && m_Products[iProduct].Suffix )
		strcat( Name, m_Products[iProduct].Suffix );

	if ( Flags & GN_DESC )
	{
		strcat( Name, " " );
		strcat( Name, m_Products[iProduct].Desc );
	} 

	return Name;
}




const char* ChipDefBase::GetProductSummary( inout char* TextBuf, in char* LineTerminator, in int NumTextCols )
{
	static const char* ChipSummaryMargin = "                    ";
	static const char* Disclosure = "This reference is to be used as a quick reference only. Please refer to the Hardware Functional Specification for details on each register.";

	assert( NumTextCols>=74 );

	// Print title.
	sprintf( TextBuf, "EPSON %s Quick Register Reference", GetProductName(GetProduct(),GN_NAME|GN_PREFIX|GN_SUFFIX) );

	// Print disclosure.
	if ( LineTerminator ) strcat( TextBuf, LineTerminator );
	for ( int iD = 0; iD < (int) strlen( Disclosure ); )
	{
		// Print only one line of the disclosure (at a time).
		int TextBufLen, nWrap;

		if (LineTerminator) strcat( TextBuf, LineTerminator ); 

		strcat( TextBuf, ChipSummaryMargin );

		TextBufLen = strlen( TextBuf );

		nWrap = DetectWordWrap( Disclosure+iD, NumTextCols-strlen(ChipSummaryMargin) );

		for ( int iT = nWrap; iT >= 0; iT-- )
			TextBuf[ TextBufLen + iT ] = Disclosure[ iD + iT ];

		TextBuf[ TextBufLen+nWrap + 1 ] = '\0';

		iD += nWrap + 1;
	}

	// Print information about each register.
	for ( UInt32 i=0; i<m_NumRegisters; i++ )
	{
		if ( !m_Registers[i].FakeReg && MatchToCurrentProduct( m_Registers[i].Product ) && 
			 (m_DebugMode || !IsRegisterReserved( m_Registers[i].RegIndex, false)) )
		{
			if (LineTerminator) strcat( TextBuf, LineTerminator );
			if (LineTerminator) strcat( TextBuf, LineTerminator );
			if (LineTerminator) strcat( TextBuf, LineTerminator );
			if (LineTerminator) strcat( TextBuf, LineTerminator );

			GetRegisterSummary( m_Registers[i].RegIndex, TextBuf+strlen(TextBuf), false, NULL, LineTerminator, NumTextCols, false );
		}
	} 
 
	if (LineTerminator) strcat( TextBuf, LineTerminator );
	if (LineTerminator) strcat( TextBuf, LineTerminator );

	return TextBuf;
}




bool ChipDefBase::SetProduct( in const char* Keyname )
{
	return LookupProduct( Keyname, &m_CurProduct );
}




bool ChipDefBase::EnuProducts( in UInt32 Index, out char* Keyname )
{
	if ( Index < m_NumProducts )
	{
		strcpy( Keyname, m_Products[Index].Keyname );
		return true;
	} 

	return false;
}




bool ChipDefBase::MatchToCurrentProduct( in const char* Keynames )
{
	bool   MatchFound = false;

	// If NO or ALL products is specified, then default to ANY.
	if ( Keynames==NULL || strcmp(Keynames,"all")==0 )
		return true;

	// Does the given product(s) match the current product?
	MatchFound = ( strstr(Keynames,m_Products[m_CurProduct].Keyname) != NULL );

	// Is the given product(s) a variant of the current product?
	MatchFound = MatchFound || (m_Products[m_CurProduct].VariantOf && 
		         strstr(Keynames,m_Products[m_CurProduct].VariantOf)!=NULL);

	// Is the current product a variant of the given product(s)?
	for ( UInt32 i=0; i<m_NumProducts; i++ )
		if ( strstr(Keynames,m_Products[i].Keyname) != NULL )
			MatchFound = MatchFound || ( m_Products[i].VariantOf && 
			strcmp( m_Products[i].VariantOf, m_Products[m_CurProduct].Keyname ) == 0 );

	return MatchFound;
}




bool ChipDefBase::EnuCategories( in UInt32 Index, out char* Keyname, out char* Name )
{
	if ( Index < m_NumCategories )
	{
		if ( Keyname )
			strcpy( Keyname, m_Categories[Index].Keyname );

		if ( Name )
			strcpy( Name, m_Categories[Index].Name );

		return true;
	}

	return false;
}




bool ChipDefBase::EnuFeatures( in UInt32 ListIndex, out const char* *Keyname )
{
	UInt32 iList, Nth;

	for ( iList=0,Nth=0; iList<m_NumFeatures; iList++ )
	{
		if ( MatchToCurrentProduct( m_Features[iList].Product ) )
		{
			if ( ListIndex == Nth )
			{
				if ( Keyname )
					*Keyname = m_Features[iList].Keyname;

				return true;
			}
			Nth++;
		}
	}

	return false;
}




bool ChipDefBase::IsFeatureValid( in const char* Keyname )
{
	UInt32 iFeature;

	if ( LookupFeature( Keyname, &iFeature ) )
		return MatchToCurrentProduct( m_Features[iFeature].Product );

	return false;
}




bool ChipDefBase::IsFeatureReserved( in const char* Keyname )
{
	UInt32 iFeature;

	if ( LookupFeature( Keyname, &iFeature ) )
		return m_Features[ iFeature ].Reserved && MatchToCurrentProduct( m_Features[ iFeature ].Reserved );

	assert( false ); // ERROR: either this keyname doesn't exist, or you should have called IsFeatureValid() first!

	return false;
}




bool ChipDefBase::IsFeatureReadOnly( in const char* Keyname )
{
	UInt32 iFeature;

	if ( LookupFeature( Keyname, &iFeature ) )
		return m_Features[ iFeature].ReadOnly;

	assert( false ); // ERROR: either this keyname doesn't exist, or you should have called IsFeatureValid() first!

	return false;
}




bool ChipDefBase::IsFeatureWriteOnly( in const char* Keyname )
{
	UInt32 iFeature;

	if ( LookupFeature( Keyname, &iFeature ) )
		return m_Features[iFeature].WriteOnly;

	assert( false ); // ERROR: either this keyname doesn't exist, or you should have called IsFeatureValid() first!

	return false;
}




UInt32 ChipDefBase::GetFeatureType( in const char* Keyname )
{
	UInt32 iFeature;

	if ( LookupFeature( Keyname, &iFeature ) )
		return m_Features[ iFeature ].Type;
	assert( false ); // ERROR: either this keyname doesn't exist, or you should have called IsFeatureValid() first!
	return 0;
}




const char* ChipDefBase::GetFeatureName( in const char* Keyname, in int Flags )
{
	UInt32 iFeature;

	if ( LookupFeature( Keyname, &iFeature ) )
	{
		char*  Name = GetCircularStr( m_SP );
		int	   iName = 0;

		if ( Flags & GN_LEX )
		{
			strcat( Name, "FEATURE_" );
			strcat( Name, m_Features[ iFeature ].Keyname );
			_strupr( Name );
		}
		else
		{
			if ( Flags & GN_NAME )
			{
				if ( m_Features[ iFeature ].Name && m_Features[ iFeature ].Name[0] )
				{
					strcat( Name, m_Features[ iFeature ].Name );
					strcat( Name, " " );
				}
				else
				{
					// It's probably a LSB|ISB|MSB feature, so fetch the name from the span parent.
					const char*	Suffix = NULL;
					const char* SpanParent = GetFeatureSpanParent( m_Features[ iFeature ].Keyname, &Suffix ); 

					if ( SpanParent )
						sprintf( Name, "%s (%s) ", GetFeatureName( SpanParent,Flags & ( GN_NAME | GN_SHORT ) ), Suffix );
				}
				iName = strlen( Name );
			}

⌨️ 快捷键说明

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