4. 使用中断及poll机制读取输入按键值

1. 电路图
2. 驱动源代码
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/irq.h>
#include <asm/uaccess.h>
#include <asm/irq.h>
#include <asm/io.h>
#include <asm/arch/regs-gpio.h>
#include <asm/hardware.h>
#include <linux/poll.h>
/* pool机制读取按键值 */

static struct class *four_drv_class;
static struct class_device *four_drv_class_dev;

/*	键值:按下时, 0x01, 0x02, 0x03, 0x04
 *	键值:松开时, 0x81, 0x82, 0x83, 0x84
 */
typedef struct
{
   
	unsigned int pin;
	unsigned int key_val;
}s3c2440_buttons_desc; 

s3c2440_buttons_desc pins_desc[]={
   
	{
   S3C2410_GPF0, 0x01},
	{
   S3C2410_GPF2, 0x02},
	{
   S3C2410_GPG3, 0x03},
	{
   S3C2410_GPG11, 0x04},
};

unsigned int key_val;
/* 等待队列: 
 * 当没有按键被按下时,如果有进程调用s3c24xx_buttons_read函数,
 * 它将休眠
 */
static DECLARE_WAIT_QUEUE_HEAD(button_waitq);

/* 中断事件标志, 中断服务程序将它置1,s3c24xx_buttons_read将它清0 */
static volatile int ev_press = 0;

irqreturn_t buttons_irq(int irq, void *dev_id
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值