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

📄 plato_backlight.cpp

📁 Windows CE 6.0 BSP for VOIP sample phone. Intel PXA270 platform.
💻 CPP
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES OR INDEMNITIES.
//
//
//------------------------------------------------------------------------------
//
//  File: plato_backlight.c
//
//  Backlight PDD driver source code, Plato-specific
//
#include <windows.h>
#include <ceddk.h>
#include <bulverde.h>


#ifdef  RETAIL_DEBUG
#ifndef DEBUG
#define DEBUG 1
extern DBGPARAM dpCurSettings;
#undef DEBUGMSG
#define DEBUGMSG RETAILMSG
#endif
#endif

#ifdef DEBUG
#define ZONE_BACKLIGHT      DEBUGZONE(0)
#define ZONE_FUNCTION       DEBUGZONE(1)
#define ZONE_ERROR          DEBUGZONE(15)
#else
#define ZONE_BACKLIGHT      1
#define ZONE_FUNCTION       1
#define ZONE_ERROR          1
#endif

#include "xllp_defs.h"


//
// INTC Register definitions
//
typedef struct
{
  XLLP_VUINT32_T    pwmcr0;       // PWM0 control register
  XLLP_VUINT32_T    pwmdcr0;       // PWM0 duty cycle Register
  XLLP_VUINT32_T    pwmpcr0;       // PWM 0 period Register 
} XLLP_PWM_T, *P_XLLP_PWM_T;

volatile XLLP_GPIO_T * v_pGPIORegs = NULL;  // used to access hardware bits for bkl on/off
volatile XLLP_PWM_T * v_pPWMRegs = NULL;  
volatile XLLP_CLKMGR_T * v_pClkMgr = NULL;


extern "C"
DWORD BacklightPowerUp()
{

    DEBUGMSG(ZONE_BACKLIGHT, (TEXT("BKL: BacklightPowerUp\r\n")));

    v_pGPIORegs->GPCR0 |= XLLP_GPIO_BIT_PWM_OUT0; // turn backlight off
    
    // set GPIO 16 Dir to output
    v_pGPIORegs->GPDR0 |= XLLP_GPIO_BIT_PWM_OUT0;

    // Set GPIO16 Alt Fn to 2
    v_pGPIORegs->GAFR0_U |= XLLP_GPIO_AF_BIT_PWM_OUT0;


    // Program the PWM0 registers
    v_pPWMRegs->pwmcr0 = 0x00000000; // Prescale = 1
    v_pPWMRegs->pwmpcr0 = 0xFF; // 256 clocks
    v_pPWMRegs->pwmdcr0 = 0x00;

    return TRUE;
}


//-----------------------------------------------------------------------------
//  Initialize hardware etc
//  Returned DWORD will be passed to BacklightDeInit and should be used to store context if necessary
//  pDeviceState should be set to the start state of the backlight (usually D0)
//

extern "C"
DWORD BacklightInit(LPCTSTR pContext, LPCVOID lpvBusContext, CEDEVICE_POWER_STATE *pDeviceState)
{
    PHYSICAL_ADDRESS PA;

    PA.QuadPart  = BULVERDE_BASE_REG_PA_CLKMGR;
    v_pClkMgr   = (volatile XLLP_CLKMGR_T *) MmMapIoSpace(PA, sizeof(XLLP_CLKMGR_T), FALSE);
    
    PA.QuadPart  = BULVERDE_BASE_REG_PA_PWM0_2;
    v_pPWMRegs   = (volatile XLLP_PWM_T *) MmMapIoSpace(PA, sizeof(XLLP_PWM_T), FALSE);

    PA.QuadPart  = BULVERDE_BASE_REG_PA_GPIO;
    v_pGPIORegs  = (volatile XLLP_GPIO_T *) MmMapIoSpace(PA, sizeof(XLLP_GPIO_T), FALSE);
    
    if (!v_pGPIORegs || !v_pPWMRegs)
    {
        return FALSE;
    }

    DEBUGMSG(ZONE_BACKLIGHT, (TEXT("BKL: Init\r\n")));

    *pDeviceState = D4;
    BacklightPowerUp();
    
    v_pPWMRegs->pwmdcr0 = 0x50;
    v_pClkMgr->cken |= 0x11;

    return TRUE;
}

extern "C"
void BacklightDeInit(DWORD dwContext)
{
    DEBUGMSG(ZONE_BACKLIGHT, (TEXT("BKL: De-Init\r\n")));
    if (v_pGPIORegs != NULL) {
       MmUnmapIoSpace((PVOID)v_pGPIORegs, sizeof(XLLP_GPIO_T));
    }
    if (v_pClkMgr != NULL) {
       MmUnmapIoSpace((PVOID)v_pClkMgr, sizeof(XLLP_CLKMGR_T));
    }
    if (v_pPWMRegs != NULL) {
       MmUnmapIoSpace((PVOID)v_pPWMRegs, sizeof(XLLP_PWM_T));
    }
    return;
}

extern "C"
BOOL BackLightSetState(DWORD dwContext, CEDEVICE_POWER_STATE state)
{
    // sets the backlight state (turns the backlight on and off)
    DEBUGMSG(1, (L"+BackLightSetState(0x%08x)\r\n", (DWORD) state));

    switch (state)
    {
        case D0:
            v_pClkMgr->cken |= 0x11;
            v_pPWMRegs->pwmdcr0 = 0x50; // 50% duty cycle
            DEBUGMSG(ZONE_FUNCTION, (L"+BackLightSetState - ON\r\n"));
            break;
        case D1:
        case D2:
        case D3:
        case D4:
            v_pPWMRegs->pwmdcr0 = 0x0; 
            v_pClkMgr->cken &= ~(0x11);
            DEBUGMSG(ZONE_FUNCTION, (L"+BackLightSetState - OFF\r\n"));
            break;
        default:
            RETAILMSG(ZONE_ERROR, (L"+BackLightSetState - Unsupported power state!\r\n"));
            return FALSE;
    }
    return TRUE;
}

extern "C"
UCHAR BacklightGetSupportedStates()
{
    return DX_MASK(D0) | DX_MASK(D4);     //support D0, D4 (ON, OFF)
}

extern "C"
DWORD BacklightIOControl(DWORD dwOpenContext, DWORD dwIoControlCode, LPBYTE lpInBuf, 
                   DWORD nInBufSize, LPBYTE lpOutBuf, DWORD nOutBufSize, 
                   LPDWORD lpBytesReturned)
{
    // For IOCTls that MDD doesn't know. ie non-pm IOCTLs
    return ERROR_NOT_SUPPORTED;
}

extern "C"
void BacklightRegChanged()
{
    // Called when the MDD gets a backlight registry changed event
    // eg: read brightness settings from registry and update backlight accordingly
    return;
}

extern "C"
void BacklightPwrSrcChanged(BOOL fOnAC)
{
    // Called when the MDD gets a power source changed (AC->DC or vice-versa) event
    // fOnAC will indicate whether the power source is now AC. TRUE->AC FALSE->Battery
    // eg: update brightness of backlight according to user settings
    return;
}


⌨️ 快捷键说明

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