📄 keypad.c
字号:
// keypad driver// Vencent #include <linux/module.h>#include <linux/kernel.h>#include <linux/ioport.h>#include <linux/sched.h>#include <linux/signal.h>#include <linux/errno.h>#include <linux/random.h>#include <linux/miscdevice.h>#include <linux/fs.h>#include <linux/interrupt.h>#include <linux/delay.h>#include <asm/io.h>#include <asm/irq.h>#include <asm/system.h>#include <asm/uaccess.h>#include <asm/segment.h>#include <asm/arch/s3c44b0x.h>#define KEYPAD_DEBUGint keypad_major=40; /* Select 0 for Dynamic adressing */#define NOKEY 0//keypad_arr is an keyboard_map array.unsigned char keypad_arr[5][5] = {{0,0,0,0,0},{0,'0','1','2','3'},{0,'4','5','6','7'},{0,'8','9','A','B'},{0,'C','D','E','F'}};static char key=NOKEY;static int x; static ssize_t keypad_read(struct file *file, char *buffer, size_t len, loff_t *offset){ int row,line; row=0; line=0; outl(inl(S3C44B0X_PCONG)&(0xc03f), S3C44B0X_PCONG); outl(inl(S3C44B0X_PCONG)|(0x1540), S3C44B0X_PCONG); // PG3~6 as output outl(inl(S3C44B0X_PDATG)&(0x87), S3C44B0X_PDATG); // PG3~6 ->0 outl(inl(S3C44B0X_PCONE)&(0x3303f), S3C44B0X_PCONE); // PE3~5,7 as input mdelay(10); x = inl(S3C44B0X_PDATE) & 0xb8; switch(x) { case 0xb0: row = 1; break; case 0xa8: row = 2; break; case 0x98: row = 3; break; case 0x38: row = 4; break; } outl(inl(S3C44B0X_PCONE)&(0x3303f), S3C44B0X_PCONE); outl(inl(S3C44B0X_PCONE)|(0x4540), S3C44B0X_PCONE); // PE3~5,7 as output outl(inl(S3C44B0X_PDATE)&(0x147), S3C44B0X_PDATE); // PE3~5,7 ->0 outl(inl(S3C44B0X_PCONG)&(0xc03f), S3C44B0X_PCONG); // PG3~6 as input mdelay(10); x = inl(S3C44B0X_PDATG) & 0x78; switch(x) { case 0x70: line = 1; break; case 0x68: line = 2; break; case 0x58: line = 3; break; case 0x38: line = 4; break; } key = keypad_arr[row][line]; copy_to_user(buffer,&key,1); key=NOKEY; return 1;}/* Open-Funktion des Devices */static int keypad_open(struct inode *inode, struct file *file){#ifdef KEYPAD_DEBUG printk("the keypad is open\n");#endif return 0;}/* Close-Funktion des Devices */static void keypad_close(struct inode *inode, struct file *file){#ifdef KEYPAD_DEBUG printk("the keypad is closed\n");#endif}struct file_operations keypad_fops={ read: keypad_read, open: keypad_open, release: keypad_close,}; int insert_keypad(void){ int rc; rc=register_chrdev(keypad_major, "keypad", &keypad_fops); if(rc<0) {#ifdef KEYPAD_DEBUG printk("Panic! Could not register KEYPAD-Driver\n");#endif return -ENODEV; } return 0;}int keypad_init(void){ int rc; rc=insert_keypad(); if(rc) {#ifdef KEYPAD_DEBUG printk("Panic! KEYPAD-driver could not be loaded!\n");#endif } #ifdef KEYPAD_DEBUG printk("KEYPAD-driver init OK\n");#endif outl(inl(S3C44B0X_PCONE)&(0x3cfff), S3C44B0X_PCONE); outl(inl(S3C44B0X_PCONE)|(0x1000), S3C44B0X_PCONE); //PE6 as output outl(inl(S3C44B0X_PDATE)|(0x40), S3C44B0X_PDATE); /* PE6->1, disable CPLD I/O expand */ outl(inl(S3C44B0X_PUPE)&(0x147), S3C44B0X_PUPE); outl(inl(S3C44B0X_PUPG)&(0x87), S3C44B0X_PUPG); // Pull up for row and line return rc;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -