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

📄 keyboard.c

📁 arm平台上的uclinux系统全部源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
/* * linux/arch/arm/drivers/block/keyboard.c * * Keyboard driver for Linux using Latin-1. * * Written for linux by Johan Myreen as a translation from * the assembly version by Linus (with diacriticals added) * * Some additional features added by Christoph Niemann (ChN), March 1993 * * Loadable keymaps by Risto Kankkunen, May 1993 * * Diacriticals redone & other small changes, aeb@cwi.nl, June 1993 * Added decr/incr_console, dynamic keymaps, Unicode support, * dynamic function/string keys, led setting,  Sept 1994 * `Sticky' modifier keys, 951006. * * Majorly altered for use with arm Russell King (rmk@ecs.soton.ac.uk) *  The low-level keyboard driver is now separate. *  Interfaces: *    Driver supplies: *	kbd_drv_init	- initialise keyboard driver proper *	kbd_drv_setleds	- set leds on keyboard *    Driver uses: *	kbd_keyboardkey	- process a keypress/release *	kbd_reset	- reset keyboard down array *	kbd_setregs	- set regs for scroll-lock debug */#include <linux/sched.h>#include <linux/interrupt.h>#include <linux/tty.h>#include <linux/tty_flip.h>#include <linux/mm.h>#include <linux/malloc.h>#include <linux/ptrace.h>#include <linux/signal.h>#include <linux/timer.h>#include <linux/random.h>#include <linux/ctype.h>#include <asm/bitops.h>#include <asm/system.h>#include <asm/irq.h>#include <asm/segment.h>#include "kbd_kern.h"#include "diacr.h"#include "vt_kern.h"#define SIZE(x) (sizeof(x)/sizeof((x)[0]))#define KBD_REPORT_ERR#define KBD_REPORT_UNKN#ifndef KBD_DEFMODE#define KBD_DEFMODE ((1 << VC_REPEAT) | (1 << VC_META))#endif/* * Starts with NumLock off. */#ifndef KBD_DEFLEDS#define KBD_DEFLEDS 0#endif#ifndef KBD_DEFLOCK#define KBD_DEFLOCK 0#endif#define REPEAT_TIMEOUT HZ*300/1000#define REPEAT_RATE    HZ*30/1000extern void ctrl_alt_del (void);extern void scrollback(int);extern void scrollfront(int);extern int kbd_drv_init(void);extern void kbd_drv_setleds(unsigned int leds);extern unsigned int keymap_count;/* * these are the valid i/o ports we're allowed to change. they map all the * video ports */#define GPFIRST 0x3b4#define GPLAST 0x3df#define GPNUM (GPLAST - GPFIRST + 1)/* * global state includes the following, and various static variables * in this module: shift_state, diacr, npadch, dead_key_next. * (last_console is now a global variable) *//* shift state counters.. */static unsigned char k_down[NR_SHIFT] = {0, };/* keyboard key bitmap */#define BITS_PER_LONG (8*sizeof (unsigned long))static unsigned long key_down[256/BITS_PER_LONG] = {0, };static int dead_key_next;/* * In order to retrieve the shift_state (for the mouse server), either * the variable must be global, or a new procedure must be created to * return the value. I chose the former way. *//*static*/ int shift_state;static int npadch            = -1;		/* -1 or number assembled on pad */static unsigned char diacr;static char rep;				/* Flag telling character repeat */static int kbd_repeatkey     = -1;static int kbd_repeattimeout = REPEAT_TIMEOUT;static int kbd_repeatrate    = REPEAT_RATE;static struct kbd_struct * kbd;static struct tty_struct * tty;extern void compute_shiftstate (void);typedef void (*k_hand)(unsigned char value, char up_flag);typedef void (k_handfn)(unsigned char value, char up_flag);static k_handfn	do_self, do_fn, do_spec, do_pad, do_dead, do_cons, do_cur, do_shift,	do_meta, do_ascii, do_lock, do_lowercase, do_slock, do_ignore;static k_hand key_handler[16] = {	do_self, do_fn, do_spec, do_pad, do_dead, do_cons, do_cur, do_shift,	do_meta, do_ascii, do_lock, do_lowercase, do_slock,	do_ignore, do_ignore, do_ignore};typedef void (*void_fnp)(void);typedef void (void_fn)(void);static void_fn do_null, enter, show_ptregs, send_intr, lastcons, caps_toggle,	num, hold, scroll_forw, scroll_back, boot_it, caps_on, compose,	SAK, decr_console, incr_console, spawn_console, show_stack, bare_num;static void_fnp spec_fn_table[] = {	do_null,	enter,		show_ptregs,	show_mem,	show_state,	send_intr,	lastcons,	caps_toggle,	num,		hold,		scroll_forw,	scroll_back,	boot_it,	caps_on,	compose,	SAK,	decr_console,	incr_console,	show_stack,     bare_num};/* maximum values each key_handler can handle */const int max_vals[] = {	255, SIZE(func_table) - 1, SIZE(spec_fn_table) - 1, NR_PAD - 1,	NR_DEAD - 1, 255, 3, NR_SHIFT - 1,	255, NR_ASCII - 1, NR_LOCK - 1, 255,	NR_LOCK - 1};const int NR_TYPES = SIZE(max_vals);static void put_queue(int);static unsigned char handle_diacr(unsigned char);/* pt_regs - set by keyboard_interrupt(), used by show_ptregs() */static struct pt_regs * pt_regs;/* * Many other routines do put_queue, but I think either * they produce ASCII, or they produce some user-assigned * string, and in both cases we might assume that it is * in utf-8 already. */void to_utf8(ushort c){	if (c < 0x80)		put_queue(c);			/*  0*******  */	else if (c < 0x800) {		put_queue(0xc0 | (c >> 6)); 	/*  110***** 10******  */		put_queue(0x80 | (c & 0x3f));	} else {		put_queue(0xe0 | (c >> 12)); 	/*  1110**** 10****** 10******  */		put_queue(0x80 | ((c >> 6) & 0x3f));		put_queue(0x80 | (c & 0x3f));	}	/* UTF-8 is defined for words of up to 31 bits,	   but we need only 16 bits here */}/* * As yet, we don't support setting and getting the * key codes.  I'll have to find out where this is used. */int setkeycode(unsigned int scancode, unsigned int keycode){	return -EINVAL;}int getkeycode(unsigned int scancode){	return -EINVAL;}static void key_callback(unsigned long nr){	rep = 1;	mark_bh (KEYBOARD_BH);}static struct timer_list key_timer ={	NULL, NULL, 0, 0, key_callback};void kbd_reset(void){	int i;	for (i = 0; i < NR_SHIFT; i++)		k_down[i] = 0;	for (i = 0; i < 256/BITS_PER_LONG; i++)		key_down[i] = 0;	shift_state = 0;}void kbd_setregs(struct pt_regs *regs){	pt_regs = regs;}static void kbd_processkey(unsigned int keycode, unsigned int up_flag, unsigned int autorepeat){	del_timer(&key_timer);	show_console();	add_keyboard_randomness (keycode|(up_flag?0x100:0));	tty = *vtdata.fgconsole->tty;	kbd = vtdata.fgconsole->kbd;	if (up_flag) {	    	rep = 0;		clear_bit (keycode, key_down);		/* don't report an error if key is already up - happens when a ghost key is released */	} else		rep = set_bit (keycode, key_down);	if (rep && !autorepeat)		return;	if (kbd->kbdmode == VC_RAW || kbd->kbdmode == VC_MEDIUMRAW) {		put_queue(keycode + (up_flag ? 0x80 : 0));		return;	}	/*	 * We have to do our own auto-repeat processing...	 */	if (!up_flag) {    		kbd_repeatkey = keycode;		if (vc_kbd_mode(kbd, VC_REPEAT)) {			if (rep)				key_timer.expires = jiffies + kbd_repeatrate;			else				key_timer.expires = jiffies + kbd_repeattimeout;			add_timer(&key_timer);		}	} else		kbd_repeatkey = -1;	/*	 * Repeat a key only if the input buffers are empty or the	 * characters get echoed locally.  This makes key repeat usable	 * with slow applications and under heavy loads.	 */	if (!rep ||	    (vc_kbd_mode (kbd, VC_REPEAT) && tty &&             (L_ECHO(tty) || (tty->driver.chars_in_buffer (tty) == 0)))) {		u_short keysym;		u_char  type;		/* the XOR below used to be an OR */		int     shift_final = shift_state ^ kbd->lockstate ^ kbd->slockstate;		u_short *key_map = key_maps[shift_final];		if (key_map != NULL) {			keysym = key_map[keycode];			type   = KTYP(keysym);			if (type >= 0xf0) {				type -= 0xf0;				if (type == KT_LETTER) {					type = KT_LATIN;					if (vc_kbd_led(kbd, VC_CAPSLOCK)) {						key_map = key_maps[shift_final ^ (1<<KG_SHIFT)];						if (key_map)							keysym = key_map[keycode];					}				}				(*key_handler[type])(keysym & 0xff, up_flag);				if (type != KT_SLOCK)					kbd->slockstate = 0;			} else {				/* maybe only if (kbd->kbdmode == VC_UNICODE) ? */				if (!up_flag)					to_utf8(keysym);			}		} else {			/*			 * maybe beep?			 * we have at least to update shift_state			 * how? two almost equivalent choices follow			 */#if 1			compute_shiftstate ();#else			keysym = U(plain_map[keycode]);			type   = KTYP(keysym);			if (type == KT_SHIFT)				(*key_handler[type]) (keysym & 0xff, up_flag);#endif		}	}}void kbd_keyboardkey(unsigned int keycode, unsigned int up_flag){	kbd_processkey(keycode, up_flag, 0);}static void put_queue (int ch){        wake_up (&keypress_wait);        if (tty) {                tty_insert_flip_char (tty, ch, 0);                tty_schedule_flip (tty);        }}static void puts_queue(char *cp){        wake_up (&keypress_wait);        if (!tty)                return;        while (*cp) {                tty_insert_flip_char (tty, *cp, 0);                cp++;        }        tty_schedule_flip (tty);}static void show_stack (void){        unsigned long *p;        unsigned long *q = (unsigned long *)((int)current->kernel_stack_page + 4096);        int i;        __asm__("mov %0, sp\n\t": "=r" (p));        for (i = 0; p < q; p++, i++) {                if(i && !(i & 7))                        printk("\n");                printk("%08lX ", *p);        }}static void applkey(int key, char mode){        static char buf[] = { 0x1b, 'O', 0x00, 0x00};        buf[1] = (mode ? 'O' : '[');        buf[2] = key;        puts_queue(buf);}static void enter(void){        put_queue (13);        if (vc_kbd_mode(kbd, VC_CRLF))                put_queue (10);}static void caps_toggle(void){        if(rep)                return;        chg_vc_kbd_led(kbd, VC_CAPSLOCK);}static void caps_on (void){        if (rep)                return;        set_vc_kbd_led (kbd, VC_CAPSLOCK);}static void show_ptregs (void){        if (pt_regs)                show_regs (pt_regs);}static void hold (void){        if(rep || !tty)                return;        /*         * Note: SCROLLOCK will be set (cleared) by stop_tty (start_tty);         * these routines are also activated by ^S/^Q.         * (And SCROLLOCK can also be set by the ioctl KDSKBLED.)         */        if (tty->stopped)                start_tty (tty);        else                stop_tty (tty);}static void num (void){        if(vc_kbd_mode(kbd,VC_APPLIC))                applkey('P', 1);        else                bare_num ();}/* * Bind this to Shift-NumLock if you work in application keypad mode * but want to be able to change the NumLock flag. * Bind this to NumLock if you prefer that the NumLock key always * changes the NumLock flag. */static void bare_num (void){        if (!rep)                chg_vc_kbd_led (kbd, VC_NUMLOCK);}static void lastcons (void){        /* switch to the last used console, ChN */        set_console(last_console);}static void decr_console (void){        int i;        int fgnum = vtdata.fgconsole->num - 1;        for (i = fgnum - 1; i != fgnum; i--) {                if (i == -1)                        i = MAX_NR_CONSOLES - 1;                if (vt_allocated (vt_con_data + i))

⌨️ 快捷键说明

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