Path for Linux Device Driver engineer-Input subsystem

Source: Internet
Author: User

Path for Linux Device Driver engineer-input subsystem

K-style

Reprinted please indicate from Hengyang Normal College 08 electric 2 k-style http://blog.csdn.net/ayangke,QQ:843308498 mailbox: yangkeemail@qq.com

 

I. input subsystem System Framework

The Linux kernel implements an input subsystem. Many input devices, such as buttons, keyboards, mice, and touch screens, can use the interfaces provided by the input subsystem to write drivers, this can help drive writers to reduce the workload. Because the input subsystem will help the driver complete the device methods of open, read, close and other columns. The driver writer only needs to report the corresponding event information to the event hander at the upper layer of the input subsystem when pressing the button or clicking the event. Is the framework of the input subsystem. The bottom layer is the driver layer of the input device, that is, the core layer of the input subsystem. Implemented by the input. c file. The above layer corresponds to the handler layer of the device, and each device corresponds to a handler. Handler will create the corresponding file in the/dev/Input Folder, process the time when the underlying report comes up, and complete some corresponding file operations.

II. Key Points of writing Input driver


1. Allocate, register, and cancel input devices

Struct input_dev * input_allocate_device (void)
Intinput_register_device (struct input_dev * Dev)
Voidinput_unregister_device (struct input_dev * Dev)

2. Set the event type, Event code, event value range, input_id, and other information supported by the input device.

See USB keyboard driver: usbkbd. c

Usb_to_input_id (Dev, & input_dev-> ID); // you can specify bustype, vendo, and product.
Input_dev-> evbit [0] = bit (ev_key) | bit (ev_led) | bit (ev_rep); // supported event types
Input_dev-> ledbit [0] = bit (led_numl) | bit (led_capsl) | bit (led_scrolll) | bit (led_compose) | bit (led_kana ); // event code supported by the ev_led event
For (I = 0; I <255; I ++)
Set_bit (usb_kbd_keycode [I], input_dev-> keybit); // event code supported by the ev_key event

Include/Linux/input. h defines the supported types (the 2.6.22 kernel is listed below)

# Define ev_syn 0x00
# DefineEV_KEY 0x01
# DefineEV_REL 0x02
# DefineEV_ABS 0x03
# DefineEV_MSC 0x04
# DefineEV_SW 0x05
# DefineEV_LED 0x11
# Defineev_snd 0x12
# Defineev_rep 0x14
# Define ev_ff 0x15
# Defineev_pwr 0x16
# Defineev_ff_status 0x17
# Defineev_max 0x1f

One device supports one or more event types. You also need to set the trigger event code for each event type. For example, for an ev_key event, you need to define which key event codes are supported.

3. If necessary, set the processing method when the input device opens, closes, or writes data.

See USB keyboard driver: usbkbd. c

Input_dev-> open = usb_kbd_open;
Input_dev-> close = usb_kbd_close;
Input_dev-> event = usb_kbd_event;

4. Report the event to the subsystem when an input event occurs.


Functions used to report events such as ev_key, ev_rel, and ev_abs include:

Void input_report_key (structinput_dev * Dev, unsigned int code, int value)
Void input_report_rel (structinput_dev * Dev, unsigned int code, int value)
Void input_report_abs (structinput_dev * Dev, unsigned int code, int value)

If you are in trouble, you can remember only one function (because the above functions are implemented through it)

Voidinput_event (struct input_dev * Dev, unsigned int type, unsigned int code, intvalue)

Call after report time

Input_sync (input_dev), which informs the receiver of the event that a complete report has been generated for the driver.

Reference: Liu Hongtao Linux Kernel Input subsystem analysis

 

Related Article

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.