Wince touch Driver Analysis

Source: Internet
Author: User

Wince touch Driver Analysis

 

1. Preface
The touch screen is a commonly used computer input device in embedded devices. It makes operations simple and intuitive and can be used by everyone. Touch screens are widely used in mobile phones, PDAs, and other handheld products and public service devices. The touch screen can be divided into multiple types: resistance type, Capacitive Type, and surface acoustic type. The resistance type touch screen is currently widely used, including four-wire, five-wire, and seven-wire. This article will analyze the touch screen Driver Model and implementation methods in Windows CE operating system.

2. Windows CE touch screen Driver Model
In Windows CE, the touch screen driver is a hierarchical driver. The driving Model 1 is shown in. The upper layer is the model Device Driver (MDD), and the lower layer is the platform Driver (PDD ). MDD is usually used directly without modification. MDD links to the PDD layer and defines the function interface that it wants to call: Device Driver Service Provider Interface (ddsi ). In addition, MDD provides different function sets to the operating system. These functions are called Device Driver interfaces (DDI.

3 Windows CE touch screen Driver Interface
The Touch Screen driver of Windows CE links two static link libraries, tch_cal.lib and tchmdd. Lib. The Touch Screen driver is loaded by GWES, and GWES calls the driver program through DDI to obtain the device status and set the driver function. The driver directly obtains hardware information through ddsi to determine the status of the current touch screen.
The DDI interfaces required by Windows CE touch screen drivers include touchpanelgetdevicecaps, touchpanelenable, touchpaneldisable, touchpanelsetmode, kernel, kernel, touchpanelsetcalibration, kernel, and touchpanelpowerhandler.
Ddsi interfaces required by Windows CE touch screen drivers include ddsitouchpanelattach, ddsitouchpaneldetach, ddsitouchpaneldisable, ddsitouchpanelenable, reply, ddsitouchpanelgetpoint, and reply.

 
4 Windows CE touch screen data collection
The Windows CE touch screen driver detects the touch pen press status in the interrupt mode. If the touch pen is pressed, an interruption occurs and an event is triggered to notify a worker thread to start data collection. At the same time, the driver will turn on a hardware timer, as long as it detects that the touch pen is still pressed, it will trigger the same event to notify the worker thread to collect data, until the touch pen is lifted and the timer is disabled, and re-detect the press status. The Touch Screen interrupt and timer interrupt are used in the driver, which can not only monitor the touch pen press and lift status, but also detect the drag track when the touch pen is pressed.
The Touch Screen driver calls the touchpanelenable function during initialization to enable the touch screen. The ddsi function called by this function is: ddsitouchpanelenable and ddsitouchpaneldisable. The function is implemented as follows:
1) create events htouchpanelevent and hcalibrationsampleavailable. The htouchpanelevent event is triggered when a touch pen is pressed or pressed to periodically collect data. The hcalibrationsampleavailable event is triggered when there is a calibration data input in the calibration state;
2) Check and initialize the required interrupt gintrtouch and gintrtouchchanged, and associate the interrupt gintrtouch and gintrtouchchanged to the event htouchpanelevent. When gintrtouch and gintrtouchchanged are interrupted, the htouchpanelevent event is triggered;
3) create an ISR thread touchpanelpisr. Touchpanelpisr is used to wait for and process touch screen events htouchpanelevent, which is the only event source in the entire driver.
The touchpanelpisr function is a key function for collecting touch screen data. It implements the following functions:
1) Wait loop, used to receive htouchpanelevent events and constitute the main body of the function;
2) Call the ddsitouchpanelgetpoint function to obtain the position and status information of the current touch screen;
3) collect and submit the pressed position information when obtaining valid data and in the calibration status;
4) calibration data under normal conditions and check the validity of the calibrated data;
5) Finally, call the callback function passed in by GWES to submit the location information and status information.
Therefore, the three ddsi interface functions ddsitouchpanelenable, ddsitouchpaneldisable, and ddsitouchpanelgetpoint In the touch screen driver are the key to driver implementation.
In the ddsitouchpanelenable and ddsitouchpaneldisable functions, the touch screen hardware is enabled and disabled respectively. In fact, these two functions can not really operate the hardware, but only implement software control, however, to reduce power consumption, it is best to power off the touch screen controller in ddsitouchpaneldisable and enable it in the ddsitouchpanelenable function.
Sample the touch screen data in the ddsitouchpanelgetpoint function. From the above analysis, it is learned that MDD controls sampling by detecting htouchpanelevent and hcalibrationsampleavailable events. Both events are triggered and will call this function. The two event triggers have two conditions:
1) triggered when the touch pen is pressed to interrupt gintrtouch;
2) After the touch pen is pressed, the timer is turned on. The timer will periodically interrupt gintrtouchchanged and trigger the event until the touch pen is lifted up.
Therefore, this function not only needs to sample the touch screen data, but also needs to control the status of the trigger conditions, as shown in process 2. The figure defines three variables:
1) touchirq is a static or global variable and its initial value is true. This variable must be set to false when the touch screen is pressed and the touch screen is interrupted;
2) interrupttype is a static or global variable and its initial value is sysintr_nop. It is set to sysintr_touch when the touch screen is interrupted, sysintr_touch_changed when the timer is interrupted, and sysintr_nop when the remaining values are set, after processing, you must pass it as a parameter to the interruptdone function to clear the interrupt;
3) g_nextexpectedinterrupt is a static variable or global variable. This variable indicates the interruption to be generated next time. The initial state is pen_down, that is, the touch pen is in the lift State. Therefore, the interruption to be generated next time is pen_down. When the touch screen is interrupted and the timer is interrupted, the variable is pen_up_or_timer, that is, the next possible status is the touch pen lifting status or the touch pen is pressed, but the timer is interrupted.
The ddsitouchpanelgetpoint function starts to run from the touch pen's lifting State. At this time, touchirq is equal to true. If the touch pen is pressed at this time, the value of touchirq is set to false, indicating that the sampling is due to touch screen interruption and the next call is set to be generated by the timer. Set the interrupttype status to sysintr_touch, start to collect data, and set the g_nextexpectedinterrupt variable to pen_up_or_timer, which indicates that the next interrupt is a timer interrupt. Then, judge whether the touch pen is lifted when the touch pen is pressed (g_nextexpectedinterrupt is equal to pen_up_or_timer). If the touch pen is lifted, set g_nextexpectedinterrupt to pen_down and restore to the lift state. Finally, interrupttype is passed into the interruptdone function as a parameter to clear the interrupt. When the touch pen is pressed and the timer is interrupted, touchirq is set to false. In this case, interrupttype is set to sysintr_touch_changed. The remaining actions are basically the same as the above process.

5 Windows CE touch screen Calibration
The resistive touch screen must be calibrated. The application requires reference values to convert the received touch screen coordinate data into screen coordinates required by the high-rise software. Ideally, the calibration program runs once during the initial power-on test of the product, and the reference values are stored in non-volatile memory. Ideally, only two groups of raw data are needed, that is, the minimum and maximum values read on the diagonal corner of the screen. In practical application, because many resistive touch screens have significant non-linear characteristics, a simple insertion position between the minimum and maximum values may cause the driver to be very inaccurate.
In Windows CE, you can set the number of calibration points in the ddsitouchpanelgetdevicecaps function and obtain the screen coordinates of each calibration point in touchdrivercalibrationpointget. The number of common calibration points is 5. The calibration UI displays a cross at the on-site coordinate. You need to precisely press the touch screen at the cross position, and the driver reads the corresponding touch screen coordinate value through the touchpanelreadcalibrationpoint function, then start the next school on-time. After the number of cycles is set, the collected touch screen coordinates and the on-time screen coordinates are sent to the touchpanelsetcalibration function for processing. This function generates calibration benchmark parameters.
The touchpanelsetcalibration function executes a set of mathematical algorithms. The specific content is:
If the relationship between the touch screen data and its location offset is the same as the linear relationship between the screen pixel and its location offset, the location information returned by the touch screen is converted to 2D coordinate. The Conversion Relationship Between the touch screen coordinate (TX, Ty) of the touch screen pressed by the touch screen and the screen coordinate (sx, Sy) of the point that matches the display device location, it can be expressed by the following coordinate transformations:
SX = A1 * Tx + B1 * ty + C1
Sy = a2 * Tx + B2 * ty + C2
The specific work of touchpanelsetcalibration is to determine A1, B1, C1, A2, B2, C2 by the screen coordinate obtained through the calibration action and the touch screen coordinate touchcoordinate.

6. Conclusion
The author's innovation point: From the Perspective of analyzing the model and implementation method of touch screen driver in the embedded Windows CE operating system, it deeply analyzes the execution process of touch screen Data Acquisition and calibration in Windows CE, it provides some authentication for drive development of similar systems.

Reprinted from: http://www.cublog.cn/u2/78300/showart_2119919.html

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.