datasheet

Tiny210驱动之KEY测试

2018-10-12来源: eefocus 关键字:Tiny210驱动  KEY测试

second_drv.c驱动源码:

#include "linux/device.h"

#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"

static struct class *seconddrv_class;

volatile unsigned long *gph2con;

volatile unsigned long *gph2dat;

volatile unsigned long *gph3con;

volatile unsigned long *gph3dat;

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

{

    // 配置GPH2_3为输入引脚 

    *gph2con &= ~(0xf<<(3*4));

    // 配置GPH3_0,GPH3_1,GPH3_2,GPH3_3为输入引脚 

    *gph3con &= ~((0xf<<(0*4)) | (0xf<<(1*4)) | (0xf<<(2*4)) | (0xf<<(3*4)));

    return 0;

}

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

{

    // 返回5个引脚的电平 

    unsigned char key_vals[5];

    int regval;

    if (size != sizeof(key_vals))

        return -EINVAL;

    // 读GPH2_3 

    regval = *gph2dat;

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

    // 读GPH3_0,GPH3_1,GPH3_2,GPH3_3 

    regval = *gph3dat;

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

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

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

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

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

    return sizeof(key_vals);

}

static struct file_operations sencod_drv_fops = {

    .owner  =   THIS_MODULE,    // 这是一个宏,推向编译模块时自动创建的__this_module变量 

    .open   =   second_drv_open,     

    .read   =   second_drv_read,       

};

int major;

static int second_drv_init(void)

{

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

    seconddrv_class = class_create(THIS_MODULE, "second_drv");

    device_create(seconddrv_class, NULL, MKDEV(major, 0), NULL, "buttons"); // /dev/buttons 

    gph2con = (volatile unsigned long *)ioremap(0xe0200c40, 16);

    gph2dat = gph2con + 1;

    gph3con = (volatile unsigned long *)ioremap(0xE0200C60, 16);

    gph3dat = gph3con + 1;

    return 0;

}

static void second_drv_exit(void)

{

    unregister_chrdev(major, "second_drv");

    device_destroy(seconddrv_class, MKDEV(major, 0));

    class_destroy(seconddrv_class);

    iounmap(gph2con);

    iounmap(gph3con);

    return 0;

}

module_init(second_drv_init);

module_exit(second_drv_exit);

MODULE_LICENSE("GPL");

====================================================================

seconddrvtest.c测试程序:

#include "sys/types.h"

#include "sys/stat.h"

#include "fcntl.h"

#include "stdio.h"

// seconddrvtest 

int main(int argc, char **argv)

{

    int fd;

    unsigned char key_vals[5];

    int cnt = 0;

    

    fd = open("/dev/buttons", O_RDWR);

    if (fd < 0)

    {

        printf("can't open!\n");

    }

    while (1)

    {

        read(fd, key_vals, sizeof(key_vals));

        if (!key_vals[0] || !key_vals[1] || !key_vals[2] || !key_vals[3] || !key_vals[4])

        {

            printf("d key pressed: %d %d %d %d %d\n", cnt++, key_vals[0], 

                                                                                             key_vals[1], key_vals[2], 

                                                                                             key_vals[3], key_vals[4]);

        }

    }

    return 0;

}


关键字:Tiny210驱动  KEY测试

编辑:什么鱼 引用地址:http://www.eeworld.com.cn/mcu/2018/ic-news101241707.html
本网站转载的所有的文章、图片、音频视频文件等资料的版权归版权所有人所有,本站采用的非本站原创文章及图片等内容无法一一联系确认版权者。如果本网所选内容的文章作者及编辑认为其作品不宜公开自由传播,或不应无偿使用,请及时通过电子邮件或电话通知我们,以迅速采取适当措施,避免给双方造成不必要的经济损失。

上一篇:Tiny210驱动之按键中断实验
下一篇:Tiny210驱动之LED测试

关注eeworld公众号 快捷获取更多信息
关注eeworld公众号
快捷获取更多信息
关注eeworld服务号 享受更多官方福利
关注eeworld服务号
享受更多官方福利

推荐阅读

Tiny210驱动之LED测试

first_drv.c驱动源码:#include "linux/device.h"#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"stati
发表于 2018-10-12

Tiny210驱动之按键中断实验

[5] = {    {S5PV210_GPH2(3), 0x01},    {S5PV210_GPH3(0), 0x02},    {S5PV210_GPH3(1), 0x03},    {S5PV210_GPH3(2), 0x04},    {S5PV210_GPH3(3), 0x05},};// 确定按键值 static irqreturn_t buttons_irq(int irq, void *dev_id){ 
发表于 2018-10-12

Tiny210驱动之按键poll机制

;struct pin_desc pins_desc[5] = {    {S5PV210_GPH2(3), 0x01},    {S5PV210_GPH3(0), 0x02},    {S5PV210_GPH3(1), 0x03},    {S5PV210_GPH3(2), 0x04},    {S5PV210_GPH3(3), 0x05},};// 确定按键值static irqreturn_t buttons_irq(int
发表于 2018-10-12

Tiny210驱动之按键异步通知

, 0x84, 0x85 static unsigned char key_val;struct pin_desc pins_desc[5] = {    {S5PV210_GPH2(3), 0x01},    {S5PV210_GPH3(0), 0x02},    {S5PV210_GPH3(1), 0x03},    {S5PV210_GPH3(2), 0x04},    {S5PV210_GPH3(3), 0x05
发表于 2018-10-12

Tiny210按键互斥锁、原子变量驱动

, 0x84 static unsigned char key_val;// 键值: 按下时, 0x01, 0x02, 0x03, 0x04, 0x05 // 键值: 松开时, 0x81, 0x82, 0x83, 0x84, 0x85 static unsigned char key_val;struct pin_desc pins_desc[5] = {    {S5PV210_GPH2(3), 0x01},    {S5PV210_GPH3(0), 0x02},    {S5PV210
发表于 2018-10-12

世强&keysight免费开放实验室,为提供企业IOT物联网射频测试

IOT物联网射频性能测试,「世强&Keysight」开放实验室有什么?「世强&Keysight」开放实验室针对IOT物联网射频性能测试提供E4440A频谱分析仪和N5172B、N5182A、E4432B信号发生器。可用于无线抄表、智能家居、智能开关、智能照明、智能锁、智能穿戴等物联网领域,为客户提供测试FSK/OOK通用调制方式及符合ZigBee和BLE协议调制信号方式的无线射频发射功率、中心频率误差、容限及接收灵敏度,帮助客户了解IOT物联网产品相关射频指标的收发性能。如有IOT物联网射频性能测试需求,可复制以下网站进行预约:https://www.sekorm.com/labOrder/order 频谱分析仪
发表于 2018-06-27
世强&keysight免费开放实验室,为提供企业IOT物联网射频测试

小广播

何立民专栏

单片机及嵌入式宝典

北京航空航天大学教授,20余年来致力于单片机与嵌入式系统推广工作。

电子工程世界版权所有 京ICP证060456号 京ICP备10001474号 电信业务审批[2006]字第258号函 京公海网安备110108001534 Copyright © 2005-2018 EEWORLD.com.cn, Inc. All rights reserved
pt type="text/javascript" src="//v3.jiathis.com/code/jia.js?uid=2113614" charset="utf-8">