📄 hw_rm970key.c
字号:
/******************************************************************/
/* Copyright (C) 2007 ROCK-CHIPS FUZHOU . All Rights Reserved. */
/*******************************************************************
File : hw_keyboard.c
Desc : 扫描按键消息\接口函数的实现
Author : huangxinyu
Date : 2007-07-05
Notes :
$Log: hw_Rm970key.c,v $
Revision 1.4 2008/06/25 06:24:02 HSL
修改按键检测流程,按键检测统一集中在 RockKeyScanning 函数里面.
Revision 1.3 2008/06/23 09:54:05 HSL
增加 AD按键的支持,修改按键消息发送和长按检测接口.
Revision 1.2 2008/06/19 04:43:32 Administrator
代码整理!
Revision 1.1.1.1 2008/05/07 04:15:08 Administrator
no message
Revision 1.1.1.1 2008/03/06 13:29:05 Lingzhaojun
no message
Revision 1.1 2007/12/24 07:58:05 Lingzhaojun
同步蓝魔版本基本模块
Revision 1.1.1.1 2007/12/19 09:39:45 Lingzhaojun
no message
Revision 1.2 2007/12/14 15:09:29 Hanjiang
rm972 pp后的版本上传
Revision 1.1.1.1 2007/12/11 14:19:29 cvsadmin
no message
Revision 1.1.1.1 2007/12/01 01:30:06 Lingzhaojun
no message
Revision 1.1 2007/11/26 14:30:11 Huangxinyu
改变matrixkey目录
Revision 1.10 2007/11/23 07:32:10 Huangshilin
no message
Revision 1.9 2007/11/07 13:28:05 Huangxinyu
两个按键同时按下问题的修改
Revision 1.8 2007/11/01 01:46:14 Huangxinyu
增加RK2706的兼容性
Revision 1.7 2007/10/24 09:20:06 Huangxinyu
根据LCD管脚冲突情况重新修改阵列按键
Revision 1.6 2007/10/20 04:46:31 Huangshilin
for RK2700
Revision 1.5 2007/10/16 04:16:49 Huangxinyu
阵列键盘调试完成提交
Revision 1.4 2007/10/15 09:16:37 Huangxinyu
根据RK27提交修改driver
Revision 1.3 2007/10/08 02:38:45 Lingzhaojun
添加版本自动注释脚本
*********************************************************************/
#include "include.h"
#include "hw_include.h"
#include "hw_Rm970key.h"
#include "hw_gpio.h"
#include "hw_serial.h"
#include "hw_timer.h"
#if (KEY_TYPE == RM970KEY)
static UINT8 gKeyPioState; /* 用于记录GPIO口用作keyboard之前的状态,在反初始化时可恢复 */
// gKeyPortValue[x][y] 的 x 用于记录上次按键和本次按键的状态 , y 用于记录MatrixKey_COL_1\MatrixKey_COL_2\MatrixKey_COL_3的按下值
UINT8 gKeyPortValue[2][3] = { {0x00, 0x00, 0x00}, {0x00, 0x00, 0x00} }; /* 用于记录 按键 PIO 的状态,相应位为高表示按下,相应位为低表示没有按下或弹起 */
UINT8 gKeyPlayOnState = 0 ;
#if (CHIPTYPE == RK2700)
#define MatrixKey_ROW_1 GPIOPortA_Pin7
#define MatrixKey_ROW_2 GPIOPortC_Pin6
#define MatrixKey_ROW_3 GPIOPortC_Pin5
#define MatrixKey_COL_1 GPIOPortC_Pin4
#define MatrixKey_COL_2 GPIOPortC_Pin3
#define MatrixKey_COL_3 GPIOPortC_Pin2
#define MatrixKey_COL_PORT GPIOPortC
#define MatrixKey_COL_SHIFT 2
#define MatrixKey_COL_MASK 0x7
#elif(CHIPTYPE == RK2706)
#define MatrixKey_ROW_1 GPIOPortC_Pin4
#define MatrixKey_ROW_2 GPIOPortC_Pin5
#define MatrixKey_ROW_3 GPIOPortC_Pin6
#define MatrixKey_COL_1 GPIOPortC_Pin3
#define MatrixKey_COL_2 GPIOPortC_Pin2
#define MatrixKey_COL_3
#define MatrixKey_COL_PORT GPIOPortC
#define MatrixKey_COL_SHIFT 2
#define MatrixKey_COL_MASK 0x3
#elif defined(LDK)
#define MatrixKey_ROW_1 GPIOPortA_Pin4
#define MatrixKey_ROW_2 GPIOPortA_Pin5
#define MatrixKey_ROW_3 GPIOPortA_Pin6
#define MatrixKey_COL_1 GPIOPortA_Pin3
#define MatrixKey_COL_2 GPIOPortA_Pin2
#define MatrixKey_COL_3 GPIOPortA_Pin1
#define MatrixKey_COL_PORT GPIOPortA
#define MatrixKey_COL_SHIFT 1
#define MatrixKey_COL_MASK 0x7
#else
#define MatrixKey_ROW_1
#define MatrixKey_ROW_2
#define MatrixKey_ROW_3
#define MatrixKey_COL_1
#define MatrixKey_COL_2
#define MatrixKey_COL_3
#define MatrixKey_COL_PORT
#define MatrixKey_COL_SHIFT
#define MatrixKey_COL_MASK
#endif
static UINT8 gMatrixKeyPin[] = {MatrixKey_ROW_1, MatrixKey_ROW_2, MatrixKey_ROW_3, MatrixKey_COL_1, MatrixKey_COL_2, MatrixKey_COL_3};
static UINT8 gKeyPrePortValue[7];
static UINT8 gKeyCurPortValue[7];
/**************************************************************************
* 函数描述: 矩阵按键初始化
* 入口参数: 无
* 出口参数: 无
* 返回值: 无
***************************************************************************/
void RockKey_PowerOnInit(void)
{
UINT8 i;
gKeyPioState = GPIO_GetPortDirection(PIO_KEY);
GPIO_SetPinDirection(GPIOPortC_Pin1, GPIO_IN);
GPIO_SetPinDirection(GPIOPortC_Pin2, GPIO_IN);
GPIO_SetPinDirection(GPIOPortC_Pin3, GPIO_IN);
GPIO_SetPinDirection(GPIOPortC_Pin4, GPIO_IN);
GPIO_SetPinDirection(GPIOPortC_Pin6, GPIO_IN);
GPIO_SetPinDirection(GPIOPortC_Pin5, GPIO_OUT);
for (i = 0;i < 7;i++)
{
gKeyPrePortValue[i] = 0;
}
for (i = 0;i < 7;i++)
{
gKeyCurPortValue[i] = 0;
}
// 增加单独PC1口做PlayOn按键,设置为输入
}
/**************************************************************************
* 函数描述: 矩阵按键硬件检测
* 矩阵扫描对于处于十字位置的3键不能检测
* 入口参数: 无
* 出口参数: 无
* 返回值: 无
***************************************************************************/
void RockKeyScanning(void)
{
UINT8 keys;
UINT8 press;
UINT8 NoPress234 = 1;
UINT8 i, j;
UINT8 pioData;
UINT8 GPIOPortC[] = {GPIOPortC_Pin2, GPIOPortC_Pin3, GPIOPortC_Pin4};
//PLAY
// add by cst
gKeyCurPortValue[0] = GPIO_GetPinLevel(GPIOPortC_Pin1);
keys = gKeyCurPortValue[0] ^ gKeyPrePortValue[0];
gKeyPrePortValue[0] = gKeyCurPortValue[0];
if (keys)
{
#ifdef RM970_NEWBOARD
if (1 == gKeyCurPortValue[0])
press = 0;
else
press = 1;
#else
if (1 == gKeyCurPortValue[0])
press = 1;
else
press = 0;
#endif
RockKeySendKeyMsg(press, 0 );
return;
}
//end by cst
//HOLD
gKeyCurPortValue[1] = GPIO_GetPinLevel(GPIOPortC_Pin6);
keys = gKeyCurPortValue[1] ^ gKeyPrePortValue[1];
gKeyPrePortValue[1] = gKeyCurPortValue[1];
if (keys)
{
// add by cst
#ifdef RM970_NEWBOARD
//HOLD 键改为低有效
if (1 == gKeyCurPortValue[1])
press = 0;
else
press = 1;
#else
if (1 == gKeyCurPortValue[1])
press = 1;
else
press = 0;
#endif
RockKeySendKeyMsg(press, 1 );
return;
}
GPIO_SetPinLevel(GPIOPortC_Pin5, GPIO_LOW);
for (i = 2; i <= 4; i++)
{
gKeyCurPortValue[i] = GPIO_GetPinLevel(GPIOPortC[i-2]);
if (1 == gKeyCurPortValue[i])
NoPress234 = 0;
keys = gKeyCurPortValue[i] ^ gKeyPrePortValue[i];
gKeyPrePortValue[i] = gKeyCurPortValue[i];
if (keys)
{
if (1 == gKeyCurPortValue[i])
press = 1;
else
press = 0;
RockKeySendKeyMsg(press, i );
return;
}
}
if (0 == NoPress234)
return;
GPIO_SetPinLevel(GPIOPortC_Pin5, GPIO_HIGH);
gKeyCurPortValue[5] = GPIO_GetPinLevel(GPIOPortC_Pin4);
keys = gKeyCurPortValue[5] ^ gKeyPrePortValue[5];
gKeyPrePortValue[5] = gKeyCurPortValue[5];
if (keys)
{
if (1 == gKeyCurPortValue[5])
press = 1;
else
press = 0;
RockKeySendKeyMsg(press, 5 );
return;
}
gKeyCurPortValue[6] = GPIO_GetPinLevel(GPIOPortC_Pin3);
keys = gKeyCurPortValue[6] ^ gKeyPrePortValue[6];
gKeyPrePortValue[6] = gKeyCurPortValue[6];
if (keys)
{
if (1 == gKeyCurPortValue[6])
press = 1;
else
press = 0;
RockKeySendKeyMsg(press, 6 );
return;
}
//
}
/**************************************************************************
* 函数描述: 矩阵按键反初始化
* 入口参数: 无
* 出口参数: 无
* 返回值: 无
***************************************************************************/
void RockKey_PowerOffDeinit(void)
{
GPIO_SetPortDirection(PIO_KEY, gKeyPioState); // restore key port
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -