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

📄 hal_host.c

📁 一款SmartPhone的驱动代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/***************************************************************
*	Copyright(C) 2003--2006  
*	Epson Electronic Technology Development (ShenZhen) co., LTD
*	All rights reserved.
*	
*	File name:	HAL_HOST.C
*	Author:		Eric ding
*	Dept:		Electronic Enginerring Department 
*	Date:		03/19/2003
*	Descriptions:	the mcu interface function
*	Modified: 
***************************************************************/
#include "string.h"

#include "sysLCDC.h"


// the Global Variable.
static unsigned long		gnHalErrCode;
static unsigned long		gHalMemAddr;
static unsigned long		gHalRegAddr;
static BOOL			gfDebugRegWrites;
static BOOL			gfDebugHalDelay;

// The messages in this array must correspond to the error codes contained in the HAL.H enumeration.
static const char * gapszErrMsg[ERR_FAILED + 1] =
{
	"There was no error detected",					// ERR_NONE
	"This program has not been configured",			// ERR_NOT_CONFIGURED
	"Config CRC does not match configuration",			// ERR_BAD_CFG_DATA
	"I2C bus/device initialization failure",				// ERR_BAD_I2C_INIT
	"An unspecified error occured"					// ERR_FAILED
};


// the define address for the indirect mode
unsigned char *  pIndirectCmd = NULL;
unsigned char *  pIndirectData8 = NULL;
unsigned short *  pIndirectData16 = NULL;

/****************************************************************************
; Function:	Get the type of chip 	
; Input :		None
; Output :	the type of chip
; Format :	ChipTypeDef GetChipType(void)
;****************************************************************************/
ChipTypeDef GetChipType(void)
{
	if (HalInfo.dwFlags & fVER_13710)
		return cl_S1D13710;
	else if (HalInfo.dwFlags & fVER_13711)
		return cl_S1D13711;
	else
		return cl_S1D13712;
}

/****************************************************************************
; Function:	Get the Name of chip 	
; Input :		None
; Output :	the Name of chip
; Format :	char *GetChipName(void)
;****************************************************************************/
char * GetChipName( void )
{
	return HalInfo.szChipId;
}

/****************************************************************************
; Function:	Get the ID Code of chip 	
; Input :	None
; Output :	the ID Code of chip
; Format :	void GetChipId(unsigned long *pProductCode, unsigned long *pRevisionCode)
;****************************************************************************/
void GetChipID(unsigned long *pProductCode, unsigned long *pRevisionCode)
{
	unsigned long Reg00 = halReadReg16(REG0000_PRODUCT_INFORMATION);

	*pProductCode = (Reg00 >> 2) & 0x3f;
	*pRevisionCode = Reg00 & 0x03;
}


/****************************************************************************
; Function:	Get the Memory Size of chip 	
; Input :	None
; Output :	the Memory Size of chip
; Format :	ChipTypeDef GetChipType(void)
;****************************************************************************/
unsigned long GetMemSize(void)
{
	unsigned long reg = halReadReg16(REG0000_PRODUCT_INFORMATION);
	return (((reg >> 8) & 0x00FF) * 4096UL);
}

/*************************************************************************************
; Function:	write value to the register of LCD controller  
; Input :	Index	: the address of register
;		Value	: the value of register
; Output :	None
; Format : 	void halWriteReg8  (unsigned long  Index, unsigned char Value )
;		void halWriteReg16 (unsigned long  Index, unsigned short Value)
;		void halWriteReg32 (unsigned long  Index, unsigned long Value )
;*************************************************************************************/
void halWriteReg8 ( unsigned long  Index, unsigned char  Value )
{
	if (HalInfo.dwFlags & fINDIRECT_INTERFACE)
		halIndirectWriteReg8(Index, Value);
	else
		*(volatile unsigned char * )(gHalRegAddr + Index) = Value;

}

void halWriteReg16 (  unsigned long  Index, unsigned short  Value )
{
	if (HalInfo.dwFlags & fINDIRECT_INTERFACE)
		halIndirectWriteReg16(Index, Value);
	else
		*(volatile unsigned short * )(gHalRegAddr + Index) = Value;

}

void halWriteReg32 ( unsigned long  Index, unsigned long  Value )
{
	if (HalInfo.dwFlags & fINDIRECT_INTERFACE)
		halIndirectWriteReg32(Index, Value);
	else
		*(volatile unsigned long *)(gHalRegAddr + Index) = Value;

}

 /*************************************************************************************
; Function:	Read the value from the register of LCD controller  
; Input :	Index	: the address of register
; Output:	Value	: the value of register
; Format : 	unsigned char  halReadReg8  (unsigned long Index )
;		unsigned short halReadReg16 (unsigned long Index )
;		unsigned long  halReadReg32 (unsigned long Index )
;*************************************************************************************/
unsigned char halReadReg8( unsigned long  Index )
{
	if (HalInfo.dwFlags & fINDIRECT_INTERFACE)
		return halIndirectReadReg8(Index);
	else
		return *(volatile unsigned char *)(gHalRegAddr + Index);
}

unsigned short halReadReg16( unsigned long  Index )
{
	if (HalInfo.dwFlags & fINDIRECT_INTERFACE)
		return halIndirectReadReg16(Index);
	else
		return *(volatile unsigned short *)(gHalRegAddr + Index);
}

unsigned long halReadReg32( unsigned long  Index )
{
	if (HalInfo.dwFlags & fINDIRECT_INTERFACE)
		return halIndirectReadReg32(Index);
	else
		return *(volatile unsigned long *)(gHalRegAddr + Index);
}

/*************************************************************************************
; Function:	write value to the buffer of LCD controller  
; Input	:	Offset 	: the Offset value of buffer start address
;		Value  	: the value of buffer
;		Count 	: the sizes of buffer need operation 
; Output:	None
; Format: 	void halWriteDisplay8  ( unsigned long  Offset, unsigned char Value)
;			void halWriteDisplay16 ( unsigned long  Offset, unsigned short Value)
;			void halWriteDisplay32 ( unsigned long  Offset, unsigned long Value )
;*************************************************************************************/
void halWriteDisplay8( unsigned long  Offset, unsigned char Value )
{
	volatile unsigned char * pMem;

	if (HalInfo.dwFlags & fINDIRECT_INTERFACE)
	{
		halIndirectWriteDisplayAddress(Offset);	// set the display address 
		*pIndirectData8 = Value;			// write the display data 
	}
	else
	{
		pMem = (volatile unsigned char *)(gHalMemAddr + Offset);
		*pMem++ = Value;
	}
}

void halWriteDisplay16(  unsigned long  Offset, unsigned short Value)
{

	volatile unsigned short * pMem;
	if (HalInfo.dwFlags & fINDIRECT_INTERFACE)
	{
		halIndirectWriteDisplayAddress(Offset);
		*pIndirectData16 = Value;
	}
	else
	{
		pMem = (volatile unsigned short *)(gHalMemAddr + Offset);
		*pMem++ = Value;
	}
}

void halWriteDisplay32( unsigned long  Offset, unsigned long Value )
{
	volatile unsigned long * pMem;
	if (HalInfo.dwFlags & fINDIRECT_INTERFACE)
	{
		halIndirectWriteDisplayAddress(Offset);
		*pIndirectData8 = (unsigned char) Value;
		*pIndirectData8 = (unsigned char) (Value >> 8);
		*pIndirectData8 = (unsigned char) (Value >> 16);
		*pIndirectData8 = (unsigned char) (Value >> 24);
	}
	else
	{
		pMem = (volatile unsigned long *)(gHalMemAddr + Offset);
		*pMem++ = Value;
	}
}


/*************************************************************************************
; Function:	Read the value from the buffer of LCD controller  
; Input :	offset	: the Offset value of buffer start addressr
; Output :	Value	: the value of register
; Format  : 	unsigned char   halReadReg8  ( unsigned long  Offset )
;		unsigned short  halReadReg16 ( unsigned long  Offset )
;		unsigned long   halReadReg32 ( unsigned long  Offset )
;*************************************************************************************/
unsigned char  halReadDisplay8( unsigned long  Offset )
{
	if (HalInfo.dwFlags & fINDIRECT_INTERFACE)
		return halIndirectReadDisplay8(Offset);
	else
		return *(volatile unsigned char *)(gHalMemAddr + Offset);
}

unsigned short  halReadDisplay16( unsigned long  Offset )
{
	if (HalInfo.dwFlags & fINDIRECT_INTERFACE)
		return halIndirectReadDisplay16(Offset);
	else
		return *(volatile unsigned short*)(gHalMemAddr + Offset);
}

unsigned long  halReadDisplay32( unsigned long  Offset )
{
	if (HalInfo.dwFlags & fINDIRECT_INTERFACE)
		return halIndirectReadDisplay32(Offset);
	else
		return *(volatile unsigned long *)(gHalMemAddr + Offset);
}


/*************************************************************************************
; Function:	Initialize the LCD Controller registers
; Input :	None
; Output :	None
; Format : 	void halpInitRegisters( void )
;*************************************************************************************/
void halInitRegisters( void )
{
	unsigned long idx;
	unsigned long ulIndex;
	unsigned long i;
	
	for (idx = 0; idx < NUM_REGS; idx++)
	{
		ulIndex = HalInfo.Regs[idx].Index;					// get the register address

		if (ulIndex < REG_RESERVED)
		{
			halWriteReg16(ulIndex, HalInfo.Regs[idx].Value);	// set the register
			for(i=0;i<10000;i++);

			if (ulIndex == REG0012_PLL_SETTING2)
				for(i=0;i<100000;i++);

		}
		else
		{
			switch(ulIndex)
			{
				case REG_POWER_OFF_DELAY:
				case REG_POWER_ON_DELAY:
					//	halDelayUS(HalInfo.Regs[idx].Value * 50);
						break;
				case REG_END_OF_TABLE:
						idx = NUM_REGS;
						break;
				default:
					break;
			}
		}
	}
}



/*************************************************************************************
; Function:	Initialize I2C bus
; Input :		None
; Output :	None
; Format : 	BOOL halpInitI2C( void )
;*************************************************************************************/
BOOL halpInitI2C(void)
{
	return TRUE;
}


/*************************************************************************************
; Function:	Initialize the Look_Up Table
; Input :		None
; Output :	None
; Format : 	void halInitLUT( void )
;*************************************************************************************/
void halInitLUT( void )
{
	unsigned long i;

	unsigned long LutIndex;
	unsigned char red, green, blue;
	unsigned short val;
	unsigned long PipBpp;
	unsigned char  *pLut;
	
	
	LutIndex = REG0400_LUT1_DATA0;
	pLut = LutInfo.lut1;

⌨️ 快捷键说明

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