Input subsystem Study Notes 4 software design process and related APIs

Source: Internet
Author: User

[Thanks to Terminator for posting this article]

Next, let's start to look at the software design process of the input subsystem. When I read it, I also sorted out the relevant APIs in the design code, and detailed the Code Implementation of the input subsystem in the next article.

Input subsystem software design process

The software design process is as follows:

Allocate an input device -- register an input device -- Report input events -- cancel an input device -- release an input device

Design related APIs

Allocate an input device

C/C ++ code
  1. Struct input_dev * input_allocate_device *(Void);

Register an input device

C/C ++ code
  1. Int input_register_device (StructInput_dev * Dev );

Driver implementation-event support

C/C ++ code
  1. Set_bit (ev_key, button_dev.evbit)
  2. // Set_bit tells the inout subsystem what events it supports
  3. // Struct input_dev has two members: evbit and keybit, which indicate the event and key types supported by the device.

Event Type

The event types of input devices in Linux are as follows (only common events are listed here. For more information, see Linux/input. h ):

C/C ++ code
  1. Ev_syn 0x00 synchronization event
  2. Ev_key 0x01 key event
  3. Ev_rel 0x02 relative coordinates
  4. Ev_abs 0x03 absolute coordinates
  5. Ev_msc 0x04 others
  6. Ev_led 0x11 led
  7. Ev_snd 0x12 sound
  8. Ev_rep 0x14 repeat
  9. Ev_ff 0x15 Force Feedback event

Button type

When the event type is ev_key, you also need to specify the key type:

C/C ++ code
  1. Btn_left left mouse button
  2. Btn_right right-click
  3. Btn_middle
  4. Btn_0 digit 0 Key
  5. Btn_1 digit 1 key

The above set_bit function completes the ev_key assignment to button_dev.evbit.

Driving implementation-Reporting events

C/C ++ code
  1. Void input_event (StructInput_dev * Dev, unsignedIntType, unsignedIntCode,IntValue); // report the input event of the specified type and code
  2. Void input_report_key (StructInput_dev * Dev, unsignedIntCode,IntValue);/* report the key value, code: Event code. If the event is ev_key, this code is the device's keyboard code. For example, the Code for mouse keys is 0x110 ~ 0x116, where 0x110 (btn_left), 0x111 (btn_right), 0x112 (btn_middle ). For other massage meanings, see include/Linux/input. h file */
  3. Value: The Event value. If the event type is ev_key, the value is 1 when the key is pressed and 0 when the key is released.
  4. Void input_report_rel (StructInput_dev * Dev, unsignedIntCode,IntValue); // report relative coordinates
  5. Void input_report_abs (StructInput_dev * Dev, unsignedIntCode,IntValue); // report absolute coordinates
  6. Void input_sync (StructInput_dev * Dev);/* Report the synchronization event. input_sync () is used to report the end of the high-speed input core report and process the reported information */

In the touch screen drive design, the whole reporting process of one coordinate and one pressing state is as follows:

C/C ++ code
  1. Input_report_abs (input_dev, abs_x, x); // X coordinate
  2. Input_report_abs (input_dev, abs_y, Y); // y coordinate
  3. Input_report_abs (input_dev, abs_pressure, Pres); // pressure
  4. Input_sync (StructInput_dev * Dev); // synchronize

Release and cancel a device

C/C ++ code
  1. Void input_free_device (StructInput_dev * Dev );
  2. Void input_unregister_device (StructInput_dev *);

Original link http://www.ourunix.org/post/293.html

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.