📄 uldrui.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.
//
#include <updateappui.h>
#include <bsp.h>
// Global: dpCurSettings
//
// Set debug zones names and initial setting for driver
//
#ifdef DEBUG
DBGPARAM dpCurSettings = {
L"ULDRUI", {
L"Undefined", L"Undefined", L"Undefined", L"Undefined",
L"Undefined", L"Undefined", L"Undefined", L"Undefined",
L"Undefined", L"Undefined", L"Undefined", L"Undefined",
L"Undefined", L"Undefined", L"Undefined", L"Undefined"
},
0x0000
};
#endif
volatile S3C2440X_IOPORT_REG *s2440IOP;
volatile S3C2440X_LCD_REG *s2440LCD;
//------------------------------------------------------------------------------
BOOL InitDisplay(
DWORD width, DWORD height, DWORD bpp, DWORD orientation
) {
bool rc = FALSE;
unsigned int clkval_calc;
s2440IOP = (volatile S3C2440X_IOPORT_REG *)VirtualAlloc(0, sizeof(S3C2440X_IOPORT_REG), MEM_RESERVE, PAGE_NOACCESS);
if(s2440IOP == NULL)
RETAILMSG(TRUE,(TEXT("ULDR: (InitDisplay) IOPreg virtual allocation is failed.\r\n")));
else
if(!(VirtualCopy((PVOID)s2440IOP, (PVOID)(S3C2440X_BASE_REG_PA_IOPORT >> 8), sizeof(S3C2440X_IOPORT_REG), PAGE_PHYSICAL|PAGE_READWRITE|PAGE_NOCACHE )))
RETAILMSG(TRUE,(TEXT("ULDR: (InitDisplay) IOPreg virtual Copy is failed.\r\n")));
s2440LCD = (volatile S3C2440X_LCD_REG *)VirtualAlloc(0, sizeof(S3C2440X_LCD_REG), MEM_RESERVE, PAGE_NOACCESS);
if(s2440LCD == NULL)
RETAILMSG(TRUE,(TEXT("ULDR: (InitDisplay) LCDreg virtual allocation is failed.\r\n")));
else
if(!(VirtualCopy((PVOID)s2440LCD, (PVOID)(S3C2440X_BASE_REG_PA_LCD >> 8), sizeof(S3C2440X_LCD_REG), PAGE_PHYSICAL|PAGE_READWRITE|PAGE_NOCACHE )))
RETAILMSG(TRUE,(TEXT("ULDR: (InitDisplay) LCDreg virtual Copy is failed.\r\n")));
// We support only 16 bpp...
if (bpp != 16) {
RETAILMSG(TRUE, (L"ERROR: InitDisplay: "
L"Display doesn't support %d bpp\r\n", bpp
));
goto cleanUp;
}
if(width != 240){
RETAILMSG(TRUE, (L"ERROR: InitDisplay: "
L"Display doesn't support %d width\r\n", width
));
goto cleanUp;
}
if(height != 320){
RETAILMSG(TRUE, (L"ERROR: InitDisplay: "
L"Display doesn't support %d height\r\n", height
));
goto cleanUp;
}
s2440IOP->GPCUP = 0xFFFFFFFF;
s2440IOP->GPCCON = 0xAAAAAAAA;
s2440IOP->GPDUP = 0xFFFFFFFF;
s2440IOP->GPDCON = 0xAAAAAAAA;
clkval_calc = (WORD)((float)(S3C2440X_HCLK)/(2.0*5000000)+0.5)-1;
s2440LCD->LCDCON1 = (clkval_calc << 8) | /* VCLK = HCLK / ((CLKVAL + 1) * 2) -> About 7 Mhz */
(LCD_MVAL << 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 */
(1 << 3) | /* PWREN : Disable PWREN */
(0 << 2) | /* ENLEND : Disable LEND signal */
(0 << 1) | /* BSWP : Swap Disable */
(1 << 0) ; /* HWSWP : Swap Enable */
s2440LCD->LCDSADDR1 = ((IMAGE_FRAMEBUFFER_DMA_BASE >> 22) << 21) |
((M5D(IMAGE_FRAMEBUFFER_DMA_BASE >> 1)) << 0);
s2440LCD->LCDSADDR2 = M5D((IMAGE_FRAMEBUFFER_DMA_BASE + (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 &= (~7);
s2440LCD->LPCSEL |= (0x1<<4);
s2440LCD->TPAL = 0x0;
s2440LCD->LCDCON1 |= 1;
memset((void*)IMAGE_FRAMEBUFFER_UA_BASE, 0x001f, LCD_ARRAY_SIZE_TFT_16BIT);
// Done
rc = TRUE;
cleanUp:
return rc;
}
//------------------------------------------------------------------------------
BOOL DeinitDisplay()
{
memset((void*)IMAGE_FRAMEBUFFER_UA_BASE, 0x0, LCD_ARRAY_SIZE_TFT_16BIT);
s2440IOP->GPGDAT &= ~(1<<4);
s2440LCD->LCDCON1 = 0;
s2440LCD->LCDCON2 = 0;
s2440LCD->LCDCON3 = 0;
s2440LCD->LCDCON4 = 0;
s2440LCD->LCDCON5 = 0;
s2440LCD->LCDSADDR1 = 0;
s2440LCD->LCDSADDR2 = 0;
s2440LCD->LCDSADDR3 = 0;
s2440LCD->LPCSEL = 0;
s2440LCD->TPAL = 0;
VirtualFree((void*)s2440IOP, sizeof(S3C2440X_IOPORT_REG), MEM_RELEASE);
VirtualFree((void*)s2440LCD, sizeof(S3C2440X_LCD_REG), MEM_RELEASE);
return TRUE;
}
//------------------------------------------------------------------------------
BOOL BltRect(RECT rc, DWORD stride, VOID *pBuffer)
{
volatile USHORT *pFrame = (USHORT *)IMAGE_FRAMEBUFFER_UA_BASE;
DWORD screenWidth = 240;
USHORT *pData = (USHORT*)pBuffer;
LONG xs, ys, xt, yt;
// Convert stride from bytes to words
stride /= sizeof(USHORT);
for (yt = rc.top, ys = 0; yt < rc.bottom; yt++, ys++) {
for (xt = rc.left, xs = 0; xt < rc.right; xt++, xs++) {
pFrame[yt * screenWidth + xt] = pData[ys * stride + xs];
}
}
return TRUE;
}
//------------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -