矩阵式小键盘的linux驱动编写参考『转』
矩阵式小键盘的linux驱动编写参考 //在EINT0的中断处理中以扫描方式读取键值 //列输入脚(读出键值) #define GPE13 13 //行输出脚(输出扫描码) //读取键值程序 //输出扫描码 printk("the EXTINT0 is 0x%x\n",EXTINT0); return ret;
电路设计上4*5键盘, 采用9个I/O口,以中断方式(EINT0)获取键值,当然也可以采用定时查询方式等。这里提供部分矩阵键盘的linux驱动代码参考,可以应用在ARMSYS2410/2440上。
完整的键盘驱动文件可以参考driver/char/s3c2410_kbd.c文件(这个驱动采用的是专用芯片来连接键盘,不是矩阵键盘的例子,但可以参考一下该驱动的结构等信息)。
static int key_interrupt(int nr, void *devid, struct pt_regs *regs)
{
int i,scannum;
unsigned short temp = 0;
unsigned char tempc0,tempc1;
int ret;
mdelay(10);
for(i = 0; i < scannum="scan_s[i];" temp =" (scannum" i =" 0;" ret =" key_ascii[i];">= 20)
printk("default key 0x%x\n", temp);
}
if ( ret != KBCTL_NODATA )
{
if ( (ret != KBCTL_AGAIN )&& (ret != KK_NONE))
handle_scancode(ret, !(ret & 0x80));
tasklet_schedule(&keyboard_tasklet);
handle_scancode(0,1);
}
mdelay(10);
tempc0 = 0;
scan_key(tempc0);
beep_off;
SRCPND = 1;
}
#define GPE12 12
#define GPE11 11
#define GPG2 2
#define GPE15 15 //GPE
#define GPE14 14 //IICSDA and IICSCL is open drain output
#define GPB0 0
#define GPH10 10
#define GPH9 9
#define read_key(x) { \
x = 0; \
x |= (((GPEDAT >> GPE13) & 0x1) <<>> GPE12) & 0x1) <<>> GPE11) & 0x1) <<>> GPG2) & 0x1) <<>
#define scan_key(x) { \
GPHDAT = (GPHDAT | (0x3 << gpbdat =" (GPBDAT">> 2) & 0x1) << gpedat =" (GPEDAT">> 3) & 0x3) << style="color: rgb(9, 9, 247);">//初始化中断
static int __init HW_kbd_init(void)
{
int ret = -ENODEV;
int delay ;
set_external_irq(IRQ_KBD, EXT_FALLING_EDGE, GPIO_PULLUP_DIS);
key_init;
scan_key(0);
/*
* Claim the appropriate interrupts
*/
ret = request_irq(IRQ_KBD, key_interrupt, SA_INTERRUPT,
"keyboard", key_interrupt);
if (ret) {
printk(KERN_INFO "request IRQ failed (%d)\n", IRQ_KBD);
return ret;
}
}
0 意見:
发表评论