Windows XP driver touch panel (detailed development)

Source: Internet
Author: User

1. Model of touch screen driver

1.1 layered touch screen drive Sequence Structure

The Touch Screen driver adopts a hierarchical driver structure. Its driver model is shown in. This structure distinguishes the driver code from the upper-layer model device driver layer (MDD ), the lower layer is the driver layer (PDD) of the platform ). The MDD layer can be directly used without modification. The modified part provides the DDI interface for GWES, while MDD calls PDD through the specified ddsi function interface, this is what we usually need to implement. In addition to the ddsi function set interface, the PDD and MDD sections also implement some specified variable definitions or variable initialization actions (for example, gintrtouch and gintrtouchchanged are defined at the PDD layer, but it is mainly used at the MDD layer .), That is to say, the MDD layer and the PDD layer are not necessarily implemented using a strict layered model. Sometimes, they also need to share variables to complete interaction.

1.2 DDI function set (MDD layer)

Touchpanelpowerhandler (bool boff)

The power management function of touch screen. Boff: True indicates power off, and false indicates power on. It only calls the ddsitouchpanelpowerhandler () function, which is generated when the function enters or exits the poweroff state.

Touchpanelcalibrationapoint ()

This function is used to calibrate the input touch screen coordinates and convert the touch screen coordinates to the display coordinates, the formula SX = A1 * Tx + B1 * ty + C and SY = a2 * Tx + B2 * ty + C2 are used.

Touchpanelreadcalibrationpoint ()

When performing the touch screen calibration program, use this function to obtain the touch screen coordinates clicked on the cross of the current calibration point.

Touchpanelreadcalibrationabord ()

This function is called when the calibration is canceled (the calibration is canceled when the touch screen calibration program is running) and is returned only after the status bit and event are set.

Touchpaneldisable ()

The touch panel device is disabled. This function disables ISR, stops interrupt and logout events, and other means of synchronization. This function calls the ddsitouchpaneldisable () function.

Touchpanelenable (pfn_touch_panel_callback pfncallback)

Pfncallback refers to the callback function for processing touch panel events. The execution of this function is as follows:

(1) create events htouchpanelevent and hcalibrationsampleavailable, where the htouchpanelevent event is triggered when the pen is pressed or lifted or the timer is interrupted, and the hcalibrationsampleavailable event is triggered when there is a calibration data input.

(2) initialize the critical section, initialize the required touch screen interrupt gintrtouch and gintrtouchchanged, and associate them with the event htouchpanelevent.

(3) create an ist touchpanelpisr and set its priority.

Touchpanelsetcalibration ()

This function obtains the display coordinate (sx, Sy) and the touch coordinate (TX, Ty) pressed on the cross by the calibration action when the touch screen calibration program is run for calculating the calibration parameter A1, b1, C1, A2, B2, C2.

Touchpanelgetdevicecaps ()

This interface is used to query specific functions supported by touch screen devices. You can use the ddsi function to query the corresponding information and save the screen information when querying the screen coordinate information for subsequent programs to calculate the calibration parameters.

Touchpanelsetmode ()

It is used to set the working mode of the touch screen (low sampling rate or high sampling rate). When the IST priority is set, it is directly completed through the kernel API, and other settings are directly handed over to the ddsitouchpanelsetmode () function for processing.

1.3 wince ddsi function set (PDD layer)

Ddsitouchpanelgetdevicecaps (INT iindex, lpvoid lpoutput)

Query Information about the touch panel device.

Iindex: the index value to be queried. The value is as follows:

Tpdc_sample_rate_id: queries the sampling rate information.

Tpdc_calibration_point_count_id: queries the number of vertices used for verification.

Tpdc_calibration_point_id: query the coordinates of vertices to be verified.

Lpoutput: The iindex value points to the relevant information.

Ddsitouchpanelsetmode ()

Set the touch panel working mode.

Iindex: schema Index

Tpsm_samplerate_high_id: high sampling rate

Tpsm_samplerate_low_id: low sampling rate

Lpinput: Point to memory containing relevant information

Ddsitouchpanelenable ()

Action executed by the function:

(1) allocate memory space for the I/O, ADC, PWM, and INT registers to be used.

(2) registers for configuring the touch screen controller, interrupt controller, and PWM.

(3) apply for touch screen interrupt gintrtouch and timer interrupt gintrtouchchanged and initialize them to assign the corresponding system Logical interrupt number to the physical interrupt number ..

Ddsitouchpaneldisable ()

Shields touch screen interrupt and releases the wince memory space allocated to I/O, ADC, PWM, and INT registers.

Ddsitouchpanelattach ()

Simply return 1.

Ddsitouchpaneldetach ()

It simply returns 0.

Ddsitouchpanelgetpoint (touch_panel_sample_flags * ptipstateflags,

Int * puncalx,

Int * puncaly)

Obtains the status and coordinates of the pressed point on the touch panel.

◆ Ptipstate: the status of the current touch point, such as the invalid point, valid point, and pressed point.

◆ Puncalx: X coordinate of the touch point

◆ Puncaly: Y coordinate of the touch point

◆ Ddsitouchpanelpowerhandler ()

Set the power status of the touch panel. Boff: True indicates that the power is disabled, and false indicates that the power is turned on,

2. Implementation of touch screen driver

Windowsce5.0 touch screen driver detects the touch pen press status by means of interruption. If the touch pen is detected, 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. Touch screen driver Process

3. Working Principle of 4-wire resistive touch screen

The structure 1 of the four-wire resistive touch screen is covered by a two-layer Turbine on a glass or acrylic substrate with an even conductive ITO layer as the x electrode and y electrode respectively, they are separated by a uniformly arranged transparent lattice. The ITO on the lower layer is attached to the glass substrate, and the ITO on the upper layer is attached to the pet film. The positive and negative ends of the X and Y electrodes are derived from the two ends respectively, and the positions of the X and Y electrodes are perpendicular to each other. The lead-end X-, x +, Y-, and Y + have a total of four lines. This is the origin of the four-wire resistive touch screen name. When an object is exposed to the touch screen surface and subjected to a certain amount of pressure, the ITO conductive layer on the upper layer is deformed and the ITO on the lower layer is in contact. This structure can be equivalent to the corresponding circuit,

The X and Y coordinates of the contact are calculated in the following two steps:

1. the Y coordinate is calculated, and the driving voltage vdrive, Y-electrode grounding, and x + are applied on the Y + Electrode to obtain the contact point voltage, the ratio of the contact voltage to the vdrive voltage is equal to the ratio of the contact y coordinate to the screen height.

2. after the X coordinate is calculated, the driving voltage vdrive, X-electrode grounding, and Y + are applied on the X + Electrode to obtain the contact point voltage, the ratio of the contact voltage to the vdrive voltage is equal to the ratio of the contact X coordinate to the screen width.

After the measured voltage is converted from the ADC to the original coordinate of the touch point (the value range is determined by the number of digits of the selected A/D converter), the actual pixels of the LCD screen must be converted, after conversion, it is directly converted to the on-screen coordinates through calibration for GWES.

4. Touch Screen Interface

◆ X +: tsxp connected to the touch screen controller ,.

◆ X-: tsxm connected to the touch screen controller.

◆ Y +: connect to the tsyp of the touch screen controller.

◆ Y-: connect to the tsym of the touch screen controller.

When using the touch screen interface, tsxm or tsym should be connected to the touch screen interface.

5. Configure the controller hardware

5.1 ADCCON-----ADC control register

Ecflg: adccon [15], ad (read-only), 0 indicates that the ad is in progress, and 1 indicates that the ad ends.

Prscen: adccon [14], Active Directory converter pre-divider enabling, In this enabling, so it is 1.

Prscvl: adccon [], the pre-divider value of the AD converter, which is 49 here.

Sel_mux: adccon []. Select the analog signal input channel. Select XP here, so it is 7.

Stdbm: adccon [2]. Select the standby operation mode. Select normal operation mode here, so the value is 0.

Read_start: adccon [1], which starts A/D conversion by reading. In this case, the/D conversion is started because the read operation is invalid, so it is 0.

Enable_start, adccon [0], enable this bit to start A/D conversion, and select no operation here. This bit is enabled after A/D conversion starts.

5.2 ADCTSC-----ADC touch screen control register

Ud_sen: adctsc [8], where the interruption signal is detected when the pen is pressed, so it is 0.

Ym_sen: adctsc [7], ym switch enabling, select ym output drive effective (Gnd) Here, so it is 1.

Yp_sen: adctsc [6], YP switch enabling. In this case, the YP output driver is invalid (ain5), so it is 1.

Xm_sen: adctsc [5], enabled by the XM switch. In this case, the XM output driver is invalid (hi-z), so it is 0.

Xp_sen: adctsc [4], enabling the XP switch. Here, the XP output driver is invalid (ain7), so it is 1.

Pull_up: adctsc [3]. The pull_up function is enabled. the pull-up function is valid on XP. Therefore, the pull_up function is 0.

Auto_pst: adctsc [2]. during initialization, the automatic continuous measurement X and Y coordinates are selected here, so the value is 0. However, if the conversion starts, set the value to 1.

Xy_pst: adctsc [1:0]. Manually measure the X and Y coordinates. Here, select the waiting interruption mode, so it is 3.

Note: When the touch screen is interrupted, the xp_sen bit (XP output is invalid) should be set to 1 and the pull_up (XP pull_up enabling) bit should be set to 0.

5.3 ADCDLY-----ADC start delay register

Delay: adcdly [154: 0]. Because the waiting interruption mode is selected, this value indicates that when the trigger appears in sleep mode, a signal is generated for introducing the sleep mode, the interval is several milliseconds. The value here is 40000 ????????? (40 s, too long, right ?)

Subintmsk ----- wince neutron interrupt shielding register

This register has 11 bits, each associated with an interrupt source. The Touch Screen interrupt request is valid, so the 10th digit should be set to 0.

V_pintregs-> intsubmsk & = ~ (1 <irq_sub_tc );

5.4 TCFG1-----5 multiplexing and DMA mode selection register

Mux3: tcfg1 [], selects multiple inputs for PWM timer 3, and initializes its value. Each timer has a clock divider, which can generate different frequency signals (1/2, 1/4, 1/8, 1/16, and tclk), select 1/16.

V_ppwmregs-> tcfg1 & = ~ (0xf <12);/* timer3's divider value */

V_ppwmregs-> tcfg1 | = (3 <12);/* 1/16

TCNTB3-----PWM timer 3 count cache register, select timer 3 for the clock, for example, define 10 ms interrupt once, provide touch screen sampling time reference, that is, 10 ms touch screen sampling once. The clock frequency of timer3 = pclk/(1000/100 + 1) is 17 × 170 = 400, and pclk = 244 MHz/6 ). 16. The touch screen can be counted to generate a scheduled interrupt for 10 ms for one sampling.

 

6. Determine whether the touch screen is touched or interrupted.

We adopt the interrupt wait mode. When the touch pen is pressed, the touch screen controller generates an interrupt signal (int_tc) to the interrupt controller. After the interrupt handler captures this physical interrupt, call the registered ISR to determine how to handle the hardware interruption. ISR returns the logical interrupt number corresponding to the physical interrupt to the kernel. For example, when we press the touch screen with a pen, int_tc physical interrupt occurs. ISR maps the physical interrupt number into a logical interrupt signal, then, the operating system triggers the associated wince event Kernel Object gintrtouch based on the physical interrupt number, so as to wait for the IST (touchpanelpisr, the name should not be reasonable and should be changed to touchpanelpist) of the event kernel object) to start interrupt processing.

Two interrupt sources are used in the driver. One is touch screen interrupt (including touch pen press or lift interrupt, which is determined by the ud_sen bit of the ADC touch screen control register adctsc, the name in the Code is gintrtouch). That is to say, when the pen is pressed or lifted, a physical interrupt int_tc is generated. The logical interrupt number is sysintr_touch; the other is a timer interrupt (timer3 is used here ), as long as the pen is still pressed, the scheduled int_timer3 will be generated at a scheduled time (10 ms in this example, the name in the Code is gintrtouchchanged), and the logical interrupt number is sysintr_touch_changed. The two interruptions will trigger the same event htouchpanelevent, and then the touchpanelpisr thread will start to execute.

The following are conditions for interruption

(1) Touch Screen interruption occurs when the pen is pressed.

(2) Touch Screen interruption occurs when the pen is lifted.

(3) When the touch pen is pressed to generate a touch screen interruption, the Driver opens the hardware timer timer3. As long as the touch pen is detected to be still in the pressed state, the timer is interrupted every 10 ms.

The procedure for determining the touch screen activity of a touch screen is as follows:

7. obtain stable and dejitters location measurement data

After obtaining the original coordinates of the touch point (the value range is determined by the number of digits of the selected A/D converter), convert the values based on the actual pixels of the LCD screen, after the conversion, the calibration is directly converted to the on-screen coordinates to facilitate subsequent development of the graphic interface. Then, the screen coordinates and sampling status parameters are passed to GWES through the callback function.

The human-machine interface has the following operations on the touch screen for three minutes:

(1) The position of the touch pad on the touch screen remains unchanged.

(2) The touch pad slides continuously on the touch screen.

(3) The touch pad has a great jump on the touch screen.

7.1 touch screen sampling program

When the touch pen is pressed, the touch coordinate sampling of the touch screen starts, and the timer interrupt is enabled at the same time to prepare for the timer interruption after 10 ms. The sampling process is as follows:

(1) Enable Automatic Measurement of X and Y coordinates by setting adccon and adctsc on the ADC control registers.

(2) wait until the adswitch is complete. The access to the ecflg of adccon can determine whether the adswitch is complete or not.

(3) After the adconversion is complete, the Y coordinate and X coordinate value of the touch screen coordinate are read from the adcdat0 and adcdat1 data registers of the ADC conversion data.

(4) return to the first step, obtain 5 sets of data consecutively, sum and calculate its average value, if the difference between the average value and the last data of the five groups is greater than the threshold value we set (this threshold value should be determined based on the resolution of the LCD screen we use), the sample value is invalid, at the same time, modify the adctsc settings of the Register so that it is in the waiting interrupt mode to prepare for the next interruption (when the pen raises the interrupt ).

7.2 touch screen filter program

After obtaining the touch screen coordinate at the position where the touch pen is pressed by using the tsp_getxy () function, it passes the calibrated coordinate to GWES through the callback function. In this callback function, touchpanelenable (pfncallback) is called through GWES) this process includes the following steps:

(1) Use the tsp_getxy () function to obtain the touch screen coordinate at the position where the pen is pressed.

(2) convert the touch screen coordinates based on the actual pixels of the LCD screen.

Tsp_transxy () is used to convert the touch screen coordinates obtained by the tsp_getxy () function.

X = W * (x-x1)/(x2-x1), Y = H * (y-y1)/(y2-y1), where (x1, Y1) and (X2, Y2) the sampling coordinates of the touch screen corresponding to the upper left corner and upper right corner of the display area are displayed. The resolution of the screen is 240 × 320, in the Code (x1, Y1) and (X2, Y2) the values are (85,105) and (965,980). These values are determined after the resolution is 240 × 4 and 320 × 4. Correspondingly, we also need to process W and H: W = 4 * w, H = 4 * h, (x, y) is the sampling coordinate of any point on the touch screen (where there is a doubt, why is the X value in the lower-right coordinate 965? Isn't it greater than 240 × 4 ?).

(3) determine the coordinate value obtained by (2). If the X coordinate value is greater than or equal to 240x4, or if the Y coordinate value is greater than or equal to 320x4 (that is, the X coordinate value before the conversion is greater than or equal to 965, And the Y coordinate value is greater than or equal to 980), we think this sample value is invalid, or if the difference between the corresponding X coordinate values of the last two samples or the difference between the Y coordinate values is less than or equal to 15 and 40, it indicates that the touch pen remains in the same position during the two sampling times, so the latest sampling value is ignored; if the difference between the corresponding X coordinate values of the last two samples or the difference between the Y coordinate values is greater than 15 and 40, the pen is moving during the two sampling times, this sample is valid.

(4) use the touchpanelcalibrateapoint () function to convert the coordinates of the valid touch screen pressed points into the coordinates of the corresponding display device points, SX = A1 * Tx + B1 * ty + C and SY = a2 * Tx + B2 * ty + C2 are used, among which A1, B1, C1, A2, B2, c2 is calculated using the touchpanelsetcalibration () function when performing the touch screen calibration program.

Returns the displayed coordinates through the (4) conversion. Checks the boundary of these values if the X coordinate value is greater than or equal.

Callback calls back the pointer passed in by the touchpanelenable (pfncallback) function, transmits the sampling status, and displays the coordinates after calibration to GWES.

After the touch screen coordinates pressed by the pen are calibrated, The callbak function is used to sample the status and position change information and sent to the higher level graphics software through GWES.

8. Calibrate the touch screen

The Touch Screen calibration process is as follows:

(1) Call the touchpanelenable function to enable touch screen sampling.

(2) Call the touchpanelgetdevicecaps function to obtain the number of calibration contacts.

(3) On-site arrival:

I: Call the touchpanelgetdevicecaps function to get the coordinates of the calibration point.

II: Draw a cross at the above-mentioned admission point and wait for the user to click.

III: After clicking the cross graph, the user calls the touchpanelreadcalibrationpoint function to obtain the coordinates of the touch screen at the above calibration points.

(4) After obtaining the expected calibration point, call the touchpanelsetcalibration function to calculate the calibration coefficients A1, B1, C1, A2, B2, C2.

After completing the above steps, the development of the touch screen driver on the wince platform has been basically completed, and the specific hardware environment needs to be considered in actual operations.

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.