📄 bspkeypad.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) 2004, Motorola Inc. All Rights Reserved
//
//------------------------------------------------------------------------------
//
// Copyright (C) 2004, Freescale Semiconductor, Inc. All Rights Reserved
// THIS SOURCE CODE IS CONFIDENTIAL AND PROPRIETARY AND MAY NOT
// BE USED OR DISTRIBUTED WITHOUT THE WRITTEN PERMISSION OF
// Freescale Semiconductor, Inc.
//
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//
// File: bspkeypad.c
//
// Provides BSP-specific configuration routines for the KPP peripheral.
// Implementation of the keyboard platform dependent scan code to
// Virtual Key mapping for keyboard driver.
//
// Exports ScanCodeToVKey for the PDD to use to map scan codes to virtual
// keys. A version of this will be needed for every physical/virtual key
// configuration.
//
//------------------------------------------------------------------------------
#include <windows.h>
#include <winuser.h>
#include <winuserm.h>
#include <ceddk.h>
#include <keybddr.h>
#include <laymgr.h>
#include <devicelayout.h>
#include "bsp.h"
#include "Keypad.hpp"
//------------------------------------------------------------------------------
// External Functions
//------------------------------------------------------------------------------
// External Variables
extern PCSP_KPP_REGS g_pKPP;
//------------------------------------------------------------------------------
// Defines
#define ScanCodeTableFirst 0x00
#define ScanCodeTableLast 0x3F
#define KEY_DEBOUNCE_PERIOD 40 // msec
#define MAX_KEY_EVENTS 16
#define KPP_COLUMN_INUSE 8
#define KPP_ROW_INUSE 8
#define KEY_NUMBER (KPP_COLUMN_INUSE*KPP_ROW_INUSE)
#define KPP_COLUMN_MASK ((0x1<<KPP_COLUMN_INUSE) -1)
#define KPP_ROW_MASK ((0x1<<KPP_ROW_INUSE) - 1)
#define VK_HOLD VK_APP3
//------------------------------------------------------------------------------
// Types
struct VirtualKeyMapping {
UINT32 uiVk;
UINT32 uiVkGenerated;
};
//------------------------------------------------------------------------------
// Global Variables
//------------------------------------------------------------------------------
// Local Variables
static volatile BOOL g_SysSuspend = FALSE;
static volatile BOOL g_bRestoreClocks = FALSE;
// This variable is global to this file because it
// will later be used in BSPKppPowerOff.
// Record of which keys were down the last time columns were scanned.
static UINT8 keyDown[KPP_COLUMN_INUSE];
static UINT32 prevDownTime[KEY_NUMBER]; // Time that the key went down.
static BOOL keyDownSent[KEY_NUMBER]; // Tells whether the key down event
// has already been passed up.
// Reset to false after key goes up.
static UINT8 kppStatus[KPP_COLUMN_INUSE]; // Row data from the last time
// columns were scanned.
// Copies of scan sequence variables used to store and restore
// key data in case system enters suspend state
static WORD g_wKPSRStored;
static UINT8 keyDownStored[KPP_COLUMN_INUSE];
static UINT32 prevDownTimeStored[KEY_NUMBER];
static BOOL keyDownSentStored[KEY_NUMBER];
static UINT8 kppStatusStored[KPP_COLUMN_INUSE];
UINT8 ScanCodeToVKeyTable[] =
{
//column 0
0,
0,
0,
0,
0,
0,
0,
0,
//column 1
0,
0,
VK_TAB, //SW3 HOLD
0,
0,
VK_TEND, //SW4 VK_APP1
0,
0,
//column 2
0,
0,
VK_BACK, //VK_VOLUME_DOWN, //SW2
VK_ESCAPE, //VK_VOLUME_UP, //SW1
VK_MENU, //VK_APP2, //SW5
0,
0,
0,
//column 3
0,
0,
0,
0,
0,
0,
VK_UP, //VK_RIGHT, //S1
0,
//column 4
0,
0,
0,
0,
0,
0,
VK_RIGHT, //VK_DOWN, //S1
0,
//column 5
0,
0,
0,
0,
0,
0,
VK_DOWN, //VK_LEFT, //S1
0,
//column 6
0,
0,
0,
0,
0,
0,
VK_LEFT, //VK_UP, //S1
0,
//column 7
0,
0,
0,
0,
0,
0,
0,
VK_RETURN, //S1
};
static ScanCodeToVKeyData scvkEngUS =
{
0,
ScanCodeTableFirst,
ScanCodeTableLast,
ScanCodeToVKeyTable
};
static ScanCodeToVKeyData *rgscvkKPPEngUSTables[] =
{
&scvkEngUS
};
// There is currently no Key Remapping being performed.
// If key remapping is needed, this structure definition
// will need to be moved down below the Remap function.
static DEVICE_LAYOUT dlKPPEngUs =
{
sizeof(DEVICE_LAYOUT),
KPP_PDD,
rgscvkKPPEngUSTables,
dim(rgscvkKPPEngUSTables),
NULL, //KPPUsRemapVKey,
};
//------------------------------------------------------------------------------
// Local Functions
BOOL BSPKppSetClockGatingMode(BOOL startClocks);
static UINT KppScanSequence(UINT32 rguiScanCode[16], BOOL rgfKeyUp[16], BOOL allowSysCalls);
static void KppRestoreRegState();
static void KppSaveRegState();
static void KppBusyWait(DWORD waitTime);
//------------------------------------------------------------------------------
//
// Function: KPPUsRemapVKey
//
// Remapping function for the keypad. Called from the layout manager.
// Returns the number of remapped events placed in pRmpKbdEvents
// Call with pRmpKbdEvents == NULL anc cMaxRmpKbdEvents == 0 to get the
// maximum size necessary for pRmpKbdEvents buffer.
//
// Parameters:
// pKbdEvents -
// [in] List of events to remap.
//
// cKbdEvents -
// [in] Count of events in pKbdEvents
//
// pRmpKbdEvents -
// [out] Buffer where remapped events will be placed
//
// cMaxRmpKbdEvents -
// [in] Maximum number of remapped events
//
// Returns:
// The number of remapped events.
//
//------------------------------------------------------------------------------
static UINT WINAPI KPPUsRemapVKey(
const KEYBD_EVENT *pKbdEvents,
UINT cKbdEvents,
KEYBD_EVENT *pRmpKbdEvents,
UINT cMaxRmpKbdEvents
)
{
static BOOL fFnDown = FALSE;
UINT cRmpKbdEvents = 0;
SETFNAME(_T("KPPUsRemapVKey"));
DEBUGMSG(ZONE_FUNCTION, (TEXT("++%s\r\n"), pszFname));
if (pRmpKbdEvents == NULL)
{
// 1 to 1 mapping
DEBUGCHK(cMaxRmpKbdEvents == 0);
return cKbdEvents;
}
DEBUGCHK(pKbdEvents != NULL);
if (cMaxRmpKbdEvents < cKbdEvents)
{
DEBUGMSG(ZONE_ERROR, (_T("%s: Buffer is not large enough!\r\n"),
pszFname));
return 0;
}
DEBUGMSG(ZONE_FUNCTION, (TEXT("--%s\r\n"), pszFname));
return cRmpKbdEvents;
}
//------------------------------------------------------------------------------
//
// Function: KPPLayout
//
// This function initializes the device layout for the EVB keypad.
//
// Parameters:
// None.
//
// Returns:
// TRUE if success, FALSE if failure.
//
//------------------------------------------------------------------------------
extern "C" BOOL KPPLayout(PDEVICE_LAYOUT pDeviceLayout)
{
BOOL fRet = FALSE;
DEBUGCHK(pDeviceLayout != NULL);
if (pDeviceLayout->dwSize != sizeof(DEVICE_LAYOUT))
{
RETAILMSG(1, (_T("KPPLayout: data structure size mismatch\r\n")));
goto Leave;
}
// Make sure that the Sc->Vk tables are the sizes that we expect
DEBUGCHK(dim(ScanCodeToVKeyTable) == (1 + ScanCodeTableLast - ScanCodeTableFirst));
*pDeviceLayout = dlKPPEngUs;
fRet = TRUE;
Leave:
return fRet;
}
#ifdef DEBUG
// Verify function declaration against the typedef.
static PFN_DEVICE_LAYOUT_ENTRY v_pfnDeviceLayout = KPPLayout;
#endif
//------------------------------------------------------------------------------
//
// Function: BSPKppRegInit
//
// Initializes the keypad port registers.
//
// Parameters:
// None.
//
// Returns:
// None.
//
//------------------------------------------------------------------------------
void BSPKppRegInit()
{
KPP_FUNCTION_ENTRY();
// Enable KPP clocks to access KPP registers
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -