免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1264 | 回复: 1
打印 上一主题 下一主题

模块驱动问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-06-03 10:07 |只看该作者 |倒序浏览
小弟编了个按键驱动,是用查询法来读按键有没有按下
[code
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/version.h>
#include <linux/init.h>
#include <asm/hardware.h>
#include <asm/arch/regs-gpio.h>
#include <linux/fs.h>
#include <asm/segment.h>

static int device_major=0;
#define device_name "shushi_key"

unsigned long key_table[]=
{
        S3C2410_GPG0,             //按键引脚
        S3C2410_GPG3,
        S3C2410_GPG5,
        S3C2410_GPG6,
        S3C2410_GPG7,
        S3C2410_GPG11,       
};

unsigned long key_table_cfg[]=
{
        S3C2410_GPG0_INP,
        S3C2410_GPG3_INP,   //都配置为输入
        S3C2410_GPG5_INP,       
        S3C2410_GPG6_INP,
        S3C2410_GPG7_INP,
        S3C2410_GPG11_INP,       
};

static int shushi_key_ioctl(struct inode *,struct file *,unsigned int,unsigned long);
static int shushi_key_init(void);
static void shushi_key_exit(void);

struct file_operations f_ops=
{
        owner:THIS_MODULE,
        ioctl:shushi_key_ioctl,
};

static int shushi_key_ioctl(struct inode *inode,struct file *file,unsigned int cmd,unsigned long arg)
{
              int temp;//arg来选定来读取哪个按键,cmd没有使用,但是再应用程序中都赋值为1,这样arg不会无效
        temp=(~(s3c2410_gpio_getpin(key_table[arg])))&0x1;
        return temp;
}


static int shushi_key_init(void)
{
        int result,i;
        result=register_chrdev(device_major,device_name,&f_ops);
        if(result<0)
        {
                printk("<1>register fail\n");
                return -1;
        }
        device_major=result;
        for(i=0;i<6;i++)       //设置按键为输入
                s3c2410_gpio_cfgpin(key_table,key_table_cfg);
        for(i=0;i<6;i++)      //按键都带上啦电阻,这里到底是0为带上啦,还是1为带上啦呢?
                s3c2410_gpio_pullup(key_table,1);       
        printk("<1>register success\n");
        return 0;
}

static void shushi_key_exit(void)
{
        unregister_chrdev(device_major,device_name);
}


module_init(shushi_key_init);
module_exit(shushi_key_exit);

按键按下都是直接接再地上面的,但是只能读出一个键值,其他怎么一开始就自动接地了类?

论坛徽章:
0
2 [报告]
发表于 2009-06-03 18:33 |只看该作者
我可以直接用shushi_key_ioctl函数的返回值直接返回到用户程序的ioctl作为ioctl的返回值不?
而是要用put_user函数将值传递到用户程序的buf中呢
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP