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

📄 chipdef.cpp

📁 用C语言设计的EPSON LCD控制器S1D13700驱动。
💻 CPP
📖 第 1 页 / 共 5 页
字号:

				/////////////////
				// Draw border //
				/////////////////

				// Draw left and reght borders.
				for ( j = 0; j < uiBpp; j++ )
				{
					uwBlockOffset = (UInt16) ( wStartAddr1 + uwBytePerLine *  uwBlockHeight *  j );

					for ( i = 0; i < uwBlockHeight; i++ )
					{
						uwLineOffset1 = UInt16 ( uwBlockOffset + uwBytePerLine * i );
						uwLineOffset2 = UInt16 ( uwLineOffset1 + uwBytePerLine - 1 );

						halWriteDisplay8( uwLineOffset1, (UInt8) ( Pattern2Bpp[ j ]		| 0xc0 ), 1 );
						halWriteDisplay8( uwLineOffset2, (UInt8) ( Pattern2Bpp[ j + 1 ]	| 0x03 ), 1 );
					}
				}
				
				// Write buttom line
				halWriteDisplay8( uwLineOffset1, 0xff, uwBytePerLine  );
				// Write upper line
				halWriteDisplay8( wStartAddr1,   0xff, uwBytePerLine  );
				// move the cursor out of sight.
				halWriteReg16( REG001C_CSRW_P1 , ++uwLineOffset2 ); 
				break;

			case 4:
				UInt8 k1, k2, k3;

				for ( k = 0; k < uiBpp; k++ )
				{
					uwBlockOffset = (UInt16) ( wStartAddr1 + uwBytePerLine * uiDisplayHeightInLine * k / 4 );
					k1 = ( UInt8 ) ( k + 1 );
					k2 = ( UInt8 ) ( k + 2 );
					k3 = ( UInt8 ) ( k + 3 );

					for ( j = 0; j < uwBlockHeight; j++ )
					{

						uwLineOffset1 = ( UInt16 ) ( uwBlockOffset + uwBytePerLine * j );
						uwLineOffset2 = ( UInt16 ) ( uwLineOffset1 + uiLineSectionLength );
						uwLineOffset3 = ( UInt16 ) ( uwLineOffset1 + uiLineSectionLength * 2 );
						uwLineOffset4 = ( UInt16 ) ( uwLineOffset1 + uiLineSectionLength * 3 );

						for ( i = 0; i < uwBytePerLine; i++)
						{
							halWriteDisplay8( uwLineOffset1, Pattern4Bpp[ k  ],	uiLineSectionLength  );
							halWriteDisplay8( uwLineOffset2, Pattern4Bpp[ k1 ],	uiLineSectionLength  );
							halWriteDisplay8( uwLineOffset3, Pattern4Bpp[ k2 ],	uiLineSectionLength  );
							halWriteDisplay8( uwLineOffset4, Pattern4Bpp[ k3 ],	uiLineSectionLength  );
						}
					}
				}



				/////////////////
				// Draw border //
				/////////////////

				// Draw left and reght borders.
				for ( j = 0; j < uiBpp; j++ )
				{
					uwBlockOffset = (UInt16) ( wStartAddr1 + uwBytePerLine *  uwBlockHeight *  j );

					for ( i = 0; i < uwBlockHeight; i++ )
					{
						uwLineOffset1 = ( UInt16 ) ( uwBlockOffset + uwBytePerLine * i );
						uwLineOffset2 = ( UInt16 ) ( uwLineOffset1 + uwBytePerLine - 1 );

						halWriteDisplay8( uwLineOffset1, ( UInt8 ) ( Pattern4Bpp[ j ]			| 0xf0 ), 1 );
						halWriteDisplay8( uwLineOffset2, ( UInt8 ) ( Pattern4Bpp[ j + uiBpp ]	| 0x0f ), 1 );
					}
				}

				// Write buttom line
				halWriteDisplay8( uwLineOffset1, 0xff, uwBytePerLine  );
				// Write upper line
				halWriteDisplay8( wStartAddr1,   0xff, uwBytePerLine  );
				// move the cursor out of sight.
				halWriteReg16( REG001C_CSRW_P1 , ++uwLineOffset2 ); 

				break;
		}
	}
	else
	{
		//////////////////////////////////////////////////////////////////////////////////
		///									Text mode									//
		//////////////////////////////////////////////////////////////////////////////////
		UInt8	Value = 0x20;
		UInt32	Count; 

		if( uiCharHeight > 8 )
			wNumLines = (UInt16)(uiSl1 / 16);
		else    
			wNumLines = (UInt16)(uiSl1 / 8);

		Count = uiDisplayWidthInChar * wNumLines;

		while( Count-- )
		{
			halWriteDisplay8( wStartAddr1++, Value++, 1 );
			if(Value==0x7F) Value = 0x20;
		}

		halWriteReg16( REG001C_CSRW_P1 , ++wStartAddr1 ); // move the cursor out of sight.
	}


	m_fHotHotHot = fOldHotHotHot;	// Restore hot flag to previous state.

	return true;
}




bool ChipDef::ImportConfigurationData( const UInt8* pData, UInt32 Size, const char* *ErrorText )
//
//    If this method successfully imports configuration data from the supplied
//    buffer, then this instance of chipdef will load the new configuration data
//    and change it's entire state to match the newly loaded configuration data.
//
{
	int			Success = 0; // -1=FAIL(but recognized), 0=FAIL(unknown), 1=SUCCESS
	HAL_STRUCT	HalNew = {0};
	int			iConfigFormatUsed;
	const char* pszError = NULL;

	for ( iConfigFormatUsed=0; iConfigFormatUsed<m_NumConfigDataFormats; iConfigFormatUsed++ )
		if ( (Success = (this->*(m_pfnReadConfigData[iConfigFormatUsed]))(&HalNew,pData,Size,true,&pszError)) != 0 )
			break;    // Found HalInfo.

	if ( Success == 1 )
	{
		if ( HalNew.wDetectEndian == HAL_BIG_ENDIAN )
			SwapHalInfoMembers( HalNew );		// If big endian format, swap everything back to little endian format.
		m_HalInfo = HalNew;						// Update master HalInfo structure.
		for ( m_MaxHalInfoRegIndex=0; m_HalInfo.Regs[m_MaxHalInfoRegIndex].Index!=REGFLAG_ENDOFTABLE; m_MaxHalInfoRegIndex++ )
			continue;							// Recalculate max HalInfo reg index.

		// Just to be safe, kill the chip initialized and hot flags.
		m_fHotHotHot = m_fChipInitialized = false;

//	m_UserSAddr = GetFeatureRawValue("saddr") - GetFeatureNumValue("saddrbias");

	}

	if ( ErrorText )
		*ErrorText = pszError;

	return ( Success == 1 );
}




bool ChipDef::ExportConfigurationData( UInt8* pData, UInt32& Size, bool fKeepAddresses, const char* *ErrorText )
//
//    The supplied buffer must contain a valid HalInfo data structure that this
//    method can locate and overwrite with the current configuration data.
//
//    Note the Size argument is a reference, and this function can change Size to reflect the
//    new desired file size.  If the file size is not to change, then Size must not be altered
//    by this method, or by the WriteConfigData sub-functions.
//
{
	int			Success = 0;	// -1=FAIL(but recognized), 0=FAIL(unknown), 1=SUCCESS
	HAL_STRUCT	HalTemp = {0};
	int			iConfigFormatUsed;
	const char*	pszError = NULL;

	for ( iConfigFormatUsed=0; iConfigFormatUsed<m_NumConfigDataFormats; iConfigFormatUsed++ )
		if ( (Success = (this->*(m_pfnReadConfigData[iConfigFormatUsed]))(&HalTemp,pData,Size,false,&pszError)) != 0 )
		break;	// Found HalInfo.

	if ( Success == 1 )
	{
		// Retain info that was in the original configuration data.
		bool   fBigEndian = (HalTemp.wDetectEndian==HAL_BIG_ENDIAN);
		UInt32 dwBaseAddress = HalTemp.dwBaseAddress;

		HalTemp = m_HalInfo;

		// If the old format was BigEndian, swap everything to match format.
		if ( fBigEndian )
		SwapHalInfoMembers( HalTemp );

		// If desired, restore addresses to original endian state.
		if ( fKeepAddresses )
			HalTemp.dwBaseAddress = dwBaseAddress;

		// Calculate native (little or big endian) CRC.
		HalTemp.wHalCRC = CalculateHalInfoCRC( HalTemp );
		if ( fBigEndian )    // Restore CRC to original endian.
			HalTemp.wHalCRC = swap16( HalTemp.wHalCRC );

		// Write the new HalInfo back to the configuration data.
		Success = (this->*(m_pfnWriteConfigData[iConfigFormatUsed]))( &HalTemp, pData, Size, &pszError );
	}

	if ( ErrorText )
		*ErrorText = pszError;

	return ( Success == 1 );
}




int ChipDef::GetAppConfigText( char* Text, int Size, int BuildNumber )
{
	int FieldWidth = 24;
	int iT = 0;
	int i;

	if ( Text == NULL )
		return 0;

	DOTEXT	"//=================================================================="  NL
			"//  HAL_STRUCT information generated by %sCFG.EXE (Build %u)"          NL
			"//  Copyright (c) Seiko Epson Corporation 2003-2005."                  NL
			"//  All rights reserved."                                              NL
			"//"                                                                    NL,    GetProductName(NULL,GN_NAME), BuildNumber );
	DOTEXT	"//"                                                                    NL
			"//  This file INSTANTIATES the HalInfo structure, and should"          NL
			"//  only be included, one time, by the mini-HAL."                      NL
			"//=================================================================="  NL
			""                                                                      NL
			"#include \"hal_private.h\""                                            NL
			""                                                                      NL
			"#ifndef HAL_STRUCT_NAME"                                               NL
			"#define HAL_STRUCT_NAME HalInfo"                                       NL
			"#endif"                                                                NL
			""                                                                      NL
			"HAL_STRUCT HAL_STRUCT_NAME ="                                          NL
			"{"                                                                     NL );
    DOTEXT  "    %s"                    "// HAL ID string"                          NL,    sprintfield(FieldWidth, ",", "HALCHIPID\"%s\"", HALSIGSUFFIX) );
    DOTEXT  "    %s"                    "// Configuration description"              NL,    sprintfield(FieldWidth, ",", "\"%s\"", MakeFriendlyString(m_HalInfo.szConfigString,false)) );
    DOTEXT  "    %s"                    "// Chip ID"                                NL,    sprintfield(FieldWidth, ",", "%s",     "HALCHIPID") );
    DOTEXT  ""                                                                      NL );
    DOTEXT  "    %s"                    "// Sizeof this structure"                  NL,    sprintfield(FieldWidth, ",", "%s",     "sizeof(HAL_STRUCT)") );
    DOTEXT  "    %s"                    "// CRC of the rest of structure"           NL,    sprintfield(FieldWidth, ",", "0x%04X", CalculateHalInfoCRC(m_HalInfo)) );
    DOTEXT  "    %s"                    "// Endian detect (LE=0x%04X)"              NL,    sprintfield(FieldWidth, ",", "0x%04X", HAL_LITTLE_ENDIAN), HAL_LITTLE_ENDIAN );
    DOTEXT  "    %s"                    "// Desired frame rate (in Hz)"             NL,    sprintfield(FieldWidth, ",", "%uL",    m_HalInfo.wFrameRate) );
    DOTEXT  ""                                                                      NL );
    DOTEXT  "    %s"                    "// Embedded OSC frequency (in Hz)"         NL,    sprintfield(FieldWidth, ",", "%uL",    m_HalInfo.dwInternalOSC) );
    DOTEXT  "    %s"                    "// CLKI frequency (in Hz)"                 NL,    sprintfield(FieldWidth, ",", "%uL",    m_HalInfo.dwClkI) );
    DOTEXT  "    %s"                    "// PCLK frequency (in Hz)"                 NL,    sprintfield(FieldWidth, ",", "%uL",    m_HalInfo.dwPClk) );
    DOTEXT  ""                                                                      NL );
    DOTEXT  "    %s"                    "// in pixel"                               NL,    sprintfield(FieldWidth, ",", "%u",     m_HalInfo.wPanelWidth) );
    DOTEXT  "    %s"                    "// in lineof pixel"                        NL,    sprintfield(FieldWidth, ",", "%u",     m_HalInfo.wPanelHeight) );
    DOTEXT  "    %s"                    "// Gray scale Bpp"                         NL,    sprintfield(FieldWidth, ",", "%u",     m_HalInfo.wBpp) );
    DOTEXT  "    %s"                    "// Padding"                                NL,    sprintfield(FieldWidth, ",", "%u",     0) );
    DOTEXT  ""                                                                      NL );
    DOTEXT  "    %s"                    "// Physical base memory address"           NL,    sprintfield(FieldWidth, ",", "0x%08X", GetFeatureNumValue("baseaddr")) );
    DOTEXT  "    %s"                    "// Register offset form base address"      NL,    sprintfield(FieldWidth, ",", "0x%08X", GetFeatureNumValue("regoffset")) );
    DOTEXT  "    %s"                    "// Memory offset form base address"        NL,    sprintfield(FieldWidth, ",", "0x%08X", GetFeatureNumValue("memoffset")) );
    DOTEXT  ""                                                                      NL );
    DOTEXT  "    %s"                    "// Required VRAM (in bytes)"               NL,    sprintfield(FieldWidth, ",", "%uL",    m_HalInfo.dwRequiredVRAM) );
    DOTEXT  "    %s"                    "// Hal Information flags"                  NL,    sprintfield(FieldWidth, ",", "%s",     MakeHalFlagsString(m_HalInfo.dwFlags)) );
    DOTEXT  ""                                                                      NL );

    DOTEXT    "    %*s"                    "// %s init registers"                        NL,    -FieldWidth, "{", GetProductName(NULL,GN_NAME|GN_PREFIX) );
    for ( i=0; i<m_MaxHalInfoRegIndex; i++ )
        if ( IsRegisterValid(i,true) )
            DOTEXT"        { %s"                                    "0x%0*X },"        NL,    sprintfield(38, ",", "%s", GetRegisterName(i,true,GN_LEX)), GetRegisterValueFieldWidth(i,true), m_HalInfo.Regs[i].Value );
    DOTEXT        "        { %s"                                    "0x%0*X }"        NL,    sprintfield(38, ",", "%s", GetRegisterName(REGFLAG_ENDOFTABLE,false,GN_LEX)), GetRegisterValueFieldWidth(REGFLAG_ENDOFTABLE,false), 0 );
    DOTEXT    "    }"                                                                    NL );
    DOTEXT    "};"                                                                    NL );

    // Add extra lines because Juro states that gcc needs them otherwise a warning occurs.
    DOTEXT    ""                                                                        NL );
    DOTEXT    ""                                                                        NL );

    assert( iT < Size );
    return iT;
}




int ChipDef::GetChipHeaderText( char* Text, int Size, int BuildNumber )
{
    int        iT = 0;
    UInt32    RegIndex;

    if ( Text == NULL )
        return 0;

    DOTEXT  "//=================================================================="     NL
            "//  Chip Header information generated by %sCFG.EXE (Build %u)"            NL
            "//  Copyright (c) Seiko Epson Corporation 2003-2005."                     NL
            "//  All rights reserved."                                                 NL
            "//"                                                                       NL
            "//  This file establishes name/value pairs for all the registers,"        NL
            "//  which can be used by software, such as display drivers."              NL
            "//=================================================================="     NL,    GetProductName(NULL,GN_NAME), BuildNumber );

    DOTEXT    ""                                                                       NL
            "enum eReg"                                                                NL
            "{"                                                                        NL );
    for ( UInt32 i=0; EnuRegisters(false,i,RegIndex); i++ )
        if ( IsRegisterValid(RegIndex,false) )
            DOTEXT "    %s= %s// %s"                                                   NL,    sprintfield(m_DefaultRegIndexField+20+1," ","%s",GetRegisterName(RegIndex,false,GN_LEX)),
                                                                                        sprintfield(m_DefaultRegIndexField+6,",","0x%0*X",m_DefaultRegIndexField,RegIndex),
                                                                                        GetRegisterName(RegIndex,false,GN_NAME|GN_ATTRS) );
    BlankLastCommaInString( Text+iT );
    DOTEXT    "} eReg;"                                                                NL );

    // Add extra lines because Juro states that gcc needs them otherwise a warning occurs.
    DOTEXT    ""                                                                        NL );
    DOTEXT    ""                                                                        NL );

    assert( iT < Size );
    return iT;
}

⌨️ 快捷键说明

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