keyboard.c
来自「usoc在北京博创兴业有限公司的实验平台s3c2410上运行。 2. 各实验的全」· C语言 代码 · 共 148 行
C
148 行
/***************************************************************************\
Copyright (c) 2004-2007 threewater@up-tech.com, All rights reserved.
by threewter 2004.4.26
\***************************************************************************/
/***************************************************************************\
#说明: 键盘驱动
---------------------------------- Bug --------------------------------------
---------------------------------- TODO list --------------------------------------
----------------------------------修正--------------------------------------
2004-5-9 创建
\***************************************************************************/
#include "../inc/reg2410.h"
//#include "../inc/zlg7290.h"
#include "../inc/lib.h"
#include "../inc/macro.h"
#include "../inc/isr.h"
#include "../inc/KeyBoard.h"
#include "../inc/iic.h"
#include "../inc/Uart.h"
#include "inc/lcd.h"
#include <stdio.h>
#include <string.h>
#define KBDTYPE_ZLG7290 1
#define KBDTYPE_MCUIIC 2
#define KEYBOARD_TYPE KBDTYPE_MCUIIC
#define KEY_DOWN (1ul<<31)
#include "../inc/i2c-tomega8.h"
#define IRQ_KBD IRQ_IIC
//#define MCU_IICCON (IICCON_ACKEN |IICCON_CLK512 | IICCON_INTR | IICCON_CLKPRE(0x3))
#define MCU_IICCON (IICCON_ACKEN | IICCON_INTR | IICCON_CLKPRE(7))
//static unsigned short KeyBoard_Map[256];
unsigned short mcukey,tempmcukey,count,down,up;
static void Key_ISR(int vector, void* data)
{
static int framecnt=0;
U8 status ,kdata;
status = rIICSTAT ;
//printk("enter key_ISR");
if( (status & IICSTAT_MODE_MSK) != IICSTAT_MODE_SR)
return;
//must slave receive mode
kdata = rIICDS;
switch(framecnt){
case 0:
if(status & IICSTAT_SLAVEADDR){
//match the own slave address. begin to slave receive data.
//DPRINTK("key irq: 111\n");
framecnt++;
}
break;
case 1:
if(GetI2C_Devtype(kdata) != DTYPE_MKEYB){
//DPRINTK("key irq: not key farme\n");
framecnt=0;
}
framecnt++;
break;
case 2:
mcukey = kdata;
if(mcukey&0x80)
{framecnt=0;
down=1;
break;}
else if((mcukey&0x80)==0)
{tempmcukey=mcukey;
up=1;
count=1;
/* Uart_Printf(0,"\nthe isr tempmcukey is %x",tempmcukey);
LCD_printf("\nthe isr tempmcukey is %x ",tempmcukey);
Uart_Printf(0,"\nthe isr count is %x",count);*/
framecnt=0;
break;
}
/*else
tempmcukey=0;
Uart_Printf(0,"\nthe up tempmcukey is %x",tempmcukey);
framecnt=0;
break;*/
}
rIICCON &= ~IICCON_INTPEND;
}
void Key_init(void)
{
I2C_control i2c_ctrl;
IIC_init();
Set_IIC_mode(MCU_IICCON, NULL);
//set owner i2c address to mega8
i2c_ctrl.cmd=CMD_MST_ADDR;
i2c_ctrl.ctrl=I2COWNER_ADDRESS;
IIC_Send(MEGA8_I2CADDRESS, (const char*)&i2c_ctrl, sizeof(i2c_ctrl));
//enable keyboard
i2c_ctrl.cmd=CMD_CTRL;
i2c_ctrl.ctrl = CTRL_MKEn;
IIC_Send(MEGA8_I2CADDRESS, (const char*)&i2c_ctrl, sizeof(i2c_ctrl));
INTS_OFF();
SetISR_Interrupt(IRQ_KBD, Key_ISR, NULL);
INTS_ON();
}
int GetKey()
{extern unsigned short tempmcukey,count,down,up;
int scankey=17;
unsigned char kKeyBoard_Map[]={0,0,10,0,0,7,4,1,0,0,11
,14,0,8,5,2,0,13,12,0,0
,9,6,3,16,0,0,0,0,14,0
,15,0,1,0,0,17,2,0,0,0
,4,0,6,0,5,0,0,0,7,0
,9,15,8,0,0,0,0,0,0,0
,0,0,0
}; //64,键值映射表
if((up==1)&&(count==1)){
up=0;
count=0;
scankey=(int)kKeyBoard_Map[tempmcukey];
}
return scankey;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?