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

📄 bspkeypad.cpp

📁 freescale i.mx31 BSP CE5.0全部源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
//------------------------------------------------------------------------------
//
// 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)

//------------------------------------------------------------------------------
// 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
#ifdef PLAT_PMC
    VK_RETURN,     //SW60
#else
    VK_TACTION,    //SW60
#endif
    VK_TSOFT1,     //SW11
    VK_T3,         //SW19
    VK_T9,         //SW27
    'A',           //SW35
    VK_TAB,        //SW43
    'B',           //SW51
    VK_SPACE,      //SW59

    //column 1
//    VK_UP,         //SW60 // Commented out because this was
                            // changed when the hardware did not
                            // match up with the ZAS EVB keypad
                            // schematic
    VK_LEFT,         //SW60
    VK_TTALK,      //SW10
    VK_T2,         //SW18
    VK_TPOUND,     //SW26
    'S',           //SW34
    VK_SYMBOL,     //SW42
    'H',           //SW50
#ifdef PLAT_PMC
    VK_OFF,        //SW58
#else
    VK_MENU,       //SW58  // Hack to allow use of the "ALT" key,
                          // which provides more power to
                          // navigate WinCE in the absence of 
                          // touch support.
#endif

    //column 2
//    VK_RIGHT,      //SW60
    VK_DOWN,       //SW60
#ifdef PLAT_PMC
    VK_HOME,       //SW9
#else
    VK_THOME,      //SW9
#endif
    VK_T1,         //SW17
    VK_T8,         //SW25
    'D',           //SW33
    VK_CAPITAL,    //SW41
    'N',           //SW49
    VK_PERIOD,     //SW57

    //column 3
//    VK_DOWN,       //SW60
    VK_RIGHT,      //SW60
#ifdef PLAT_PMC
    VK_F1,         //SW8
#else
    VK_APP1,       //SW8
#endif
    VK_T4,         //SW16
    VK_T0,         //SW24
    'E',           //SW32
    'Z',           //SW40
    'M',           //SW48
    VK_RETURN,     //SW56

    //column 4
//    VK_LEFT,       //SW60
    VK_UP,       //SW60
#ifdef PLAT_PMC
    VK_VOLUME_UP,  //SW7
    VK_VOLUME_DOWN,//SW15
#else
    VK_TVOLUMEUP,  //SW7
    VK_TVOLUMEDOWN,//SW15
#endif
    VK_TSTAR,      //SW23
    'F',           //SW31
    'X',           //SW39
    'J',           //SW47
    'L',           //SW55

    //column 5
    VK_TSOFT2,     //SW3
#ifdef PLAT_PMC
    VK_F2,         //SW6
#else
    VK_APP2,       //SW6
#endif
    VK_T7,         //SW14
    VK_TRECORD,    //SW22
    'R',           //SW30
    'C',           //SW38
    'K',           //SW46
    VK_BACK,       //SW54

    //column 6
    VK_TEND,       //SW2
#ifdef PLAT_PMC
    VK_F3,         //SW5
#else
    VK_APP3,       //SW5
#endif
    VK_T5,         //SW13
    'Q',           //SW21
    'T',           //SW29
    'V',           //SW37
    'U',           //SW45
    'P',           //SW53

    //column 7
#ifdef PLAT_PMC
    VK_BACK,       //SW1
    VK_F4,         //SW4
#else
    VK_TBACK,      //SW1
    VK_APP4,       //SW4
#endif
    VK_T6,         //SW12
    'W',           //SW20
    'Y',           //SW28
    'G',           //SW36
    'I',           //SW44
    'O',           //SW52
};

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))

⌨️ 快捷键说明

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