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

📄 hal_host.c

📁 一款SmartPhone的驱动代码
💻 C
📖 第 1 页 / 共 2 页
字号:

	// Calculate bpp for 13712 Main window
	switch (halReadReg16(REG0200_DISPLAY_MODE_SETTING0) & 0x0003)
	{
		case 0 : 
		default: PipBpp = 8; break;
		case 1 : PipBpp = 16; break;
		case 2 : PipBpp = 24; break;
		case 3 : PipBpp = 32; break;
	}

	// Write the LUT1 Data
	for (i = 0; i < 256; i++)
	{
	
		val = *pLut++;					// red
		val |= (*pLut++ << 8);				// green

		halWriteReg16(LutIndex, val);
		LutIndex += 2;

		val = *pLut++;					// blue
		halWriteReg16(LutIndex, val);
		LutIndex += 2;
	}


	LutIndex = REG0800_LUT2_DATA0;

	if (PipBpp == 16)					// Program LUT2 for 16 bpp 5-6-5 LUT
	{
		for (i = 0; i < 64; i++)
		{
			if (i < 32)
				red = blue = (unsigned char ) ((i * 0xff) / 31);
			else
				red = blue = 0xff;

			green = (unsigned char ) ((i * 0xff) / 63);

			val = (unsigned short )((green << 8) | red);
			halWriteReg16(LutIndex, val);
			LutIndex += 2;

			halWriteReg16(LutIndex, blue);
			LutIndex += 2;
		}
	}
	else  								// Program LUT2 for 8 bpp 3-3-2 LUT
	{
		for (i = 0; i < 8; i++)
		{
			red = green = (unsigned char) ((i * 0xff) / 7);

			if (i < 4)
				blue = (unsigned char) ((i * 0xff) / 3);
			else
				blue = 0xff;

			val = (unsigned short)((green << 8) | red);
			halWriteReg16(LutIndex, val);
			LutIndex += 2;

			halWriteReg16(LutIndex, blue);
			LutIndex += 2;
		}
	}
}

/*************************************************************************************
; Function:	Clean the buffer in LCD controller
; Input :	the start address of buffer 
; Output:	None
; Format : 	void halpClearVmem( unsigned long * ptr )
;*************************************************************************************/
void halpClearVmem( unsigned long * ptr )
{
	unsigned long ulNumDwords;
	unsigned long cnt;
		
	ulNumDwords = ((halReadReg32(0x00) >> 8) & 0xFF) * 4096 / 4;

	for (cnt = 0; cnt < ulNumDwords; cnt++, ptr++)
		*ptr = 0x0;
}

/****************************************************************************
; Function:	Initialize HOST communicate LCDC using indirect interface 	
; Input :	Indirect Command Address
; Output :	None	
; Format :	void halInitIndirectInterface(unsigned char * addr)
;****************************************************************************/
void halInitIndirectInterface(unsigned char * addr)
{
	pIndirectCmd = addr;							// set the command address
	pIndirectData8 = pIndirectCmd+2;				// set the data address
	pIndirectData16 = (unsigned short *) pIndirectData8;
}

/****************************************************************************
; Function:	Set the buffer of LCDC using indirect interface 	
; Input :	addr	: the display buffer address			
; Output :	None	
; Format :	void halIndirectWriteDisplayAddress(unsigned   long addr)
; Warning:	DO NOT USE ODD ADDRESSES FOR WORD ACCESSES !!!
;****************************************************************************/
void halIndirectWriteDisplayAddress(unsigned long addr)
{
	halIndirectWriteReg16(REG0022_INDIRECT_MEM_ADDR1, (unsigned short) addr);
	halIndirectWriteReg16(REG0024_INDIRECT_MEM_ADDR2, (unsigned short) (addr >> 16));
	*pIndirectCmd = REG0028_INDIRECT_MEM_PORT;
}


/****************************************************************************
; Function:	write the registers of LCDC using indirect interface 	
; Input :	index	: the offset address of register
;		value	: the value of register
; Output :	None	
; Format :	void halIndirectWriteReg8(unsigned long index, unsigned char  value)
;		void halIndirectWriteReg16(unsigned long index, unsigned short  value)
;		void halIndirectWriteReg32(unsigned long index, unsigned long  value)
; Warning:	DO NOT USE ODD ADDRESSES FOR WORD ACCESSES !!!
;****************************************************************************/
void halIndirectWriteReg8(unsigned long index, unsigned char value)
{
	*pIndirectCmd = (unsigned char) index;
	*pIndirectData8 = value;
}

void halIndirectWriteReg16(unsigned long index, unsigned short value)
{
	*pIndirectCmd = (unsigned char) index;
	*pIndirectData16 = value;
}

void halIndirectWriteReg32(unsigned long index, unsigned long value)
{
	halIndirectWriteReg8(index, (unsigned char) value);
	halIndirectWriteReg8(index+1, (unsigned char) (value >> 8));
	halIndirectWriteReg8(index+2, (unsigned char) (value >> 16));
	halIndirectWriteReg8(index+3, (unsigned char) (value >> 24));
}

/****************************************************************************
; Function:	Read the registers of LCDC using indirect interface 	
; Input :	index	: the register address			
; Output :	value	: the value of register	
; Format :	unsigned char  halIndirectReadReg8 (unsigned long  index)
;		unsigned short halIndirectReadReg16(unsigned long index)
;		unsigned long halIndirectReadReg32(unsigned long index)
; Warning:	DO NOT USE ODD ADDRESSES FOR WORD ACCESSES !!!
;****************************************************************************/
unsigned char halIndirectReadReg8(unsigned long index)
{
	*pIndirectCmd = (unsigned char) index;

	return *pIndirectData8;
}

unsigned short halIndirectReadReg16(unsigned long index)
{
	*pIndirectCmd = (unsigned char) index;

	return *pIndirectData16;
}

unsigned long halIndirectReadReg32(unsigned long index)
{
	unsigned long value;

	value = halIndirectReadReg8(index);
	value |= halIndirectReadReg8(index+1) << 8;
	value |= halIndirectReadReg8(index+2) << 16;
	value |= halIndirectReadReg8(index+3) << 24;

	return value;
}

/****************************************************************************
; Function:	write the buffer of LCDC using indirect interface 	
; Input :	addr	: the buffer address			
;			data	: the data of buffer
; Output :	None	
; Format :	void  halIndirectWriteDisplay8 (unsigned long  addr,unsigned char data  )
;		void  halIndirectWriteDisplay16 (unsigned long addr,unsigned short data )
;		void  halIndirectWriteDisplay32 (unsigned long addr,unsigned long data )
; Warning:	DO NOT USE ODD ADDRESSES FOR WORD ACCESSES !!!
;****************************************************************************/
void halIndirectWriteDisplay8(unsigned long  addr,unsigned char data  )
{
	halIndirectWriteDisplayAddress(addr);

	*pIndirectData8 = data;
}

void halIndirectWriteDisplay16(unsigned long  addr,unsigned short data  )
{
	halIndirectWriteDisplayAddress(addr);

	*pIndirectData16 = data;
}

void halIndirectWriteDisplay32(unsigned long  addr,unsigned long data  )
{
	halIndirectWriteDisplayAddress(addr);

	*pIndirectData8 = (unsigned char) data;
	*pIndirectData8 = (unsigned char) (data >> 8);
	*pIndirectData8 = (unsigned char) (data >> 16);
	*pIndirectData8 = (unsigned char) (data >> 24);
}

/****************************************************************************
; Function:	Read the buffer of LCDC using indirect interface 	
; Input :	addr	: the buffer address			
; Output :	data	: the data of buffer	
; Format :	unsigned char  halIndirectReadDisplay8 (unsigned long  addr )
;		unsigned short halIndirectReadDisplay16 (unsigned long addr)
;		unsigned long halIndirectReadDisplay32 (unsigned long addr)
; Warning:	DO NOT USE ODD ADDRESSES FOR WORD ACCESSES !!!
;****************************************************************************/
unsigned char halIndirectReadDisplay8( unsigned long addr)
{
	halIndirectWriteDisplayAddress(addr);

	return *pIndirectData8;
}

unsigned short halIndirectReadDisplay16(unsigned long addr)
{
	halIndirectWriteDisplayAddress(addr);

	return *pIndirectData16;
}

unsigned long halIndirectReadDisplay32(unsigned long addr)
{
	unsigned long value;

	halIndirectWriteDisplayAddress(addr);

	value = *pIndirectData8;
	value |= *pIndirectData8 << 8;
	value |= *pIndirectData8 << 16;
	value |= *pIndirectData8 << 24;

	return value;
}

/****************************************************************************
; Function:	Get the last error of hal 	
; Input :		Error Message point and Max size			
; Output :	Error Code 	
; Format :	long halGetLastError( char * ErrMsg, long MaxSize )
;****************************************************************************/
long halGetLastError( char * ErrMsg, long MaxSize )
{
	char szTmp[160];

	if (NULL != ErrMsg)
	{
		if (ERR_NONE == gnHalErrCode)								// Format a suitable error message,
			strncpy(ErrMsg, gapszErrMsg[gnHalErrCode], MaxSize);
		else
		{
			strncpy(ErrMsg, szTmp, MaxSize);
		}
	}
	return gnHalErrCode;
}

/*************************************************************************************
; Function:	Initialize the LCD controller  
; Input :	Flag
; Outpu:	BOOL
; Forma : 	BOOL halInitController( unsigned long Flags )
;*************************************************************************************/
BOOL halInitController( unsigned long  Flags )
{
	// if the program has not been CFGed then we can not init the controller.
	// set  error code and return FALSE.
	gnHalErrCode = ERR_NONE;
	gfDebugHalDelay = FALSE;							// Don't debug delays during init, as they are special-cased!

	// set the display and register address of lcdc 
	gHalRegAddr  = HalInfo.dwRegisterAddress;
	gHalMemAddr  = HalInfo.dwMemoryAddress;
	if (HalInfo.dwFlags & fINDIRECT_INTERFACE)				// set indirect interface address
		halInitIndirectInterface((unsigned char *) gHalRegAddr);

	// reset the lcd controller  by software  
	if ( !(Flags & fDONT_RESET) && !(HalInfo.dwFlags & fNO_RESET) )
	{
		halWriteReg16(REG0016_SOFTWARE_RESET, 0);		// reset the lcdc
	//	halDelayUS(HAL_DELAY_RESET);
	}
	// init the registers following the config information
	if (!(Flags & fDONT_INIT_REGS))
		halInitRegisters();
	
	// init the LUT 
	if (!(Flags & fDONT_INIT_LUT))
		halInitLUT();
	
	// init the I2C bus
	if ( !(Flags & fDONT_INIT_I2C) && !(HalInfo.dwFlags & fNO_INIT_I2C) )
		if (!halpInitI2C())
			gnHalErrCode = ERR_BAD_I2C_INIT;
	
	// clear display memory
	if (!(Flags & fDONT_CLEAR_MEM))
		halpClearVmem((unsigned long*)gHalMemAddr);
	
	return (gnHalErrCode == ERR_NONE);
}















⌨️ 快捷键说明

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