2.3
Evdev_handler
Implementation
Linux
Several input subsystems have been created
Handler
It is used to process several common events, such as the mouse, keyboard, and joystick. The most basic is
Evdev_handler
, It is in
Driver/input/evdev. c
. It can receive any type of events, any
ID
The device can be connected to it, and its corresponding device node is
/Dev/eventx
The range of the sub-device number is
64
~
95
.
2.3.1
Initialization and
Input_device_id
For example
Program list
2
. 6
.
Program list
2
.
6
Evdev_handler
/* Driver/input/evdev. C */
Static const struct input_device_id evdev_ids [] = {
{
. Driver_info = 1 },
/* Matches all devices
*/
{},
/* Terminating zero entry
*/
};
Module_device_table (input, evdev_ids );
Static struct input_handler evdev_handler = {
. Event
= Evdev_event,
. Connect
=
Evdev_connect,
. Disconnect
=
Evdev_disconnect,
. Fops
=
& Evdev_fops,
. Minor
= Evdev_minor_base,
. Name
= "Evdev ",
. Id_table
=
Evdev_ids,
};
Static int _ init evdev_init (void)
{
Return
Input_register_handler (& evdev_handler );
}
Static void _ exit evdev_exit (void)
{
Input_unregister_handler (& evdev_handler );
}
Module_init (evdev_init );
Module_exit (evdev_exit );
The initialization process is very simple, that is
Evdev_handler
The registration process is already in
2.2
I have discussed this section.
Evdev_handler
Only initialized
Id_table
,
According
Program list
1
. 11
The
(1)
Step analysis, we can know this
Input_device_id
And any device
ID
Match.
By
2.2
We know the maximum number of sub-devices.
3
BITs are used
Handler
In
Input_table
Medium addressing, then each
Handler
The number of sub-devices is the lowest.
5
Number of BITs, total
32
. So
Evdev_handler
Up
32
Input devices are connected to them.
2.3.2
Establish a connection
Evdev_handler
The following is a prototype of the function used to establish a connection:
Static int evdev_connect (struct input_handler
* Handler, struct input_dev * Dev, const struct input_device_id * ID );
Its main task is to apply for
Input_handle
Struct
Handler
And
Dev
Connect. At the same time, the device that establishes the connection occupies one device number. This device number is
64
~
95
The minimum idle value. If no idle device number is available, the connection fails.
2.3.3
Open a device Node
Since each
Evdev_handler
All devices that have established connections use device numbers, so you can create corresponding device nodes. Each time a device node is opened,
FIFO
Ring message buffer, capable of Storage
64
Messages.
2.3.4
User space read/write messages
You can
Evdev_handler
Messages are written to the connected device node. The format of data written is as follows:
Program list
1
. 2
The write length is the number of bytes of data. When the buffer is full, it is written from the beginning, directly overwriting the previous messages without notifying the user program. Because the message is written through
Input Core
Therefore, the invalid messages written do not enter the message buffer.
In addition, although each thread that opens a node has a message buffer, the written messages are sent to every thread that opens the same node. It will also be passed to the same
Input_dev
Other device nodes.
Read messages only from the message buffer. The format of the read message is also as follows:
Program list
1
. 2
In
Input_event
Same. Each message can only be read once.
2.3.5
Event Processing
Evdev_handler
Slave
Input Core
After an event is received, it is sent to the thread of the exclusive device.
(
If
)
Or all the threads that open the device. Before the event is distributed, it is first packaged
Input_event
And add the timestamp.
2.3.6
Synchronous Message
Each
Input_dev
Synchronization events are supported by default (
Ev_syn
). However
Evdev_handler
Instead of using a synchronization event, you just write it into the buffer as a general event. Because every write operation is timely, no synchronization is required.
2.3.7
Evdev_handler
Applicability
Evdev_handler
Only package messages
Input_event
. The event reports sent by all devices are visible to the user space. The program that needs to directly use the original device event can read
Eventx
For mouse or more complex devices,
Evdev_handler
Not suitable.