📄 ms2_backlight.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.
//
//
//------------------------------------------------------------------------------
//
// File: ms2_backlight.c
//
// Backlight PDD driver source code, Mainstone-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
volatile XLLP_GPIO_T * v_pGPIORegs = NULL; // used to access hardware bits for bkl on/off
//-----------------------------------------------------------------------------
// 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 ioPhysicalBase = {BULVERDE_BASE_REG_PA_GPIO, 0 };
v_pGPIORegs = (volatile XLLP_GPIO_T *)MmMapIoSpace(ioPhysicalBase, sizeof(XLLP_GPIO_T),FALSE);
if (!v_pGPIORegs)
{
return FALSE;
}
DEBUGMSG(ZONE_BACKLIGHT, (TEXT("BKL: Init\r\n")));
v_pGPIORegs->GPCR0 |= XLLP_GPIO_BIT_PWM_OUT0; // turn backlight off
*pDeviceState = D4;
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));
}
return;
}
extern "C"
BOOL BackLightSetState(DWORD dwContext, CEDEVICE_POWER_STATE state)
{
// sets the backlight state (turns the backlight on and off)
DEBUGMSG(ZONE_FUNCTION, (L"+BackLightSetState(0x%08x)\r\n", (DWORD) state));
switch (state)
{
case D0:
v_pGPIORegs->GPSR0 |= XLLP_GPIO_BIT_PWM_OUT0;
DEBUGMSG(ZONE_FUNCTION, (L"+BackLightSetState - ON\r\n"));
break;
case D1:
case D2:
case D3:
case D4:
v_pGPIORegs->GPCR0 |= XLLP_GPIO_BIT_PWM_OUT0;
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 + -