?? s3c2440x_lcd.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.
//
/*++
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
#include <s3c2440x.h>
#include <ceddk.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");
#ifdef ROTATE
static TCHAR gszROTATE[256] = _T("System\\GDI\\ROTATION");
#endif
#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[241][320];
S3C2440DISP::S3C2440DISP (void)
{
RETAILMSG(0, (TEXT("++S3C2440DISP::S3C2440DISP\r\n")));
// setup up display mode related constants
m_nScreenWidth = 240;
m_nScreenHeight = 320;
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);
}
#ifdef ROTATE
HKEY hkRotate;
DWORD dwStatus,dwType,dwSize;
DWORD dwAngle = 0;
int angle=DMDO_0;
// open the registry key and read our configuration
dwStatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE, gszROTATE, 0, 0, &hkRotate);
dwType = REG_DWORD;
if(dwStatus == ERROR_SUCCESS && dwType == REG_DWORD) {
dwSize = sizeof(DWORD);
dwStatus = RegQueryValueEx(hkRotate, _T("Angle"), NULL, &dwType,
(LPBYTE) &dwAngle, &dwSize);
}
// close the registry key
if(hkRotate != NULL) {
RegCloseKey(hkRotate);
}
if(dwAngle == 90)
angle = DMDO_90;
if(dwAngle == 180)
angle = DMDO_180;
if(dwAngle == 270)
angle = DMDO_270;
DynRotate(angle);
#endif
// 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")));
}
static BOOL InitializeLCDRegisters(DWORD dwPhysicalFrameBase)
{
volatile S3C2440X_IOPORT_REG *s2440IOP = NULL;
volatile S3C2440X_LCD_REG *s2440LCD = NULL;
PHYSICAL_ADDRESS pa;
// Map the s3c2440x register pointers.
//
pa.QuadPart = S3C2440X_BASE_REG_PA_IOPORT;
s2440IOP = (S3C2440X_IOPORT_REG *) MmMapIoSpace(pa, sizeof(S3C2440X_IOPORT_REG), FALSE);
pa.QuadPart = S3C2440X_BASE_REG_PA_LCD;
s2440LCD = (S3C2440X_LCD_REG *) MmMapIoSpace(pa, sizeof(S3C2440X_LCD_REG), FALSE);
if (!s2440IOP || !s2440LCD)
{
RETAILMSG(1, (TEXT("ERROR: s3c2440x_lcd: InitializeLCDRegisters failed.\r\n")));
return(FALSE);
}
// Set up the LCD controller registers to display a power-on bitmap image.
//
s2440IOP->GPCUP = 0xFFFFFFFF;
s2440IOP->GPCCON = 0xAAAAAAAA;
s2440IOP->GPDUP = 0xFFFFFFFF;
s2440IOP->GPDCON = 0xAAAAAAAA;
s2440IOP->GPGUP &= ~(1 << 4);
s2440IOP->GPGCON &= ~(3 << 8);
s2440LCD->LCDCON1 = (9 << 8) | /* VCLK = HCLK / (CLKVAL * 2) -> About 7 Mhz */
(13 << 7) | /* 0 : Each Frame */
(3 << 5) | /* TFT LCD Pannel */
(12 << 1) | /* 16bpp Mode */
(0 << 0) ; /* Disable LCD Output */
s2440LCD->LCDCON2 = (LCD_VBPD << 24) | /* VBPD : 1 */
(LCD_LINEVAL_TFT << 14) | /* Vertical Size : 320 - 1 */
(LCD_VFPD << 6) | /* VFPD : 2 */
(LCD_VSPW << 0) ; /* VSPW : 1 */
s2440LCD->LCDCON3 = (LCD_HBPD << 19) | /* HBPD : 6 */
(LCD_HOZVAL_TFT << 8) | /* HOZVAL_TFT : 240 - 1 */
(LCD_HFPD << 0) ; /* HFPD : 2 */
s2440LCD->LCDCON4 = (LCD_MVAL << 8) | /* MVAL : 13 */
(LCD_HSPW << 0) ; /* HSPW : 4 */
s2440LCD->LCDCON5 = (0 << 12) | /* BPP24BL : LSB valid */
(1 << 11) | /* FRM565 MODE : 5:6:5 Format */
(0 << 10) | /* INVVCLK : VCLK Falling Edge */
(1 << 9) | /* INVVLINE : Inverted Polarity */
(1 << 8) | /* INVVFRAME : Inverted Polarity */
(0 << 7) | /* INVVD : Normal */
(0 << 6) | /* INVVDEN : Normal */
(0 << 5) | /* INVPWREN : Normal */
(0 << 4) | /* INVENDLINE : Normal */
(0 << 3) | /* PWREN : Disable PWREN */
(0 << 2) | /* ENLEND : Disable LEND signal */
(0 << 1) | /* BSWP : Swap Disable */
(1 << 0) ; /* HWSWP : Swap Enable */
s2440LCD->LCDSADDR1 = ((dwPhysicalFrameBase >> 22) << 21) |
((M5D(dwPhysicalFrameBase >> 1)) << 0);
s2440LCD->LCDSADDR2 = M5D((dwPhysicalFrameBase + (LCD_XSIZE_TFT * LCD_YSIZE_TFT * 2)) >> 1);
s2440LCD->LCDSADDR3 = (((LCD_XSIZE_TFT - LCD_XSIZE_TFT) / 1) << 11) | (LCD_XSIZE_TFT / 1);
// s2440LCD->LPCSEL |= 0x3;
s2440LCD->LPCSEL &= ~(0x7);
s2440LCD->LPCSEL |= 0x2; //240*320
s2440LCD->TPAL = 0x0;
s2440LCD->LCDCON1 |= 1;
// Unmap register buffers.
//
MmUnmapIoSpace((PVOID)s2440IOP, 0);
MmUnmapIoSpace((PVOID)s2440LCD, 0);
return(TRUE);
}
void S3C2440DISP::InitializeHardware (void)
{
WORD *ptr;
DWORD index;
HKEY hkDisplay = NULL;
DWORD dwLCDPhysicalFrameBase = 0;
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;
}
// Initialize LCD registers.
if (!InitializeLCDRegisters(dwLCDPhysicalFrameBase))
{
RETAILMSG(0, (_T("SALCD2: InitializeHardware: failed to initialize LCD registers.\r\n")));
return;
}
// map frame buffer into process space memory
m_VirtualFrameBuffer = (DWORD)VirtualAlloc(0, (0x40000), 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, (0x40000), 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;
// clear rest of frame buffer out
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;
}
}
RETAILMSG(0, (_T("--S3C2440DISP::InitializeHardware\r\n")));
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -