一、開發環境
1、硬體平台:fs2410
2、主機:ubuntu 10.10
3、核心版本: linux 2.6.35
4、交叉編譯工具鏈:arm-none-linux-gnueabi-
二、詳細**
button_scan.c:
#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define device_name "button"
#define gpecon 0x56000040
#define gpedat 0x56000044
#define gpfcon 0x56000050
#define gpfdat 0x56000054
#define gpgcon 0x56000060
#define gpgdat 0x56000064
#define extint0 0x56000088
#define extint1 0x5600008c
#define extint2 0x56000090
static int button_major = 255;
struct button_dev
;struct button_irq_desc
;static struct button_irq_desc button_irqs =
, ,
, ,
};struct button_dev dev;
static volatile unsigned int *gpecon;
static volatile unsigned int *gpedat;
static volatile unsigned int *gpfcon;
static volatile unsigned int *gpfdat;
static volatile unsigned int *gpgcon;
static volatile unsigned int *gpgdat;
static volatile unsigned int *extint0;
static volatile unsigned int *extint1;
static volatile unsigned int *extint2;
static void init_gpio(void)
writel(readl(extint0) | (2 << 0), extint0);
writel(readl(extint0) | (2 << 8), extint0);
writel(readl(extint1) | (2 << 12), extint1);
writel(readl(extint2) | (2 << 12), extint2);
}static __inline unsigned char button_scan(int irq)
static irqreturn_t button_interrupt(int irq, void *dev_id)
static int request_irqs(void)
} return 0;
}static __inline void free_irqs(void)
return;
}void ioremap_gpio(void)
static int button_open(struct inode *inode,struct file *filp)
static int button_release(struct inode *inode,struct file *filp)
static ssize_t button_read(struct file *filp, char *buf, size_t size, loff_t *ppos)
ret = size;
dev.key_value = 0;
return ret;
}static ssize_t button_write(struct file *filp, const char __user *buf, size_t size, loff_t *ppos)
static int button_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
static unsigned int button_poll(struct file *filp, poll_table *wait)
static struct file_operations button_fops =
;static void button_setup_cdev(struct cdev *dev, int index)
static int __init button_init(void)
if(result < 0)
return result;
printk("button_major : %d\n", button_major);
button_setup_cdev(&dev.cdev, 0);
init_waitqueue_head(&dev.r_wait);
return 0;
}void iounmap_gpio(void)
static void __exit button_exit(void)
module_init(button_init);
module_exit(button_exit);
module_author("yhr");
module_license("gpl");
應用測試程式:(button_test.c)
#include #include #include int main(void)
while(1) }
return 0;
}
makefile:
ifeq ($(kernelrelease),)
#kerneldir ?= /your/target/source/directory/
kerneldir ?= /home/linux/linux-2.6.35/
pwd := $(shell pwd)
modules:
$(make) -c $(kerneldir) m=$(pwd) modules
modules_install:
$(make) -c $(kerneldir) m=$(pwd) modules_install
clean:
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions module* modules*
.phony: modules modules_install clean
else
obj-m := button_scan.o
endif
platform裝置驅動之按鍵掃瞄(cdev裝置)
一 開發環境 1 硬體平台 fs2410 2 主機 ubuntu 10.10 3 核心版本 linux 2.6.35 4 交叉編譯工具鏈 arm none linux gnueabi 二 詳細 1 button device.c platform device include include inc...
輸入裝置驅動之按鍵裝置驅動
linux輸入子系統就是乙個基於分層模式的系統,其基本的層次分解如下圖所示。在圖中我們可以發現輸入子系統主要包括三個部分裝置驅動層 input driver 核心層 input core 和輸入事件驅動層。輸入子系統的劃分使得輸入裝置的驅動程式設計越來越簡單,但是其中的思想採用我們學習的重點和難點。...
字元裝置驅動按鍵防抖
由於機械開關按鍵時,金屬彈片會出現多次抖動,這樣就會產生多次中斷,讀取多次鍵值。需要引入定時器,比如10ms後再處理定時器函式,這樣每次抖動產生中斷會過10ms後再處理,這樣多次抖動會響應一次定時器中斷處理。定時器使用 兩要素 a.時間 b.函式4 1 定義乙個定時器結構體 static struc...