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

📄 hal.c

📁 s1d13716的源码 windiws ce 或8位单片机
💻 C
📖 第 1 页 / 共 2 页
字号:
//=============================================================================
//	HAL.C
//-----------------------------------------------------------------------------
//	The routines in this file comprise the core of the LCD controller miniHAL.
//-----------------------------------------------------------------------------
//
//  Copyright (c) 2003 Epson Research and Development, Inc.
//  All Rights Reserved.
//
//=============================================================================



#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "hal_private.h"
#include "hal_i2c.h"
#include "hal_indirect.h"
//#include "hal_platform.h"


//===========================================================================
// PRIVATE GLOBAL VARIABLES (local to HAL only)
//===========================================================================

static DATA_STRUCT gHD;							
//{
	//members are default initialized to zero.
//};// Global HAL private data storage

//===========================================================================
// PUBLIC GLOBAL VARIABLES
//===========================================================================

const DATA_STRUCT* const gpHalData = &gHD;

//===========================================================================
// PRIVATE (STATIC) FUNCTION PROTOTYPES (local to HAL only)
//===========================================================================

static void		InitRegisters( void );
static void		ProgramParallelPanels( void );
static void		ClearVideoMemory( void );
static UInt16		CalculateHalInfoCRC( const PHAL_STRUCT pHalData );




//===========================================================================
// PUBLIC FUNCTIONS EXPORTED IN HAL.H
//===========================================================================



//---------------------------------------------------------------------------
// PUBLIC FUNCTION: halAcquireController()
//---------------------------------------------------------------------------
Boolean halAcquireController( void )
{
	static Boolean fFirstTime = FALSE;

	memset(&gHD,0,sizeof(gHD));
	
	gHD.nErrorCode = ERR_NONE;

	// Init, one time, default state of debug register writes flag.

	if ( !fFirstTime )
	{
		fFirstTime = TRUE;
	}
	
	// Use the configured base address to retrieve the virtual address, if any.  On
	// non-Windows platforms, the base address will be copied to the virtual address.

	if ( gHD.BaseAddress == 0 )	// Only do this once, so we are re-entrant.
	{
		gHD.BaseAddress=	HalInfo.dwBaseAddress;
		gHD.RegisterAddress = gHD.BaseAddress + HalInfo.dwRegisterOffset;
		gHD.MemoryAddress   = gHD.BaseAddress + HalInfo.dwMemoryOffset;

		//if ( HalInfo.dwMemoryOffset == HalInfo.dwRegisterOffset )
		//{
		//	gHD.nErrorCode=ERR_SAME_REGMEM;;
		//	return FALSE;
		//}
	}

	halpIndirectInit( gHD.BaseAddress );

	return TRUE;
}



//---------------------------------------------------------------------------
// PUBLIC FUNCTION: halInitController()
//---------------------------------------------------------------------------
Boolean halInitController( UInt32 Flags )
{
	// If the program has not been CFGed then we CANNOT init the controller.
	// Set and error code and return FALSE.

	gHD.nErrorCode = ERR_NONE;

	// If the caller specified ANY of the fJUST_xxx flags, then replace ALL the 
	// fDONT_xxx flags with the inverted logic of the fJUST_xxx flags.
	if ( (Flags & (fJUST_RESET|fJUST_INIT_I2C|fJUST_INIT_REGS|fJUST_PROG_LCDS|fJUST_INIT_LUT|fJUST_CLEAR_MEM|fJUST_CHECK_CRC)) )
		Flags = (~Flags & (fJUST_RESET|fJUST_INIT_I2C|fJUST_INIT_REGS|fJUST_PROG_LCDS|fJUST_INIT_LUT|fJUST_CLEAR_MEM|fJUST_CHECK_CRC)) >> 16;

	// Fail if halAcquireController() was not called, or if it failed.
	if ( gHD.BaseAddress == 0 )
	{
		gHD.nErrorCode = ERR_NOT_ACQUIRED;
		return FALSE;
	}

	// Should we reset the controller?
	if ( !(Flags & fDONT_RESET))
	{
		HAL_WRITE_REG(REG0008_SOFTRESET, 0);
		halDelayUS( HAL_DELAY_RESET );
	}

	// Init the registers - unless the caller has requested us not to
	if ( !(Flags & fDONT_INIT_REGS) )
	{
		// Make sure that the LCD Interface Auto Transfer Enable is turned off, or else this function will hang.
		if ( HAL_READ_REG(0x38) & 0x1 )
		{
			HAL_WRITE_REG( REG003C_LCDXFER, 0 );
			while ( HAL_READ_REG(0x38) & 0x1 )
				continue;
		}

		InitRegisters();
	}

	// Program the parallel LCD panels - unless:
	//	a) the caller has requested us not to
	//	b) CFG has requested us not to
	if ( !(Flags & fDONT_PROG_LCDS) && ((HalInfo.LCD1Regs[0] != HAL_LCD_ENDOFTABLE) || (HalInfo.LCD2Regs[0] != HAL_LCD_ENDOFTABLE) ))
	{
		ProgramParallelPanels();
	}

	// Init the LUT - unless the caller has requested us not to
	//if ( !(Flags & fDONT_INIT_LUT) )
	//{
	//	halInitLUT( FALSE );
	//}

	// Init the I2C bus - unless the caller or config has requested us not to.
	// Programming Epson Camera may corrupt VRAM, so clear it AFTER this.
	if ( !(Flags & fDONT_INIT_I2C) )
	{
		if ( !halpInitI2C(-1) )
			gHD.nErrorCode = ERR_BAD_I2C_INIT;
	}

	// Clear video memory - unless the caller has requested us not to.
	if ( !(Flags & fDONT_CLEAR_MEM) )
	{
		ClearVideoMemory();
	}

	return ( gHD.nErrorCode == ERR_NONE );
}

//-----------------------------------------------------------------------------
// PUBLIC FUNCTION: halGetLastError()
//-----------------------------------------------------------------------------
int halGetLastError()
{
	return gHD.nErrorCode;
}

//---------------------------------------------------------------------------
// PUBLIC FUNCTION: halInitLUT()
//---------------------------------------------------------------------------
void halInitLUT( Boolean fUseGradientPalette )
{
	UIntReg Reg4C;
	int bpp, LutBypass;
	int i;
	RGB_UNION CR;
	UInt8 *pLut;

	Reg4C = HAL_READ_REG(REG004C_DISPSETTING);
	bpp       = (0 == (Reg4C & 0x20))? 16 : 8;
	LutBypass = (0 == (Reg4C & 0x10)) ? TRUE : FALSE;

	if (8 == bpp)
	{
		// At 8 BPP there are three configurations we may be setting the LUT
		//	- If the LUT is bypassed configure for 3-3-2 bypass
		//	- If a gradient LUT is specified, configure for a gradient LUT
		//	- Else use the static LUT
		if (LutBypass)
		{
			// 8 bpp LUT bypass - fill LUT with 3-3-2 data
			for (i = 0; i < 8; i++)
			{
				// Only the first 4 Blue elements are used. the
				// next 4 values are discarded by the controller.
				CR.rgb.Blue  = (UInt8)((i * 0xFF) / 3);
				CR.rgb.Red   = (UInt8)((i * 0xFF) / 7);
				CR.rgb.Green = (UInt8)((i * 0xFF) / 7);
				HAL_WRITE_LUT(i, CR.Value32);
			}
		}
		else if (fUseGradientPalette)
		{
			// 8 bpp  - gradient filled LUT
			for (i = 0; i < 256; i++)
			{
				UInt8 c = (UInt8)(i << 2);

				CR.Value32 = 0x000000;
				switch (i/64)
				{
				  case 0:	CR.rgb.Red   = c;								break;
				  case 1:	CR.rgb.Green = c;								break;
				  case 2:	CR.rgb.Blue  = c;								break;
				  case 3:	CR.rgb.Red = CR.rgb.Green = CR.rgb.Blue = c;	break;
				}

				HAL_WRITE_LUT(i, CR.Value32);
			}
		}
		else
		{
			pLut = LutInfo.lut1;

			// 8 bpp - static LUT table
			for (i = 0; i < 256; i++)
			{
				CR.rgb.Red   = *pLut++;
				CR.rgb.Green = *pLut++;
				CR.rgb.Blue  = *pLut++;
				HAL_WRITE_LUT(i, CR.Value32);
			}
		}
	}
	else	// we are at 16 bpp
	{
		// 16 BPP is selected - configure for 5-6-5
		for (i = 0; i < 64; i++)
		{
			if (i < 32)
				CR.rgb.Red = CR.rgb.Blue = (UInt8)((i * 0xFF) / 31);
			else
				CR.rgb.Red = CR.rgb.Blue = 0xFF;

			CR.rgb.Green = (UInt8)((i * 0xFF) / 63);
			HAL_WRITE_LUT(i, CR.Value32);
		}
	}

}

//===========================================================================
// COMMON FUNCTIONS exported in HALAPI.H
//===========================================================================




//-----------------------------------------------------------------------------
// COMMON FUNCTION: halReadDisplay8()
// COMMON FUNCTION: halReadDisplay16()
// COMMON FUNCTION: halReadDisplay32()
//-----------------------------------------------------------------------------
UInt8 halReadDisplay8( UInt32 Offset )
{
	if ( HalInfo.dwFlags & fINDIRECT_SERIAL )
		return halpSerReadDisplay8( Offset );
	else
		return halpParReadDisplay8( Offset );
}

UInt16 halReadDisplay16( UInt32 Offset )
{
	if ( HalInfo.dwFlags & fINDIRECT_SERIAL )
		return halpSerReadDisplay16( Offset );
	else
		return halpParReadDisplay16( Offset );
}

UInt32 halReadDisplay32( UInt32 Offset )
{
	if ( HalInfo.dwFlags & fINDIRECT_SERIAL )
		return halpSerReadDisplay32( Offset );
	else
		return halpParReadDisplay32( Offset );
}


⌨️ 快捷键说明

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