📄 xllp_keypad.c
字号:
//
// 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 1999-2001 Intel Corp. */
#include "xllp_keypad.h"
#include "xllp_gpio.h"
//#include "windows.h"
static XLLP_UINT32_T XllpKpdGpioDirOutList[]={7,96,103,104,105,106,107,108};
static XLLP_UINT32_T XllpKpdGpioDirInList[]={9,93,94,95,97,98,99,100,101,102};
static XLLP_UINT32_T XllpKpdGpioAltFnPinList[]={16,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108};
static XLLP_UINT32_T XllpKpdGpioAltFnValList[]={16,1,1,3,3,3,3,3,1,1,1,2,2,2,2,2,2};
static XLLP_UINT32_T XllpKpdGpioDirNonScrollWheelInList[]={7,95,97,98,99,100,101,102};
XLLP_UINT32_T KP_Status;
//#define NMD
//---------------------------------------------------------------------------------------------------------------
// Function: ReadScanCodeAutomatically
// Purpose: This functions reads the scan code from the KeyPad controller triggered by setting of the ASACT bit
// in the KeyPad Control register. If there is a valid key detected then it returns the scan code.
// Returns: success/failure.
//---------------------------------------------------------------------------------------------------------------
XLLP_BOOL_T ReadScanCodeAutomatically(XLLP_KEYPAD_REGS *v_pKeyPadRegs,XLLP_UINT8_T *key)
{
XLLP_BOOL_T retval=XLLP_FALSE;
XLLP_UINT32_T C,R,RthBit,c0,c1,c2,c3,c4,c5,c6,c7;
XLLP_UINT32_T numOfKeysPressed=0;
if(KP_Status & MATRIX_INTR_BIT)
{
numOfKeysPressed = ((v_pKeyPadRegs->kpAutomaticScanReg & MULTI_KEYS_PRESS) >> 26);
// RETAILMSG(1,(TEXT("XLLP:ReadScanCodeAutomatically numOfKeysPressed %x>\r\n"),numOfKeysPressed));
// checks to see if it was a "Major" key that was pressed
if(numOfKeysPressed == 1)
{
C = (v_pKeyPadRegs->kpAutomaticScanReg & COL_SELECTED_MASK);
R = (v_pKeyPadRegs->kpAutomaticScanReg & ROW_SELECTED_MASK);
*key = (unsigned char) (C | R);
}
else
// if it was a "Minor" key, then more than one key was activated and that is how
// you can determine which register to read from.
if(numOfKeysPressed > 1)
{
c0 = v_pKeyPadRegs->kpAutoScanMultiKeyPress0 & 0xFF;
c1 = ((v_pKeyPadRegs->kpAutoScanMultiKeyPress0 >> 16) & 0xFF);
c2 = v_pKeyPadRegs->kpAutoScanMultiKeyPress1 & 0xFF;
c3 = ((v_pKeyPadRegs->kpAutoScanMultiKeyPress1 >> 16) & 0xFF);
c4 = v_pKeyPadRegs->kpAutoScanMultiKeyPress2 & 0xFF;
c5 = ((v_pKeyPadRegs->kpAutoScanMultiKeyPress2 >> 16) & 0xFF);
c6 = v_pKeyPadRegs->kpAutoScanMultiKeyPress3 & 0xFF;
c7 = ((v_pKeyPadRegs->kpAutoScanMultiKeyPress3 >> 16) & 0xFF);
// these keys are the "minor keys", the ones that needs top right and bottom left of the
// cooresponding 4 keys surrounding them to trigger the correct key. Doing a binary search
// there are 5 keys, the middle key reads 0x8, the first key reads 0x2 and the last reads 0x20.
// this needs to be done for each row. This will be encorporated into a routine for the next
// upgrade of keypad.
if(c0!=0)
{
C = 0x7;
if(c0 == 0x8)
{
RthBit = 0x2;
}
else
if(c0 > 0x8)
{
if (c0 < 0x20)
RthBit = 0x3;
else
RthBit = 0x4;
}else
{
if (c0 > 0x2)
RthBit = 0x1;
else
RthBit = 0x0;
}
}else
if(c1!=0)
{
C = 0x8;
if(c1 == 0x8)
{
RthBit = 0x2;
}
else
if(c1 > 0x8)
{
if (c1 < 0x20)
RthBit = 0x3;
else
RthBit = 0x4;
}else
{
if (c1 > 0x2)
RthBit = 0x1;
else
RthBit = 0x0;
}
}else
if(c2!=0)
{
C = 0x9;
if(c2 == 0x8)
{
RthBit = 0x2;
}
else
if(c2 > 0x8)
{
if (c2 < 0x20)
RthBit = 0x3;
else
RthBit = 0x4;
}else
{
if (c2 > 0x2)
RthBit = 0x1;
else
RthBit = 0x0;
}
}else
if(c3!=0)
{
C = 0xa;
if(c3 == 0x8)
{
RthBit = 0x2;
}
else
if(c3 > 0x8)
{
if (c3 < 0x20)
RthBit = 0x3;
else
RthBit = 0x4;
}else
{
if (c3 > 0x2)
RthBit = 0x1;
else
RthBit = 0x0;
}
}else
if(c4!=0)
{
C = 0xb;
if(c4 == 0x8)
{
RthBit = 0x2;
}
else
if(c4 > 0x8)
{
if (c4 < 0x20)
RthBit = 0x3;
else
RthBit = 0x4;
}else
{
if (c4 > 0x2)
RthBit = 0x1;
else
RthBit = 0x0;
}
}
*key = (unsigned char) ((C<<4) | RthBit);
}
else
*key = NO_KEY;
// RETAILMSG(1,(TEXT("R is %x C is %x key is %x\r\n"), RthBit,C,*key));
retval = XLLP_TRUE;
}
// RETAILMSG(1,(TEXT("ReadScanCodeAutomatically<\r\n")));
return(retval);
}
//---------------------------------------------------------------------------------------------------------------
// Function: XllpKpKeypressIsInProgress
// Purpose: This function reports nonzero if the keypad is currently active during a keypress.
// (Keypress active as indicated by non-rotary DKIN levels high, any MKIN levels high
// or any MKOUT levels low (indicates scan is active))
//
// Note: It cannot detect the debouncing of a complete key up event. Therefore, full
// protection from performing conflicting actions during keypad activity must include
// support from higher level software. (One example is avoiding entering Standby while
// a key release is being debounced because the key release detection could be lost.)
//
// Returns: nonzero ("true") / zero ("false")
// Limitations: Platform-specific because it requires complete knowledge of keypad configuration
//---------------------------------------------------------------------------------------------------------------
XLLP_UINT32_T XllpKpKeypressIsInProgress (XLLP_GPIO_T *v_pGPIOReg)
{
// Note that GPIOs used here only include MKOUTs, MKINs and non-rotary DKINs.
static XLLP_BOOL_T xllpKpKIP_Initialized = XLLP_FALSE;
static XLLP_UINT32_T gplr0_InPinMask, gplr0_OutPinMask, gplr0_AllPinsMask,
gplr1_InPinMask, gplr1_OutPinMask, gplr1_AllPinsMask,
gplr2_InPinMask, gplr2_OutPinMask, gplr2_AllPinsMask,
gplr3_InPinMask, gplr3_OutPinMask, gplr3_AllPinsMask;
XLLP_UINT32_T i;
XLLP_UINT32_T gpioRegTmp;
XLLP_UINT32_T activity = 0;
// Set up masks only once. Do this in code rather than precalculation to expose
// the algorithm and make it easily re-usable. Perform full init because fairly
// fast and only done once.
if (!xllpKpKIP_Initialized)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -