📄 xllp_keypad.c
字号:
/******************************************************************************
**
** INTEL CONFIDENTIAL
** Copyright 2000-2004 Intel Corporation All Rights Reserved.
**
** The source code contained or described herein and all documents
** related to the source code (Material) are owned by Intel Corporation
** or its suppliers or licensors. Title to the Material remains with
** Intel Corporation or its suppliers and licensors. The Material contains
** trade secrets and proprietary and confidential information of Intel
** or its suppliers and licensors. The Material is protected by worldwide
** copyright and trade secret laws and treaty provisions. No part of the
** Material may be used, copied, reproduced, modified, published, uploaded,
** posted, transmitted, distributed, or disclosed in any way without Intel抯
** prior express written permission.
**
** No 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. Any license under such intellectual property rights
** must be express and approved by Intel in writing.
**
** FILENAME: xllp_keypad.c
**
** VALID FOR: MAINSTONE II platform with Fastap keypad
**
******************************************************************************/
#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: ReadDirectKeys
// Purpose: This function looks for any Thumbwheel movement or button press and returns a scan code.
// Returns: success/failure.
//---------------------------------------------------------------------------------------------------------------
XLLP_BOOL_T ReadDirectKeys(XLLP_KEYPAD_REGS *v_pKeyPadRegs,XLLP_UINT8_T *key)
{
XLLP_UINT32_T CurrCount,SaveKpRotaryEncoderCountReg;
static XLLP_UINT32_T PrevCount=START_VALUE;
XLLP_BOOL_T retval;
if(KP_Status & DIRECT_INTR_BIT)
{
SaveKpRotaryEncoderCountReg = v_pKeyPadRegs->kpRotaryEncoderCountReg;
CurrCount = SaveKpRotaryEncoderCountReg & COUNT_MASK;
if(SaveKpRotaryEncoderCountReg & OVERFLOW_ROTARY_ENC_0)
{
v_pKeyPadRegs->kpRotaryEncoderCountReg = START_VALUE;
PrevCount = START_VALUE;
*key = SCAN_CODE_SCROLL_UP; // Scroll Up
}
else if(SaveKpRotaryEncoderCountReg & UNDERFLOW_ROTARY_ENC_0)
{
v_pKeyPadRegs->kpRotaryEncoderCountReg = START_VALUE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -