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

📄 dispdrvr.c

📁 WinCE boot下驱动LCD的源程序
💻 C
📖 第 1 页 / 共 5 页
字号:
void DirtyRectDumpPortraitLoop_C_rectfill(BYTE    *pDstBuf, WORD srcColor,DWORD yTop,DWORD yBottom,
     DWORD srcWidthB, DWORD bytesPerRow, DWORD bytesPerPixel, DWORD srcMarginWidth, DWORD dstMarginWidth)
{
    DWORD   row;
    DWORD   i;
    WORD  * pwDst;
    WORD    rowLen;

    //16-bit
    srcWidthB >>= 1;
    pwDst       = (WORD *)pDstBuf;
    
    //first row for pwSrc, then column for pwDst
    rowLen = (WORD)(yBottom - yTop);

    bytesPerRow    >>= 1;
    dstMarginWidth >>= 1;
    srcMarginWidth >>= 1;

    for (i = 0; i < srcWidthB; i++)
    {
        for (row = 0; row < (DWORD)(rowLen >> 2); row++)
        {
            *pwDst++ = srcColor;
            *pwDst++ = srcColor;
            *pwDst++ = srcColor;                
            *pwDst++ = srcColor;
        }

        for (row = 0; row < (DWORD)(rowLen & 0x3); row++)
        {
            *pwDst++ = srcColor;
        }

        pwDst += dstMarginWidth;
    }
}
   
void DispDrvrDirtyRectDump_rectfill(LPCRECT prc, DWORD color)
{
    BYTE  * pDstBuf;
    BYTE  * pSrcBuf;
    WORD    srcColor = (WORD)color;
    DWORD   xLeft;
    DWORD   yTop;
    DWORD   xRight;
    DWORD   yBottom;
    DWORD   bytesPerRow;
    DWORD   bytesPerPixel;
    DWORD   srcWidthB;
    DWORD   srcMarginWidth;
    DWORD   dstMarginWidth;
    DWORD   srcStartRow;
    DWORD   dstStartRow;
    DWORD   srcMarginWidth2; 
    DWORD   dstMarginWidth2;
    DWORD   dstStep;

    bytesPerPixel = bpp / 8;

    xLeft   = prc->left   < 0                    ? 0                 : prc->left;
    yTop    = prc->top    < 0                    ? 0                 : prc->top;
    xRight  = prc->right  > DispDrvr_cxScreen    ? DispDrvr_cxScreen : prc->right;
    yBottom = prc->bottom > DispDrvr_cyScreen    ? DispDrvr_cyScreen : prc->bottom;

    if ((LONG)xLeft >= (LONG)xRight || (LONG)yTop >= (LONG)yBottom)
    {
        return;
    }

    xLeft       *= bytesPerPixel;
    xRight      *= bytesPerPixel;
    bytesPerRow  = DispDrvr_cxScreen * bytesPerPixel;

    srcWidthB       = xRight - xLeft;
    srcStartRow     = (yBottom - 1) * bytesPerRow;
    srcMarginWidth  = (yBottom - yTop) * bytesPerRow;
    dstStartRow     = xLeft * DispDrvr_cyScreen;
    dstMarginWidth  = (DispDrvr_cyScreen - (yBottom - yTop)) * bytesPerPixel;
    pDstBuf         = gFrameBuffer + dstStartRow + (DispDrvr_cyScreen -yBottom) * bytesPerPixel;
    dstStep         = DispDrvr_cyScreen * bytesPerPixel; //portrait frame buffer step
    srcMarginWidth2 = DispDrvr_cxScreen * bytesPerPixel + (xRight - xLeft);
    dstMarginWidth2 = (xRight - xLeft) * dstStep / bytesPerPixel;
    pSrcBuf         = gDibBuffer + srcStartRow + xLeft;

//2007-9-12 10:38 Bruce
//    EnterCriticalSection(&displayMutex);
    
    DirtyRectDumpPortraitLoop_C_rectfill(pDstBuf, srcColor, yTop, yBottom, srcWidthB, bytesPerRow, 
        bytesPerPixel, srcMarginWidth, dstMarginWidth);

//2007-9-12 10:37    Bruce
//    LeaveCriticalSection(&displayMutex);
}    

//void DispDrvrDirtyRectDump2(LPCRECT prc,DWORD color)
//{
//    WORD  * pDstBuf;
//    WORD    srcColor = (WORD)color;
//    DWORD   xLeft;
//    DWORD   yTop;
//    DWORD   xRight;
//    DWORD   yBottom;
//    DWORD   srcWidthB;
//    DWORD   dstMarginWidth;
//    DWORD   dstStartRow;
//    
//    xLeft   = prc->left   < 0                    ? 0                 : prc->left;
//    yTop    = prc->top    < 0                    ? 0                 : prc->top;
//    xRight  = prc->right  > DispDrvr_cxScreen    ? DispDrvr_cxScreen : prc->right;
//    yBottom = prc->bottom > DispDrvr_cyScreen    ? DispDrvr_cyScreen : prc->bottom;
//    
//    if ((LONG)xLeft >= (LONG)xRight || (LONG)yTop >= (LONG)yBottom)
//    {
//        return;
//    }
//
//    srcWidthB      = xRight - xLeft;
//    dstStartRow    = xLeft * DispDrvr_cyScreen;
//    dstMarginWidth = (DispDrvr_cyScreen - (yBottom - yTop));
//    pDstBuf        = (WORD *)gFrameBuffer + dstStartRow + (DispDrvr_cyScreen - yBottom);
//    
////2007-9-12 10:38 Bruce
////    EnterCriticalSection(&displayMutex);
//
//    ellipse_core_ASM(srcColor, (dstMarginWidth + 1) * 2, srcWidthB, pDstBuf);
//    
////2007-9-12 10:37    Bruce
////    LeaveCriticalSection(&displayMutex);
//}

void DispDrvrMoveCursor(INT32 xLocation,INT32 yLocation)
{
    // will be rewritten to take advantage of the new hardware cursor support
/*
    // First clear the cursor's old location
    gDrawCursorFlag = FALSE;
    DispDrvrDirtyRectDump(&gCursorRect);
    // Now set the new location of the cursor and redraw
    gCursorRect.left = xLocation - gxHot;
    if (gCursorRect.left < 0) {
        gCursorRect.left = 0;
    }
    gCursorRect.top = yLocation - gyHot;
    if (gCursorRect.top < 0) {
        gCursorRect.top = 0;
    }
    gCursorRect.right = xLocation - gxHot + CURSOR_XSIZE;
    gCursorRect.bottom = yLocation - gyHot + CURSOR_YSIZE;
    gDrawCursorFlag = TRUE;
    DispDrvrDirtyRectDump(&gCursorRect);
*/
}

#define VIDEO_REG_PATH     TEXT("Drivers\\Display\\PXA27x\\Config")
#define VIDEO_ROW_RES      TEXT("CxScreen")
#define VIDEO_COL_RES      TEXT("CyScreen")
#define PIXEL_DEPTH        TEXT("Bpp")
#define VIDEO_DISPLAY_TYPE TEXT("DisplayType")

BOOL ReadRegistryData()
{
//    LONG  regError;
//    HKEY  hKey;
//    DWORD dwDataSize;
//    TCHAR DisplayType[64];

    bpp               = 0;
    DispDrvr_cyScreen = 0;
    DispDrvr_cxScreen = 0;

    // Open the registry key
//    regError = RegOpenKeyEx(HKEY_LOCAL_MACHINE,VIDEO_REG_PATH,0,KEY_ALL_ACCESS,&hKey);
//    if (regError != ERROR_SUCCESS)
//    {
//        DEBUGMSG(DEBUGZONE(0),(VIDEO_REG_PATH));
//        DEBUGMSG(DEBUGZONE(0),(TEXT("Failed opening \\Drivers\\Display\\PXA27x\\Config\r\n")));
//        return (FALSE);        
//    }

    // Display width
//    dwDataSize = sizeof(DispDrvr_cxScreen);
//    regError   = RegQueryValueEx(hKey,VIDEO_ROW_RES, NULL, NULL,(LPBYTE)&DispDrvr_cxScreen,&dwDataSize);
//    if (regError != ERROR_SUCCESS)
//    {
//        DEBUGMSG(DEBUGZONE(0),(TEXT("Failed to get display x value, Error 0x%X\r\n"),regError));
//        return (FALSE);
//    }
	DispDrvr_cxScreen=320;//640;

    // Display height
//    dwDataSize = sizeof(DispDrvr_cyScreen);
//    regError   = RegQueryValueEx(hKey,VIDEO_COL_RES,NULL,NULL,(LPBYTE)&DispDrvr_cyScreen,&dwDataSize);
//    if (regError != ERROR_SUCCESS) {
//        DEBUGMSG(DEBUGZONE(0),(TEXT("Failed to get display y value, Error 0x%X\r\n"),regError));
//        return (FALSE);
//    }
	DispDrvr_cyScreen=240;//480;
	
    // Color depth
//    dwDataSize = sizeof(bpp);
//    regError=RegQueryValueEx(hKey,PIXEL_DEPTH,NULL,NULL,(LPBYTE)&bpp,&dwDataSize);
//    if (regError != ERROR_SUCCESS)
//    {
//        bpp = 0;
//    }
	bpp=16;
    // Display Type
//    dwDataSize = sizeof(DisplayType);
//    regError   = RegQueryValueEx(hKey,VIDEO_DISPLAY_TYPE,NULL,NULL,(LPBYTE)DisplayType,&dwDataSize);
//    if (regError != ERROR_SUCCESS)
//    {
//        DEBUGMSG(DEBUGZONE(0),(TEXT("Failed to get display type, Error 0x%X\r\n"),regError));
//        return (FALSE);
//    }
//    
//    RegCloseKey (hKey);
//    RETAILMSG(1, (TEXT("Done getting Registry values:\r\nbpp: 0x%x\r\n CxScreen: 0x%x\r\n CyScreen: 0x%x\r\nDisplay Type: %s\r\n"), bpp, DispDrvr_cxScreen, DispDrvr_cyScreen,DisplayType));
//        
//    if (_wcsicmp(DisplayType, TEXT("LTM04C380K")) == 0)
//    {
//        nDisplayType = LTM04C380K;
//    }
//    else
//    {
//        nDisplayType = NONE;
//    }
	//nDisplayType = VLFSDD320240;//LTM04C380K;
	nDisplayType=GetDisplayType();
	EdbgOutputDebugString("nDisplayType=%d\r\n",nDisplayType);
	switch(nDisplayType)
	{
		case 	VLFSDD320240:
				DispDrvr_cxScreen=320;
				DispDrvr_cyScreen=240; 
				bpp=16;//8;
				break;
		case 	NANYALM702:
				DispDrvr_cxScreen=640;
				DispDrvr_cyScreen=480; 
				bpp=16;//8;
				break;

		case 	AU104:
				DispDrvr_cxScreen=800;
				DispDrvr_cyScreen=600; 
				bpp=16;
				break;
	}
    // bDoRotation is used to indicate whether or not a rotation of the frame buffer
    // is required in order to orient it correctly for the target display.
    bDoRotation = FALSE;
    switch (nDisplayType)
    {
    case LTM04C380K:    // native landscape 640x480
    case LM8V31:        // native landscape 640x480
        if (DispDrvr_cxScreen < DispDrvr_cyScreen)
        {
            bDoRotation = TRUE;
        }
        break;

    case LQ64D341:        // native portrait, 176x220
    case LTM035A776C:    // native portrait, 240x320
        if (DispDrvr_cxScreen > DispDrvr_cyScreen)
        {
            //bDoRotation = TRUE;
        }
        break;

    default:
        break;
    }

    // Calculate the stride of the frame buffer
    DispDrvr_cdwStride = DispDrvr_cxScreen * bpp / 8;

    return (TRUE); 
}

void ScrollBuffer(int direction)
{
//2007-9-12 10:38 Bruce
//    EnterCriticalSection(&frameDescriptorMutex);

    // Set the physical address of the frame buffer for all three frame descriptors
    if (direction == 1) // scroll up
    {
        frameDescriptorCh0fd1->FSADR += DispDrvr_cdwStride << 2;
        frameDescriptorCh0fd2->FSADR += DispDrvr_cdwStride << 2;
        frameDescriptorCh1->FSADR    += DispDrvr_cdwStride << 2;
    }
    else // scroll down
    {
        frameDescriptorCh0fd1->FSADR -= DispDrvr_cdwStride << 2;
        frameDescriptorCh0fd2->FSADR -= DispDrvr_cdwStride << 2;
        frameDescriptorCh1->FSADR    -= DispDrvr_cdwStride << 2;
    }

//2007-9-12 10:37    Bruce
//    LeaveCriticalSection(&frameDescriptorMutex);
}

void Overlay2_Enable(P_XLLP_OVERLAY_T pXllpOverlay)
{
    XllpLCD_Overlay2_Enable(&XllpLCD, pXllpOverlay);
}

void Overlay2_Disable(P_XLLP_OVERLAY_T pXllpOverlay)
{
    XllpLCD_Overlay2_Disable(&XllpLCD, pXllpOverlay);
}

void Overlay2_DMA_Length(P_XLLP_OVERLAY_T pXllpOverlay)
{
    XllpLCD_DMALength(pXllpOverlay);
}

#define PALETTE_SIZE                256


PALETTEENTRY _rgbIdentity[PALETTE_SIZE] =                                               \
{                                                                                       \
    { 0x00, 0x00, 0x00, 0 },    /* 0 Sys Black      gray 0  */                          \
    { 0x80, 0x00, 0x00, 0 },    /* 1 Sys Dk Red  */                                     \
    { 0x00, 0x80, 0x00, 0 },    /* 2 Sys Dk Green  */                                   \
    { 0x80, 0x80, 0x00, 0 },    /* 3 Sys Dk Yellow  */                                  \
    { 0x00, 0x00, 0x80, 0 },    /* 4 Sys Dk Blue  */                                    \
    { 0x80, 0x00, 0x80, 0 },    /* 5 Sys Dk Violet  */                                  \
    { 0x00, 0x80, 0x80, 0 },    /* 6 Sys Dk Cyan  */                                    \
    { 0xc0, 0xc0, 0xc0, 0 },    /* 7 Sys Lt Grey    gray 192  */                        \

⌨️ 快捷键说明

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