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

📄 2440_gpio.c

📁 linux下2440的gpio驱动
💻 C
字号:
#include <linux/config.h>#include <linux/module.h>#include <linux/kernel.h>   			//这个驱动看似简单但是有个问题就是你传入的不同值的时候,也就是你用不同芯片的时候										 //他的引脚定义是不同的,就是输入输出是不同的,这和串行通信,以及其他的驱动有很大的区别										 //这直接导致了底层驱动程序的复杂性#include <linux/fs.h>#include <linux/init.h>#include <linux/devfs_fs_kernel.h>#include <linux/miscdevice.h>#include <linux/delay.h>#include <asm/irq.h>#include <asm/arch/regs-gpio.h>#include <asm/hardware.h>#define DEVICE_NAME	"leds"#define LED_MAJOR 231static unsigned long led_table [] = {	S3C2410_GPF1,	S3C2410_GPF5,	S3C2410_GPF8,	//S3C2410_GPB8,};																						//3=自定义static unsigned int led_cfg_table [] = {   //查看如何接收外边的值,如何通信,可以利用数组进行选择,0=入,1=出低,2=出高,4=定义结束	S3C2410_GPB5_OUTP,              //对于这个可以用二维数组,进行每个一维中有三个,对应0,1,2	S3C2410_GPB6_OUTP,	S3C2410_GPB7_OUTP,	S3C2410_GPB8_OUTP,        //#define S3C2410_GPB7_INP     (0x00 << 14)              00 表示输入	                          //#define S3C2410_GPB7_OUTP    (0x01 << 14)             01表示输出                            //  #define S3C2410_GPB7_nXDACK1 (0x02 << 14)        10特殊功能,在kernel\include\arch-s3c2410\regs-gpio.h中							//也可以利用宏定义的拼接字符功能,选怎就三个然后把S3C2410_GPF8和_OUTP接起来};static int sbc2440_leds_ioctl(	struct inode *inode, 	struct file *file, 	unsigned int cmd, 	unsigned long arg){	switch(cmd) {	case 0:	case 1:		if (arg > 4) {			return -EINVAL;		}		s3c2410_gpio_setpin(led_table[arg], !cmd);		return 0;	default:		return -EINVAL;	}}static struct file_operations sbc2440_leds_fops = {	.owner	=	THIS_MODULE,	.ioctl	=	sbc2440_leds_ioctl,};static int __init sbc2440_leds_init(void){	int ret;	int i;	ret = register_chrdev(LED_MAJOR, DEVICE_NAME, &sbc2440_leds_fops);	if (ret < 0) {	  printk(DEVICE_NAME " can't register major number\n");	  return ret;	}	devfs_mk_cdev(MKDEV(LED_MAJOR, 0), S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP, DEVICE_NAME);		//for (i = 0; i < 4; i++) {	//	s3c2410_gpio_cfgpin(led_table[i], led_cfg_table[i]);	//	s3c2410_gpio_setpin(led_table[i], 1);	//}	printk(DEVICE_NAME " initialized\n");	return 0;}static void __exit sbc2440_leds_exit(void){	devfs_remove(DEVICE_NAME);	unregister_chrdev(LED_MAJOR, DEVICE_NAME);}module_init(sbc2440_leds_init);module_exit(sbc2440_leds_exit);

⌨️ 快捷键说明

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