📄 ipu_adc.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
//
//------------------------------------------------------------------------------
//
// File: IPU_ADC.cpp
//
// Implementation of class IPU_ADC.
//
//------------------------------------------------------------------------------
#include <windows.h>
#include <Devload.h>
#include <ceddk.h>
#include <types.h>
#include <winddi.h>
#include <gpe.h>
#include "bsp.h"
#include "adc_init.h"
#include "ipu_adc.h"
//------------------------------------------------------------------------------
// External Functions
// This gets around problems exporting from .lib
BOOL APIENTRY GPEEnableDriver(ULONG iEngineVersion,
ULONG cj,
DRVENABLEDATA *pded,
PENGCALLBACKS pEngCallbacks);
//------------------------------------------------------------------------------
// External Variables
extern "C" PCSP_IPU_REGS g_pIPU;
//------------------------------------------------------------------------------
// Defines
#define VIDEO_REG_PATH TEXT("Drivers\\Display\\IPU_ADC")
#define VIDEO_ROW_RES TEXT("CxScreen")
#define VIDEO_COL_RES TEXT("CyScreen")
#define PIXEL_DEPTH TEXT("Bpp")
#define DISPLAY_ROTATION TEXT("System\\GDI\\Rotation")
//------------------------------------------------------------------------------
// Types
//------------------------------------------------------------------------------
// Global Variables
//------------------------------------------------------------------------------
// Local Variables
static ulong gBitMasks24[] = {0xFF0000, 0x00FF00,0x0000FF};
static ulong gBitMasks16[] = {0xF800, 0x07E0,0x001F};
static GPE *pGPE = (GPE *)NULL;
static void *DispDrvrPhysicalFrameBuffer;
static int width;
static int height;
static int bpp;
INSTANTIATE_GPE_ZONES(0x0003,"IPU ADC Driver","unused1","unused2")
//------------------------------------------------------------------------------
//
// Function: DrvEnableDriver
//
// Enable display driver.
//
// Parameters:
// iEngineVersion
// [in] DDI version number that the graphics device interface (GDI)
// was written for. DDI_DRIVER_VERSION is always the current
// version; drivers should use this manifest constant, declared
// in Winddi.h.
// cj
// [in] Size, in bytes, of the DRVENABLEDATA structure. If the
// structure is larger than expected, do not modify the extra
// members.
// pded
// [out] Pointer to a DRVENABLEDATA structure. The GDI
// zero-initializes cj bytes before the call. The driver fills in
// its own data.
// pEngCallbacks
// [in] Structure containing function pointers to the GDI helper
// functions for display drivers. This is passed from GDI through
// DrvEnableDriver to GPEEnableDriver. It allows the display
// driver to obtain information from GDI.
//
// Returns
// TRUE indicates success. FALSE indicates failure.
//
//------------------------------------------------------------------------------
BOOL APIENTRY DrvEnableDriver(ULONG iEngineVersion,
ULONG cj,
DRVENABLEDATA *pded,
PENGCALLBACKS pEngCallbacks)
{
return GPEEnableDriver(iEngineVersion, cj, pded, pEngCallbacks);
}
//------------------------------------------------------------------------------
//
// Function: GetGPE
//
// Main entry point for a GPE-compliant driver
//
// Parameters:
//
// Returns:
// Instanse of class IPU_ADC.
//------------------------------------------------------------------------------
GPE *GetGPE()
{
if( !pGPE )
{
pGPE = new IPU_ADC();
}
return pGPE;
}
//------------------------------------------------------------------------------
//
// Function: IPU_ADC::IPU_ADC
//
// Class IPU_ADC constructor
//
// Parameters:
//
// Returns:
//
//------------------------------------------------------------------------------
IPU_ADC::IPU_ADC()
{
LONG regError;
HKEY hKey;
DWORD dwDataSize;
PHYSICAL_ADDRESS phyAddr;
EGPEFormat pixelFormat = gpe24Bpp;
DEBUGMSG(GPE_ZONE_INIT, (TEXT("+%s()\r\n"), __WFUNCTION__));
// Open the registry key
regError = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
VIDEO_REG_PATH,
0,
0,
&hKey);
if (regError != ERROR_SUCCESS)
{
DEBUGMSG(GPE_ZONE_WARNING,
(TEXT("Failed opening \\Drivers\\Display\\IPU_ADC\r\n")));
}
// Display width
dwDataSize = sizeof(width);
regError = RegQueryValueEx(hKey,
VIDEO_ROW_RES,
NULL, NULL,
(LPBYTE)&width,
&dwDataSize);
if (regError != ERROR_SUCCESS)
{
DEBUGMSG(GPE_ZONE_WARNING,
(TEXT("Failed to get display width, Error 0x%X\r\n"),
regError));
m_nScreenWidth = SCREEN_PIX_WIDTH;
}
// Display height
dwDataSize = sizeof(height);
regError = RegQueryValueEx(hKey,
VIDEO_COL_RES,
NULL,
NULL,
(LPBYTE)&height,
&dwDataSize);
if (regError != ERROR_SUCCESS)
{
DEBUGMSG(GPE_ZONE_WARNING,
(TEXT("Failed to get display height, Error 0x%X\r\n"),
regError));
m_nScreenHeight = SCREEN_PIX_HEIGHT;
}
// Color depth
dwDataSize = sizeof(bpp);
regError = RegQueryValueEx(hKey,
PIXEL_DEPTH,
NULL,
NULL,
(LPBYTE)&bpp,
&dwDataSize);
if (regError != ERROR_SUCCESS)
{
DEBUGMSG(GPE_ZONE_WARNING,
(TEXT("Failed to get display bpp, Error 0x%X\r\n"), regError));
bpp = DISP_BPP;
}
RegCloseKey(hKey);
m_nScreenWidth = width;
m_nScreenHeight = height;
m_iRotate = GetRotateModeFromReg();
SetRotateParams();
// setup up display mode related constants
m_ModeInfo.modeId = 0;
m_ModeInfo.width = m_nScreenWidth;
m_ModeInfo.height = m_nScreenHeight;
m_ModeInfo.Bpp = bpp;
m_ModeInfo.frequency = 30;
if (bpp == 16)
{
pixelFormat = gpe16Bpp;
}
m_ModeInfo.format = pixelFormat;
m_pMode = &m_ModeInfo;
// Map peripheral physical address to virtual address
phyAddr.QuadPart = BSP_BASE_REG_PA_FRAMEBUFFER;
DispDrvrPhysicalFrameBuffer = MmMapIoSpace(phyAddr,
(width * height * (bpp / 8)), FALSE);
// Check if virtual mapping failed
if (DispDrvrPhysicalFrameBuffer == NULL)
{
DEBUGMSG(GPE_ZONE_ERROR,
(TEXT("%s(): MmMapIoSpace failed!\r\n"), __WFUNCTION__));
}
else
{
DEBUGMSG(GPE_ZONE_INIT,
(TEXT("%s(): FrameBuffer = 0x%x\r\n"),
__WFUNCTION__, DispDrvrPhysicalFrameBuffer));
// Fill the sreen with white
memset(DispDrvrPhysicalFrameBuffer, 0xFF, width * height * (bpp / 8));
}
m_pVirtualFrameBuffer = DispDrvrPhysicalFrameBuffer;
m_nVideoMemorySize = width * height * (bpp / 8);
m_p2DVideoMemory = new Node2D(m_nScreenWidthSave,
m_nScreenHeightSave,
0,
0,
4);
if(!m_p2DVideoMemory)
{
DEBUGMSG(GPE_ZONE_ERROR,
(TEXT("%s(): new Node2D!\r\n"), __WFUNCTION__));
return;
}
m_pPrimarySurface = new IPU_ADCSurf(m_nScreenWidthSave,
m_nScreenHeightSave,
0,
m_pVirtualFrameBuffer,
m_nScreenWidthSave * (bpp / 8),
pixelFormat,
m_p2DVideoMemory);
((GPESurfRotate *)m_pPrimarySurface)->SetRotation(m_nScreenWidth,
m_nScreenHeight,
m_iRotate);
// Initialize IPU ADC.
if (InitializeADC(width, height, bpp) != TRUE)
{
DEBUGMSG(GPE_ZONE_ERROR, (TEXT("Failed to initialise IPU ADC\r\n")));
return;
}
//Enable ADC, start normal operation.
EnableADC();
DEBUGMSG(GPE_ZONE_INIT, (TEXT("-%s()\r\n"), __WFUNCTION__));
}
//------------------------------------------------------------------------------
//
// Function: IPU_ADC::SetMode
//
// Set display mode.
//
// Parameters:
// modId
// [in] Mode number to set
// pPalette
// [in] pointer to palette
//
// Returns:
// S_OK if successful; E_INVALIDARG is the input parameters are invalid.
//
//------------------------------------------------------------------------------
SCODE IPU_ADC::SetMode(int modeId, HPALETTE *pPalette)
{
if(modeId != 0)
{
return E_INVALIDARG;
}
if (pPalette)
{
if (bpp == 16)
{
*pPalette = EngCreatePalette(PAL_BITFIELDS, 0, NULL,
gBitMasks16[0],
gBitMasks16[1],
gBitMasks16[2]);
}
else
{
*pPalette = EngCreatePalette(PAL_BITFIELDS, 0, NULL,
gBitMasks24[0],
gBitMasks24[1],
gBitMasks24[2]);
}
}
return S_OK; // Mode is inherently set
}
//------------------------------------------------------------------------------
//
// Function: IPU_ADC::GetModeInfo
//
// Get mode information by mode number.
//
// Parameters:
// pMode
// [out] Pointer to a GPEMode structure.
// modeNo
// [in] Integer specifying the mode to return information about.
//
// Returns:
// S_OK if successful.
//
//------------------------------------------------------------------------------
SCODE IPU_ADC::GetModeInfo(GPEMode *pMode, int modeNo)
{
if( modeNo != 0 )
{
return E_INVALIDARG;
}
*pMode = m_ModeInfo;
return S_OK;
}
//------------------------------------------------------------------------------
//
// Function: IPU_ADC::NumModes
//
// Get number of display modes supported by the driver
//
// Parameters:
//
// Returns:
// The number of display modes supported by a driver.
//
//------------------------------------------------------------------------------
int IPU_ADC::NumModes()
{
return 1;
}
//------------------------------------------------------------------------------
//
// Function: IPU_ADC::SetPointerShape
//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -