1.3
Input subsystem device driver description
1.3.1
Enable and disable Functions
Struct input_dev
In
Open
And
Close
Two function pointers. In
Handler
It will be called after the first connection
Open
Function, which is called when the connection is disconnected.
Close
.
Open
Hardware initialization should be completed, and other resources, such as the interrupt number, should be applied.
Close
Functions do the opposite.
1.3.2
Event Type
Linux
The types of events supported by the input subsystem are as follows:
ProgramList
1
.6
.
Program list
1
.
6
Input subsystem Event Type
/* Include/Linux/input. H */
# define ev_syn
0x00
/*
synchronization event
*/
# define ev_key
0x01
/*
key events
*/
# define ev_rel
0x02
/*
relative coordinates
*/
# define ev_abs
0x03
/*
absolute coordinates
*/
# Define ev_msc
0x04
# Define ev_sw
0x05
# define ev_led
0x11
/*
led
*/
# define ev_snd
0x12
/*
beep
*/
# define ev_rep
0x14
/*
combo event
*/
# Define ev_ff
0x15
# Define ev_pwr
0x16
# Define ev_ff_status
0x17
# Define ev_max
0x1f
# Define ev_cnt
(Ev_max + 1)
Key event
(Ev_key)
Is the simplest event type, used to describe buttons or buttons. The following functions are used to report key events:
Input_report_key (struct
Input_dev * Dev, int code, int value)
Code
Value in
<
Kernel
> Include/Linux/input. h
Medium definition, size
Slave
0
To
Key_max
.
Value
Is
0
Indicates that the key is lifted, not
0
Press the time table button. For the same button, only when
Value
Is different from the previous event.
In addition to button events, relative coordinate events
(Ev_rel)
And absolute coordinate events
(Ev_abs)
It is also a common event.
To enable devices to support these two types of events
Struct input_dev
Of
Evbit
Bitwise
1
In
Relbit
And
Absbit
In the bitmap, set the supported coordinate axes.
1
. Reference
1.2
Section
7
,
8
Two steps.
A relative coordinate event is used to describe a message similar to moving a mouse. Functions for reporting relative coordinates are as follows:
Input_report_rel (struct
Input_dev * Dev, int code, int value)
Code
Description axis,
Value
Indicates relatively moving (positive or negative ). Only when
Value
When the value is not zero, a valid event can be generated.
Absolute coordinates require additional work. Fill in during initialization
Input_dev
In
Some data domains. Call the following functions for each supported coordinate axis:
Input_set_abs_params (struct input_dev * Dev, int axis,
Int min, int Max, int fuzz, int flat );
Function parameters represent the input device pointer, coordinate axis, minimum value, maximum value, resolution, and reference value from right to left. The last two parameters can also be set
0
It indicates that the device is very accurate and can always return to the center accurately.
Input_set_abs_params
FunctionCodeFor example
Program list
1
.7
.
Program list
1
.
7
Input_set_abs_params
Static inline void input_set_abs_params (struct
Input_dev * Dev, int axis, int min, int Max, int fuzz, int flat)
{
Dev-> absmin [axis]
= Min;
Dev-> absmax [axis]
= Max;
Dev-> absfuzz [axis]
= Fuzz;
Dev-> absflat [axis]
= Flat;
Dev-> absbit [bit_word (axis)]
| = Bit_mask (axis );
/*
Coordinates have been registered for this line.
*/
}
In addition, synchronization events are often used in input device drivers.
(Ev_syn)
The input subsystem supports this event by default, and the driver does not need to register. A device such as a mouse or touchpad needs to use it to prompt that a complete event report has been sent to the upper layer. The report form for synchronization events is as follows:
Input_sync (zlgkpd-> input );
1.3.3
Keycode
,
Keycodemax
And
Keycodesize
First, describe the difference between the scan code and the key value. For example
Program list
1
.4
As shown in, the example contains the values of the four buttons, so the scan code range is
0 ~ 3
The key value is
Keypad_keycode
.
Keycode
,
Keycodemax
And
Keycodesize
The values stored in these three data fields are the first address of the key value array, the number of key values, and the size of each key value in bytes. With these three variables, you can change the key-value ing of the keyboard at runtime. For example, the fourth key value in the original array is
Key_z
Can be changed
Key_d
Or other values. In this way, the same scan Code corresponds to different key values.
After these three domains are correctly filled, the kernel can use
Input_dev
To modify the key-value ing. The ing modification function is
Input_dev
In
Setkeycode
,
Getkeycode
The two function pointers correspond to functions. If they are not initialized before registration, the initialization function assigns the default functions to them.
Eviocgkeycode
And
Eviocskeycode
The two
IOCTL
The command is used to view and modify the key values respectively.
1.3.4
Automatic button combo
We all have this experience: Hold down the direction key and keep pulling the document in a certain direction. This function is used to automatically send a button event before the button is lifted.
Button combo event
(Ev_rep)
In
Input_devd
Of
Evbit
Bitwise
1
You can.
Dev-> rep [rep_delay]
And
Dev-> rep [rep_period]
Respectively store the latency and cycle of the combo. If the driver does not assign values to them, the system assigns them
250
And
33
. The latency is the interval from the key to the first one. The cycle is the interval between two consecutive clicks. They are all in milliseconds.
1.3.5
Bus Type
Input_dev
Medium
Input_id
The bus type is used. The bus types supported by the input subsystem are as follows:
Program list
1
.8
.
Program list
1
.
8
Input subsystem Bus Type
/* Include/Linux/input. H */
# Define bus_pci
0x01
# Define bus_isapnp
0x02
# Define bus_usb
0x03
# Define bus_hil
0x04
# Define bus_bluetooth
0x05
# Define bus_virtual
0x06
# Define bus_isa
0x10
# Define bus_i8042
0x11
# Define bus_xtkbd
0x12
# Define bus_rs232
0x13
# Define bus_gameport
0x14
# Define bus_parport
0x15
# Define bus_amiga
0x16
# Define bus_adb
0x17
# Define bus_i2c
0x18
# Define bus_host
0x19
# Define bus_gsc
0x1a
# Define bus_atari
0x1b
1.3.6
Other event types
Ev_led
And
Ev_snd
The event is for the keyboard.
LED
And buzzer. These two types of events are sent to the driver by the input subsystem kernel.
If the driver supports these two types of events, fill in
Input_dev
In
Event
The function pointer is actually a callback function. In addition, fill
Input_dev
Medium
Evbit
The corresponding bit.
This callback function may be called at the bottom half of the interrupt or interrupt, therefore,
event
the function cannot sleep and must end as soon as possible.