Linux 按键输入驱动实验

本文介绍了如何编写Linux按键驱动程序,包括驱动的加载与测试APP的创建。通过执行'depmod'和'modprobe key.ko'命令加载驱动模块,然后使用自编写的keyApp与'/dev/key'设备交互进行测试。
摘要由CSDN通过智能技术生成

按键驱动程序编写

#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/delay.h>
#include <linux/ide.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/errno.h>
#include <linux/gpio.h>
#include <linux/cdev.h>
#include <linux/device.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/of_gpio.h>
#include <linux/semaphore.h>
#include <asm/mach/map.h>
#include <asm/uaccess.h>
#include <asm/io.h>

#define KEY_CNT 1 /* 设备号个数 */
#define KEY_NAME "key" /* 名字 */
 
 /* 定义按键值 */
 #define KEY0VALUE 0XF0 /* 按键值 */
 #define INVAKEY 0X00 /* 无效的按键值 */
 
 /* key 设备结构体 */
 struct key_dev{
 dev_t devid; /* 设备号 */
 struct cdev cdev; /* cdev */
 struct class *class; /* 类 */
 struct device *device; /* 设备 */
 int major; /* 主设备号 */ int minor; /* 次设备号 */
 struct device_n
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值