📄 chipdef.cpp
字号:
UInt32 iFeature;
if ( LookupFeature(Keyname,&iFeature) )
{
if ( m_Features[iFeature].NeedCode )
{
if ( FEATUREIS("baseaddr") ) m_HalInfo.dwBaseAddress = RawValue;
else if ( FEATUREIS("regoffset") ) m_HalInfo.dwRegisterOffset = RawValue;
else if ( FEATUREIS("memoffset") ) m_HalInfo.dwMemoryOffset = RawValue;
else if ( FEATUREIS("mastertype") )
{
m_CurMasterPanelType = RawValue;
SetFeatureRawValue( "rgbtft", (m_CurMasterPanelType==2?1:0) );
}
else if ( FEATUREIS("vram") ) m_HalInfo.dwRequiredVRAM = RawValue;
else if ( FEATUREIS("autostride") ) SETFEATUREHALFLAG( fFIXED_STRIDE, true )
else if ( FEATUREIS("ii") ) SETFEATUREHALFLAG( fINDIRECT_INTERFACE, false )
else if ( FEATUREIS("pccard") ) SETFEATUREHALFLAG( fPCCARD_INTERFACE, false )
else if ( FEATUREIS("sysclksrc") ) SETFEATUREHALFLAG( fSOURCE_CLKI, false )
else if ( FEATUREIS("regwrite") ) SETFEATUREHALFLAG( fDEBUG_REG_WRITES, false )
else if ( FEATUREIS("clki") ) m_HalInfo.dwClkI = RawValue;
else if ( FEATUREIS("iosc") ) m_HalInfo.dwInternalOSC = RawValue;
else if ( FEATUREIS("cnf4") ) SETFEATUREHALFLAG( fCNF4, false )
else if ( FEATUREIS("cnf32") )
{
m_HalInfo.dwFlags &= ~(fCNF3|fCNF2);
if( RawValue&2 ) m_HalInfo.dwFlags |= fCNF3;
if( RawValue&1 ) m_HalInfo.dwFlags |= fCNF2;
}
else if ( FEATUREIS("pclkdiv") ) assert( false );
else if ( FEATUREIS("fpshiftdiv") )
{
m_HalInfo.dwFlags &= ~(fCNF1|fCNF0);
if( RawValue&2 ) m_HalInfo.dwFlags |= fCNF1;
if( RawValue&1 ) m_HalInfo.dwFlags |= fCNF0;
}
else if ( FEATUREIS("sysclk") ) assert( false );
else if ( FEATUREIS("pclk") ) assert( false );
else if ( FEATUREIS("pshiftclk") ) assert( false );
else if ( FEATUREIS("stride") ||
FEATUREIS("rawbpp") )
{
ChipDefBase::SetFeatureRawValue( Keyname, RawValue );
}
else if ( FEATUREIS("bpp") )
{
switch ( RawValue )
{
default:
case 1: SetFeatureRawValue("rawbpp",0); break;
case 2: SetFeatureRawValue("rawbpp",1); break;
case 4: SetFeatureRawValue("rawbpp",2); break;
}
}
else
return ChipDefBase::SetFeatureRawValue( Keyname, RawValue );
return true;
}
return ChipDefBase::SetFeatureRawValue( Keyname, RawValue );
}
assert( false ); // ERROR: Keyname doesn't exist for this product! Caller must test IsFeatureValid() first!
return false;
}
bool ChipDef::SetFeatureStrValue( in const char* Keyname, in const char* StrValue )
{
UInt32 iFeature;
if ( LookupFeature(Keyname,&iFeature) )
{
if ( m_Features[iFeature].NeedCode )
{
if ( FEATUREIS("cfgdesc") )
{
strcpy( m_HalInfo.szConfigString, StrValue );
return true;
}
}
return ChipDefBase::SetFeatureStrValue( Keyname, StrValue );
}
assert( false ); // ERROR: Keyname doesn't exist for this product! Caller must test IsFeatureValid() first!
return false;
}
bool ChipDef::EnuRegisters( in bool UseHALList, in UInt32 ListIndex, out UInt32& RegIndex )
{
if ( UseHALList )
{
if ( ListIndex < (UInt32)m_MaxHalInfoRegIndex )
{
RegIndex = m_HalInfo.Regs[ListIndex].Index;
return true;
}
return false;
}
return ChipDefBase::EnuRegisters( UseHALList, ListIndex, RegIndex );
}
int ChipDef::DiagnoseForErrors( char* Text, int Size )
{
int iT = 0;
assert( Text!=NULL );
if ( GetFeatureNumValue("bpp")>16 && GetFeatureRawValue("lut1bypass")==0 )
iT += _snprintf( Text+iT, Size-iT, "ERROR: %s cannot =0 when %s >16.\n", GetFeatureName("lut1bypass",GN_NAME|GN_REG|GN_SHORT), GetFeatureName("bpp",GN_NAME|GN_REG|GN_SHORT) );
return iT;
}
int ChipDef::DiagnoseForWarnings( char* Text, int Size )
{
int iT = 0;
assert( Text!=NULL );
// ROC TODO: Hook up the following line and one for DiagnoseForErrors (it breaks now because ChipDefBase::DiagnoseForWarnings acess all registers or something).
// return iT + ChipDefBase::DiagnoseForWarnings( Text+iT, Size-iT );
return iT;
}
bool ChipDef::InitializeHotChip( in UInt32 HalInitFlags, in char* * ErrorText )
{
bool fInitChip = false;
// Copy the active HalInfo data to the master, which the HAL uses.
::HalInfo = m_HalInfo;
::HalInfo.wHalCRC = CalculateHalInfoCRC( ::HalInfo );
// Once the controller is aquired, don't do it again.
if ( !m_fAcquiredChip )
m_fAcquiredChip = !!halAcquireController(NULL,NULL);
// If the controller was aquired, setup caller's flag and initialize.
if ( m_fAcquiredChip )
fInitChip = !!halInitController( HalInitFlags );
if ( m_fAcquiredChip && fInitChip )
{
// Set not initialized and not hot if this request for a software reset
// but the registers were not programmed (that's just a raw reset),
// otherwise, flag a successful initialization.
if ( HalInitFlags && fDONT_INIT_REGS ) // if want software reset and don't want to init registers
m_fChipInitialized = m_fHotHotHot = false;
else
m_fChipInitialized = true;
// If caller has set auto test pattern, show it after initialization.
if ( m_fShowTestPattern )
m_nTimerTick = 1;
if ( ErrorText )
{
char* Text = GetCircularStr( m_SP );
int HalRev = (strchr(gpHalData->pszHALRevision,':')) ? atoi(strchr(gpHalData->pszHALRevision,':')+1) : 0;
sprintf( Text, "Initialized %s using HAL build %u.\n", GetProductName(NULL,GN_NAME|GN_PREFIX), HalRev );
*ErrorText = Text;
}
}
else
{
// Not successful, so kill the status flags, and report the error.
m_fChipInitialized = m_fHotHotHot = false;
if ( ErrorText )
{
char* pszHalError = GetCircularStr( m_SP );
char* pszError = GetCircularStr( m_SP );
halGetLastError( pszHalError, 1024 );
sprintf( pszError, "Cannot Initialize: %s.\n", pszHalError );
*ErrorText = pszError;
}
}
return m_fChipInitialized;
}
int ChipDef::ShowTestPattern( void )
{
bool fOldHotHotHot = m_fHotHotHot;
UInt16 wStartAddr1; // start addresses of block1
UInt16 uwBlockOffset = 0, uwBlockHeight;
UInt16 uwLineOffset1 = 0, uwLineOffset2 = 0, uwLineOffset3 = 0, uwLineOffset4 = 0;
UInt16 wNumLines;
UInt16 uiDisplayWidthInPixel, uiDisplayHeightInLine;
UInt16 uiSl1; // number of lines of layer 1
UInt16 uwBytePerLine;
UInt16 uwPanelWidth,uwPanelHeight, uiRequiredMemorSize ;
UInt8 uiMode1; // Attributes of Block 1: Text or Graphics
UInt8 uiDisplayWidthInChar;
UInt8 uiCharWidth, uiCharHeight, uiLineSectionLength;
UInt8 uiBpp, i, j, k;
UInt8 Pattern1Bpp[2] = {0xff, 0x0 },
Pattern2Bpp[4] = {0xff, 0xaa, 0x55, 0x00},
Pattern4Bpp[16] = {0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88,
0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x0};
// Do nothing if we're not initialized.
if ( !m_fChipInitialized )
return 2;
m_fHotHotHot = true; // Force reading from chip for all GetValue methods below.
uwPanelWidth = (UInt16) GetFeatureRawValue("width");
uwPanelHeight = (UInt16) GetFeatureRawValue("height");
uiBpp = (UInt8)GetFeatureRawValue("bpp");
uiRequiredMemorSize = ( UInt16 ) ( uwPanelWidth * uiBpp / 8 * uwPanelHeight );
if ( uiRequiredMemorSize > EMBEDDED_DISPLAY_MEM_SIZE )
return 3;
wStartAddr1 = halReadReg16( 0x0b );
uiSl1 = (UInt8) (halReadReg8( 0x0d ) + 1);
uiMode1 = (UInt8) (halReadReg8(0x18) >> 2);
uiCharWidth = (UInt8) ( (halReadReg8( 0x01 ) & 0x0f) + 1 );
uiCharHeight = (UInt8) ( (halReadReg8( 0x02 ) & 0x0f) + 1 );
uiDisplayWidthInChar = (UInt8) ( halReadReg8( 0x03 ) + 1 );
uiDisplayWidthInPixel = (UInt16) ( uiDisplayWidthInChar * uiCharWidth / uiBpp);
uiDisplayHeightInLine = (UInt16) ( halReadReg8( 0x05 ) + 1 );
uwBytePerLine = ( UInt16 ) ( halReadReg8( REG0003_SYSTEMSET_P4 ) + 1 );
uwBlockHeight = (UInt16) ( uiDisplayHeightInLine / uiBpp );
uiLineSectionLength = ( uiBpp == 1 ) ? (UInt8) ( uwBytePerLine / 2 ) : (UInt8) ( uwBytePerLine / uiBpp );
if ( uiMode1 )
{
//////////////////////////////////////////////////////////////////////////////////
// Graphics Mode //
//////////////////////////////////////////////////////////////////////////////////
switch ( uiBpp )
{
default:
case 1:
for ( j = 0; j < uiDisplayHeightInLine; j++ )
{
uwLineOffset1 = ( UInt16 ) ( wStartAddr1 + uwBytePerLine * j );
uwLineOffset2 = ( UInt16 ) ( uwLineOffset1 + uiLineSectionLength );
halWriteDisplay8( uwLineOffset1, Pattern1Bpp[0], uiLineSectionLength );
halWriteDisplay8( uwLineOffset2, Pattern1Bpp[1], 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) ( Pattern1Bpp[ j ] | 0x80 ), 1 );
halWriteDisplay8( uwLineOffset2, (UInt8) ( Pattern1Bpp[ j + 1 ] | 0x01 ), 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 2:
for ( k = 0; k < uiBpp; k++ )
{
uwBlockOffset = (UInt16) ( wStartAddr1 + uwBytePerLine * uiDisplayHeightInLine * k / uiBpp );
for ( j = 0; j < uwBlockHeight ; j++ )
{
uwLineOffset1 = ( UInt16 ) ( uwBlockOffset + uwBytePerLine * j );
uwLineOffset2 = ( UInt16 ) ( uwLineOffset1 + uiLineSectionLength );
for ( i = 0; i < uwBytePerLine; i++)
{
halWriteDisplay8( uwLineOffset1, Pattern2Bpp[ k ], uiLineSectionLength );
halWriteDisplay8( uwLineOffset2, Pattern2Bpp[ k + 1 ], uiLineSectionLength );
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -