E-book reader project of embedded Linux system 4 -- Event System Input

Label: EmbeddedLinuxC languageSmart210Touch screen
236 people read comment(0) Collection Report
Classification:

OneInput event system(EventSystem Input)Architecture andAPI

1).Input event system framework design

Enter the framework of the event system as shown in Fig.OneAs shown.

chartOneInput event system framework

Similar to several other subsystems, the input event subsystem is also a core layer+Mode of loading components,

And the bottom of the actual input device(asTouchscreen)

Raw data generated(input data raw)Input event formatted for encapsulation layer(event input)provide forBook EngineVisit。

This hides the complexity and diversity of the event input device. As a learning project, the core function of the input event system is adopted.

Can be configured to achieve a variety of ways to allow enthusiasts to learn more about the pros and cons of various methods.

2).Input event system frameworkAPISummary

Eventsystem inputTheAPIStatement is locatedInclude/myinpu.hHeader file.

Input eventInput_ev:

The package structure of the input event is declared as follows

Structinput_ev typedef {
Timeval time struct;
Int type; / * stdin, touchsceen * /
Int Val; / * * /
}input_ev;


Time - the system time of the event

Type -To determine which specific device to produce the input event(Currently onlyStdin/touchscreen), the related macro values are as follows:

#defineINPUT_TYPE_STDIN 0
#defineINPUT_TYPE_TSC 1

Val -After abstracting the value of the input event, currently supports the following macro values:

#defineINPUT_VAL_UP 0
#defineINPUT_VAL_DOWN 1
#defineINPUT_VAL_EXIT 2
-1 #defineINPUT_VAL_UNKNOWN
The value is the input device (inputdev) by acquiring the original input values (such as the keyboard "U", "N", touchscreen to the right of the 10%x coordinates)

Through the internal of the device module componentGet_input_ev ()Logic processing and transformation of the original value, submitted toEvent system core inputLayer.

INPUT_VAL_UP -Said PgUp event,INPUT_VAL_DOWN -Said the event page down,INPUT_VAL_EXIT -

Exit ebook event,INPUT_VAL_UNKNOWN -Indicates that the unknown value is obtained, and the exception handling is required.

In this way, the input characteristics of the bottom layer and the value of the input device are encapsulated, providing a uniform abstraction.Event inputInterface。
Kernel descriptorInput_dev:

The core descriptor is declared as follows,

Structinput_dev{typedef
*name char;
Input_method mthd union;
Int (*init_dev) (void);
Int (*exit_dev) (void);
Int (*get_input_ev) (input_ev*pev struct);
Input_dev *next struct;
}input_dev;
Mthd is a combination, according to the different input strategies (such as select mechanism, multi thread, etc.) the actual implementation of the method, according to the configuration, from the macro switch,


According to the actual need to be configuredSelectFile descriptor, or the thread under the multi threadID.

Next:

Loaded by the systemInput_devList, note that the loaded input device is not necessarily activated.

After loading, only throughEnable_input_dev_set ()Function enables the device to generate input response.

Init_dev ()andExit_dev ():

The initialization of the actual input device and the withdrawal function need to be realized in the function of different input devices according to the characteristics of the equipment,

stayEnable_input_dev_set ()andDisable_input_dev_set ()Function to be called.

Get_input_ev ():

The input event acquisition function of the actual input device component is converted into a function of the original input value through a bit logic processing.Input_ev

Then submit toEventsystem core inputLayer.

Get_rt_input_ev ():

thisAPIBe called by the user, getInput_ev ()The. It will come from all theEnbleTheInput DevTo detect whether input events are generated,

And then return the results, the difference of different implementation methods, and then describe the next section.

Enable_input_dev_set ()andDisable_input_dev_set ():

The function according to the list of input parametersDev inputTheNameEnable/Close the input load to the system.Input_dev, only to enable the

Dev inputWill have input response.

3).A variety of input event system functions to achieve a variety of ways to achieve

Eventsystem inputFunction implementation is located inMyinput/myinput.cFile in.

Other functions and previous systems are similar, are linked list related loading, debugging operation, the most important function isGet_rt_input_ev ()

Get_rt_input_ev ()Implementation method of:

Polling (query) method:

Polling methodGet_rt_input_ev ()functionThe implementation method is as follows. It turns the input device by turns.Get_input_ev ()Function,

Input event occurred, returnZeroExpress success, otherwiseQueryAfter all the devices, there is no input event, the return-1.

RET int;
Input_dev *tmp_dev struct = idev_h;
While (tmp_dev) {
//printf ("inputdev:%s\n use", tmp_dev->name);
If (tmp_dev->get_input_ev (PEV) = = 0)
Return 0;
=tmp_dev->next tmp_dev;
}
-1 return;
The method is suitable for the initial project verification and debugging of a single enable input device. The main shortcomings are:

High occupancy rate of 1.CPU (polling of the old problems)

2 when different input_devGet_input_ev ()Function implementation mechanism is not the same(asStdinThe non blocking mechanism is adoptedTscreenDevice blocking mechanism),

Is likely to lead to the non blocking mechanism of the device in a state of starvation, e-book application process will be blocked in theTscreenDevice until the input values are obtained,

suchStdinThe input of the device will not be responsive. In this way, the upper interface has to consider the underlying components of the implementation mechanism.

So this is not a formalReleaseA good mechanism for the project, only to do the initial commissioning.

Select mechanism:

Select mechanismGet_rt_input_ev ()functionThe implementation method is as follows. It's in everyInput_devComponentInit_dev ()In the implementation of a function, the device descriptorFD

Join inEvent system core inputTheFd_setTo pass throughSelectQuery mechanismInput_evWhether or not.

RET int;
Input_dev *tmp_dev struct = idev_h;
Tmp_rd_set fd_set = idev_fd_set;
RET = select (max_fd_val, &tmp_rd_set, NULL, NULL, NULL,);
If (RET > 0) {
While (tmp_dev) {
If (FD_ISSET (tmp_dev->mthd.fd, &tmp_rd_set))
If (tmp_dev->get_input_ev (PEV) = = 0)
Return0;
=tmp_dev->next tmp_dev;
}
}
-1 return;

By using the select mechanism, we can solve the problem.2 problems, regardless of the underlying input_dev, are described in the method of polling (query).Get_input_ev ()How to achieve the function,

as long asSelectFunction.Tmp_rd_setThe descriptor has an input event that occurs while theSelectThe function will return, and will not produce a device in a state of starvation.

But the method also has disadvantages-Make e-book application process inSelectFunction block, affecting the overall efficiency of the system.

 

Multi thread mechanism:

Multi thread mechanismGet_rt_input_ev ()functionThe implementation method is as follows: it is for each input device in eachInput_devComponentInit_dev ()When you open a thread,

And then the user callsGet_rt_input_ev ()When the function is generatedInput_evThe thread submits the conditional signal, and then gets theInput_devGenerated byInput_evValue.

Pthread_mutex_lock (&input_mutex);
Pthread_cond_wait (&input_cond, &input_mutex);
Memcpy (PEV, &sh_iev, sizeof (input_ev struct));
Pthread_mutex_unlock (&input_mutex);
Return 0;


By using the method of multi thread, the CPU occupies a relatively low, and the processing is relatively efficient, and there is no starvation problem arising from the realization mechanism of the device.

TwoInput event system(EventSystem Input)Module component

1) dev stdin

Stdin_devComponents of the source code to achieveMyinput/stdin_dev.cFile in. Similar to other subsystems,Stdin_devMainly also filled

Implementation coreInput_devDescriptor, the implementation of the fill code is as follows:

Structinput_dev stdin_dev static = {
.name = "stdin_dev",
.init_dev = init_stdin_dev,
.exit_dev = exit_stdin_dev,
=get_stdin_dev_ev.Get_input_ev,
};
Init_stdin_dev ():

       BecauseStdin_devEquipment is mainly usedTTYTerminal standard inputStdinAssociated keyboard"U" / "N" / "Q""With the end of three page,

This function asStdin_devThe initialization function, preferred to the standard input terminalStdinSet toNon-canonModel, buffer is set to the minimum.

Used by this function.LinuxSystem terminal function and structure of the use of details, you can refer toUnixA book on advanced programming environment.

Exit_stdin_dev ():

       This function is also calledLinuxSystem terminal correlationAPI, will be the terminalTTYNormal mode of state recovery.

Get_stdin_dev_ev ():

       The function acquisition terminalStdinThe original input, and if encounteredU/N/QThree key inputs, thenInput_evTheValValue is set to the corresponding

INPUT_VAL_UP/INPUT_VAL_DOWN/INPUT_VAL_EXIT, and then submit the input event to theSystem core input.

 

2) touchscreen

Smart210Characteristics and using method of touch screen for development board:

Smart210Development board touch screen isSevenInch multi touch capacitive touch screen, but not@Wei Dongshan teacher video with the resistance screen. And, as a result ofSmart210

UsedGOODIXNon open source of the company's capacitive touch screen driver, used a callOnewireThe driver, the package of the touch screenEventEnter the event, and thus the Wei Dongshan

The teacher's source code, need to be modified in order toSmart210Development board use.

Smart210 development board of the original file system (3.0.8 Linux kernel), in fact, usr/lib and usr/lib/ts have been installed in the tslib library, cross tool chain also has tslib related header files,

The difference between its library and the original tslib is as follows:

chart2 differences in Smart210 environment variables in tslib



Figure 3 tslib ts.config Smart210 difference


Figure 4 tslib Smart210 dynamic link library under the file lib/ts


Figure 2 shows the configuration of the Smart210 development board tslib related environment, pay attention to the red line, TSLIB_TSDEVICE used by the Smart210 is not the usual /dev/input/event*,

And should be the GOODIX chip capacitive touch screen 1Wire mode of the special non open source drive equipment.

Figure 3 is the difference between the ts.config, where the yellow line, module_raw used in the library, and the video configuration is different from the Dongshan, Smart210 development board has a special touch screen for it

Device in the application layer to encapsulate a bottom driver used library, the library where the path is shown in figure 4. The library is tslib original code compiled out of the.

Smart210 development board only use the configuration, the matching of the relevant device and module_raw, application layer program can work properly to get data,

The above is the Smart210 capacitive touch screen and Wei Dongshan video JZ2440 resistive screen configuration on the part of the difference.

TouchsreenImplementation of module components

TouchsreenModule component inMyinput/tscreen.cImplementation in file. The component uses the open sourceTslibTouch screen library, the relevant source code can be TslibOpen source library code download Download to.

TslibThe need to install the configuration, related to the tutorial can refer to this articleTslibCompile and install method .

TouchsreenComponents also need to be filledInput_devStructure bodyInit_tscreen_dev ()Mainly callTslibTheAPITo be related to the initialization, you can refer to

APIUse tutorial.

Get_tscreen_ev ():

         This function is obtainedTouchscreenRaw input data(input raw)And convert it toInput_evCorresponding values are then presented.

Input_evThe relationship between the event and the touch screen input is shown in Figure 5Shown

                                                                                            Figure 5Input_evCorresponding relation of touch screen action

Through figure 5It is known that the function will slide to the left.10%Touch screenXThe abscissa axis defined as PgUp, slide10%Defined as the page down. The function is to deal with the logic, and to determine whether the hand has been on the screen, there is no way to leave.Is_out_of_time ()Function is used to delay the elimination of jitter and other error.


top
One
step on
Zero

Reference knowledge base

Guess you're looking for
View comments
* the above user comments only represent their personal views, does not represent the views or position of the CSDN website
    personal data
    • Visit:5963 times
    • Integral:One hundred and ninety
    • Grade:
    • Rank:Thousands of miles away
    • Original:13
    • Reproduced:0
    • Translation:0
    • Comments:3
    Latest comments