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

📄 bspddlcdc.cpp

📁 LP1071 无线局域网卡WinCE驱动程序
💻 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) 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 <gpe.h>
#include "bsp.h"
#include "bspddlcdc.h"
#include "fs453.h"

//------------------------------------------------------------------------------
// GLOBAL DEFINITIONS    
//------------------------------------------------------------------------------
ULONG BitMasks[] = {RGB565_RED, RGB565_GREEN, RGB565_BLUE};
static PCSP_PBC_REGS pPBC = NULL;

//------------------------------------------------------------------------------
// The mode according to supported panel types
//------------------------------------------------------------------------------
GPEMode ModeArray[numPanels] =
{
    // DISPLAY_SHARP_LQ035Q7DB02
    {DISPLAY_MODE_SHPQVGA, 240, 320, BSP_PREF_DISPLAY_BPP, 60, gpe16Bpp}, // 240*320*16bpp

    // DISPLAY_SHARP_LQ035Q7DB02
    {DISPLAY_MODE_NECVGA, 640, 480, BSP_PREF_DISPLAY_BPP, 60, gpe16Bpp}, // 640*480*16bpp

    // Put other panel info here in future expansion
    // ... ...
};

// TVOUT related
GPEMode NTSCMode = {DISPLAY_MODE_NTSC, 640, 480, BSP_PREF_DISPLAY_BPP, 60, gpe16Bpp};  //mode listed as 320*240*16, but upsized to 640*480*16bpp
GPEMode PALMode = {DISPLAY_MODE_PAL, 640, 480, BSP_PREF_DISPLAY_BPP, 50, gpe16Bpp};  //mode listed as 320*240*16, but upsized to 640*480*16bpp


//--------------------------------------------------------------------------
//
// Function: BSPGetLCDCBitMasks
//
// This function returns the bitmask to CSP.
//
// Parameters:
//      None.
//
// Returns:
//      Returns bitmask.
//
//--------------------------------------------------------------------------
ULONG* BSPGetLCDCBitMasks(void)
{
    return BitMasks;
}


//--------------------------------------------------------------------------
//
// Function: BSPInitLCDC
//
// This function initiaizes the LCDC parameters specific to BSP
// and does initializaion for BSP hardware.
//
// Parameters:
//      pContext
//          [out] This argument will be filled with LCDC BSP parameters and
//          used by CSP.
//
// Returns:
//      Returns TRUE if the function properly initiaizes BSP LCDC. 
//      Returns FALSE if not.
//
//--------------------------------------------------------------------------
BOOL BSPInitLCDC(PLCDCCTX pContext)
{
    PHYSICAL_ADDRESS phyAddr;

    // Setting the current panel
    GetDisplayModeFromRegistry();

    if (m_dwPanelType >= numPanels)
    {
        // Use default panel type
        m_dwPanelType = PANEL_TYPE_DEFAULT;
    }

    // Build array of supported modes
    if(m_dwDisplayMode == 0) // LCD panel
    {
        if (m_dwPanelType == 0) // SHARP
            m_pSupportedModes = &ModeArray[DISPLAY_MODE_SHPQVGA];
        if (m_dwPanelType == 1) // NEC
            m_pSupportedModes = &ModeArray[DISPLAY_MODE_NECVGA];
    }
    if(m_dwDisplayMode == 1) // LCD panel
    {
        if (m_dwTVType == 0) // TV PAL
            m_pSupportedModes = &PALMode;
        if (m_dwTVType == 1) // TV NTSC
            m_pSupportedModes = &NTSCMode;
    }
  
    if(!pContext) return FALSE;
    pContext->pGPEModeInfo = m_pSupportedModes;
    pContext->VideoFrameHight = m_pSupportedModes->height;
    pContext->VideoFrameWidth = m_pSupportedModes->width;
    pContext->VideoMemoryPhyAdd = IMAGE_SHARE_FRAMEBUFFER_RAM_PA_START;
    pContext->VideoMemorySize = (UINT32)IMAGE_SHARE_FRAMEBUFFER_RAM_SIZE;

    if(pPBC == NULL)
    {
      phyAddr.QuadPart = BSP_BASE_REG_PA_PBC_BASE;
      pPBC = (PCSP_PBC_REGS)MmMapIoSpace(phyAddr, sizeof(CSP_PBC_REGS), FALSE);
      if (pPBC  ==  NULL)
      {
          return FALSE;
      }
    }

    return TRUE;
}


//------------------------------------------------------------------------------
//
// Function: BSPDeinitLCDC
//
// This function deinitiaizes the LCDC BSP-secific hardware.
//
// Parameters:
//      None.
//
// Returns:
//      None.
//
//------------------------------------------------------------------------------
void BSPDeinitLCDC(PLCDCCTX pContext)
{
    if(pPBC != NULL)
    {
        MmUnmapIoSpace(pPBC, sizeof(CSP_PBC_REGS));
        pPBC = NULL;
    }
}

/////////////// enable PBC lcd for lcd panel, disable PBC lcd for tv
//------------------------------------------------------------------------------
//
// Function: BSPTurnOnLCD
//
// This function enables the Sharp display panel by turning on the
// LCD through the Peripheral Bus Controller.
//
// Parameters:
//      None.
//
// Returns:
//      TRUE if success; FALSE if failure.
//
//------------------------------------------------------------------------------
void BSPTurnOnLCD(void)
{
    if(pPBC != NULL)
    {
        OUTREG16(&pPBC->BCTRL1_SET, CSP_BITFMASK(PBC_BCTRL1_LCDON));
    }
}


//------------------------------------------------------------------------------
//
// Function: BSPTurnOffLCD
//
// This function disables the Sharp display panel by turning off the
// LCD through the Peripheral Bus Controller.
//
// Parameters:
//      None.
//
// Returns:
//      TRUE if success; FALSE if failure.
//
//------------------------------------------------------------------------------
void BSPTurnOffLCD(void)
{
    if(pPBC != NULL)
    {
        OUTREG16(&pPBC->BCTRL1_CLEAR, CSP_BITFMASK(PBC_BCTRL1_LCDON));
    }
}


//--------------------------------------------------------------------------
//
// Function: GetDisplayModeFromRegistry
//
// This function gets the current display mode from registry.
//
// Parameters:
//      None.
//
// Returns:
//      Panel type number for initial display panel.
//
//--------------------------------------------------------------------------
BOOL  GetDisplayModeFromRegistry(void) 
{
    LONG result;
    BOOL ret = TRUE;
    HKEY  hKey = NULL;
    DWORD dwSize;

    DEBUGMSG(GPE_ZONE_ENTER, (TEXT("++GetDisplayModeFromRegistry\r\n")));
    
    m_dwDisplayMode = 0;
    m_dwPanelType = 0;
    m_dwTVType = 0;

    // Get DDLCDC key
    result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, DDLCDC_REG_PATH, 0 , 0, &hKey);
    if(result != ERROR_SUCCESS)
    {
        DEBUGMSG(GPE_ZONE_ERROR, (TEXT("GetDisplayModeFromRegistry:Open the RegKey failed\r\n")));
        ret = FALSE;
        goto cleanup;
    }
    
    // Get display mode
    dwSize = sizeof(m_dwDisplayMode);
    result = RegQueryValueEx(hKey, DISPLAY_MODE, NULL, NULL,(LPBYTE)&m_dwDisplayMode, 
        (LPDWORD) &dwSize);
    if(result != ERROR_SUCCESS)
    {
        DEBUGMSG(GPE_ZONE_ERROR, (TEXT("GetDisplayModeFromRegistry: Get m_dwDisplayMode failed\r\n")));
        ret = FALSE;
        goto cleanup;
    }

    // Get LCD panel type
    dwSize = sizeof(m_dwPanelType);
    result = RegQueryValueEx(hKey, PANEL_TYPE, NULL, NULL,(LPBYTE)&m_dwPanelType, 
        (LPDWORD) &dwSize);
    if(result != ERROR_SUCCESS)
    {
        DEBUGMSG(GPE_ZONE_ERROR, (TEXT("GetDisplayModeFromRegistry: Get m_dwPanelType failed\r\n")));
        ret = FALSE;
        goto cleanup;
    }

    // Get TV type
    dwSize = sizeof(m_dwTVType);
    result = RegQueryValueEx(hKey, TV_TYPE, NULL, NULL,(LPBYTE)&m_dwTVType, 
        (LPDWORD) &dwSize);
    if(result != ERROR_SUCCESS)
    {
        DEBUGMSG(GPE_ZONE_ERROR, (TEXT("GetDisplayModeFromRegistry: Get m_dwTVType failed\r\n")));
        ret = FALSE;
        goto cleanup;
    }        
    
cleanup:
    // Close the video key
    if (hKey != NULL)
        RegCloseKey(hKey);   

    RETAILMSG (0, (TEXT("m_dwTVType 0x%x ret 0x%x\r\n"), m_dwTVType, ret) );

    DEBUGMSG(GPE_ZONE_ENTER, (TEXT("--GetPanelTypeFromRegistry\r\n")));  
    return (ret);
}


//--------------------------------------------------------------------------
//
// Function: BSPGetModeNum
//
// This function returns the number of display modes supported by a driver. 
// A simple implementation returns 1.
//
// Parameters:
//      None.
//
// Returns:
//      Returns the number of display modes supported by a driver.
//
//--------------------------------------------------------------------------
ULONG BSPGetModeNum(void)
{
    return MAX_NUM_MODES;
}

//--------------------------------------------------------------------------
//
// Function: BSPSetMode
//
// This function 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, now only support one mode one time
//
//      pPalette
//          [in, out] On input, a handle to a palette. On output, 
//                    this parameter provides a palette filled in by the EngCreatePalette function.
//
// Returns:
//      Returns S_OK if successfully.
//      Returns S_FALSE if not successfully.
//
//--------------------------------------------------------------------------
SCODE BSPSetMode(int modeId, HPALETTE *pPalette)
{
    SCODE result = S_OK;
    
    DEBUGMSG(GPE_ZONE_ENTER, (TEXT("++BSPSetMode\r\n")));
    if(modeId != 0)
      return E_INVALIDARG;
        
    // Create a palette for MGDI
    if(pPalette != NULL)
    {
        // 15,16,24, and 32bpp primaries are defined by red,green, and blue
        if(!(*pPalette = EngCreatePalette(PAL_BITFIELDS, 0, NULL, RGB565_RED, 
            RGB565_GREEN, RGB565_BLUE)))
        {
            DEBUGMSG(GPE_ZONE_ERROR, (TEXT("SetMode:Create a palette for MGDI failed\r\n")));
            result = S_FALSE;
            goto cleanup;
        }         
    }
    
cleanup:
    DEBUGMSG(GPE_ZONE_ENTER, (TEXT("--BSPSetMode\r\n")));
    return (result);
}


//--------------------------------------------------------------------------
//
// Function: BSPGetMode
//
// This function returns the mode used by CSP.
//
// Parameters:
//      None.
//
// Returns:
//      Returns the mode used by CSP.
//
//--------------------------------------------------------------------------
GPEMode BSPGetMode(void)
{
    return (*m_pSupportedModes);
}


//------------------------------------------------------------------------------
//
// Function: BSPInitializeTVOut
//
// This function initializes the FS453 TV out encoder.
//
// Parameters:
//      None
//
// Returns:
//      Returns TRUE if success. 
//      Returns FALSE if failure.
//
//------------------------------------------------------------------------------
BOOL BSPInitializeTVOut(BOOL tvout_ntsc)
{
    BOOL retVal = FALSE;

    // I2C read ID
    if (!Fs453Init()) 
    {
        DEBUGMSG(1, (TEXT("Fs453Init Failed")));
        goto done;
    }

    // Config mode
    if (!Fs453Configure(TVIN_COLOR_RGB, (tvout_ntsc == TRUE) ? TVOUT_MODE_NTSC : TVOUT_MODE_PAL )) 
    {
        DEBUGMSG(1, (TEXT("Fs453Configure Failed")));
        goto done;
    }

    // Enable output
    if (!Fs453DACOn(TVOUT_DAC_ALL))
    {
        DEBUGMSG(1, (TEXT("Fs453DACOn Failed")));
        goto done;
    }
    
    // Can be used for TVOUT test
    // Fs453ColorBarOn(TRUE);
    
    retVal = TRUE;
    
done:
    return retVal;
}


//------------------------------------------------------------------------------
//
// Function: BSPDeinitializeTVOut
//
// This function deinitializes the FS453 TV out encoder.
//
// Parameters:
//      None
//
// Returns:
//      Returns TRUE if success. 
//      Returns FALSE if failure.
//
//------------------------------------------------------------------------------
BOOL BSPDeinitializeTVOut()
{
    BOOL retVal = FALSE;

    if (!Fs453DACOff(TVOUT_DAC_ALL))
    {
        DEBUGMSG(1, (TEXT("Fs453DACOff Failed")));
        goto done;
    }
    
    if (!Fs453Deinit())
    {
        DEBUGMSG(1, (TEXT("Fs453Deinit Failed")));
        goto done;
    }
    
    retVal = TRUE;

done:
    return retVal;
}


//------------------------------------------------------------------------------
//
// Function: BSPPowerOnTVOut
//
// This function powers on the FS453 TV out encoder.
//
// Parameters:
//      None
//
// Returns:
//      None
//
//------------------------------------------------------------------------------
void BSPPowerOnTVOut()
{
    Fs453DACOn(TVOUT_DAC_ALL);
}


//------------------------------------------------------------------------------
//
// Function: BSPPowerOffTVOut
//
// This function powers off the FS453 TV out encoder.
//
// Parameters:
//      None
//
// Returns:
//      None
//
//------------------------------------------------------------------------------
void BSPPowerOffTVOut()
{
    Fs453DACOff(TVOUT_DAC_ALL);
}


//------------------------------------------------------------------------------
//
// Function: BSPConfigPanel
//
// This function selects the panel used.
//
// Parameters:
//      bTVModeActive
//          [in] This argument choose config for TV mode or LCD mode.
//      bTVNTSCOut
//          [in] This argument choose config for NTSC or PAL mode.
//      dwPanelType
//          [in] This argument choose config for SHARP QVGA or NEC VGA mode.
//
// Returns:
//      Returns the panel used. 
//
//------------------------------------------------------------------------------
struct DisplayPanel*  BSPConfigPanel(BOOL bTVModeActive, BOOL bTVNTSCOut, DWORD dwPanelType)
{
    struct DisplayPanel *pDisplayPanel;
  
    if(bTVModeActive)
    {
        if(bTVNTSCOut)
            pDisplayPanel = &panelTVNTSC;
        else
            pDisplayPanel = &panelTVPAL;
    }
    else
    {
        if(dwPanelType == 0) // SHPQVGA
            pDisplayPanel = &panelSHARPQVGA;
        else // NECVGA
            pDisplayPanel = &panelNECVGA;
    }
    
    return pDisplayPanel;
}

⌨️ 快捷键说明

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