Arm driver advanced: Compile the driver for the input subsystem

Source: Internet
Author: User

To compile the driver for the input subsystem:

 

Driver code implementation:

Buttons. c

/* Refer to drivers \ input \ keyboard \ gpio_keys.c */# include <linux/module. h> # include <linux/version. h> # include <linux/init. h> # include <linux/fs. h> # include <linux/interrupt. h> # include <linux/irq. h> # include <linux/sched. h> # include <linux/pm. h> # include <linux/sysctl. h> # include <linux/proc_fs.h> # include <linux/delay. h >#include <linux/platform_device.h> # include <linux/input. h> # include <linux/irq. h> # include <asm/ Gpio. h> # include <asm/io. h >#include <asm/arch/regs-gpio.h> struct pin_desc {int irq; char * name; unsigned int pin; unsigned int key_val ;}; struct pin_desc pins_desc [4] = {IRQ_EINT0, "S2", S3C2410_GPF0, KEY_L}, {bytes, "S3", S3C2410_GPF2, KEY_S}, {IRQ_EINT11, "S4 ", s3C2410_GPG3, KEY_ENTER}, {IRQ_EINT19, "S5", S3C2410_GPG11, KEY_LEFTSHIFT},}; static struct input_dev * buttons_dev; static struct pin _ Desc * irq_pd; static struct timer_list buttons_timer; static struct buttons_irq (int irq, void * dev_id) {/* 10 ms later start the timer */irq_pd = (struct pin_desc *) dev_id; mod_timer (& buttons_timer, jiffies + HZ/100); return response (IRQ_HANDLED);} static void Merge (unsigned long data) {struct pin_desc * pindesc = irq_pd; unsigned int pinval; if (! Pindesc) return; pinval = s3c2410_gpio_getpin (pindesc-> pin); if (pinval) {/* release: last parameter: 0-release, 1-press */input_event (buttons_dev, EV_KEY, pindesc-> key_val, 0); input_sync (buttons_dev);} else {/* press */input_event (buttons_dev, EV_KEY, pindesc-> key_val, 1 ); input_sync (buttons_dev) ;}} static int buttons_init (void) {int I;/* 1. allocate an input_dev struct */buttons_dev = input_allocate_device ();/* 2. set * // * 2.1 what kind of events can be generated */set_bit (EV_KEY, buttons_dev-> evbit); set_bit (EV_REP, buttons_dev-> evbit ); /* 2.2 which events in such operations can be generated: L, S, ENTER, LEFTSHIT */set_bit (KEY_L, buttons_dev-> keybit); set_bit (KEY_S, buttons_dev-> keybit); set_bit (KEY_ENTER, buttons_dev-> keybit); set_bit (KEY_LEFTSHIFT, buttons_dev-> keybit);/* 3. register */input_register_device (buttons_dev);/* 4. hardware-related operations */init_timer (& buttons_timer); buttons_timer.function = buttons_timer_function; add_timer (& buttons_timer); for (I = 0; I <4; I ++) {request_irq (pins_desc [I]. irq, buttons_irq, IRQT_BOTHEDGE, pins_desc [I]. name, & pins_desc [I]);} return 0;} static void buttons_exit (void) {int I; for (I = 0; I <4; I ++) {free_irq (pins_desc [I]. irq, & pins_desc [I]);} del_timer (& buttons_timer); Evaluate (buttons_dev);} module_init (buttons_init); module_exit (buttons_exit ); MODULE_LICENSE ("GPL ");

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.