📄 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 OR INDEMNITIES.
//
/* Copyright 1999-2001 Intel Corp. */
#include <windows.h>
#include "xllp_keypad.h"
#include "xllp_gpio.h"
XLLP_UINT32_T KP_Status;
//#define NMD
static XLLP_UINT32_T GetRNumber(XLLP_UINT32_T x)
{
XLLP_UINT32_T th=0, i;
for (i=0; i<8; i++)
th += (x > i) * i;
return th;
}
//---------------------------------------------------------------------------------------------------------------
// 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, Col;
// XLLP_UINT32_T C,R,RthBit,c0,c1,c2,c3,c4,c5,c6,c7,Col;
XLLP_UINT32_T numOfKeysPressed=0;
if(!(KP_Status & MATRIX_INTR_BIT))
{
return retval;
}
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(numOfKeysPressed == 2)
{
C = (v_pKeyPadRegs->kpAutomaticScanReg & COL_SELECTED_MASK);
R = (v_pKeyPadRegs->kpAutomaticScanReg & ROW_SELECTED_MASK);
*key = (unsigned char) (C | R);
RETAILMSG(1,(L"auto scan:%d R is %x C is %x key is %x\r\n", numOfKeysPressed, R,C,*key));
Col = v_pKeyPadRegs->kpAutoScanMultiKeyPress0 & 0xFFFFFF;
if (Col)
{
RETAILMSG(1,(L"1: 0x%x \r\n", Col));
if (Col & 0xFF)
{
C = 0;
R = GetRNumber(Col);
}
else
{
C = 1;
R = GetRNumber(Col >> 16);
}
*key = (unsigned char)((C << 4)| R);
goto scan_exit;
}
Col = v_pKeyPadRegs->kpAutoScanMultiKeyPress1 & 0xFFFFFF;
if (Col)
{
RETAILMSG(1,(L"2: 0x%x \r\n", Col));
if (Col & 0xFF)
{
C = 2;
R = GetRNumber(Col);
}
else
{
C = 3;
R = GetRNumber(Col >> 16);
}
*key = (unsigned char)((C << 4)| R);
goto scan_exit;
}
Col = v_pKeyPadRegs->kpAutoScanMultiKeyPress2 & 0xFFFFFF;
if (Col)
{
RETAILMSG(1,(L"3: 0x%x \r\n", Col));
if (Col & 0xFF)
{
C = 4;
R = GetRNumber(Col);
}
else
{
C = 5;
R = GetRNumber(Col >> 16);
}
*key = (unsigned char)((C << 4)| R);
goto scan_exit;
}
Col = v_pKeyPadRegs->kpAutoScanMultiKeyPress3 & 0xFFFFFF;
if (Col)
{
RETAILMSG(1,(L"4: 0x%x \r\n", Col));
if (Col & 0xFF)
{
C = 6;
R = GetRNumber(Col);
}
else
{
C = 7;
R = GetRNumber(Col >> 16);
}
*key = (unsigned char)((C << 4)| R);
goto scan_exit;
}
}
else
{
C = 0xF;
R = 0xF;
// *key = NO_KEY;
}
scan_exit:
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;
PrevCount = START_VALUE;
*key = SCAN_CODE_SCROLL_DOWN; // Scroll Down
}
else if(CurrCount > PrevCount)
{
*key = SCAN_CODE_SCROLL_UP;
PrevCount = CurrCount; // Scroll Up
}
else if(CurrCount < PrevCount)
{
*key = SCAN_CODE_SCROLL_DOWN;
PrevCount = CurrCount; // Scroll Down
}
else if(v_pKeyPadRegs->kpDirectKeyReg & DIRECT_KEY_IN_2)
{
*key = SCAN_CODE_ACTION; // Action Key
}
retval = XLLP_TRUE; // Signal availability
}
else
{
retval = XLLP_FALSE;
}
return(retval);
}
//---------------------------------------------------------------------------------------------------------------
// Function: XllpReadScanCode
// Purpose:
// Returns:
//---------------------------------------------------------------------------------------------------------------
XLLP_BOOL_T XllpReadScanCode(XLLP_KEYPAD_REGS *v_pKeyPadRegs,XLLP_UINT8_T *pui8Data)
{
// Initialise to NO Key scan code, same as key UP
XLLP_UINT8_T key = NO_KEY;
// if(!ReadDirectKeys(v_pKeyPadRegs,&key))
// Plato keypad doesn't use direct keypad interface
ReadScanCodeAutomatically(v_pKeyPadRegs,&key);
// Assign the Key Here
*pui8Data = key;
if(*pui8Data == NO_KEY)
return(XLLP_FALSE);
else
return(XLLP_TRUE); // Enjoy
}
//---------------------------------------------------------------------------------------------------------------
// Function: XllpSetUpKeyPadInterrupts
// Purpose: This function will Enable/Disable the Interrupts.
// Returns: success/failure.
//---------------------------------------------------------------------------------------------------------------
XLLP_BOOL_T XllpSetUpKeyPadInterrupts(XLLP_KEYPAD_REGS *v_pKeyPadRegs,XLLP_BOOL_T fEnDis)
{
KP_Status = v_pKeyPadRegs->kpControlReg;
if(fEnDis)
{
// EN_DIRECT_KEYS_INTR();
EN_MAT_KEYS_INTR();
}
else
{
// DISABLE_DIRECT_KEYS_INTR();
DISABLE_MAT_KEYS_INTR();
}
return(XLLP_TRUE);
}
//-----------------------------------------------------------------------------------------
// Function: XllpKeyPadConfigure
// Purpose: This function configures the KeyPad Controller on the RV TEC with the
// appropriate settings.
// Returns: success/failure.
//------------------------------------------------------------------------------------------
// PIN# GPIO PIN NAME DIRECTION ALTERNATE FUNCTION
//
// 97 KP_MKIN_3 Input 3
// 98 KP_MKIN_4 Input 3
// 99 KP_MKIN_5 Input 1
// 100 KP_MKIN_0 Input 1
// 101 KP_MKIN_1 Input 1
// 102 KP_MKIN_2 Input 1
//
// 96 KP_MKOUT_6 Output 3
// 104 KP_MKOUT_1 Output 2
// 105 KP_MKOUT_2 Output 2
// 106 KP_MKOUT_3 Output 2
// 107 KP_MKOUT_4 Output 2
// 108 KP_MKOUT_5 Output 2
//
//--------------------------------------------------------------------------------------------
XLLP_BOOL_T XllpKeyPadConfigure(XLLP_KEYPAD_REGS *v_pKeyPadRegs,XLLP_GPIO_T *v_pGPIOReg)
{
XLLP_BOOL_T retval=XLLP_FALSE;
XLLP_UINT32_T GpioDirOutList[]={6,96,104,105,106,107,108};
XLLP_UINT32_T GpioDirInList[]={6,97,98,99,100,101,102};
XLLP_UINT32_T GpioAltFnPinList[]={12,96,97,98,99,100,101,102,104,105,106,107,108};
XLLP_UINT32_T GpioAltFnValList[]={12, 3, 3, 3, 1, 1, 1, 1, 2, 2, 2, 2, 2};
if(v_pGPIOReg != 0)
{
XllpGpioSetDirectionIn(v_pGPIOReg, GpioDirInList);
XllpGpioSetDirectionOut(v_pGPIOReg, GpioDirOutList);
XllpGpioSetOutputState1(v_pGPIOReg, GpioDirOutList);
// XllpGpioSetOutput0(v_pGPIOReg, GpioDirOutList);
XllpGpioSetAlternateFn(v_pGPIOReg, GpioAltFnPinList, GpioAltFnValList);
}
if(v_pKeyPadRegs != 0)
{
// Init the control regs for direct keys
v_pKeyPadRegs->kpControlReg = (MATRIX_KP_NUMBER_OF_ROWS | MATRIX_KP_NUMBER_OF_COLUMNS |
// IGNORE_MULTIPLE_KEY_PRESS |
AUTO_SCAN_ON_ACTIVITY |
MATRIX_INTR_ENABLE | //DIRECT_INTR_BIT |
MAT_SCAN_LINE0 | MAT_SCAN_LINE1 | MAT_SCAN_LINE2 | MAT_SCAN_LINE3 |
MAT_SCAN_LINE4 | MAT_SCAN_LINE5 | MAT_SCAN_LINE6 | MAT_SCAN_LINE7 |
MATRIX_KP_ENABLE) ; //NMD
// v_pKeyPadRegs->kpRotaryEncoderCountReg = START_VALUE;
v_pKeyPadRegs->kpKeyDebounceInterval = MAINSTONE_KP_DEBOUNCE_INTERVAL;
retval = XLLP_TRUE;
}
return(retval);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -