⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clps711x_keyb.c

📁 linux和2410结合开发 用他可以生成2410所需的zImage文件
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * drivers/char/clps711x_keyb.c * * Copyright (C) 2001 Thomas Gleixner <gleixner@autronix.de> * * based on drivers/edb7211_keyb.c, which is copyright (C) 2000 Bluemug Inc. *  * Keyboard driver for ARM Linux on EP7xxx and CS89712 processors * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. See the file COPYING  * in the main directory of this archive for more details. * * * Hardware:  * * matrix scan keyboards based on EP7209,7211,7212,7312 and CS89712  * on chip keyboard scanner.		 * Adaption for different machines is done in init function. * * Basic Function: * * Basicly the driver is interrupt driven. It sets all column drivers	 * high. If any key is pressed, a interrupt occures. Now a seperate scan of * each column is done. This scan is timer based, because we use a keyboard  * interface with decoupling capacitors (neccecary if you want to survive  * EMC compliance tests). Always one line is set high. When next timer event  * occures the scan data on port A are valid. This makes also sure, that no * spurious keys are scanned. The kbd int on these CPU's is not deglitched! * After scanning all columns, we switch back to int mode, if no key is * pressed. If any is pressed we reschedule the scan within a programmable * delay. If we would switch back to interrupt mode as long as a key is pressed, * we come right back to the interrupt, because the int. is level triggered ! * The timer based scan of the seperate columns can also be done in one * timer event (set fastscan to 1). * * Summary: * The design of this keyboard controller chip is stupid at all ! * * Matrix translation: * The matrix translation table is based on standard XT scancodes. Maybe * you have to adjust the KEYISPRINTABLE macro if you set other codes. * * HandyKey: * * On small matrix keyboards you don't have enough keys for operation. * The intention was to implement a operation mode as it's used on handys. * You can rotate trough four scancode levels and produce e.g. with a 4x3 * matrix 4*3*4 = 48 different keycodes. That's basicly enough for editing * filenames or things like that. The HandyKey function takes care about  * nonprintable keys like cursors, backspace, del ... * If a key is pressed and is a printable keycode, the code is put to the * main keyboard handler and a cursor left is applied. If you press the same * key again, the current character is deleted and the next level character * is applied. (e.g. 1, a, b, c, 1 ....). If you press a different key, the * driver applies cursor right, before processing the new key. * The autocomplete feature moves the cursor right, if you do not press a * key within a programmable time. * If HandyKey is off, the keyboard behaviour is that of a standard keyboard * HandyKey can be en/disabled from userspace with the proc/keyboard entry *  * proc/keyboard: *  * Read access gives back the actual state of the HandyKey function	 *	h:0	Disabled *	h:1	Enabled * Write access has two functions. Changing the HandyKey mode and applying * a different scancode translation table. * Syntax is: 	h:0	disable Handykey *		h:1	enabled Handykey *		t:array[256] of bytes	Transfer translation table	 */#include <linux/config.h>#include <linux/sched.h>#include <linux/interrupt.h>#include <linux/tty.h>#include <linux/tty_flip.h>#include <linux/mm.h>#include <linux/slab.h>#include <linux/ptrace.h>#include <linux/signal.h>#include <linux/timer.h>#include <linux/tqueue.h>#include <linux/random.h>#include <linux/ctype.h>#include <linux/init.h>#include <linux/kbd_ll.h>#include <linux/kbd_kern.h>#include <linux/delay.h>#include <linux/proc_fs.h>#include <asm/bitops.h>#include <asm/keyboard.h>#include <asm/irq.h>#include <asm/hardware.h>#include <asm/uaccess.h>#include <asm/io.h>#include <asm/system.h>void clps711x_kbd_init_hw(void);/* * Values for the keyboard column scan control register. */#define KBSC_HI	    0x0	    /*   All driven high */#define KBSC_LO	    0x1	    /*   All driven low */#define KBSC_X	    0x2	    /*   All high impedance */#define KBSC_COL0   0x8	    /*   Column 0 high, others high impedance */#define KBSC_COL1   0x9	    /*   Column 1 high, others high impedance */#define KBSC_COL2   0xa	    /*   Column 2 high, others high impedance */#define KBSC_COL3   0xb	    /*   Column 3 high, others high impedance */#define KBSC_COL4   0xc	    /*   Column 4 high, others high impedance */#define KBSC_COL5   0xd	    /*   Column 5 high, others high impedance */#define KBSC_COL6   0xe	    /*   Column 6 high, others high impedance */#define KBSC_COL7   0xf	    /*   Column 7 high, others high impedance *//** Keycodes for cursor left/right and delete (used by HandyKey)	*/#define KEYCODE_CLEFT	0x4b#define KEYCODE_CRIGHT  0x4d#define KEYCODE_DEL	0x53#define KEYISPRINTABLE(code) ( (code > 0x01 && code < 0x37 && code != 0x1c \				 && code != 0x0e) || code == 0x39) /* Simple translation table for the SysRq keys */#ifdef CONFIG_MAGIC_SYSRQunsigned char clps711x_kbd_sysrq_xlate[128] =	"\000\0331234567890-=\177\t"			/* 0x00 - 0x0f */	"qwertyuiop[]\r\000as"				/* 0x10 - 0x1f */	"dfghjkl;'`\000\\zxcv"				/* 0x20 - 0x2f */	"bnm,./\000*\000 \000\201\202\203\204\205"	/* 0x30 - 0x3f */	"\206\207\210\211\212\000\000789-456+1"		/* 0x40 - 0x4f */	"230\177\000\000\213\214\000\000\000\000\000\000\000\000\000\000" /* 0x50 - 0x5f */	"\r\000/";					/* 0x60 - 0x6f */#endif/*  * This table maps row/column keyboard matrix positions to XT scancodes. * It's a default table, which can be overriden by writing to proc/keyboard  */#ifdef CONFIG_ARCH_AUTCPU12static unsigned char autcpu12_scancode[256] = {/*  Column:   Row       0     1     2     3     4     5     6     7   *//* A0 */  0x08, 0x09, 0x0a, 0x0e, 0x05, 0x06, 0x00, 0x00,/* A1 */  0x07, 0x53, 0x02, 0x03, 0x04, 0x0f, 0x00, 0x00,/* A2 */  0x0c, 0x0b, 0x33, 0x1c, 0xff, 0x4b, 0x00, 0x00,/* A3 */  0x48, 0x50, 0x4d, 0x3b, 0x3c, 0x3d, 0x00, 0x00,/* A4 */  0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,/* A5 */  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,/* A6 */  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,/* A7 */  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,/* A0 */  0x1e, 0x20, 0x22, 0x0e, 0x24, 0x32, 0x00, 0x00,/* A1 */  0x19, 0x53, 0x1f, 0x2f, 0x15, 0x0f, 0x00, 0x00,/* A2 */  0x0c, 0x39, 0x34, 0x1c, 0xff, 0x4b, 0x00, 0x00,/* A3 */  0x48, 0x50, 0x4d, 0x3b, 0x3c, 0x3d, 0x00, 0x00,/* A4 */  0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,/* A5 */  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,/* A6 */  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,/* A7 */  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,/* A0 */  0x30, 0x12, 0x23, 0x0e, 0x25, 0x31, 0x00, 0x00,/* A1 */  0x10, 0x53, 0x14, 0x11, 0x2c, 0x0f, 0x00, 0x00,/* A2 */  0x0c, 0x0b, 0x27, 0x1c, 0xff, 0x4b, 0x00, 0x00,/* A3 */  0x48, 0x50, 0x4d, 0x3b, 0x3c, 0x3d, 0x00, 0x00,/* A4 */  0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,/* A5 */  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,/* A6 */  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,/* A7 */  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,/* A0 */  0x2e, 0x21, 0x17, 0x0e, 0x26, 0x18, 0x00, 0x00,/* A1 */  0x13, 0x53, 0x16, 0x2D, 0x04, 0x0f, 0x00, 0x00,/* A2 */  0x0c, 0x39, 0x35, 0x1c, 0xff, 0x4b, 0x00, 0x00,/* A3 */  0x48, 0x50, 0x4d, 0x3b, 0x3c, 0x3d, 0x00, 0x00,/* A4 */  0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,/* A5 */  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,/* A6 */  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,/* A7 */  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,};#endifstatic int keys[8];static int new_keys[8];static int previous_keys[8];static int fastscan;static int scan_interval;static int scan_delay;static int last_column; static int key_is_pressed;static unsigned char *act_scancode;static struct kbd_handy_key {	int		ena;	int		code;	int		shift;	int		autocomplete;	unsigned long 	expires;	unsigned long	delay;	unsigned char 	left;	unsigned char	right;	unsigned char   del;} khandy;static struct tq_struct kbd_process_task;static struct timer_list clps711x_kbd_timer;static struct timer_list clps711x_kbdhandy_timer;static struct proc_dir_entry *clps711x_keyboard_proc_entry = NULL;/* * Translate a raw keycode to an XT keyboard scancode. */static int clps711x_translate(unsigned char scancode, unsigned char *keycode,		 		 char raw_mode){	*keycode = act_scancode[scancode];	return 1;}/** Initialize handykey structure* clear code, clear shift* scan scancode for cursor right/left and delete*/static void clps711x_handykey_init(void) {	int	i;	khandy.ena = 0;	khandy.code = 0;	khandy.shift = 0;	khandy.autocomplete = 0;	for(i = 0; i < 64; i++) {		switch(act_scancode[i]) {			case KEYCODE_CLEFT: 	khandy.left = i; break;				case KEYCODE_CRIGHT: 	khandy.right = i; break;				case KEYCODE_DEL: 	khandy.del = i; break;		}	}	} /** Check for handy key and process it	*/void inline clps711x_checkhandy(int col, int row) {	int scode, down;	unsigned char kcode;		scode = (row<<3) + col;	down  = keys[col]>>row & 0x01;	kcode = act_scancode[scode];		if (!khandy.ena) {		if (khandy.code) {						handle_scancode(khandy.right,1);			handle_scancode(khandy.right,0);		}		khandy.code = 0;		khandy.shift = 0;		khandy.autocomplete = 0;	}	if(!kcode)		return;	if (!down || !khandy.ena) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -