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

📄 ddipu_sdc_power.cpp

📁 Freescale ARM11系列CPU MX31的WINCE 5.0下的BSP
💻 CPP
字号:
//-----------------------------------------------------------------------------
//  Copyright (C) 2004-2005, MOTOROLA, INC. All Rights Reserved
//  THIS SOURCE CODE IS CONFIDENTIAL AND PROPRIETARY AND MAY NOT
//  BE USED OR DISTRIBUTED WITHOUT THE WRITTEN PERMISSION OF
//  MOTOROLA, INC.
//------------------------------------------------------------------------------
//
//  Copyright (C) 2005-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:  ddipu_sdc_power.cpp
//
//  Implementation of DDIPU_SDC power handling routines.
//
//------------------------------------------------------------------------------
#include "precomp.h"
#ifdef PLAT_PMC
#include <disppm.h>
#endif


//------------------------------------------------------------------------------
// External Functions
extern BOOL BSPEnableLCD();
extern BOOL BSPDisableLCD();


//------------------------------------------------------------------------------
// External Variables


//------------------------------------------------------------------------------
// Defines


//------------------------------------------------------------------------------
// Types


//------------------------------------------------------------------------------
// Global Variables


//------------------------------------------------------------------------------
// Local Variables


//------------------------------------------------------------------------------
// Local Functions


//------------------------------------------------------------------------------
//
// Function: AdvertisePowerInterface
//
// This routine notifies the OS that we support the
// Power Manager IOCTLs (through ExtEscape(), which
// calls DrvEscape()).
//
// Parameters:
//      hInst
//          [in] handle to module DLL
//
// Returns:
//      TRUE            successful
//      FALSE           failed
//
//------------------------------------------------------------------------------
BOOL DDIPU_SDC::AdvertisePowerInterface(HMODULE hInst)
{
    GUID gTemp;
    BOOL fOk = FALSE;
    HKEY hk;
    DWORD dwStatus;

    // assume we are advertising the default class
    _tcscpy(m_szGuidClass, PMCLASS_DISPLAY);
    m_szGuidClass[MAX_PATH-1] = 0;
    fOk = ConvertStringToGuid(m_szGuidClass, &gTemp);
    DEBUGCHK(fOk);

    // check for an override in the registry
    dwStatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("System\\GDI\\Drivers"), 0, 0, &hk);
    if(dwStatus == ERROR_SUCCESS)
    {
        DWORD dwType, dwSize;
        dwSize = sizeof(m_szGuidClass);
        dwStatus = RegQueryValueEx(hk, _T("DisplayPowerClass"), NULL, &dwType, (LPBYTE)m_szGuidClass, &dwSize);
        if(dwStatus == ERROR_SUCCESS && dwType == REG_SZ)
        {
            // got a guid string, convert it to a guid
            fOk = ConvertStringToGuid(m_szGuidClass, &gTemp);
            DEBUGCHK(fOk);
        }

        // release the registry key
        RegCloseKey(hk);
    }

    // figure out what device name to advertise
    if(fOk)
    {
        fOk = GetModuleFileName(hInst, m_szDevName, sizeof(m_szDevName) / sizeof(m_szDevName[0]));
        DEBUGCHK(fOk);
    }

    // now advertise the interface
    if(fOk)
    {
        fOk = AdvertiseInterface(&gTemp, m_szDevName, TRUE);
        DEBUGCHK(fOk);
    }

    return fOk;
}


#ifdef PLAT_PMC
BOOL DDIPU_SDC::CallSetDisplayPower(
                         PVOID handle,
                         CEDEVICE_POWER_STATE cspDx,
                         CEDEVICE_POWER_STATE cspCurrentDx
                         )
{
    DEBUGCHK(handle != NULL);
    DDIPU_SDC* pDisplay = (DDIPU_SDC*)handle;
    pDisplay->SetDisplayPower(cspDx);
    return TRUE;
}
#endif

//------------------------------------------------------------------------------
//
// Function: SetDisplayPower
//
// This function sets the display hardware according
// to the desired video power state. Also updates
// current device power state variable.
//
// Parameters:
//      dx
//          [in] Desired video power state.
//
// Returns:
//      None.
//
//------------------------------------------------------------------------------
VOID DDIPU_SDC::SetDisplayPower(CEDEVICE_POWER_STATE dx)
{
    static BOOL bOverlayWindowRestore = FALSE;
    switch(dx)
    {
        case D0:
            if(m_Dx != dx)
            {
                // Enable LCD
                BSPEnableLCD();

                // Enable display controller
                EnableSDC();

                // If overlay window was running, re-enable it.
                if (bOverlayWindowRestore || m_pOverlaySurfaceOp->isOverlayWindowRunning)
                {
					// If last mode is not TV mode, we do not re-enable
                    // foreground window, since we will need to change the size
                    // of the image (due to changes between LCD and TV modes).
                    // We let the PPOverlayRoutine handle this later.
					ForegroundWindowRestore();

					OverlayWindowSetup();

					m_pOverlaySurfaceOp->isOverlayWindowRunning = TRUE;
                    bOverlayWindowRestore = FALSE;
				}

                // TODO: We need check with Microsoft which surface shall we restore to after
                // system resume from suspension: primary one or last displaying one??
                SetVisibleSurface(m_pPrimarySurface, TRUE);

#ifdef PLAT_PMC
				DISPLSetMode((DWORD)this, DISPLAY_MODE_DEVICE, FALSE);
#endif
                m_Dx = D0;
            }
            break;

        case D1:
        case D2:
        case D3:
            break;

        case D4:
            if(m_Dx != D4)
            {
#ifdef PLAT_PMC
                DISPLSetMode((DWORD)this, DISPLAY_MODE_NONE, TRUE);
#endif

                // If overlay window was running, disable it, but
                // leave isOverlayWindowRunning variable set to TRUE.
                // We will use this to restore the overlay upon power up.
                if (m_pOverlaySurfaceOp->isOverlayWindowRunning)
                {
                    bOverlayWindowRestore = TRUE;
                    m_pOverlaySurfaceOp->isOverlayWindowRunning = FALSE;
                    ForegroundWindowDisable();
                }

                if (m_bTVModeActive)
                {
                    // If TV mode was active, we call to set the
                    // display mode to LCD.  We always want to
                    // emerge from suspend in LCD mode.
                    SetMode(DISPLAY_MODE_DEVICE, NULL);
#ifdef PLAT_PMC
                    DISPLSetMode((DWORD)this, DISPLAY_MODE_DEVICE, FALSE);
#endif
                }

                // Disable display controller
                DisableSDC();

                // Disable LCD
                BSPDisableLCD();

                m_Dx = D4;
            }
            break;

        default:
            break;
    }
}


//------------------------------------------------------------------------------
//
// Function: PmToVideoPowerState
//
// This function maps between power manager power
// states and video ioctl power states.
//
// Parameters:
//      dx
//          [in] Desired power manager device power state.
//
// Returns:
//      Corresponding video ioctl power state.
//
//------------------------------------------------------------------------------
VIDEO_POWER_STATE DDIPU_SDC::PmToVideoPowerState(CEDEVICE_POWER_STATE dx)
{
    VIDEO_POWER_STATE vps;

    switch(dx)
    {
        // turn the display on
        case D0:
            vps = VideoPowerOn;
            break;

        // if asked for a state we don't support, go to the next lower one
        case D1:
        case D2:
        case D3:
        case D4:
            vps = VideoPowerOff;
            break;

        default:
            DEBUGMSG(GPE_ZONE_ERROR, (L"MX21DDLcdc PmToVideoPowerState: mapping unknown PM state %d to VideoPowerOn\r\n", dx));
            vps = VideoPowerOn;
            break;
    }
    return vps;
}


//------------------------------------------------------------------------------
//
// Function: VideoToPmPowerState
//
// This function maps between video power states
// to PM power states.
//
// Parameters:
//      vps
//          [in] Desired video power state.
//
// Returns:
//      Corresponding PM device power state.
//
//------------------------------------------------------------------------------
CEDEVICE_POWER_STATE DDIPU_SDC::VideoToPmPowerState(VIDEO_POWER_STATE vps)
{
    CEDEVICE_POWER_STATE dx;

    switch(vps)
    {
        case VideoPowerOn:
            dx = D0;
            break;

        case VideoPowerStandBy:
        case VideoPowerSuspend:
        case VideoPowerOff:
            dx = D4;
            break;

        default:
            dx = D0;
            DEBUGMSG(GPE_ZONE_WARNING, (L"MX21DDLcdc VideoToPmPowerState: mapping unknown video state %d to pm state %d\r\n",
                     vps, dx));
            break;
    }

    return dx;
}


//------------------------------------------------------------------------------
//
// Function: ConvertStringToGuid
//
// This converts a string into a GUID.
//
// Parameters:
//      pszGuid
//          [in] Pointer to GUID in string format.
//
//      pGuid
//          [out] Pointer to GUID struct for output
//
// Returns:
//      TRUE            successful
//      FALSE           failed
//
//------------------------------------------------------------------------------
BOOL DDIPU_SDC::ConvertStringToGuid(LPCTSTR pszGuid, GUID * pGuid)
{
    UINT Data4[8];
    int  Count;
    BOOL fOk = FALSE;
    TCHAR *pszGuidFormat = _T("{%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}");

    DEBUGCHK(pGuid != NULL && pszGuid != NULL);
    __try
    {
        if (_stscanf(pszGuid, pszGuidFormat, &pGuid->Data1,
            &pGuid->Data2, &pGuid->Data3, &Data4[0], &Data4[1], &Data4[2], &Data4[3],
            &Data4[4], &Data4[5], &Data4[6], &Data4[7]) == 11)
        {
            for(Count = 0; Count < (sizeof(Data4) / sizeof(Data4[0])); Count++)
            {
                        pGuid->Data4[Count] = (UCHAR) Data4[Count];
            }
        }
        fOk = TRUE;
    }
    __except(EXCEPTION_EXECUTE_HANDLER)
    {
    }

    return fOk;
}

⌨️ 快捷键说明

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