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

📄 chipdefbase.cpp

📁 用C语言设计的EPSON LCD控制器S1D13700驱动。
💻 CPP
📖 第 1 页 / 共 5 页
字号:
				switch ( i )
				{
					case 0:  strcat(TempKeyname,"LSB");  break;
					case 1:  strcat(TempKeyname,"ISB");  break;
					case 2:  strcat(TempKeyname,"MSB");  break;
				}
				if ( LookupFeature(TempKeyname,&iTempFeature) )
				{
					bitpos32( m_Features[iTempFeature].RegMask, &LeftBit, &RightBit );
					RetVal |= GetFeatureRawValue(TempKeyname) << nShift;
					nShift += LeftBit - RightBit + 1;
				}
				else
					assert( i==1 );  // Only ISB is optional.
			}
		}
		else if ( m_fHotHotHot )
			RetVal = GetRegisterHotValue( m_Features[iFeature].RegIndex );
		else
			RetVal = GetRegisterValue( m_Features[iFeature].RegIndex, false );

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




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

	if ( LookupFeature(Keyname,&iFeature) )
	{
		UInt32 RetVal = 0;

		switch ( m_Features[iFeature].Type )
		{
		  case FT_NUMB:
		  case FT_ADDR:
		  case FT_FREQ:
			RetVal = GetFeatureRawValue( Keyname );
			RetVal = ApplyOp( RetVal, m_Features[iFeature].Op1 );
			RetVal = ApplyOp( RetVal, m_Features[iFeature].Op2 );
			RetVal = minmax( RetVal, m_Features[iFeature].Min, m_Features[iFeature].Max );
			break;
		  case FT_TEXT:
			assert( false );
			break;
		  case FT_LIST:
		  case FT_BOOL:
			RetVal = GetFeatureRawValue( Keyname );
			break;
		}

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




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

	if ( LookupFeature(Keyname,&iFeature) )
	{
		assert( m_Features[iFeature].Type==FT_NUMB || m_Features[iFeature].Type==FT_ADDR || m_Features[iFeature].Type==FT_FREQ );

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




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

	if ( LookupFeature(Keyname,&iFeature) )
	{
		assert( m_Features[iFeature].Type==FT_NUMB || m_Features[iFeature].Type==FT_ADDR || m_Features[iFeature].Type==FT_FREQ );

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




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

	if ( LookupFeature(Keyname,&iFeature) )
	{
		assert( m_Features[iFeature].Type==FT_NUMB || m_Features[iFeature].Type==FT_ADDR || m_Features[iFeature].Type==FT_FREQ );

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




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

	if ( LookupFeature(Keyname,&iFeature) )
	{
		assert( m_Features[iFeature].Type==FT_NUMB || m_Features[iFeature].Type==FT_ADDR || m_Features[iFeature].Type==FT_FREQ );

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




const char* ChipDefBase::GetFeatureStrValue( in const char* Keyname, in bool OnRead )
{
	UInt32 iFeature;

	if ( LookupFeature(Keyname,&iFeature) )
	{
		char*  RetVal = GetCircularStrEx( m_SP, 4096 );		// ROC FIXIT - dsm quick to make BIG buffer.
		UInt32 iFeatureValue;
		UInt32 Value;

		assert( m_Features[iFeature].WriteOnly==false );
		strcpy( RetVal, "OOPS, A MISTAKE ROC MADE! #401" );

		switch ( m_Features[iFeature].Type )
		{
		  case FT_NUMB:
		  case FT_ADDR:
		  case FT_FREQ:
			Value = GetFeatureNumValue( Keyname );
			switch ( m_Features[iFeature].Radix )
			{
			  case 16:
				{
					int LeftBit, RightBit;
					bitpos32( m_Features[iFeature].RegMask, &LeftBit, &RightBit );
					sprintf( RetVal, "%0*Xh", (LeftBit-RightBit+4)/4, Value );
				}
				break;
			  case 10:
				sprintf( RetVal, "%lu", Value );
				break;
			  case 2:
				strcpynum( RetVal, Value, 2, 0 );
				break;
			}
			break;

		  case FT_TEXT:
			assert( false );	// The chip-specific class should have handled this!
			break;

		  case FT_LIST:
		  case FT_BOOL:
			Value = GetFeatureRawValue( Keyname );
			if ( LookupFeatureValue(iFeature,Value,&iFeatureValue) )
			{
				if ( OnRead )
					strcpy( RetVal, (m_Features[iFeature].Values[iFeatureValue].ReadValueName?m_Features[iFeature].Values[iFeatureValue].ReadValueName:m_Features[iFeature].Values[iFeatureValue].ValueName) );
				else
					strcpy( RetVal, (m_Features[iFeature].Values[iFeatureValue].WriteValueName?m_Features[iFeature].Values[iFeatureValue].WriteValueName:m_Features[iFeature].Values[iFeatureValue].ValueName) );
			}
			else
				sprintf( RetVal, "[RESERVED SETTING OF %Xh]", Value );
			break;

		  case FT_SEQU:
			{
				UInt32 Type;
				UInt32 Value;
				char*  Label;

				RetVal[0] = '\0';
				for ( int i=0; GetFeatureSeqValue(Keyname,i,&Type,&Value,&Label); i++ )
				{
					switch ( Type )
					{
						case SEQ_COMMAND:	strcat(RetVal,"c");  break;
						case SEQ_PARAM:		strcat(RetVal,"p");  break;
						case SEQ_DELAY:		strcat(RetVal,"d");  break;
					}
					strcatnum( RetVal, Value, (Type==SEQ_DELAY?10:16), 0 );
					if ( Label && Label[0] )
					{
						strcat( RetVal, "(" );
						strcat( RetVal, Label );
						strcat( RetVal, ")" );
					}
					strcat( RetVal, "  " );
				}
				if ( i )
					RetVal[ strlen(RetVal)-2 ] = '\0';
			}
			break;
		}
		if ( m_Features[iFeature].Unit )
			strcat( RetVal, m_Features[iFeature].Unit );

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




const char* ChipDefBase::GetFeatureStrValue( in const char* Keyname, in UInt32 RawValue, in bool OnRead )
{
	UInt32 iFeature;

	if ( LookupFeature(Keyname,&iFeature) )
	{
		char*  RetVal = GetCircularStr( m_SP );
		UInt32 iFeatureValue;
		UInt32 Value;

		strcpy( RetVal, "OOPS, A MISTAKE ROC MADE! #401" );

		switch ( m_Features[iFeature].Type )
		{
		  case FT_NUMB:
		  case FT_ADDR:
		  case FT_FREQ:
			Value = ApplyOp( RawValue, m_Features[iFeature].Op1 );
			Value = ApplyOp( Value, m_Features[iFeature].Op2 );
			Value = minmax( Value, m_Features[iFeature].Min, m_Features[iFeature].Max );
			switch ( m_Features[iFeature].Radix )
			{
			  case 16:
				{
					int LeftBit, RightBit;
					bitpos32( m_Features[iFeature].RegMask, &LeftBit, &RightBit );
					sprintf( RetVal, "%0*Xh", ((LeftBit-RightBit+1)/4)+1, Value );
				}
				break;
			  case 10:
				sprintf( RetVal, "%lu", Value );
				break;
			  case 2:
				strcpynum( RetVal, Value, 2, 0 );
				break;
			}
			break;

		  case FT_TEXT:
			assert( false );	// This makes no sense!
			break;

		  case FT_LIST:
		  case FT_BOOL:
			if ( LookupFeatureValue(iFeature,RawValue,&iFeatureValue) )
			{
				if ( OnRead )
					strcpy( RetVal, (m_Features[iFeature].Values[iFeatureValue].ReadValueName?m_Features[iFeature].Values[iFeatureValue].ReadValueName:m_Features[iFeature].Values[iFeatureValue].ValueName) );
				else
					strcpy( RetVal, (m_Features[iFeature].Values[iFeatureValue].WriteValueName?m_Features[iFeature].Values[iFeatureValue].WriteValueName:m_Features[iFeature].Values[iFeatureValue].ValueName) );
			}
			else
				sprintf( RetVal, "[RESERVED SETTING OF %Xh]", RawValue );
			break;

		  case FT_SEQU:
			{
				UInt32 Type;
				UInt32 Value;
				char*  Label;

				RetVal[0] = '\0';
				if ( GetFeatureSeqValue(Keyname,RawValue,&Type,&Value,&Label) )
				{
					switch ( Type )
					{
						case SEQ_COMMAND:	strcat(RetVal,"c");  break;
						case SEQ_PARAM:		strcat(RetVal,"p");  break;
						case SEQ_DELAY:		strcat(RetVal,"d");  break;
					}
					strcatnum( RetVal, Value, (Type==SEQ_DELAY?10:16), 0 );
					if ( Label && Label[0] )
					{
						strcat( RetVal, "(" );
						strcat( RetVal, Label );
						strcat( RetVal, ")" );
					}
				}
			}
			break;
		}
		if ( m_Features[iFeature].Unit )
			strcat( RetVal, m_Features[iFeature].Unit );

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




bool ChipDefBase::SetFeatureRawValue( in const char* Keyname, in UInt32 RawValue )
{
	UInt32 iFeature;

	if ( LookupFeature(Keyname,&iFeature) )
	{
		bool   RetVal = true;
		int    nShift = 0;

		assert( m_Features[iFeature].Type != FT_TEXT );

		if ( m_Features[iFeature].RegSpan )
		{
			// "keynameMSB"&MSBmask<<(ISBmaskwidth+LSBmaskwidth) + "keynameISB"&ISBmask<<LSBmaskwidth + "keynameLSB"&LSBmask
			char   TempKeyname[16];
			UInt32 iTempFeature;
			int    LeftBit, RightBit;

			for ( int i=0; i<3; i++ )
			{
				strcpy( TempKeyname, Keyname );
				switch ( i )
				{
					case 0:  strcat(TempKeyname,"LSB");  break;
					case 1:  strcat(TempKeyname,"ISB");  break;
					case 2:  strcat(TempKeyname,"MSB");  break;
				}
				if ( LookupFeature(TempKeyname,&iTempFeature) )
				{
					bitpos32( m_Features[iTempFeature].RegMask, &LeftBit, &RightBit );
					RetVal &= SetFeatureRawValue( TempKeyname, (RawValue>>nShift)&(m_Features[iTempFeature].RegMask>>RightBit) );
					nShift += LeftBit - RightBit + 1;
				}
				else
					assert( i==1 );  // Only ISB is optional.
			}
		}
		else
		{
			if ( m_Features[iFeature].RegMask != 0xFFFFFFFF )
			{
				UInt32 PrevValue = GetRegisterValue(m_Features[iFeature].RegIndex,false) & ~m_Features[iFeature].RegMask;

				bitpos32( m_Features[iFeature].RegMask, NULL, &nShift );
				if ( RawValue > (m_Features[iFeature].RegMask>>nShift) )
					return false;	// The given value must be smaller than field width!
				RawValue = PrevValue | ((RawValue<<nShift)&m_Features[iFeature].RegMask);
			}
				RetVal = SetRegisterValue( m_Features[iFeature].RegIndex, false, RawValue );
		}

		// Show (pending) auto test pattern if we're hot, and it's enabled, and this feature's value
		// has actually changed, and if this feature affects the test pattern.
		if ( m_fHotHotHot && m_fShowTestPattern && m_Features[iFeature].RedrawPattern )
			m_nTimerTick = 1;

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




bool ChipDefBase::SetFeatureNumValue( in const char* Keyname, in UInt32 Value )
{
	UInt32 iFeature;

	if ( LookupFeature(Keyname,&iFeature) )
	{
		bool RetVal = false;
		char Text[16];

		switch ( m_Features[iFeature].Type )
		{
		  case FT_NUMB:
		  case FT_ADDR:
		  case FT_FREQ:
			RetVal = true;
			if ( Value < m_Features[iFeature].Min )
			{
				Value = m_Features[iFeature].Min;
				RetVal = false;
			}
			else if ( Value > m_Features[iFeature].Max )
			{
				Value = m_Features[iFeature].Max;
				RetVal = false;
			}
			Value = ApplyOp( Value, m_Features[iFeature].Op2, true );
			Value = ApplyOp( Value, m_Features[iFeature].Op1, true );
			RetVal = SetFeatureRawValue(Keyname,Value) && RetVal;
			break;
		  case FT_TEXT:
			assert( false );
			break;
		  case FT_LIST:
			if ( m_Features[iFeature].Radix == 10 )
			{
				sprintf( Text, "%lu", Value );
				RetVal = SetFeatureStrValue( Keyname, Text );
			}
			else if ( m_Features[iFeature].Radix == 16 )
			{
				sprintf( Text, "%X", Value );
				RetVal = SetFeatureStrValue( Keyname, Text );
			}
			break;
		  case FT_BOOL:
			RetVal = SetFeatureRawValue( Keyname, Value );
			break;
		}

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




bool ChipDefBase::SetFeatureStrValue( in const char* Keyname, in const char* StrValue )
{
	UInt32 iFeature;

	if ( LookupFeature(Keyname,&iFeature) )
	{

⌨️ 快捷键说明

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