📄 lcdcclass.cpp
字号:
//------------------------------------------------------------------------------
//
// 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.
//
//------------------------------------------------------------------------------
//
// Copyright (C) 2004-2006, Freescale Semiconductor, Inc. All Rights Reserved.
// THIS SOURCE CODE, AND ITS USE AND DISTRIBUTION, IS SUBJECT TO THE TERMS
// AND CONDITIONS OF THE APPLICABLE LICENSE AGREEMENT
//
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// INCLUDE FILES
//------------------------------------------------------------------------------
#include <windows.h>
#include <winddi.h>
#include <ceddk.h>
#include <gpe.h>
#include <emul.h>
#include <Winreg.h>
#include <Pwingdi.h>
#include <pm.h>
#include "csp.h"
#include "lcdc.h"
#include "LcdcClass.h"
//------------------------------------------------------------------------------
// GLOBAL DEFINITIONS
//------------------------------------------------------------------------------
// The dpCurSettings structure
/* Start with Errors, warnings, and temporary messages */
INSTANTIATE_GPE_ZONES((GPE_ZONE_ERROR|GPE_ZONE_INIT),"DDI Driver","unused1","unused2")
//------------------------------------------------------------------------------
// GLOBAL OR STATIC VARIABLES
//------------------------------------------------------------------------------
static GPE *gGPE = (GPE *) NULL;
static DHPDEV (*pOldDrvEnablePDEV)(
DEVMODEW *pdm,
LPWSTR pwszLogAddress,
ULONG cPat,
HSURF *phsurfPatterns,
ULONG cjCaps,
ULONG *pdevcaps,
ULONG cjDevInfo,
DEVINFO *pdi,
HDEV hdev,
LPWSTR pwszDeviceName,
HANDLE hDriver );
//------------------------------------------------------------------------------
// STATIC FUNCTION PROTOTYPES
//------------------------------------------------------------------------------
// This prototype avoids problems exporting from .lib
BOOL APIENTRY GPEEnableDriver( ULONG engineVersion,
ULONG cj,
DRVENABLEDATA *data,
PENGCALLBACKS engineCallbacks);
//------------------------------------------------------------------------------
// EXPORTED FUNCTIONS
//------------------------------------------------------------------------------
//------------------------------------------------------------------------
// Function: Tell GDI that the 256 Palettes are not settable, as
// MC9328LCD is a fixed palette device.
//------------------------------------------------------------------------
DHPDEV LcdcDrvEnablePDEV
(
DEVMODEW *pdm,
LPWSTR pwszLogAddress,
ULONG cPat,
HSURF *phsurfPatterns,
ULONG cjCaps,
ULONG *pdevcaps,
ULONG cjDevInfo,
DEVINFO *pdi,
HDEV hdev,
LPWSTR pwszDeviceName,
HANDLE hDriver
)
{
DHPDEV pPDEV;
pPDEV=(*pOldDrvEnablePDEV) (pdm,
pwszLogAddress,
cPat,
phsurfPatterns,
cjCaps,
pdevcaps,
cjDevInfo,
pdi,
hdev,
pwszDeviceName,
hDriver );
BSPSetDevCaps((GDIINFO *)pdevcaps);
return (pPDEV);
}
//------------------------------------------------------------------------------
//
// FUNCTION: DrvEnableDriver
//
// DESCRIPTION: This function is the initial driver entry point exported
// by the driver DLL for devices that link directly to GWES
//
// PARAMETERS:
//
// RETURNS:
//
//------------------------------------------------------------------------------
BOOL APIENTRY DrvEnableDriver( ULONG engineVersion,
ULONG cj,
DRVENABLEDATA *data,
PENGCALLBACKS engineCallbacks)
{
DEBUGMSG(GPE_ZONE_INIT, (TEXT("LCDClass::DrvEnableDriver\r\n")));
if(!GPEEnableDriver(engineVersion, cj, data, engineCallbacks))
DEBUGMSG(GPE_ZONE_ERROR, (TEXT("GPEEnableDriver return FALSE!\r\n")));
// Tell GDI palette is not settable.
pOldDrvEnablePDEV = data->DrvEnablePDEV;
data->DrvEnablePDEV = LcdcDrvEnablePDEV;
return TRUE;
}
//------------------------------------------------------------------------------
//
// FUNCTION: DrvGetMasks
//
// DESCRIPTION:
//
// PARAMETERS:
//
// RETURNS:
//
////------------------------------------------------------------------------------
ULONG *APIENTRY DrvGetMasks(DHPDEV dhpdev)
{
DEBUGMSG(GPE_ZONE_INIT, (TEXT("LCDClass::DrvGetMasks\r\n")));
//return BitMasks;
return BSPGetLCDCBitMasks();
}
//------------------------------------------------------------------------------
//
// FUNCTION: RegisterDDHALAPI
//
// DESCRIPTION:
//
// PARAMETERS:
//
// RETURNS:
//
//------------------------------------------------------------------------------
void RegisterDDHALAPI(void)
{
DEBUGMSG(GPE_ZONE_INIT, (TEXT("LCDClass::RegisterDDHALAPI\r\n")));
return; // no DDHAL support
}
//------------------------------------------------------------------------------
// PRIVATE FUNCTIONS
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//
// FUNCTION: GetGPE
//
// DESCRIPTION: Main entry point for a GPE-compliant driver.
//
// PARAMETERS:
//
// RETURNS:
// GPE class pointer
//
//------------------------------------------------------------------------------
GPE *GetGPE(void)
{
if (!gGPE)
{
gGPE = new LcdcClass;
}
DEBUGMSG(GPE_ZONE_INIT, (TEXT("LCDClass::GetGPE(0x%08x)\r\n"), gGPE));
return gGPE;
}
//------------------------------------------------------------------------------
//
// FUNCTION: LcdcClass
//
// DESCRIPTION: Constructor of LcdcClass
// Map the linear frame buffer
// Map the the LCDC module space for user access
//
// PARAMETERS:
//
// RETURNS:
//------------------------------------------------------------------------------
LcdcClass::LcdcClass(void)
{
BOOL initState;
PHYSICAL_ADDRESS phyAddr;
DDK_GPIO_CFG cfg;
// Enable LCDC pins
DDK_GPIO_SET_CONFIG(cfg, LCDC);
initState = DDKGpioEnable(&cfg);
if(initState != TRUE)
{
ERRORMSG(1, (TEXT("LCDC Class: LCDC pins enable failed!\r\n")));
return;
}
// Enable LCDC hw clocks
initState = DDKClockSetGatingMode(DDK_CLOCK_GATE_INDEX_LCDC, DDK_CLOCK_GATE_MODE_ENABLE);
if(initState != TRUE)
{
ERRORMSG(1, (TEXT("LCDC Class: LCDC hw clock enable failed!\r\n")));
return;
}
BSPInitLCDC(&m_LcdcCtx);
// setup local mode info structure
m_ModeInfo = *(GPEMode*)m_LcdcCtx.pGPEModeInfo;
m_VideoFrameSize = m_LcdcCtx.VideoFrameWidth * m_LcdcCtx.VideoFrameHight * BSPGetPixelSizeInByte();
m_nVideoMemorySize = m_LcdcCtx.VideoMemorySize;
phyAddr.QuadPart = m_LcdcCtx.VideoMemoryPhyAdd;
m_pLinearVideoMem = (UINT8 *)MmMapIoSpace(phyAddr, m_nVideoMemorySize, FALSE);
if (m_pLinearVideoMem == NULL)
{
DEBUGMSG (GPE_ZONE_ERROR, (TEXT("Frame Buffer MmMapIoSpace failed!\r\n")) );
return;
}
DEBUGMSG(GPE_ZONE_INIT, (TEXT("Actual memory detected: %d bytes\r\n"), m_nVideoMemorySize));
// allocate blank frame buffer for backing up the frame buffer in power handler
m_pBlankVideoMem = (UINT8*)malloc(m_VideoFrameSize);
if(!m_pBlankVideoMem)
{
ERRORMSG(1, (TEXT(" buffers Alloc Failed!\r\n")));
return;
}
// set blank frame buffer as white
memset( (PVOID)m_pBlankVideoMem, 0xFF, m_VideoFrameSize);
//Mem maps the LCDC module space for user access
phyAddr.QuadPart = CSP_BASE_REG_PA_LCDC;
m_pLCDC = (CSP_LCDC_REGS *)MmMapIoSpace(phyAddr, sizeof(CSP_LCDC_REGS), FALSE);
if (m_pLCDC == NULL)
{
DEBUGMSG (GPE_ZONE_ERROR, (TEXT("LcdcClass: VirtualAlloc failed!\r\n")) );
return;
}
// Notify the system that we are a power-manageable device
m_Dx = D0;
AdvertisePowerInterface(g_hmodDisplayDll);
//pass mode information to protected variables
m_pMode = (GPEMode*)m_LcdcCtx.pGPEModeInfo;
m_nScreenWidth = m_pMode->width;
m_nScreenHeight = m_pMode->height;
m_nScreenStride = (m_nScreenWidth * m_pMode->Bpp) / 8;
m_iRotate = GetRotateModeFromReg();
SetRotateParms();
m_pMode->width = m_nScreenWidth;
m_pMode->height = m_nScreenHeight;
//create an instance of Node2D class to allocate memory as single rectangular blocks
m_p2DVideoMemory = new Node2D(m_nScreenStride * 8UL / m_pMode->Bpp, m_nVideoMemorySize/m_nScreenStride);
if(!m_p2DVideoMemory)
{
DEBUGMSG(GPE_ZONE_ERROR,
(TEXT("LcdcClass: error creating new Node2D!\r\n")));
return;
}
// for the inserted software cursor
m_colorDepth = m_ModeInfo.Bpp;
if(FAILED(AllocSurface(&m_pPrimarySurface, m_nScreenWidthSave, m_nScreenHeightSave, m_pMode->format, GPE_REQUIRE_VIDEO_MEMORY)))
{
DEBUGMSG(GPE_ZONE_ERROR, (TEXT("Couldn't allocate primary surface\n")));
return;
}
DEBUGMSG(GPE_ZONE_INIT,(TEXT("Screen Width : %d\r\n"), m_nScreenWidth));
DEBUGMSG(GPE_ZONE_INIT,(TEXT("Screen Height : %d\r\n"), m_nScreenHeight));
DEBUGMSG(GPE_ZONE_INIT,(TEXT("Screen rotation : %x\r\n"), m_iRotate));
((GPESurfRotate *)m_pPrimarySurface)->SetRotation(m_nScreenWidth,
m_nScreenHeight,
m_iRotate);
DEBUGMSG(GPE_ZONE_INIT, (TEXT("lcdcClass: Constructor completed!! \r\n")));
}
//------------------------------------------------------------------------------
//
// FUNCTION: ~LcdcClass
//
// DESCRIPTION: Destructor of LcdcClass
// Free the linear frame buffer
// Free the the LCDC module space for user access
//
// PARAMETERS:
//
// RETURNS:
//------------------------------------------------------------------------------
LcdcClass::~LcdcClass(void)
{
DDK_GPIO_CFG cfg;
DEBUGMSG(GPE_ZONE_INIT, (TEXT("LCDClass::~LcdcClass\r\n")));
// Free memory
if(m_pPrimarySurface)
delete m_pPrimarySurface;
if(m_p2DVideoMemory)
delete m_p2DVideoMemory;
// free frame buffer
if (m_pLinearVideoMem != NULL)
{
// blank display memory
memset (m_pLinearVideoMem, 0xFF, m_VideoFrameSize);
MmUnmapIoSpace(m_pLinearVideoMem, m_nVideoMemorySize);
m_pLinearVideoMem = NULL;
}
// Free the blank frame buffer
if(m_pBlankVideoMem)
{
free((void*)m_pBlankVideoMem);
m_pBlankVideoMem = NULL;
}
//free mapped LCDC module space
if (m_pLCDC != NULL)
{
// disable LCDC
INSREG32BF(&m_pLCDC->RMCR, LCDC_RMCR_SELF_REF, LCDC_RMCR_SELF_REF_DISABLE);
MmUnmapIoSpace(m_pLCDC, sizeof(CSP_LCDC_REGS));
m_pLCDC = NULL;
}
// Disable LCDC hw clocks
DDKClockSetGatingMode(DDK_CLOCK_GATE_INDEX_LCDC, DDK_CLOCK_GATE_MODE_DISABLE);
// Disable LCDC module pins
DDK_GPIO_SET_CONFIG(cfg, LCDC);
DDKGpioDisable(&cfg);
BSPDeinitLCDC(&m_LcdcCtx);
//free all static objects
DEBUGMSG(GPE_ZONE_INIT, (TEXT("lcdcClass: Destructor completed!! \r\n")));
}
//------------------------------------------------------------------------------
//
// FUNCTION: SetMode
//
// DESCRIPTION: This method executes to enable the device driver
// based on the Graphics Primitive Engine (GPE)
// and to request a specific mode for the display.
//
// PARAMETERS:
// modeID [in] Mode number to set.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -