linux--Input Subsystem __linux

Source: Internet
Author: User

1. In Linux development, the input subsystem can generate those events.

The type of event for input devices in Linux (here is a list of some of the most commonly used, more see LINUX/INPUT.H):

Ev_syn 0x00 Sync Events
Ev_key 0x01 Key Event
Ev_rel 0x02 Relative coordinates
Ev_abs 0x03 Absolute coordinates
Ev_msc 0x04 Other
ev_led 0x11 LED
EV_SND 0x12 Sound
Ev_rep 0x14 Repeat
EV_FF 0x15 Force Feedback
~~~~~~~~~~~~~~~~~~~~~~~~
EV_PWR power supply
Ev_ff_status State

2, the composition of the input subsystem

The input subsystem consists of driving layer, input subsystem core and event processing layer. An input event, such as a mouse move, an application in which the keyboard presses inferior to reach the user control in the order of Driver->inputcore->event Handler->userspace.

 

 

Drive Layer: Converts the underlying hardware input into a unified event form and wants to report to the core (input cores).

input subsystem Core: Connecting link. Provide input device registration and operation interface for drive layer, such as: Input_register_device; Notify event processing layer to process event; Generate appropriate device information in/proc

Event-handling layer: primarily interacting with user space. (in Linux, all devices are processed as files in user space, due to the provision of fops interfaces in general drivers, and the generation of corresponding device files in/dev with nod, which is done by the event processing layer in the input subsystem)

3. Implement input Drive

3.1 Device Description:input_dev structure

3.2 Implement device drive core work is: report to the System key, touch screen and other input events (event, through input_event structure description), no longer need to care about file operation interface. Drive report events reach user space via Inputcore and EventHandler.

3.3 Register input device function:int input_register_device (struct Input_dev *dev)

3.4 Logout input device function:void input_unregister_device (struct Input_dev *dev)

3.5 Drive Implementation-initialization (event support):

Set_bit () tells the input subsystem which events and which keys to support. For example:

Set_bit (Ev_key,button_dev.evbit) (where Button_dev is struct Input_dev type)

The 3.6 struct Input_dev has two members:

Evbit:

event types, including

Ev_rst,ev_rel,ev_msc,ev_key,ev_abs,ev_rep, etc.)

Keybit:

key type (included when event type is Ev_key )

Btn_left,btn_0,btn_1,btn_middle, etc.)

 

3.7 Drive Implementation--reporting events:

the functions used to report Ev_key,ev_rel,ev_abs events are

void Input_report_key (struct input_dev *dev,unsigned int code,int value)

void Input_report_rel (structinput_dev *dev,unsigned int code,int value)

void Input_report_abs (struct input_dev *dev,unsigned int code,int value)

 

Drive implementation-end of report:

Input_sync () synchronization is used to tell the input core subsystem report to end.

Example 1: In touch screen device driver, the whole report process of one click is as follows:

Input_reprot_abs (input_dev,abs_x,x); X coordinates

Input_reprot_abs (input_dev,abs_y,y); Y-coordinate

Input_reprot_abs (input_dev,abs_pressure,1);

Input_sync (Input_dev);//sync End

Example Analysis 2 (key interrupt program):

//Key initialization

static int __init button_init (void)

{//Application interrupted

if (REQUEST_IRQ (button_irq,button_interrupt,0, "button", NUll))

return–ebusy;

set_bit (ev_key,button_dev.evbit);//Support Ev_key event

 

set_bit (btn_0,button_dev.keybit);//support device two keys

 

set_bit (btn_1,button_dev.keybit);

 

Input_register_device (&button_dev)//Registered input device

}

/ * Report the event in the key interrupt * *

Static void button_interrupt (int irq,void *dummy,struct pt_regs *fp)

{

Input_report_key (&BUTTON_DEV,BTN_0,INB (BUTTON_PORT0))//Read value of register button_port0

Input_report_key (&BUTTON_DEV,BTN_1,INB (Button_port1));

Input_sync (&button_dev);

}

Summary: The input subsystem is still a character device driver, but the amount of code is much reduced, and the input subsystem needs to do only two things: initialization and event reporting (which is done through interrupts in Linux). Readers may wish to use SOURCEINSIGNT input input_init to search for the implementation of the input subsystem

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.