- 1、本文档共9页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
传感器驱动和测试程序
传感器驱动和测试程序
#include linux/module.h
#include linux/kernel.h
#include linux/fs.h
#include linux/init.h
#include linux/delay.h
#include linux/miscdevice.h
#include linux/irq.h
#include asm/irq.h
#include linux/interrupt.h
#include asm/uaccess.h
#include asm/io.h
#include mach/regs-gpio.h
#include mach/hardware.h
#include mach/irqs.h
#include linux/device.h
#include linux/poll.h
#define DEVICE_NAME zong
#define BUTTON_MAJOR 236
#define IOCTL_ON 1
#define IOCTL_OFF 0
struct button_irq_desc
{
int irq;
int pin;
int pin_setting;
int number;
char *name;
};
static struct button_irq_desc button_irqs [] =
{
{IRQ_EINT0, S3C2410_GPF0, S3C2410_GPF0_EINT0, 0, KEY1}, /* K1 */
{IRQ_EINT2, S3C2410_GPF2, S3C2410_GPF2_EINT2, 1, KEY2}, /* K2 */
{IRQ_EINT3, S3C2410_GPF3, S3C2410_GPF3_EINT3, 2, KEY3}, /* K3 */
{IRQ_EINT4, S3C2410_GPF4, S3C2410_GPF4_EINT4, 3, KEY4}, /* K4 */
};
static volatile int key_values [] = {0, 0, 0, 0};
static unsigned long led_table [] ={
S3C2410_GPB5,
S3C2410_GPB6,
S3C2410_GPB8,
S3C2410_GPB10,
S3C2410_GPB0,
S3C2410_GPG3,
S3C2410_GPG5,
S3C2410_GPG6,
S3C2410_GPG7,
};
static unsigned int led_cfg_table [] ={
S3C2410_GPB5_OUTP,
S3C2410_GPB6_OUTP,
S3C2410_GPB8_OUTP,
S3C2410_GPB10_OUTP,
S3C2410_GPB0_OUTP,
S3C2410_GPG3_OUTP,
S3C2410_GPG5_OUTP,
S3C2410_GPG6_OUTP,
S3C2410_GPG7_OUTP,
};
static DECLARE_WAIT_QUEUE_HEAD(button_waitq);
static volatile int ev_press = 0;
static irqreturn_t buttons_interrupt(int irq, void *dev_id)
{
struct button_irq_desc *button_irqs = (struct button_irq_desc *)dev_id;
int up = s3c2410_gpio_getpin(button_irqs-pin);
if (up)
key_values[button_irqs-number] = (button_irqs-number + 1) + 0x80;
else
key_values[button_irqs-number] = (button_irqs-number + 1);
ev_press = 1;
wake_up_interruptible(button_waitq);
return IRQ_RETVAL(IRQ_HANDLED);
}
static int tope_buttons_open(struct inode *inode, struct file *file)
{
int i;
int err;
for (i = 0; i sizeof(button_irqs)/sizeof(button_irqs[0]); i++)
{
s
文档评论(0)