📄 hal_indirect.c
字号:
/*-------------------------------------------------------------------------
//
// HAL_INDIRECT.C
//
// Copyright (c) 2003 Epson Research and Development, Inc.
// All Rights Reserved.
//
//-----------------------------------------------------------------------*/
#include "hal.h"
#include "hal_indirect.h"
/*-----------------------------------------------------------------------*/
static const char Revision[] = "IO.C=$Revision: 10 $";
/*-----------------------------------------------------------------------*/
// For Disp ON/OFF, in play.exe, run "x 9 0", it will execute indirect command 59(i.e. 0x58 | 0x01 = 0x59), run
// "x 9 1", it will execute indirect command 58(i.e. 0x58 | 0x00 = 0x58).
// For CSRDIR, the Indirect Command = (0x4c | Reg[17]) where reg[17]=0,1,2,3. CSDIR=4c,4d,4e,4f.
static ICOMMAND gHalCmd[MAXCOMMANDS] =
{
//wCode, wRegToMerge, wParam[MAXPARAMS], fVirtual, SubCommands[MAXSUBCOMMANDS]
{ 0x40, 0xFF,{0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0xFF,0xFF,0xFF},FALSE,NULL,NULL }, // SYSTREM SET 0
{ 0x53, 0xFF,{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},FALSE,NULL,NULL }, // SLEEP IN 1
{ 0x40, 0xFF,{0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},FALSE,NULL,NULL }, // SLEEP OUT 2
{ 0x58, 0x09,{0x0A,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},FALSE,NULL,NULL }, // DISPLAY ON/OFF 3
{ 0x44, 0xFF,{0x0B,0x0C,0x0D,0x0E,0x0F,0x10,0x11,0x12,0x13,0x14,0xFF},FALSE,NULL,NULL }, // SCROLL 4
{ 0x5D, 0xFF,{0x15,0x16,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},FALSE,NULL,NULL }, // CSRFORM 5
{ 0x4C, 0x17,{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},FALSE,NULL,NULL }, // CSRDIR 6
{ 0x5B, 0xFF,{0x18,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},FALSE,NULL,NULL }, // OVLAY 7
{ 0x5C, 0xFF,{0x19,0x1A,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},FALSE,NULL,NULL }, // CGRAM ADDR 8
{ 0x5A, 0xFF,{0x1B,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},FALSE,NULL,NULL }, // HDOT SCR 9
{ 0x46, 0xFF,{0x1C,0x1D,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},FALSE,NULL,NULL }, // CSRW 10
{ 0x47, 0xFF,{0x1E,0x1F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},FALSE,NULL,NULL }, // CSRR 11
{ 0x60, 0xFF,{0x20,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},FALSE,NULL,NULL }, // GRAYSCALE 12
{ 0x00, 0x08,{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},TRUE,&gHalCmd[1],&gHalCmd[2] } // Power Save 13
};
static PICOMMAND gCmdTbl[HAL_NUMREGS] =
{
// 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07
&gHalCmd[0],&gHalCmd[0],&gHalCmd[0],&gHalCmd[0],&gHalCmd[0],&gHalCmd[0],NULL,&gHalCmd[0], // SYSTEM SET
// 0x08
&gHalCmd[13], // POWER SAVE
// 0x09 0x0A
&gHalCmd[3],&gHalCmd[3], // DISP ON/OFF
//0x0B 0x0C 0x0D 0x0E 0x0F 0x10 0x11 0x12 0x13 0x14
NULL,&gHalCmd[4],&gHalCmd[4],NULL,&gHalCmd[4],&gHalCmd[4],NULL,&gHalCmd[4],NULL,&gHalCmd[4],// SCROLL
// 0x15 0x16
&gHalCmd[5],&gHalCmd[5], // CSRFORM
// 0x17
&gHalCmd[6], // CSRDIR
// 0x18
&gHalCmd[7], // OVLAY
//0x19 0x1A
NULL,&gHalCmd[8], // CGRAM ADDR
// 0x1B
&gHalCmd[9], // HDOT SCR
//0x1C 0x1D
NULL,&gHalCmd[10], // CSRW
//0x1E 0x1F
&gHalCmd[11],&gHalCmd[11], // CSRR
// 0x20
&gHalCmd[12] // GRAYSCALE
};
pUInt8 pIndirectCmd = NULL;
pUInt8 pIndirectDataRead = NULL;
pUInt8 pIndirectDataWrite = NULL;
/*-------------------------------------------------------------------------
//
// halInitIndirectInterface()
//
// Initialize HAL to communicate using indirect interface
//
//-----------------------------------------------------------------------*/
void halpInitIndirectInterface( UInt32 dwMemAddr )
{
if ( HalInfo.dwFlags & fPCCARD_INTERFACE )
{
// The addresses need to multiply by 2 due to A0 line from PC card to 13700 is not used.
pIndirectCmd = (pUInt8) ( dwMemAddr + 2 ); //odd address for command, addr 2 in PC is addr 1 in 13700
pIndirectDataWrite = (pUInt8) dwMemAddr; //even addr for parameter write
pIndirectDataRead = (pUInt8) ( dwMemAddr + 2); //odd addr for parameter read, addr 2 in PC is addr 1 in 13700
}
else
{
pIndirectCmd = (pUInt8) ( dwMemAddr + 1 ); //odd address for command
pIndirectDataWrite = (pUInt8) dwMemAddr; //even addr for parameter write
pIndirectDataRead = (pUInt8) ( dwMemAddr + 1 ); //odd addr for parameter read
}
}
//---------------------------------------------------------------------------
// FUNCTION: halIndRegWrite8()
// halIndRegWrite16()
// halIndRegWrite32()
//
// DESCRIPTION:
// This routine writes register via indirect interface.
//
// PARAMETERS:
// Index - Index of the register to be writen into.
// Value - The value needs to be writen.
//
// RETURNS:
// nothing
//
// MODIFIES:
//---------------------------------------------------------------------------
void halIndRegWrite8( UInt16 Index, UInt8 Value )
{
HalInfo.Regs[Index].Value = Value;
halIndirectRegCmd( gCmdTbl[Index] );
return;
}
void halIndRegWrite16( UInt16 Index, UInt16 Value )
{
HalInfo.Regs[Index].Value = (UInt8) Value;
HalInfo.Regs[Index+1].Value = (UInt8)(Value>>8);
halIndirectRegCmd( gCmdTbl[Index] );
if(gCmdTbl[Index]!=gCmdTbl[Index+1])
halIndirectRegCmd( gCmdTbl[Index+1] );
return;
}
void halIndRegWrite32( UInt16 Index, UInt32 Value )
{
UInt16 i;
PICOMMAND pCur = gCmdTbl[Index], pPre = NULL;
HalInfo.Regs[Index ].Value = (UInt8)( Value );
HalInfo.Regs[Index+1].Value = (UInt8)( Value>>8 );
HalInfo.Regs[Index+2].Value = (UInt8)( Value>>16 );
HalInfo.Regs[Index+3].Value = (UInt8)( Value>>24 );
for( i=0; i<4; i++ )
{
if( pCur != pPre )
{
halIndirectRegCmd( pCur );
pPre = pCur++;
}
}
return;
}
//---------------------------------------------------------------------------
// FUNCTION: halIndirectRegCmd()
//
// DESCRIPTION:
// This routine sends indirect control command to 13700
//
// PARAMETERS:
// pCmd - pointer to command struct
//
// RETURNS:
// nothing
//
// MODIFIES:
//---------------------------------------------------------------------------
void halIndirectRegCmd( PICOMMAND pCmd )
{
UInt16 i;
UInt8* pParams = pCmd->wParams;
PREG_STRUCT pHalReg = HalInfo.Regs;
if( pCmd==NULL ) return;
// Command
if( pCmd->fVirtualCmd )
{
if( pHalReg[pCmd->wRegToMerge].Value & 1 )
{
if( pCmd->SubCommands[1] )
halIndirectRegCmd( (PICOMMAND)(pCmd->SubCommands[0]) );
else
assert(FALSE); // Sub command did not setup properly!
}
else
{
if( pCmd->SubCommands[0] )
halIndirectRegCmd( (PICOMMAND)(pCmd->SubCommands[1]) );
else
assert(FALSE); // Sub command did not setup properly!
}
}
else
{
if( pCmd->wRegToMerge==0xFF )
*pIndirectCmd = pCmd->wCmdCode;
else
{
*pIndirectCmd = (UInt8) (pCmd->wCmdCode | pHalReg[pCmd->wRegToMerge].Value);
}
// Parameters
if( pCmd->wCmdCode==CMD_CSRR )
for( i=0; pParams[i]!=0xFF; i++ )
pHalReg[pParams[i]].Value = *pIndirectDataRead;
else
for( i=0; pParams[i]!=0xFF; i++ )
*pIndirectDataWrite = (UInt8) pHalReg[pParams[i]].Value;
}
}
//--------------------------------------------------------------------------
// halpIndWriteDisplay8()
// halpIndWriteDisplay16()
// halpIndWriteDisplay32()
//--------------------------------------------------------------------------
void halpIndWriteDisplay8( UInt16 Offset, UInt8 Value, UInt32 Count )
{
*pIndirectCmd = (UInt8) CMD_CSRW;
*pIndirectDataWrite = (UInt8) Offset;
*pIndirectDataWrite = (UInt8)(Offset>>8);
*pIndirectCmd = (UInt8) CMD_MWRITE;
do *pIndirectDataWrite = (UInt8) Value; while(--Count); // Write memory
}
void halpIndWriteDisplay16( UInt16 Offset, UInt16 Value, UInt32 Count )
{
UInt8 bLsb = (UInt8) Value;
UInt8 bMsb = (UInt8)(Value>>8);
*pIndirectCmd = (UInt8) CMD_CSRDIR_RIGHT; // Set cursor dir to right
*pIndirectCmd = (UInt8) CMD_CSRW;
*pIndirectDataWrite = (UInt8) Offset;
*pIndirectDataWrite = (UInt8)(Offset>>8);
*pIndirectCmd = (UInt8) CMD_MWRITE;
do
{
*pIndirectDataWrite = (UInt8) bLsb;
*pIndirectDataWrite = (UInt8) bMsb;
} while(--Count);
}
void halpIndWriteDisplay32( UInt16 Offset, UInt32 Value, UInt32 Count )
{
UInt8 b0 = (UInt8) Value;
UInt8 b1 = (UInt8)(Value>>8 );
UInt8 b2 = (UInt8)(Value>>16);
UInt8 b3 = (UInt8)(Value>>24);
*pIndirectCmd = (UInt8) CMD_CSRDIR_RIGHT; // Set cursor dir to right
*pIndirectCmd = (UInt8) CMD_CSRW;
*pIndirectDataWrite = (UInt8) Offset;
*pIndirectDataWrite = (UInt8)(Offset>>8);
*pIndirectCmd = (UInt8) CMD_MWRITE;
do
{
*pIndirectDataWrite = (UInt8) b0;
*pIndirectDataWrite = (UInt8) b1;
*pIndirectDataWrite = (UInt8) b2;
*pIndirectDataWrite = (UInt8) b3;
} while(--Count);
}
//--------------------------------------------------------------------------
// halpIndReadDisplay8()
// halpIndReadDisplay16()
// halpIndReadDisplay32()
//--------------------------------------------------------------------------
UInt8 halpIndReadDisplay8( UInt16 wAddr )
{
// Set cursor position for mem read
*pIndirectCmd = (UInt8) CMD_CSRW;
*pIndirectDataWrite = (UInt8) wAddr;
*pIndirectDataWrite = (UInt8) (wAddr>>8);
// Read memory
*pIndirectCmd = (UInt8) CMD_MREAD;
return *( pIndirectDataRead );
}
UInt16 halpIndReadDisplay16( UInt16 wAddr )
{
UInt16 wRetVal;
*pIndirectCmd = (UInt8)CMD_CSRW;
*pIndirectDataWrite = (UInt8) wAddr;
*pIndirectDataWrite = (UInt8)(wAddr>>8);
*pIndirectCmd = (UInt8)CMD_MREAD;
wRetVal = *pIndirectDataRead;
wRetVal |= (*pIndirectDataRead)<<8;
return wRetVal;
}
UInt32 halpIndReadDisplay32( UInt16 wAddr )
{
UInt32 dwRetVal;
*pIndirectCmd = (UInt8)CMD_CSRW;
*pIndirectDataWrite = (UInt8) wAddr;
*pIndirectDataWrite = (UInt8)(wAddr>>8);
*pIndirectCmd = (UInt8)CMD_MREAD;
dwRetVal = *pIndirectDataRead;
dwRetVal |= (*pIndirectDataRead)<< 8;
dwRetVal |= (*pIndirectDataRead)<<16;
dwRetVal |= (*pIndirectDataRead)<<24;
return dwRetVal;
}
/*-------------------------------------------------------------------------
//
// halIndirectWriteDisplayAddress()
//
// Sets up display address
//
//-----------------------------------------------------------------------*/
void halIndirectWriteDisplayAddress(UInt16 addr)
{
*pIndirectCmd = (UInt8) CMD_CSRW;
*pIndirectDataWrite = (UInt8) addr;
*pIndirectDataWrite = (UInt8) (addr >> 8);
}
/*-------------------------------------------------------------------------
//
// halpIndInitRegisters()
//
// Sets up display address
//
//-----------------------------------------------------------------------*/
void halpIndInitRegisters( void )
{
halIndirectRegCmd( &gHalCmd[0] ); // SYSTEM SET
halIndirectRegCmd( &gHalCmd[3] ); // DISPLAY ON/OFF
halIndirectRegCmd( &gHalCmd[4] ); // SCROLL
halIndirectRegCmd( &gHalCmd[5] ); // CSRFORM
halIndirectRegCmd( &gHalCmd[6] ); // CSRDIR
halIndirectRegCmd( &gHalCmd[7] ); // OVLAY
halIndirectRegCmd( &gHalCmd[8] ); // CGRAM ADDR
halIndirectRegCmd( &gHalCmd[9] ); // HDOT SCR
halIndirectRegCmd( &gHalCmd[10] ); // CSRW
halIndirectRegCmd( &gHalCmd[12] ); // GRAYSCALE
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -