• 读取按键值驱动


    #include <linux/module.h>

    #include <linux/kernel.h>

    #include <linux/fs.h>

    #include <linux/init.h>

    #include <linux/delay.h>

    #include <asm/uaccess.h>

    #include <asm/irq.h>

    #include <asm/io.h>

    #include <asm/arch/regs-gpio.h>

    #include <asm/hardware.h>

    static  struct  class *seconddrv_class;

    static struct class_device *seconddrv_class_dev;

    volatile   unsigned  long  *gpfcon;

    volatile   unsigned  long  *gpfdat;

    volatile   unsigned  long  *gpgcon;

    volatile   unsigned  long  *gpgdat;

    static  int second_drv_open(struct  inode  *inode,  struct  file  *file ) {

    /*配置GPF0,2为输入引脚

    */ *

    gpgcon &=~((0x3<< (0*2 )) | (0x3<<(2*2)));

    /*配置GPF3,11为输入引脚 */

    *gpfcon &=~((0x3<< (3*2 )) | (0x3<<(11*2)));

    return 0;

    }

    ssize_t  second_drv_read (struct file *file, char __user *buf, size_t  size, loff_t *ppos) {

    /*返回四个引脚的电平 */

    unsigned  char key_vals[4];

    int  regval;

    if (size  !=  sizeof(key_vals))  

    return -EINVAL;

    /*读取GPF0,2*/

    regval= *gpfdat;

    key_vals [0]= ( regval & (1<<0) )  ?  1:0;

    key_vals [1]= ( regval & (1<<2) )  ?  1:0;

    /*读取GPF3,11*/

    regval= *gpgdat;

    key_vals [2]= ( regval & (1<<3) )  ?  1:0;

    key_vals [3]= ( regval & (1<<11) )  ?  1:0;

    copy_to_user(buf,  key_vals , sizeof(key_vals));

    return sizeof(key_vals);

    }

    static  struct  file_operations  second_drv_fops= {

        .owner=THIS_MODULE,    

     .open = second_drv_open,          

      .read=  second_drv_read, };

    int major;

    static  int  second_drv_init() {

    major=register_chrdev (0,  "second_drv",  & second_drv_fops);

    seconddrv_class = class_create(THIS_MODULE, "seconddrv");  

    /*if (IS_ERR(firstdrv_class))   

    return PTR_ERR(firstdrv_class);*/

    seconddrv_class_dev= class_device_create(seconddrv_class, NULL, MKDEV(major, 0), NULL, "buttons");

    /*if (unlikely(IS_ERR(firstdrv_class_dev)))    

    return PTR_ERR(firstdrv_class_dev);*/

    gpfcon =(volatile unsigned long * )ioremap(0x56000050,16);             

    gpfdat=gpfcon+1;

    gpgcon =(volatile unsigned long * )ioremap(0x56000060,16);             

    gpgdat=gpgcon+1;

    return 0;

    }

    static  void  second_drv_exit() {

    unregister_chrdev ( major,  "second_drv");

    class_device_unregister(seconddrv_class_dev);    

    class_destroy(seconddrv_class);  

    iounmap(gpfcon);  

    iounmap(gpgcon);

    return 0;

    }

    module_init(second_drv_init);

    module_exit(second_drv_exit);

    MODULE_LICENSE("GPL");

  • 相关阅读:
    LUOGU P4113 [HEOI2012]采花
    LUOGU P4251 [SCOI2015]小凸玩矩阵
    bzoj 3230 相似子串——后缀数组
    bzoj 4453 cys就是要拿英魂!——后缀数组+单调栈+set
    洛谷 5061 秘密任务——二分图染色
    bzoj 4104 [Thu Summer Camp 2015]解密运算——思路
    bzoj 4319 cerc2008 Suffix reconstruction——贪心构造
    poj 3415 Common Substrings——后缀数组+单调栈
    CF 504E Misha and LCP on Tree——后缀数组+树链剖分
    bzoj 4278 [ONTAK2015]Tasowanie——后缀数组
  • 原文地址:https://www.cnblogs.com/kingqinwang/p/5150312.html
Copyright © 2020-2023  润新知