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

📄 key_led.c

📁 按键+LED驱动实验 基于TEB-44B0实验平台 包括按键+LED驱动程序与测按键试程序
💻 C
字号:
#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 <asm/io.h>#include <asm/irq.h>#include <asm/system.h>#include <asm/uaccess.h>#include <asm/segment.h>//#include <asm/MC68VZ328.h>#include <asm/arch/s3c44b0x.h>//#define KEY&LED_DEBUGint key_led_major=30;              /* Select 0 for Dynamic adressing */DECLARE_WAIT_QUEUE_HEAD(wq);static char message;int count=2000;int x;void delay(int time){	while (time--);}static char scans(){ 	int x;	       outl(inl(S3C44B0X_PCONE)&(0x3cfff), S3C44B0X_PCONE);   	outl(inl(S3C44B0X_PCONE)|(0x1000), S3C44B0X_PCONE);    //PE6 as output  	 	outl(inl(S3C44B0X_PUPE)&(0x1bf), S3C44B0X_PUPE);         outl(inl(S3C44B0X_PDATE)&(0x1bf), S3C44B0X_PDATE);      //PE6->0    	outl(inl(S3C44B0X_PCONF)&(~((0x03)<<4)), S3C44B0X_PCONF);  	outl(inl(S3C44B0X_PCONF)|((0x01)<<4), S3C44B0X_PCONF);    //PF2 as output         outl(inl(S3C44B0X_PUPF)&(0x1fb), S3C44B0X_PUPF);         outl(inl(S3C44B0X_PDATF)|(0x04), S3C44B0X_PDATF);      //PF2->1	outl(inl(S3C44B0X_PCONG)&(0x0000), S3C44B0X_PCONG);    //PG7 ~ PG0 as input  	x = inl(S3C44B0X_PDATG);	if(x != 0x00)                       /* if key play */      {                   outl(inl(S3C44B0X_PDATF)&(0xfb), S3C44B0X_PDATF);      //PF2->0       outl(inl(S3C44B0X_PCONG)|(0x5555), S3C44B0X_PCONG);    //PG7 ~ PG0 as output       outl(x, S3C44B0X_PDATG);                               //PG7 ~ PG0 ->x	switch (x)	{	 case 0x01:		message = '1';		break;	 case 0x02:		message = '2';              break;        case 0x04:              message = '3';              break;	 case 0x08:		message = '4';		break;	 case 0x10:		message = '5';		break;	 case 0x20:		message = '6';		break;	 case 0x40:		message = '7';		break;	 case 0x80:		message = '8';		break;                }     delay(10*count);   }      return message;      }                                static ssize_t key_led_read(struct file *file, char *buffer, size_t len, loff_t *offset){	scans(); 	copy_to_user(&buffer[0],&message,1);	return 1;}/* Open-Funktion des Devices */static int key_led_open(struct inode *inode, struct file *file){	 return 0;}/* Close-Funktion des Devices */static void key_led_close(struct inode *inode, struct file *file){        //free_irq(IRQ_KEY&LED,NULL);#ifdef KEY&LED_DEBUG   	printk("the device is closed\n");#endif }struct file_operations key_led_fops={        read: key_led_read,//	 write: key_led_write,        open: key_led_open,        release: key_led_close,};                               int insert_key_led(void){	int rc;	rc=register_chrdev(key_led_major, "key_led", &key_led_fops);	if(rc<0)	{#ifdef KEY&LED_DEBUG		printk("Panic! Could not register KEY_LED-Driver\n");#endif		return rc;	};	return 0;}int key_led_init(void){	int rc;	rc=insert_key_led();	if(rc<0)	{#ifdef KEY&LED_DEBUG		printk("Panic! KEY_LED-driver could not be loaded!\n");#endif		return -ENODEV;	}	else 	{#ifdef KEY&LED_DEBUG		printk("KEY_LED-driver init OK\n");#endif	}	return 0;}

⌨️ 快捷键说明

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