设为首页 加入收藏

TOP

arm6410按键驱动程序
2014-11-24 03:19:55 来源: 作者: 【 】 浏览:1
Tags:arm6410 按键 驱动程序

通过查询的方法获取按键值
驱动程序 botton_drive.c



#include
#include
#include
#include
#include
#include
#include
#include
#include
//#include
//#include



static struct class *seconddrv_class;
static struct class_device*seconddrv_class_dev;



volatile unsigned long *gpmcon = NULL;
volatile unsigned long *gpmdat = NULL;
volatile unsigned long *gpncon = NULL;
volatile unsigned long *gpndat = NULL;




static int second_drv_open(struct inode *inode, struct file *file)
{
//printk("second_drv_open\n");
/* 配置GPm0,1,2,3为输出 */
*gpmcon &= ~((0xf<<(4*0)) | (0xf<<(4*1)) | (0xf<<(4*2)) | (0xf<<(4*3)));
*gpmcon |= ((0x1<<(4*0)) | (0x1<<(4*1)) | (0x1<<(4*2)) | (0x1<<(4*3)));
/* 配置GPn0,1,2,3,4,5为输入 */
*gpncon &= ~((0x3<<(2*0)) | (0x3<<(2*1)) | (0x3<<(2*2)) | (0x3<<(2*3)) | (0x3<<(2*4)) | (0x3<<(2*5)));
//*gpncon |= ((0xf<<(4*0)) | (0xf<<(4*1)) | (0xf<<(4*2)) | (0xf<<(4*3)) | (0xf<<(4*4)) | (0xf<<(4*5)));
return 0;
}



static ssize_t second_drv_read(struct file *file, const char __user *buf, size_t size, loff_t * ppos)
{
unsigned char KEY_val[6];
if(size != sizeof(KEY_val))
return -EINVAL;
int regval;
regval = *gpndat;



/* 读出个个引脚的状态 */
KEY_val[0] = (regval & 1<<0) 1:0;
KEY_val[1] = (regval & 1<<1) 1:0;
KEY_val[2] = (regval & 1<<2) 1:0;
KEY_val[3] = (regval & 1<<3) 1:0;
KEY_val[4] = (regval & 1<<4) 1:0;
KEY_val[5] = (regval & 1<<5) 1:0;



/* 传递给用户 */
copy_to_user(buf, KEY_val, sizeof(KEY_val));



return sizeof(KEY_val);
}



static struct file_operations second_drv_fops = {
.owner = THIS_MODULE, /* 这是一个宏,推向编译模块时自动创建的__this_module变量 */
.open = second_drv_open,
.read= second_drv_read,
};




int major;
static int second_drv_init(void)
{
//printk(KERN_ERR "second_drv_init\n");
major = register_chrdev(0, "secondt_drv", &second_drv_fops); // 注册, 告诉内核



seconddrv_class = class_create(THIS_MODULE, "seconddrv");



seconddrv_class_dev = device_create(seconddrv_class, NULL, MKDEV(major, 0), NULL, "bottons"); /* /dev/bottons */



gpmcon = (volatile unsigned long *)ioremap(0x7F008820, 16);
gpmdat = gpmcon + 1;
gpncon = (volatile unsigned long *)ioremap(0x7F008830, 16);
gpndat = gpncon + 1;



return 0;
}



static void second_drv_exit(void)
{
//printk(KERN_ERR "second_drv_exit\n");
unregister_chrdev(major, "second_drv"); // 卸载



device_unregister(seconddrv_class_dev);
class_destroy(seconddrv_class);
iounmap(gpmcon);
iounmap(gpncon);
}



module_init(second_drv_init);
module_exit(second_drv_exit);




MODULE_LICENSE("GPL");


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Linux 驱动 Printk 在终端没有输出 下一篇移植uCOS-II到Cortex-M3平台

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·如何利用Python做数 (2025-12-24 23:48:36)
·如何使用python进行 (2025-12-24 23:48:34)
·python 爬虫入门该怎 (2025-12-24 23:48:31)
·Java 实现多个大文件 (2025-12-24 23:22:00)
·Java多线程编程在工 (2025-12-24 23:21:56)