升级的时候,需要搞个提示,加个键盘控制神马的。
所以,咱得把这个键盘加到Eboot里面。
由于Eboot里面使用不了这个中断,所以只能使用扫描按键的方式。
按键接的是:
行:GPK8~GPK13
列:GPL0~GPL4(这里只需要使用到一列就够了,就使用GPL0吧,这样就有6个按键了)
参照键盘驱动KeyPad,这里把其简化,分成初始化和循环扫描处理,按键识别三部分。
使用的时候,咱先初始化一下键盘:
调用
ret = InitKey();
初始化成功后,在循环里面调用
KScan_Proc();
去检测按键按下,接着再通过
keyValue = GetKeyDown();
去获取按下的按键,然后做识别处理。
6个按键,根据行列扫描后的键值,定义如下:(Key.h)
#define KEY_ENTER (0x1)
#define KEY_SCAN (0x2)
#define KEY_CANCEL (0x4)
#define KEY_DELETE (0x8)
#define KEY_BACKSPACE (0x10)
#define KEY_UP (0x20)
Key.c的实现如下:
// *** you add ***
// for 6410 key.
// use row0 & col0~col5
#include "Key.h"
#include <windows.h>
#include "Winbase.h"
#include <oal.h>
#include <s3c6410.h>
//#ifdef _KEY_H_
//#define _KEY_H_
// define
#define SIZE_COLS 1
#define KEYIF_Row_Read (pKeyPadReg->KEYIFROW)
// KEYIFCON
#define FC_EN_DIS (0<<3)
#define FC_EN_EN (1<<3)
#define DF_EN_DIS (0<<2)
#define DF_EN_EN (1<<2)
#define INT_R_ENABLE (0<<1)
#define INT_R_DISABLE (1<<1)
#define INT_F_ENABLE (0<<0)
#define INT_F_DISABLE (1<<0)
// KEYIFFC
#define FC_DIV_VAL(n) (((n)&0x3ff)<<0)
#define KEY_POWER_ON (1<<11) // PCLKCON
#ifndef FIN
#define FIN 12000000
#endif
#define FT_CLK_DIV (FIN/32000 - 1)
// KEYIFSTSCLR
#define CLEAR_P_INT (0xFF<<0)
#define CLEAR_R_INT (0xFF<<8)
// global variable
volatile S3C6410_GPIO_REG *pGPIOReg2 = NULL;
volatile S3C6410_KEYPAD_REG *pKeyPadReg = NULL;
volatile S3C6410_SYSCON_REG *pSysConReg = NULL;
DWORD KeyState[SIZE_COLS];
// function
BOOL InitKey();
void KScan_Proc();
DWORD GetKeyDown();
void ClearKey();
BOOL InitKey()
{
// GPIO Virtual alloc
pGPIOReg2 = (S3C6410_GPIO_REG *)OALPAtoVA(S3C6410_BASE_REG_PA_GPIO, FALSE);
if(pGPIOReg2 == NULL) return FALSE;
// Keypad Virtual alloc
pKeyPadReg = (S3C6410_KEYPAD_REG *)OALPAtoVA(S3C6410_BASE_REG_PA_KEYPAD, FALSE);
if(pKeyPadReg == NULL) return FALSE;
// Syscon Virtual alloc
pSysConReg = (S3C6410_SYSCON_REG *)OALPAtoVA(S3C6410_BASE_REG_PA_SYSCON, FALSE);
if(pSysConReg == NULL) return FALSE;
// enable the Keypad Clock (PCLK)
pSysConReg->PCLK_GATE |= KEY_POWER_ON;
pKeyPadReg->KEYIFCON = INT_F_DISABLE|INT_R_DISABLE|DF_EN_EN|FC_EN_DIS;
//Keypad interfae debouncing filter clock division register
pKeyPadReg->KEYIFFC = FC_DIV_VAL(FT_CLK_DIV);
pKeyPadReg->KEYIFCOL = (0x00<<8);
// select all column - Set Keypad column GPIO to output(low)
//pGPIOReg2->GPLCON0=(pGPIOReg2->GPLCON0 & ~(0xfffff<<0)) | (0x33333<<0); //KBC_0(GPL0)~ KBC_4(GPL4)
pGPIOReg2->GPLCON0=(pGPIOReg2->GPLCON0 & ~(0xf<<0)) | (0x3<<0); //KBC_0(GPL0)
pKeyPadReg->KEYIFCOL = (0x0 & 0xff);
// configure - Set Keypad row GPIO to [Key PAD ROW]
pGPIOReg2->GPKCON1=(pGPIOReg2->GPKCON1 & ~(0xffffff<<0)) | (0x333333<<0); //KBR_0(GPK8)~ KBR_5(GPK13)
// unmask the key interrupt
pKeyPadReg->KEYIFSTSCLR = CLEAR_P_INT|CLEAR_R_INT; // Clear Pressed/Released Interrupt
return TRUE;
}
void KScan_Proc()
{
int i=0;
volatile int m=0;
// Read the Matrix
// KBC_0 ~ KBC_7
for(i = 0 ; i < SIZE_COLS; i++){
pKeyPadReg->KEYIFCOL = (0x0 & 0xff);
// select a column
pKeyPadReg->KEYIFCOL = pKeyPadReg->KEYIFCOL | (0xff & ~(0x1 << i));
for(m=0; m<2000; m++);
KeyState[i] = (~KEYIF_Row_Read) & 0xff;
for(m=0; m<2000; m++);
}
pKeyPadReg->KEYIFCOL = (0x0 & 0xff);
}
DWORD GetKeyDown()
{
DWORD key = 0x0;
int i=0;
for(i = 0 ; i < SIZE_COLS; i++){
if(KeyState[i] & KEY_ENTER) key |= KEY_ENTER;
if(KeyState[i] & KEY_SCAN) key |= KEY_SCAN;
if(KeyState[i] & KEY_CANCEL) key |= KEY_CANCEL;
if(KeyState[i] & KEY_DELETE) key |= KEY_DELETE;
if(KeyState[i] & KEY_BACKSPACE) key |= KEY_BACKSPACE;
if(KeyState[i] & KEY_UP) key |= KEY_UP;
}
return key;
}
void ClearKey()
{
memset(KeyState, 0, sizeof(KeyState)/sizeof(DWORD));
}
//#endif
特此记录一下。
仅供参考,请勿模仿~~
若存在错误,请大家指出