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

📄 s3c2440a_lcd.cpp

📁 aesop s3c2440a BSP for windowsce 6.0
💻 CPP
📖 第 1 页 / 共 3 页
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
/*++
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.
--*/

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


#pragma optimize("", off)

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;
}

WORD	TempBuffer[481][272];

S3C2440DISP::S3C2440DISP (void)
{
	RETAILMSG(0, (TEXT("++S3C2440DISP::S3C2440DISP\r\n")));
	
	// setup up display mode related constants
	m_nScreenWidth = 480;
	m_nScreenHeight = 272;
//	m_nScreenWidth = 272;
//	m_nScreenHeight = 480;
	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

    if (m_pPrimarySurface)
    {
	    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")));
}
#include <windows.h>
#include <types.h>
#include <string.h>
#include <stdio.h>
#include <tchar.h>
#include "..\..\inc\s3c2440a_lcd.h"
#include "..\..\inc\s3c2440a_ioport.h"
PVOID TSP_RegAlloc(PVOID addr, INT sz)
{
	PVOID reg;

	reg = (PVOID)VirtualAlloc(0, sz, MEM_RESERVE, PAGE_NOACCESS);

	if (reg)
	{
		if (!VirtualCopy(reg, (PVOID)((UINT32)addr >> 8), sz, PAGE_PHYSICAL | PAGE_READWRITE | PAGE_NOCACHE )) 
		{
			VirtualFree(reg, 0, MEM_RELEASE);
			reg = NULL;
		}
	}
	return reg;
}
#define S3C2440A_BASE_REG_PA_LCD                (0x4D000000)
#define S3C2440A_BASE_REG_PA_IOPORT             (0x56000000)            
void S3C2440DISP::InitializeHardware (void)
{
	WORD *ptr;
	DWORD index;
	HKEY hkDisplay = NULL;
	DWORD dwLCDPhysicalFrameBase;
	DWORD dwStatus, dwType, dwSize;
volatile S3C2440A_LCD_REG    *s2440LCD = NULL;
volatile S3C2440A_IOPORT_REG *s2440IOP = NULL;
// (S3C2440A_LCD_REG *)OALPAtoVA(S3C2440A_BASE_REG_PA_LCD, FALSE);

#if 1


		s2440LCD = (volatile S3C2440A_LCD_REG *)TSP_RegAlloc((PVOID)S3C2440A_BASE_REG_PA_LCD, sizeof(S3C2440A_LCD_REG));
    if (!s2440LCD)
    {
        return;
    }
	
		s2440IOP = (volatile S3C2440A_IOPORT_REG *)TSP_RegAlloc((PVOID)S3C2440A_BASE_REG_PA_IOPORT, sizeof(S3C2440A_IOPORT_REG));
    if (!s2440IOP)
    {
        return;
    }



#if 0

        s2440IOP->GPCDAT = 0x000000e0;
        s2440IOP->GPCUP  = 0x0000ffff;
        s2440IOP->GPCCON = 0xaaaa56a9;

	      s2440IOP->GPDDAT = 0x00000000;
        s2440IOP->GPDUP  = 0x0000ffff;
        s2440IOP->GPDCON = 0xaaaaaaaa;


        s2440LCD->LCDCON1   =0x678;
        s2440LCD->LCDCON2   =0x143C049;
        s2440LCD->LCDCON3   =0x9DF01;
        s2440LCD->LCDCON4   = 0x28;
        s2440LCD->LCDCON5   = 0xB00;
        s2440LCD->TCONSEL   = 0xe0;
        s2440LCD->TPAL      = 0x0;        
        s2440LCD->LCDCON1  |= 1;
#endif

#endif
	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
	m_VirtualFrameBuffer = (DWORD)VirtualAlloc(0, (0x100000), 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, (0x100000), PAGE_READWRITE | PAGE_NOCACHE))
	{
	    RETAILMSG(0, (TEXT("m_VirtualFrameBuffer is not mapped\n\r")));
    	VirtualFree((PVOID)m_VirtualFrameBuffer, 0, MEM_RELEASE);
    	return;
	}

	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;


  memset((void *)ptr, 0xff, 0x100000);     
#if 0
while(1)
{
        s2440IOP->GPCDAT = 0x000000e0;
        s2440IOP->GPCUP  = 0x0000ffff;
        s2440IOP->GPCCON = 0xaaaa56a9;

	      s2440IOP->GPDDAT = 0x00000000;
        s2440IOP->GPDUP  = 0x0000ffff;
        s2440IOP->GPDCON = 0xaaaaaaaa;


        s2440LCD->LCDCON1   =0x678;
        s2440LCD->LCDCON2   =0x143C049;
        s2440LCD->LCDCON3   =0x9DF01;
        s2440LCD->LCDCON4   = 0x28;
        s2440LCD->LCDCON5   = 0xB00;
        s2440LCD->TCONSEL   = 0xe0;
        s2440LCD->TPAL      = 0x0;        
        s2440LCD->LCDCON1  |= 1;
        
        if(s2440IOP->GPCDAT != 0x000000e0)
           NKDbgPrintfW(TEXT("------------%d s2440IOP->GPCDAT=%x---------\r\n"),__LINE__,s2440IOP->GPCDAT);
        if(s2440IOP->GPCUP  != 0x0000ffff)
           NKDbgPrintfW(TEXT("--------------%d s2440IOP->GPCUP=%x---------\r\n"),__LINE__,s2440IOP->GPCUP);
        if(s2440IOP->GPCCON != 0xaaaa56a9)
           NKDbgPrintfW(TEXT("--------------%d s2440IOP->GPCCON=%x---------\r\n"),__LINE__,s2440IOP->GPCCON);

	      if(s2440IOP->GPDDAT != 0x00000000)
           NKDbgPrintfW(TEXT("--------------%d s2440IOP->GPDDAT=%x---------\r\n"),__LINE__,s2440IOP->GPDDAT);
        if(s2440IOP->GPDUP  != 0x0000ffff)
           NKDbgPrintfW(TEXT("--------------%d s2440IOP->GPDUP=%x---------\r\n"),__LINE__,s2440IOP->GPDUP);
        if(s2440IOP->GPDCON != 0xaaaaaaaa)
           NKDbgPrintfW(TEXT("--------------%d s2440IOP->GPDCON=%x---------\r\n"),__LINE__,s2440IOP->GPDCON);


        if(s2440LCD->LCDCON1   !=0x679)
           NKDbgPrintfW(TEXT("--------------%d s2440LCD->LCDCON1=%x---------\r\n"),__LINE__,s2440LCD->LCDCON1);
        if(s2440LCD->LCDCON2   !=0x143C049)
           NKDbgPrintfW(TEXT("--------------%d s2440LCD->LCDCON2=%x---------\r\n"),__LINE__,s2440LCD->LCDCON2);
        if(s2440LCD->LCDCON3   !=0x9DF01)
           NKDbgPrintfW(TEXT("--------------%d s2440LCD->LCDCON3=%x---------\r\n"),__LINE__,s2440LCD->LCDCON3);
        if(s2440LCD->LCDCON4   != 0x28)
           NKDbgPrintfW(TEXT("--------------%d s2440LCD->LCDCON4=%x---------\r\n"),__LINE__,s2440LCD->LCDCON4);
        if(s2440LCD->LCDCON5   != 0xB00)
           NKDbgPrintfW(TEXT("--------------%d s2440LCD->LCDCON5=%x---------\r\n"),__LINE__,s2440LCD->LCDCON5);
        if(s2440LCD->TCONSEL   != 0xe0)
           NKDbgPrintfW(TEXT("--------------%d s2440LCD->TCONSEL=%x---------\r\n"),__LINE__,s2440LCD->TCONSEL);
        if(s2440LCD->TPAL      != 0x0)        
           NKDbgPrintfW(TEXT("--------------%d s2440LCD->TPAL=%x---------\r\n"),__LINE__,s2440LCD->TPAL);
	for (index = 0; index < 480*272; index++)
	{
			if(ptr[index] != 0xffff)
           NKDbgPrintfW(TEXT("--------------%d---------\r\n"),__LINE__);
	}
}
#endif

	// clear rest of frame buffer out
	for (index = 0; index < 480*272; index++)
	{
		if(index < 480*100)
		{
			ptr[index] = 0xf800;
		}
		else if(index < 480*200)
		{
			ptr[index] = 0x07e0;
		}
		else if(index < 480*300)
		{
			ptr[index] = 0x001f;
		}
		else
		{
			ptr[index] = 0xffff;
		}
	}

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

⌨️ 快捷键说明

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