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

📄 s3c2440disp.cpp

📁 sharp 640*480 display driver for windows ce
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
Copyright (c) 2001. Samsung Electronics, co. ltd  All rights reserved.

Module Name:  

Abstract:

	This file implements the S3C2440 LCD function

rev:
	2002.4.4	: First S3C2410 version (kwangyoon LEE, kwangyoon@samsung.com)

	2002.1.31	: CE.NET port (kwangyoon LEE, kwangyoon@samsung.com)

Notes: 
--*/

#include "precomp.h"
#ifdef CLEARTYPE
#include <ctblt.h>
#endif
#include <aablt.h>

DWORD gdwLCDVirtualFrameBase;

INSTANTIATE_GPE_ZONES(0x3,"MGDI Driver","unused1","unused2")	// Start with errors and warnings

static	GPE		*gGPE = (GPE*)NULL;
static	ulong	gBitMasks[] = { 0xF800, 0x07E0, 0x001F };		// 565 MODE

static TCHAR gszBaseInstance[256] = _T("Drivers\\Display\\S3C2440\\CONFIG");

#define dim(x)                                  (sizeof(x) / sizeof(x[0]))

// This prototype avoids problems exporting from .lib
BOOL APIENTRY GPEEnableDriver(ULONG engineVersion, ULONG cj, DRVENABLEDATA *data,
							  PENGCALLBACKS  engineCallbacks);

// GWES will invoke this routine once prior to making any other calls into the driver.
// This routine needs to save its instance path information and return TRUE.  If it
// returns FALSE, GWES will abort the display initialization.
BOOL APIENTRY
DisplayInit(LPCTSTR pszInstance, DWORD dwNumMonitors)
{
	DWORD dwStatus;
	HKEY hkDisplay;
	BOOL fOk = FALSE;

    RETAILMSG(0, (_T("SALCD2: display instance '%s', num monitors %d\r\n"),
    	pszInstance != NULL ? pszInstance : _T("<NULL>"), dwNumMonitors));

    if(pszInstance != NULL) {
        _tcsncpy(gszBaseInstance, pszInstance, dim(gszBaseInstance));
    }

	// sanity check the path by making sure it exists
	dwStatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE, gszBaseInstance, 0, 0, &hkDisplay);
	if(dwStatus == ERROR_SUCCESS) {
		RegCloseKey(hkDisplay);
		fOk = TRUE;
	} else {
		RETAILMSG(0, (_T("SALCD2: DisplayInit: can't open '%s'\r\n"), gszBaseInstance));
	}

    return fOk;
}

BOOL APIENTRY DrvEnableDriver(ULONG engineVersion, ULONG cj, DRVENABLEDATA *data,
							  PENGCALLBACKS  engineCallbacks)
{
	BOOL fOk = FALSE;

	// make sure we know where our registry configuration is
	if(gszBaseInstance[0] != 0) {
		fOk = GPEEnableDriver(engineVersion, cj, data, engineCallbacks);
	}

	return fOk;
}

//
// Main entry point for a GPE-compliant driver
//

GPE *GetGPE(void)
{
	if (!gGPE)
	{
		gGPE = new S3C2440DISP();
	}

	return gGPE;
}

#if (LCD_TYPE == TFT640_480)
WORD	TempBuffer[641][480];
#elif (LCD_TYPE == TFT240_320)
WORD	TempBuffer[321][240];
#endif


S3C2440DISP::S3C2440DISP (void)
{
	RETAILMSG(0, (TEXT("++S3C2440DISP::S3C2440DISP\r\n")));
	
	// setup up display mode related constants
#if (LCD_TYPE == TFT640_480)
	m_nScreenWidth  = 640;
	m_nScreenHeight = 480;
#elif (LCD_TYPE == TFT240_320)
	m_nScreenWidth  = 320;
	m_nScreenHeight = 240;
#endif
	m_colorDepth = 16;
	m_cbScanLineLength = m_nScreenWidth * 2;
	m_FrameBufferSize = m_nScreenHeight * m_cbScanLineLength;
	
	// memory map register access window, frame buffer, and program LCD controller
	InitializeHardware();

#ifdef ROTATE
	m_iRotate = 0;
	SetRotateParms();
#endif //ROTATE	

	// setup ModeInfo structure
	m_ModeInfo.modeId = 0;
	m_ModeInfo.width = m_nScreenWidth;
	m_ModeInfo.height = m_nScreenHeight;
	m_ModeInfo.Bpp = m_colorDepth;
	m_ModeInfo.format = gpe16Bpp;
	m_ModeInfo.frequency = 60;	// ?
	m_pMode = &m_ModeInfo;
	
	// allocate primary display surface
#ifdef 	ROTATE
	m_pPrimarySurface = new GPESurfRotate(m_nScreenWidthSave, m_nScreenHeightSave, (void*)(m_VirtualFrameBuffer), m_cbScanLineLength, m_ModeInfo.format);
#else
	m_pPrimarySurface = new GPESurf(m_nScreenWidth, m_nScreenHeight, (void*)(m_VirtualFrameBuffer), m_cbScanLineLength, m_ModeInfo.format);	
#endif //!ROTATE
	memset ((void*)m_pPrimarySurface->Buffer(), 0x0, m_FrameBufferSize);

	// init cursor related vars
	m_CursorVisible = FALSE;
	m_CursorDisabled = TRUE;
	m_CursorForcedOff = FALSE;
	memset (&m_CursorRect, 0x0, sizeof(m_CursorRect));
	m_CursorBackingStore = NULL;
	m_CursorXorShape = NULL;
	m_CursorAndShape = NULL;

#ifdef CLEARTYPE
	HKEY  hKey;
	DWORD dwValue;
	ULONG ulGamma = DEFAULT_CT_GAMMA;	
	
	if (ERROR_SUCCESS == RegCreateKeyEx(HKEY_LOCAL_MACHINE,szGamma,0, NULL,0,0,0,&hKey,&dwValue))
	{
	    if (dwValue == REG_OPENED_EXISTING_KEY)
	    {
		DWORD dwType = REG_DWORD;
		DWORD dwSize = sizeof(LONG);
		if (ERROR_SUCCESS == RegQueryValueEx(hKey,szGammaValue,0,&dwType,(BYTE *)&dwValue,&dwSize))
		{
		    ulGamma = dwValue;
		}
	    } 
	    else if (dwValue == REG_CREATED_NEW_KEY )
	    {
		RegSetValueEx(hKey,szGammaValue,0,REG_DWORD,(BYTE *)&ulGamma,sizeof(DWORD));
	    }
	    RegCloseKey(hKey);
	}

	SetClearTypeBltGamma(ulGamma);
	SetClearTypeBltMasks(gBitMasks[0], gBitMasks[1], gBitMasks[2]);
#endif //CLEARTYPE	

	RETAILMSG(0, (TEXT("--S3C2440DISP::S3C2440DISP\r\n")));
}

void S3C2440DISP::InitializeHardware (void)
{
	WORD *ptr;
	DWORD index;
	HKEY hkDisplay = NULL;
	DWORD dwLCDPhysicalFrameBase;
	DWORD dwStatus, dwType, dwSize;

	RETAILMSG(0, (_T("++S3C2440DISP::InitializeHardware\r\n")));

	// open the registry key and read our configuration
	dwStatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE, gszBaseInstance, 0, 0, &hkDisplay);
	dwType = REG_DWORD;

	if(dwStatus == ERROR_SUCCESS && dwType == REG_DWORD) {
		dwSize = sizeof(DWORD);
		dwStatus = RegQueryValueEx(hkDisplay, _T("LCDVirtualFrameBase"), NULL, &dwType, 
			(LPBYTE) &gdwLCDVirtualFrameBase, &dwSize);
	}
	if(dwStatus == ERROR_SUCCESS && dwType == REG_DWORD) {
		dwSize = sizeof(DWORD);
		dwStatus = RegQueryValueEx(hkDisplay, _T("LCDPhysicalFrameBase"), NULL, &dwType, 
			(LPBYTE) &dwLCDPhysicalFrameBase, &dwSize);
	}

	// close the registry key
	if(hkDisplay != NULL) {
		RegCloseKey(hkDisplay);
	}

	// did we get everything?
	if(dwStatus != ERROR_SUCCESS) {
		RETAILMSG(0, (_T("SALCD2: InitializeHardware: couldn't get registry configuration\r\n")));
		return;
	}

	// map frame buffer into process space memory
#if (LCD_TYPE == TFT640_480)
	m_VirtualFrameBuffer = (DWORD)VirtualAlloc(0, (0xA0000), MEM_RESERVE, PAGE_NOACCESS);
	if (m_VirtualFrameBuffer == NULL) 
	{
	    RETAILMSG(0,(TEXT("m_VirtualFrameBuffer is not allocated\n\r")));
		return;
	}
	else if (!VirtualCopy((PVOID)m_VirtualFrameBuffer, (PVOID)gdwLCDVirtualFrameBase, (0xA0000), PAGE_READWRITE | PAGE_NOCACHE))
	{
	    RETAILMSG(0, (TEXT("m_VirtualFrameBuffer is not mapped\n\r")));
    	VirtualFree((PVOID)m_VirtualFrameBuffer, 0, MEM_RELEASE);
    	return;
	}
#elif (LCD_TYPE == TFT240_320)
	m_VirtualFrameBuffer = (DWORD)VirtualAlloc(0, (0x30000), MEM_RESERVE, PAGE_NOACCESS);
	if (m_VirtualFrameBuffer == NULL) 
	{
	    RETAILMSG(0,(TEXT("m_VirtualFrameBuffer is not allocated\n\r")));
		return;
	}
	else if (!VirtualCopy((PVOID)m_VirtualFrameBuffer, (PVOID)gdwLCDVirtualFrameBase, (0x30000), PAGE_READWRITE | PAGE_NOCACHE))
	{
	    RETAILMSG(0, (TEXT("m_VirtualFrameBuffer is not mapped\n\r")));
    	VirtualFree((PVOID)m_VirtualFrameBuffer, 0, MEM_RELEASE);
    	return;
	}
#endif
	RETAILMSG(0, (TEXT("m_VirtualFrameBuffer is mapped at %x(PHY : %x)\n\r"), m_VirtualFrameBuffer, gdwLCDVirtualFrameBase));
	RETAILMSG(0, (TEXT("Clearing frame buffer !!!\n\r")));
	
	ptr = (WORD *)m_VirtualFrameBuffer;

	// clear rest of frame buffer out
#if (LCD_TYPE == TFT640_480)
	for (index = 0; index < 640*480; index++)
	{
		if(index < 640*120)
		{
			ptr[index] = 0xf800;
		}
		else if(index < 640*120*2)
		{
			ptr[index] = 0x07e0;
		}
		else if(index < 640*120*3)
		{
			ptr[index] = 0x001f;
		}
		else
		{
			ptr[index] = 0xffff;
		}
	}
#elif (LCD_TYPE == TFT240_320)
	for (index = 0; index < 320*240; index++)
	{
		if(index < 3200)
		{
			ptr[index] = 0xf800;
		}
		else if(index < 6400)
		{
			ptr[index] = 0x07e0;
		}
		else if(index < 9600)
		{
			ptr[index] = 0x001f;
		}
		else
		{
			ptr[index] = 0xffff;
		}
	}
#endif
	RETAILMSG(1, (_T("--S3C2440DISP::InitializeHardware\r\n")));
}

SCODE S3C2440DISP::SetMode (INT modeId, HPALETTE *palette)
{
	RETAILMSG(0, (TEXT("++S3C2440DISP::SetMode\r\n")));

	if (modeId != 0)
	{
		RETAILMSG(0, (TEXT("S3C2440DISP::SetMode Want mode %d, only have mode 0\r\n"),modeId));
		return	E_INVALIDARG;
	}

	if (palette)
	{
		*palette = EngCreatePalette (PAL_BITFIELDS, 0, NULL, gBitMasks[0], gBitMasks[1], gBitMasks[2]);
	}

	RETAILMSG(0, (TEXT("--S3C2440DISP::SetMode\r\n")));

	return S_OK;
}

SCODE S3C2440DISP::GetModeInfo(GPEMode *mode,	INT modeNumber)
{
	RETAILMSG(0, (TEXT("++S3C2440DISP::GetModeInfo\r\n")));

	if (modeNumber != 0)
	{
		return E_INVALIDARG;
	}

	*mode = m_ModeInfo;

	RETAILMSG(0, (TEXT("--S3C2440DISP::GetModeInfo\r\n")));

	return S_OK;
}

int	S3C2440DISP::NumModes()
{
	RETAILMSG(0, (TEXT("++S3C2440DISP::NumModes\r\n")));
	RETAILMSG(0, (TEXT("--S3C2440DISP::NumModes\r\n")));
	return	1;
}

void	S3C2440DISP::CursorOn (void)
{
	UCHAR	*ptrScreen = (UCHAR*)m_pPrimarySurface->Buffer();
	UCHAR	*ptrLine;
	UCHAR	*cbsLine;
#ifndef ROTATE
	UCHAR	*xorLine;
	UCHAR	*andLine;
#endif //!ROTATE	
	int		x, y;

	if (!m_CursorForcedOff && !m_CursorDisabled && !m_CursorVisible)
	{
#ifdef ROTATE
		RECTL rSave;
		int   iRotate;
#endif //ROTATE

		if (!m_CursorBackingStore)
		{
			RETAILMSG(0, (TEXT("S3C2440DISP::CursorOn - No backing store available\r\n")));
			return;
		}
#ifdef ROTATE
		rSave = m_CursorRect;
		RotateRectl(&m_CursorRect);
#endif //ROTATE

		for (y = m_CursorRect.top; y < m_CursorRect.bottom; y++)
		{
			if (y < 0)
			{
				continue;
			}
#ifdef ROTATE
			if (y >= m_nScreenHeightSave)
#else
			if (y >= m_nScreenHeight)
#endif //ROTATE			
			{
				break;
			}

			ptrLine = &ptrScreen[y * m_pPrimarySurface->Stride()];
			cbsLine = &m_CursorBackingStore[(y - m_CursorRect.top) * (m_CursorSize.x * (m_colorDepth >> 3))];
#ifndef ROTATE
			xorLine = &m_CursorXorShape[(y - m_CursorRect.top) * m_CursorSize.x];
			andLine = &m_CursorAndShape[(y - m_CursorRect.top) * m_CursorSize.x];
#endif //!ROTATE

			for (x = m_CursorRect.left; x < m_CursorRect.right; x++)
			{
				if (x < 0)
				{
					continue;
				}
#ifdef ROTATE
				if (x >= m_nScreenWidthSave)
#else
				if (x >= m_nScreenWidth)
#endif //!ROTATE				
				{
					break;
				}
#ifdef ROTATE
				switch (m_iRotate)
				{
					case DMDO_0:
						iRotate = (y - m_CursorRect.top)*m_CursorSize.x + x - m_CursorRect.left;
						break;
					case DMDO_90:
						iRotate = (x - m_CursorRect.left)*m_CursorSize.x + m_CursorSize.y - 1 - (y - m_CursorRect.top);   
						break;
					case DMDO_180:
						iRotate = (m_CursorSize.y - 1 - (y - m_CursorRect.top))*m_CursorSize.x + m_CursorSize.x - 1 - (x - m_CursorRect.left);
						break;
					case DMDO_270:
						iRotate = (m_CursorSize.x -1 - (x - m_CursorRect.left))*m_CursorSize.x + y - m_CursorRect.top;
						break;
					default:
					    iRotate = (y - m_CursorRect.top)*m_CursorSize.x + x - m_CursorRect.left;
						break;
				}
#endif //ROTATE					
				cbsLine[(x - m_CursorRect.left) * (m_colorDepth >> 3)] = ptrLine[x * (m_colorDepth >> 3)];
#ifdef ROTATE
				ptrLine[x * (m_colorDepth >> 3)] &= m_CursorAndShape[iRotate];
				ptrLine[x * (m_colorDepth >> 3)] ^= m_CursorXorShape[iRotate];
#else 
				ptrLine[x * (m_colorDepth >> 3)] &= andLine[x - m_CursorRect.left];
				ptrLine[x * (m_colorDepth >> 3)] ^= xorLine[x - m_CursorRect.left];
#endif //ROTATE				
				if (m_colorDepth > 8)
				{
					cbsLine[(x - m_CursorRect.left) * (m_colorDepth >> 3) + 1] = ptrLine[x * (m_colorDepth >> 3) + 1];
#ifdef ROTATE
       		        ptrLine[x * (m_colorDepth >> 3) + 1] &= m_CursorAndShape[iRotate];
					ptrLine[x * (m_colorDepth >> 3) + 1] ^= m_CursorXorShape[iRotate];				
#else
					ptrLine[x * (m_colorDepth >> 3) + 1] &= andLine[x - m_CursorRect.left];
					ptrLine[x * (m_colorDepth >> 3) + 1] ^= xorLine[x - m_CursorRect.left];
#endif //ROTATE					
					if (m_colorDepth > 16)
					{
						cbsLine[(x - m_CursorRect.left) * (m_colorDepth >> 3) + 2] = ptrLine[x * (m_colorDepth >> 3) + 2];
#ifdef ROTATE
						ptrLine[x * (m_colorDepth >> 3) + 2] &= m_CursorAndShape[iRotate];
						ptrLine[x * (m_colorDepth >> 3) + 2] ^= m_CursorXorShape[iRotate];
#else
						ptrLine[x * (m_colorDepth >> 3) + 2] &= andLine[x - m_CursorRect.left];
						ptrLine[x * (m_colorDepth >> 3) + 2] ^= xorLine[x - m_CursorRect.left];
#endif //ROTATE						
					}
				}
			}
		}
#ifdef ROTATE
		m_CursorRect = rSave;
#endif 
		m_CursorVisible = TRUE;
	}
}

void	S3C2440DISP::CursorOff (void)
{
	UCHAR	*ptrScreen = (UCHAR*)m_pPrimarySurface->Buffer();
	UCHAR	*ptrLine;
	UCHAR	*cbsLine;
	int		x, y;

	if (!m_CursorForcedOff && !m_CursorDisabled && m_CursorVisible)
	{
#ifdef ROTATE
		RECTL rSave;
#endif //ROTATE

		if (!m_CursorBackingStore)
		{
			RETAILMSG(0, (TEXT("S3C2440DISP::CursorOff - No backing store available\r\n")));
			return;
		}
#ifdef ROTATE
		rSave = m_CursorRect;
		RotateRectl(&m_CursorRect);
#endif //ROTATE

		for (y = m_CursorRect.top; y < m_CursorRect.bottom; y++)
		{
			// clip to displayable screen area (top/bottom)
			if (y < 0)
			{
				continue;
			}
#ifndef ROTATE
			if (y >= m_nScreenHeight)
#else 
			if (y >= m_nScreenHeightSave)
#endif //!ROTATE
			{
				break;
			}

			ptrLine = &ptrScreen[y * m_pPrimarySurface->Stride()];
			cbsLine = &m_CursorBackingStore[(y - m_CursorRect.top) * (m_CursorSize.x * (m_colorDepth >> 3))];

			for (x = m_CursorRect.left; x < m_CursorRect.right; x++)
			{
				// clip to displayable screen area (left/right)
				if (x < 0)
				{
					continue;
				}
#ifndef ROTATE
				if (x >= m_nScreenWidth)
#else
				if (x>= m_nScreenWidthSave)
#endif //!ROTATE
				{
					break;
				}

⌨️ 快捷键说明

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