📄 hw_ss866key.c
字号:
/******************************************************************/
/* Copyright (C) 2007 ROCK-CHIPS FUZHOU . All Rights Reserved. */
/*******************************************************************
File : hw_ss302key.c
Desc : ss302按键消息\接口函数的实现
Author : huangxinyu
Date : 2007-07-09
Notes :
$Log: hw_ss302key.c,v $
Revision 1.1.1.1 2007/12/21 02:34:33 Lingzhaojun
12.21
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:31:30 Huangxinyu
增加ss302key目录
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_SS866key.h"
#include "hw_gpio.h"
#include "hw_serial.h"
#include "hw_timer.h"
#if (KEY_TYPE == SS866KEY)
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[8];
static UINT8 gKeyCurPortValue[8];
extern UINT16 gSysState;
/**************************************************************************
* 函数描述: 矩阵按键初始化
* 入口参数: 无
* 出口参数: 无
* 返回值: 无
***************************************************************************/
void RockKey_PowerOnInit(void)
{
UINT8 i;
gKeyPioState = GPIO_GetPortDirection(PIO_KEY);
GPIO_SetPinDirection(GPIOPortC_Pin1, GPIO_IN); //play
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<8;i++)
{
gKeyPrePortValue[i]=0;
}
for(i=0;i<8;i++)
{
gKeyCurPortValue[i]=0;
}
// 增加单独PC1口做PlayOn按键,设置为输入
}
/**************************************************************************
* 函数描述: 矩阵按键硬件检测
* 矩阵扫描对于处于十字位置的3键不能检测
* 入口参数: 无
* 出口参数: 无
* 返回值: 无
***************************************************************************/
void RockKeyScanning( void )
{
UINT8 keys;
UINT8 press;
UINT8 NoPress234=1;
UINT8 i,j,KeyNo;
UINT8 pioData;
UINT8 GPIOPortC[]={GPIOPortC_Pin2,GPIOPortC_Pin3,GPIOPortC_Pin4};
GPIO_SetPinLevel(GPIOPortC_Pin5,GPIO_LOW);
#if 1
gKeyCurPortValue[7]=(GPIO_GetPinLevel(GPIOPortC_Pin3)<<1) | GPIO_GetPinLevel(GPIOPortC_Pin1);
keys = gKeyCurPortValue[7] ^ gKeyPrePortValue[7];
gKeyPrePortValue[7] = gKeyCurPortValue[7];
if( 3 == gKeyCurPortValue[7] )
{
if(keys == 1)
press = 1;
else
press = 0;
KeyNo = 7;
goto ret_position;
// RockKeySendKeyMsg(press, 7);
// return;
}
#endif
gKeyCurPortValue[0]=GPIO_GetPinLevel(GPIOPortC_Pin1);
keys = gKeyCurPortValue[0] ^ gKeyPrePortValue[0];
gKeyPrePortValue[0] = gKeyCurPortValue[0];
if( keys )
{
if( 1==gKeyCurPortValue[0] )
press = 1;
else
press = 0;
KeyNo = 0;
goto ret_position;
// RockKeySendKeyMsg(press, 0);
// return;
}
#if 1
for(i=1; i<=3; i++)
{
gKeyCurPortValue[i]=GPIO_GetPinLevel(GPIOPortC[i - 1]);
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;
KeyNo = i;
goto ret_position;
// RockKeySendKeyMsg(press, i);
// return;
}
}
#endif
if(0==NoPress234)
return;
#if 1
GPIO_SetPinLevel(GPIOPortC_Pin5,GPIO_HIGH);
// GPIO_SetPinLevel(GPIOPortC_Pin6,GPIO_LOW);
for(i=4; i<=6; i++)
{
gKeyCurPortValue[i]=GPIO_GetPinLevel(GPIOPortC[i - 4]);
keys = gKeyCurPortValue[i] ^ gKeyPrePortValue[i];
gKeyPrePortValue[i] = gKeyCurPortValue[i];
if( keys )
{
if( 1==gKeyCurPortValue[i] )
press = 1;
else
press = 0;
KeyNo = i;
goto ret_position;
// RockKeySendKeyMsg(press, i);
// return;
}
}
#endif
return;
ret_position:
if(gSysState&SYS_LCD_OFF) //黑屏先唤醒
{
if(KeyNo == 7) //HOLD键另外处理
{
RockKeySendKeyMsg(press, KeyNo);
return;
}
if(press == 1)
return;
else
RockKeySendKeyMsg(press, 8); //发送无效消息
return;
}
else
{
RockKeySendKeyMsg(press, KeyNo);
return;
}
}
/**************************************************************************
* 函数描述: 矩阵按键反初始化
* 入口参数: 无
* 出口参数: 无
* 返回值: 无
***************************************************************************/
void RockKey_PowerOffDeinit(void)
{
GPIO_SetPortDirection(PIO_KEY,gKeyPioState); // restore key port
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -