Linux input Subsystem

Source: Internet
Author: User

In Linux, key, touch screen, mouse and so on input devices can rely on the input subsystem to provide interface functions to achieve their device driver, in the input subsystem, the system has completed the characteristics of these input devices, so according to the interface provided by the subsystem, The device driver for an input device can be completed only by completing its own uniqueness.

In Linux, the input subsystem consists of three layers, the device driver layer, the core layer, and the event processing layer. The device driver layer says that the response of the underlying input device translates into a standard input event, and the event processing layer provides the application with a unified device access interface to interact with the underlying data, and the core layer is the bridge between the driver layer and the event processing layer.

The important structure in the input subsystem is the INPUT_DEV structure, which is the subject of our work, and each input device corresponds to such a structure, and some of the important contents are as follows:

unsigned long evbit[nbits (EV_MAX)];//supported event types

unsigned long keybit[nbits (KEY_MAX)];//supported key bitmap

unsigned long relbit[nbits (Rel_max)];//bitmap that supports relative coordinates

unsigned long absbit[nbits (Abs_max)];//bitmap that supports absolute coordinates

unsigned long mscbit[nbits (Msc_max)];

unsigned long ledbit[nbits (Led_max)];

unsigned long sndbit[nbits (Snd_max)];

unsigned long ffbit[nbits (Ff_max)];

unsigned long swbit[nbits (Sw_max)];

Writing a driver that conforms to the input subsystem framework typically consists of the following steps:

    1. Assigning a INPUT_DEV structure

    2. Set INPUT_DEV structure (set events, etc.)

    3. Registered

    4. Hardware-related operations

Related APIs:

(1). Assigning an input device

struct Input_dev *input_allocate_device (void)//The function allocates memory for struct Input_dev struct, returns a struct that executes the allocation successfully, fails to return null

(2). Register an input device

Input_register_device (struct Input_dev *dev)//This function is used to register an input device with the input subsystem core

3). Release the memory occupied by the struct Input_dev struct

Input_free_device (struct Input_dev *dev)


(4). Write off the input device structure of the device

Input_unregister_device (struct Input_dev *dev)


(5). Tell the subsystem which events it supports

Set_bit (int nr, volatile void * addr)


(6). The event that the report was executed

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

void Input_sync (struct Input_dev *dev)//Report synchronization events

Example: Keyboard output (part of the code) is implemented by the keys on the jz2440:

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/78/D1/wKioL1aDrZiiN4QNAADv5m9n2bs679.png "title=" 1.PNG " alt= "Wkiol1adrziin4qnaadv5m9n2bs679.png"/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/78/D3/wKiom1aDrZChYpX8AACb_CNWY3g392.png "title=" 2.PNG " alt= "Wkiom1adrzchypx8aacb_cnwy3g392.png"/>

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/78/D3/wKiom1aDrbDh2quiAAFBdooGCz4460.png "title=" 4.PNG " alt= "Wkiom1adrbdh2quiaafbdoogcz4460.png"/>

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/78/D1/wKioL1aDrb3ySXNQAAK2qKXL66g735.png "title=" 3.PNG " alt= "Wkiol1adrb3ysxnqaak2qkxl66g735.png"/>


Test:

Load driver, execute at Terminal:

Cat/dev/tty1

Press: S2,S3,S4

We can get LS.

Or:

EXEC 0</dev/tty1/* Replace the DEV/TTY1 device input with the standard input */

You can then use the keystrokes to enter

Phenomenon:

Press the key 2 3 4

Display: ls


This article is from the "June Feng Eureka" blog, please be sure to keep this source http://10274409.blog.51cto.com/10264409/1730096

Linux 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.