IMX257 Input Subsystem

Publisher:SerendipitySoulLatest update time:2024-08-14 Source: cnblogs Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Input Subsystem

1. Input subsystem structure definition

struct input_dev{

const char *name; device name

const char *phys; device path in the system

const char *uniq;

struct input_id id; used to match input hander parameters

unsigned long propbit[BITS_TO_LONGS(INPUT_PROP_CNT)];

unsigned long evbit[BITS_TO_LONGS(EV_CNT)];

//Event types supported by the device, mainly EV_SYNC, EV_KEY, EV_REL, EV_ABS, etc.

unsigned long keybit[BITS_TO_LONGS(KEY_CNT)]; //The bitmap corresponding to the key

unsigned long relbit[BITS_TO_LONGS(REL_CNT)]; //Relative coordinates corresponding to the bitmap

unsigned long absbit[BITS_TO_LONGS(ABS_CNT)]; //Absolute coordinates corresponding to the bitmap

unsigned long mscbit[BITS_TO_LONGS(MSC_CNT)];

unsigned long ledbit[BITS_TO_LONGS(LED_CNT)];

unsigned long sndbit[BITS_TO_LONGS(SND_CNT)];

unsigned long ffbit[BITS_TO_LONGS(FF_CNT)];

unsigned long swbit[BITS_TO_LONGS(SW_CNT)];

unsigned int hint_events_per_packet;

unsigned int keycodemax;

unsigned int keycodesize;

void *keycode;

int (*setkeycode)(struct input_dev *dev, const struct input_keymap_entry *ke, unsigned int *old_keycode);

int (*getkeycode)(struct input_dev *dev, struct input_keymap_entry *ke);

struct ff_device *ff;

unsigned int repeat_key;

struct timer_list timer;

int rep[REP_CNT];

struct input_mt_slot *mt;

int mtsize;

int slot;

int trkid;

struct input_absinfo *absinfo;

unsigned long key[BITS_TO_LONGS(KEY_CNT)]; //Key value corresponding to the key

unsigned long led[BITS_TO_LONGS(LED_CNT)]; //LED corresponding indicator light status

unsigned long snd[BITS_TO_LONGS(SND_CNT)];

unsigned long sw[BITS_TO_LONGS(SW_CNT)];

int (*open)(struct input_dev *dev);

void (*close)(struct input_dev *dev);

int (*flush)(struct input_dev *dev, struct file *file);

int (*event)(struct input_dev *dev, unsigned int type, unsigned int code, int value);

//Event processing function, mainly receives commands issued by users, such as lighting up LEDs;

struct input_handle __rcu *grab;

spinlock_t event_lock;

struct mutex mutex;

unsigned int users;

bool going_away;

bool sync;

struct device dev;

struct list_headh_list; //input handle supported by the device;

struct list_headnode;

};

Enter device information:

Input device information. The following parameters are mainly used when matching input hander.

struct input_id {

__u16 bustype; bus type

__u16 vendor; manufacturer number

__u16 product; Product number

__u16 version; version information

};

2. Input device event processing structure

Data structure for input device event processing:

struct input_handler {

void *private;

void (*event)(struct input_handle *handle, unsigned int type, unsigned int code, int value);

bool (*filter)(struct input_handle *handle, unsigned int type, unsigned int code, int value);

bool (*match)(struct input_handler *handler, struct input_dev *dev);

int (*connect)(struct input_handler *handler, struct input_dev *dev, const struct input_device_id *id);

//This function is called when the input device matches the input handler;

void (*disconnect)(struct input_handle *handle);

void (*start)(struct input_handle *handle);

const struct file_operations *fops; //Supported file operation operations;

int minor;

const char *name;

const struct input_device_id *id_table; //All supported input devices;

struct list_headh_list;

struct list_headnode;

};

3. Link the input_dev and input_handler structures

The data structure connecting input-dev and input handler:

struct input_handle {

void *private;

int open;

const char *name;

struct input_dev *dev; input dev

struct input_handler *handler; input handler

struct list_headd_node;

struct list_head_node;

};

4. Registration and deregistration functions

int input_register_device(struct input_dev *dev)

int input_unregister_device(struct input_dev *dev)

5. Driver event support

The device driver tells the input subsystem which events and keys it supports via set_bit(). For example:

set_bit(EV_KEY,button_dev.evbit)

Two members in struct input_dev:

evbit--event type

keybit--key type

Event Type:

EV_RST--reset

EV_REL--Relative coordinates

EV_MSC--Other

EV_SND--Sound

EV_FF--Force Feedback

EV_KEY--Key

EV_ABS--Absolute coordinates

EV_LED--led

EV_REP--repeat

When the event type is EV_KEY, the key type must also be specified:

BTN_LEFT--left mouse button

BTN_RIGHT--Right mouse button

BTN_MIDDLE--Middle mouse button

BTN_0--Digital 0 key

BTN_1--Number 1 key

6. Incident Reporting

Void input_event(struct input_dev *dev,unsigned int type,unsigned int code,int value);

//Report input events of specified type and code

Void input_report_key(struct input_dev *dev,unsigned int code,int value); //Report key value

Void input_report_rel(struct input_dev *dev,unsigned int code,int value); //Report relative coordinates

Void input_report_abs(struct input_dev *dev,unsigned int code,int value); //Report absolute coordinates

Void input_sync(struct input_dev *dev);

//Report synchronization events In the touch screen driver design, the entire reporting process of a coordinate and press status is as follows:

Input_report_abs(input_dev,ABS_X,x); //X coordinate

Input_report_abs(input_dev,ABS_Y,y); //Y坐标

Input_report_abs(input_dev,ABS_PRESSURE,pres); //压力

input_sync(struct input_dev *dev); //同步

structinput_event {

struct timeval time;

__u16 type;

__u16 code;

__s32 value;

};

① code

The event code. If the event type is EV_KEY, the code is the keyboard code of the device. For example, the key code value on the keyboard is 0--127, and the mouse button code is 0x110---0x116, where 0x110 (BTN_LEFT) is the left mouse button, and 0x111 (BTN_RIGHT) is the right mouse button. For the meaning of other codes, refer to the include/linux/input.h file.

②value

The value of the event. If the event type is EV_KEY, the value is 1 when the key is pressed and 0 when it is released.

After the report is completed, input_sync() notifies the system to accept it and tells the input core that the report has ended.

2. Program Analysis

1. Define the input subsystem structure

2. Set the GPIO pin mode and initialize the GPIO interrupt

3. Input subsystem related settings

As shown in the figure:

Line 80 allocates an input_dev structure

Line 82 sets the input subsystem to support key operations

Line 83 sets the supported key type to BTN_0

Line 84 sets the name and initializes the name

Line 86 registers the input subsystem

4. Initialize the timer for anti-jitter

5. When a key operation occurs, enter the interrupt interrupt and start the timer

As shown in the figure, the pin where the interrupt occurs is saved globally, then the timer is started and processed in the timer interrupt function.

6. Timer interrupt function

As shown in the figure, in the timer interrupt function, the key value of the key is obtained, and then the input_report_key function is used to report the event to the system. Then the input_sync function is used to notify the receiver that the report is complete.

7. Log out in the exit function

As shown in the figure, in the exit function, we release the GPIO port and GPIO interrupt we applied for earlier, and then delete the timer.

The next step is to unregister our input subsystem and release the input subsystem structure.

8. Test: Open the device in the application

As shown in the figure, there is event1 under /dev/input/.

9. Read Input Subsystem

As shown in the figure,

We use the read function to read the data of the input subsystem. Note that what we get here is an input_event structure.

Then, if our information is a key press, we print some key information, if it is a notification message, we print the syn event.

10. Compile and test

Attached driver:


1 /******************************

2     linux key_inputSystem

3  *****************************/

4 #include

5 #include

6 #include

7 #include

8 #include

9 #include

10 #include

11 #include

12 #include

13 #include

14 #include

15 #include

16 #include //error: 'TASK_INTERRUPTIBLE' undeclared

17 #include

18 #include

[1] [2]
Reference address:IMX257 Input Subsystem

Previous article:IMX257 Input Subsystem (Part 2) Keyboard Simulation
Next article:IMX257 miscdevice driver

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号