📄 keypad.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.
//
/******************************************************************************
**
** Copyright 2000-2004 Intel Corporation All Rights Reserved.
**
** Portions of the source code contained or described herein and all documents
** related to such source code (Material) are owned by Intel Corporation
** or its suppliers or licensors and is licensed by Microsoft Corporation for distribution.
** Title to the Material remains with Intel Corporation or its suppliers and licensors.
** Use of the Materials is subject to the terms of the Microsoft license agreement which accompanied the Materials.
** No other license under any patent, copyright, trade secret or other intellectual
** property right is granted to or conferred upon you by disclosure or
** delivery of the Materials, either expressly, by implication, inducement,
** estoppel or otherwise
** Some portion of the Materials may be copyrighted by Microsoft Corporation.
**
** Module Name: keypad.cpp
**
** Abstract:
** This file implements much of the generic processing for the built-in
** keypad of an Intel(c) platform, conforming to the Layout Manager
** Interface
**
/*****************************************************************************/
#include <windows.h>
#include <ceddk.h>
#include <nkintr.h>
#include <oal_intr.h>
#include <winuserm.h>
#include <keybddbg.h>
#include <keybdpdd.h>
#include <keybdist.h>
// Processor Definitions
#include <bulverde.h>
// Platform Definitions
#include <mainstoneii.h>
#include <oal.h>
#include <bsp_cfg.h>
#include <xllp_gpio.h>
#include <keypad.hpp>
// Do not have IPM yet
#define BSP_NOIPM 1
#ifndef BSP_NOIPM
#include "IPM_DrvCommon.h"
#endif
KeyPad *v_pKpd = NULL;
UINT v_uiPddId;
PFN_KEYBD_EVENT v_pfnKeybdEvent;
extern const UINT8 XllpScanCodeToWinCeScanCodeTable[XLLP_SCAN_CODE_MAX+1];
const DWORD gIntrKeyboard = SYSINTR_KEYPAD;
PFN_KEYBD_EVENT v_pfnKeyPadEvent;
static volatile BULVERDE_CLKMGR_REG *g_pClockRegs = NULL;
static volatile BULVERDE_GPIO_REG *g_pGPIORegs = NULL;
static volatile BULVERDE_KEYPAD_REG *g_pKeyPadRegs = NULL;
static volatile BULVERDE_OST_REG *g_pOSTRegs = NULL;
extern "C" PVOID VirtualAllocCopy(unsigned size,char *str,PVOID pVirtualAddress);
#define VOL_UP_DOWN_THRESHOLD 3
HANDLE hKeepAliveEvent;
HANDLE hSharedMap_init;
#ifndef BSP_NOIPM
#define IPM_SHARED_FILENAME (TEXT("IPMGlobalsFile"))
volatile IPM_GLOBALS *v_pIPMGlobals = NULL;
#endif
#ifndef BSP_NOIPM
void IPM_KeyPadInit(void)
{
NKDbgPrintfW(TEXT("Inside IPM Keypad Init\r\n"));
//
// An Event to signal IPM that there has been activity and immidiately leave its low power state.
//
hKeepAliveEvent = CreateEvent(NULL, FALSE, FALSE, KEEP_ALIVE_STR);
//
// Used to tell IPM which driver has timed out.
//
hSharedMap_init = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE,
0, sizeof(IPM_GLOBALS), IPM_SHARED_FILENAME );
// Get a valid process pointer to the buffer mapped above.
v_pIPMGlobals = (volatile IPM_GLOBALS *)MapViewOfFile( hSharedMap_init, FILE_MAP_ALL_ACCESS, 0, 0, 0 );
}
void IPM_RegisterKeyPadActivity(void)
{
v_pIPMGlobals->DeviceTimeOutTimes[DEVICE_KEYPAD] = GetTickCount();
//
// Signal IPM of keypad Activity only if need be
//
if((v_pIPMGlobals->ProcessorState == PROC_STANDBY) || (v_pIPMGlobals->ProcessorState == THIRTEEN_M))
SetEvent(hKeepAliveEvent);
} // IPM_RegisterKeyPadActivity()
#endif // ndef BSP_NOIPM
#ifndef XLLP_KP_SC_INVALID_KEY
#define XLLP_KP_SC_INVALID_KEY 0xFE
#endif // ndef XLLP_KP_SC_INVALID_KEY
#ifndef XLLP_KP_SC_NO_KEY
#define XLLP_KP_SC_NO_KEY 0xFF
#endif // ndef XLLP_KP_SC_NO_KEY
static UINT KeyPadPdd_GetEventEx2(
UINT uiPddId,
UINT32 rguiScanCode[16],
BOOL rgfKeyUp[16]
)
{
SETFNAME(_T("KeypadPdd_GetEventEx2"));
static UINT8 scPrevious = 0 ;
static UINT8 sc0xACount = 0 ;
static UINT8 sc0xBCount = 0 ;
BOOL processThisKeyStroke = XLLP_TRUE;
BOOL fKeyUp = XLLP_FALSE; // default to keydown
UINT8 ui8Data;
UINT cEvents = 0;
UINT32 rguiScanCodeLocal;
DEBUGCHK(rguiScanCode != NULL);
DEBUGCHK(rgfKeyUp != NULL);
v_pKpd->KeyPadDataRead(&ui8Data);
//DEBUGMSG(1, (TEXT("keypress happens: 0x%x\r\n"), ui8Data));
#ifndef BSP_NOIPM
IPM_RegisterKeyPadActivity();
#endif
// Have to divide down the scroll wheel. And longer debounce
// time is the wrong approach because of the way the keypad
// interface and scroll wheel work.
if (0x0A == ui8Data)
{
sc0xBCount = 0;
if (VOL_UP_DOWN_THRESHOLD >= ++sc0xACount)
{
processThisKeyStroke = XLLP_FALSE;
}
else
{
sc0xACount = 0;
}
} else if (0x0B == ui8Data)
{
sc0xACount = 0;
if (VOL_UP_DOWN_THRESHOLD >= ++sc0xBCount)
{
processThisKeyStroke = XLLP_FALSE;
}
else
{
sc0xBCount = 0;
}
} // else if (0x0B == ui8Data)
// Leave next test out of conditional compilation for simplicity.
// It is optimized out if BSP_MAINSTONE is not #defined.
if (XLLP_TRUE == processThisKeyStroke)
{
if (XLLP_KP_SC_INVALID_KEY == ui8Data) {
// Some input that could not be disambiguated.
// We'll tell the OS that it was a key-up?, but
// IPM will need to know that it wasn't really.
DEBUGMSG(1, (TEXT("Invalid key: 0x%x\r\n"), ui8Data));
} else {
// Not an invalid but real keypress. This is the real thing.
if (XLLP_KP_SC_NO_KEY == ui8Data)
{
fKeyUp = XLLP_TRUE;
ui8Data = scPrevious; // Use last key down code for keyup. Sending the 0xFF kills keyup recognition
}
else
{
scPrevious = ui8Data;
}
// Need the extra transform to get non-AT keyboard key mappings through the system.
rguiScanCodeLocal = XllpScanCodeToWinCeScanCodeTable[ui8Data];
//DEBUGMSG(1, (TEXT("KeyPadPdd_GetEventEx2 uid 0x%X, rSCL 0x%X\r\n"), ui8Data, rguiScanCodeLocal));
if (((UNIQUE_KEY_SC_RAW_MIN -1) < rguiScanCodeLocal )
&& ((UNIQUE_KEY_SC_RAW_MAX+1) > rguiScanCodeLocal ))
{
// Tighten up the table while adding the marker
rguiScanCodeLocal = (rguiScanCodeLocal - UNIQUE_KEY_SC_RAW_MIN) | UNIQUE_KEY_SC_PREPEND_MSK;
//DEBUGMSG(1,(TEXT("UniqueKey\r\n")));
}
rguiScanCode[cEvents] = rguiScanCodeLocal;
rgfKeyUp[cEvents] = fKeyUp;
++cEvents;
//DEBUGMSG(1, (TEXT("KeyPadPdd_GetEventEx2 sc 0x%X, rguiScanCodeLocal 0x%X, keyup %d, count %d\r\n"), ui8Data, rguiScanCodeLocal, fKeyUp, cEvents));
// Mainstone II has a rocker input for vol up /down that doesn't generate
// key up, so we have to simulate it.
if ((0x0A == ui8Data) || (0x0B == ui8Data))
{
//DEBUGMSG(1, (TEXT("faking keyup for 0x%X"),ui8Data));
fKeyUp = XLLP_TRUE;
ui8Data = scPrevious; // Use last key down code for keyup. Sending the 0xFF kills keyup recognition
rguiScanCodeLocal = XllpScanCodeToWinCeScanCodeTable[ui8Data];
rguiScanCode[cEvents] = rguiScanCodeLocal;
rgfKeyUp[cEvents] = fKeyUp;
++cEvents;
}
}
} // (XLLP_TRUE == processThisKeyStroke)
//DEBUGMSG(1, (TEXT("event count = %d"),cEvents));
return cEvents;
} // KeypadPdd_GetEventEx2()
BOOL KeyPad::KeyPadDataRead(UINT8 *pui8Data)
{
BOOL bRet = FALSE;
// Disable the keypad interrupt.
XllpSetUpKeyPadInterrupts((XLLP_KEYPAD_REGS *)g_pKeyPadRegs, (XLLP_BOOL_T) XLLP_KPD_INT_DISABLE);
// Read the keypad scan code.
bRet = (XllpReadScanCode((XLLP_KEYPAD_REGS *)g_pKeyPadRegs, pui8Data) == XLLP_TRUE ? TRUE : FALSE);
// Enable the keypad interrupt.
XllpSetUpKeyPadInterrupts((XLLP_KEYPAD_REGS *)g_pKeyPadRegs, (XLLP_BOOL_T) XLLP_KPD_INT_ENABLE);
return(bRet);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -