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

📄 keypad.c

📁 实现了一个简单的web服务器
💻 C
字号:
/*********************************************************************** * Filename     : xhyper250-keypad.c                                    * * Program      : xhyper250 led&key test driver                         * * Copyright    : Copyright (C) 2001, newboder                         * * Author       : newboder <newboder@hybus.net>                        * * Description  : StrongArm externd base boad interface test           * * Created at   : 2002.05.06                                           * * Based on     :                                                      * * Modified by  :                                                      * * Modified at  :                                                      * ***********************************************************************/#include <linux/module.h>#include <linux/fs.h>#include <linux/init.h>#include <linux/poll.h>#include <linux/types.h>#include <linux/fs.h>#include <linux/rtc.h>#include <linux/delay.h>#include <asm/hardware.h>#include <asm/delay.h>#define LEDnKEY_MAJOR 	251#define KEYPAD_NAME     "Keypad"#define KEYPAD_VERSION  "Version 0.1"#define EXT_KEY_CS  EXT_PORT2#define EXT_LED_CS  EXT_PORT3#define LED_SHOW    10void led_off_on(){	int i;	EXT_LED_CS = 0xff;		for(i =0 ; i<8;++i)	{		EXT_LED_CS = ~((1 << i) & 0xff);				udelay(30000);	}	EXT_LED_CS = 0xff;}int lednkey_open(struct inode *inode, struct file *filp){	MOD_INC_USE_COUNT;	return (0);          /* success */		 }int lednkey_release(struct inode *inode, struct file *filp){//	led_off_on();	MOD_DEC_USE_COUNT;	return (0);}ssize_t lednkey_read(struct file *filp, char *Putbuf, size_t length, loff_t *f_pos){	unsigned short BottonStatus;   	unsigned char Bottontmp = 0;	int i;	BottonStatus = ( EXT_KEY_CS & 0xff );	for(i = 0 ; i < 8; ++i)	{		if( ((BottonStatus >> i) & 1) == 0 ) 			Bottontmp = (i+1);	}	copy_to_user( Putbuf, &Bottontmp, length);		return length;}ssize_t lednkey_write(struct file *filp, const char *Getbuf, size_t length, loff_t *f_pos){	int num;	unsigned char UsrWantLed;	    	copy_from_user( &UsrWantLed, Getbuf, length);			num =  ( (UsrWantLed) & 0xff );		EXT_LED_CS = ~(1 << (num-1)); 	printk("the %d statues is %x\n",num,EXT_LED_CS);	return (0);	}int lednkey_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,unsigned long arg){	printk ( "\n Enter the keypad driver code - lednkey_ioctl\n" );	switch(cmd)	{		case LED_SHOW:			{				if(arg)					led_off_on();				break;			}	}	return 0;}struct file_operations lednkey_fops = {	open:       lednkey_open,	read:       lednkey_read,	write:      lednkey_write,	ioctl:      lednkey_ioctl,	release:    lednkey_release,};static int __init xhyper250_keypad_init(void){	int result;	result = register_chrdev(LEDnKEY_MAJOR, "lednkey", &lednkey_fops);	printk("%s %s initialized.\n",KEYPAD_NAME, KEYPAD_VERSION);	led_off_on();	return 0;}static void __exit xhyper250_keypad_exit(void){  	unregister_chrdev( LEDnKEY_MAJOR, "lednkey" );       	//	led_off_on();}module_init(xhyper250_keypad_init);module_exit(xhyper250_keypad_exit);

⌨️ 快捷键说明

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