What is the input device? I believe that all the aunts who sell pet puppies in Wuhan flea market can answer this question. Do you know? Yes, it is our legendary input device. Speaking of the input devices, I believe that the computers used by our friends will not be unfamiliar, that is, keys, mouse, keyboard, and a series of other information that needs to be "hands-on" by our users, then, we can discard it to a Smart PC for processing. As mentioned above, the input subsystem of the Linux kernel has implemented the interface functions of the input device, which greatly reduces our workload. Let's take the akm8973 chip (the main functional chip used for smart phone compass, in fact, an electronic compass) as an example to briefly look at what we need to do to write an input device.
First, apply for an input device in the driver module Loading Function and inform the input subsystem of the events it supports, as shown below:
AKM-> input_dev = input_allocate_device ();
Set_bit (ev_abs, AKM-> input_dev-> evbit );
Input_set_abs_params (AKM-> input_dev, abs_rx, 0, 23040, 0, 0 );
Input_set_abs_params (AKM-> input_dev, abs_ry,-11520,115 20, 0, 0 );
Input_set_abs_params (AKM-> input_dev, abs_rz,-5760,576 0, 0, 0 );
Input_set_abs_params (AKM-> input_dev, abs_throttle,-30, 85, 0, 0 );
Input_set_abs_params (AKM-> input_dev, abs_rudder, 0, 3, 0, 0 );
Input_set_abs_params (AKM-> input_dev, abs_hat0x,-2048,203 2, 0, 0 );
Input_set_abs_params (AKM-> input_dev, abs_hat0y,-2048,203 2, 0, 0 );
Input_set_abs_params (AKM-> input_dev, abs_brake,-2048,203 2, 0, 0 );
These are all set for some parameters supported by the input subsystem. ev_abs indicates that absolute value coordinates are supported, and some parameter access range settings for these coordinates are followed. As for the reason for this setup, let's proceed and we will understand it later.
Then, register the input device in the driver module function:
Err = input_register_device (AKM-> input_dev );
Then, report the events and corresponding coordinates.
Input_report_abs (data-> input_dev, abs_rx, rbuf [0]);
Input_report_abs (data-> input_dev, abs_ry, rbuf [1]);
Input_report_abs (data-> input_dev, abs_rz, rbuf [2]);
The corresponding coordinate values in the three directions are recorded by the driver.
Follow up in depth:
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 );
}
What does this function do? I will talk about it later, but you have more eyes and can use it later.
Add an input device. This is all we need to do. Next, we can use the interface functions provided by the input kernel subsystem to process these coordinate values and transmit them to the user space.
After reading this, I remembered the credit card activities in front of the canteen. Run a credit card to send a ushield. No way. In today's society, we have to pay for everything. Even when we go to the bathroom, we have to tip us, so we don't have to pay for it, even if you urinate your pants in public. So let alone Alibaba Cloud security, which is so technical to protect the security of online shopping. It takes at least 50 oceans to run a U shield at a bank. So many friends like me don't hesitate to create a credit card. Just fill in a few tables, and then you can get a free ushield. How nice is that. "Isn't this the same as our input device, to avoid perfecting the complex interface function set of devices, the lazy guys register it as an input device, so you have to apply for it first, register it and wait for a series of preparatory work (just like the forms we fill out for the U shield). After doing this, we will implement the concept of mr. Lu Xun and directly use the interface functions of the input subsystem ".
However, not all devices can be registered as inpunt devices. Just like a brother took a piece of paper, painted a chicken, and then added an aperture on his head, he was called Tang bohu's name as "the birds and Phoenix ", then they handed it to the CMB staff and said, "I have filled out the form, and I have a U shield." People will think this guy must have just come out of the mental hospital.