“With the development of information technology, embedded systems are more and more widely used in aerospace, communication equipment, industrial control and other fields. Due to size constraints, touch screens have become the preferred input tool for embedded systems instead of keyboards and mice. At the same time, the embedded system gradually abandoned the traditional loop control mode, but introduced the operating system to complete the switching between processes and task scheduling.
“
Author: Dewey; Mu Chundi
Background introduction
With the development of information technology, embedded systems are more and more widely used in aerospace, communication equipment, industrial control and other fields. Due to size constraints, touch screens have become the preferred input tool for embedded systems instead of keyboards and mice. At the same time, the embedded system gradually abandoned the traditional loop control mode, but introduced the operating system to complete the switching between processes and task scheduling. μClinux is an excellent open source embedded operating system. It has undergone various miniaturization transformations to form a highly optimized and compact embedded Linux. Although its size is small, μClinux still retains most of the advantages of Linux: stable and good portability, excellent network functions , Complete support for various file systems and standard rich API. Compared with other embedded operating systems with more applications, such as vxworks, winCE, etc., its relatively low price and convenient user program development are undoubtedly its huge advantages. Users can easily find the latest kernel versions, compilers and other necessary software environments from the Internet, which has also prompted many enthusiasts to join.
Research status
As the touch screen is used more and more widely, there are many corresponding researches and engineering practices. In the existing work, many engineers have studied the hardware connection between the touch screen controller ADS7846 and the StrongARM platform and the software driver development in the WinCE operating system, and have made some explorations on improving the hardware accuracy of the touch screen controller. The main contribution of this paper is to describe the hardware and software design of touch screen driver in μClinux, an embedded operating system. Practice has proved that this design has relatively high precision, stability and openness, and has good cross-platform performance, so it will definitely provide more choices for embedded devices.
hardware design
In this design, the hardware platform microprocessor adopts Motorola’s MC68VZ328, which is a 32-bit low-power microprocessor of M68k system, designed with SoC technology and has the characteristics of a typical embedded microprocessor; the touch screen adopts TI (original It is a product of Burr-Brown Company. Since the company has been acquired by TI Company, the ADS7843 of TI Company is used below. In this design, the CPU and the touch screen work in a master-slave mode, and the touch screen works in a slave state. The hardware circuit in this design is different from the traditional design, but makes full use of the BUSY signal line in the ADS7843, as shown in Figure 1.
ADS7843 is a four-wire resistive touch screen control chip. It mainly accomplishes two things: one is to complete the switching of the electrode voltage; the other is to collect the voltage value at the contact point. It consists of two transparent resistive conductor layers, and the middle of the conductor layers is filled with an isolation layer made of a viscous insulating liquid material and an electrode made of a material with excellent electrical conductivity.
When the touch screen is working, the upper and lower conductor layers are equivalent to a resistive network, as shown in Figure 2. When a voltage is applied to a layer of electrodes, a voltage gradient develops across the network. If there is an external force that makes the upper and lower layers contact at a certain point, the voltage at the contact point can be measured on the other layer where no voltage is applied to the electrode, so as to know the coordinates of the contact point. For example, if a voltage is applied to the electrodes (X+, X-) on the top layer, a voltage gradient will be formed on the top conductor layer; when there is an external force that makes the upper and lower layers contact at a certain point, the voltage at the contact point can be measured at the bottom layer. The voltage, and then according to the distance relationship between the voltage and the electrode (X+), the X coordinate of the place is known. The Y coordinate is then known by switching the voltage to the bottom electrodes (Y+, Y-) and measuring the voltage at the contact point on the top layer. For the voltage switching between the horizontal and vertical conductor layers and the A/D conversion, it is necessary to send the control word to the ADS7843 through the serial peripheral interface (SPI) first, and then read the voltage conversion value through the SPI after the conversion is completed.
software design
Features of Drivers under μClinux
μClinux inherits the device management method of Linux, treats all devices as specific files, and accesses devices through the file system layer. Therefore, in the framework of Clinux, the processing related to the device can be divided into two layers – the file system layer and the device driver layer. The device driver layer shields the details of specific devices, and the file system layer provides users with a set of unified and standardized user interfaces. This device management method can well achieve “device-independent”, so that Clinux can be easily expanded according to the development of hardware peripherals. A set of access interfaces suffices.
Devices in μClinux can be divided into three categories: character devices, block devices and network devices. Among them, the character device has no buffer, and the data processing is carried out in sequence in bytes. It does not support random reading and writing, and the touch screen is a kind of character device.
There are two ways to load the driver in the kernel: one is to compile the driver directly into the kernel, and the device is registered when the system is initialized; the other is the modular loading method, which compiles the driver into an object file (*. o), when you need to add a device, use the insmod command to register with the system, and when you stop using it, use the rmmod command to uninstall it. For a basic input tool such as a touch screen, it is recommended to compile it directly into the kernel, so that the system can be used as soon as it is started.
The function to register a character device with the kernel is: externintregister_chrdev(unsignedintmajor, constchar*name, structfile_operations*fops); the kernel uniquely identifies a device with the major device number and the minor device number. The parameter major corresponds to the requested major device number, name corresponds to the name of the device, and fops is a pointer to the file_operations structure, which is a key data structure used to write drivers under Clinux. Call the interface. Each entry in this data structure points to a function performed by the driver.
The TaggedStructureInitializationSyntax is adopted for this structure in the 2.4 version kernel. Compared with the 2.0 kernel, this syntax is more portable, and the program readability and code compactness are better. Take the touch screen as an example:
staticstruct file_operations ts_fops={
owner:THIS_MODULE,
read:ts_read, //read data operation
poll:ts_poll, //non-blocking operation
ioctl:ts_ioctl, //I/O control operation
open:ts_open, //Open the device
release:ts_release, //release the device
fasync:ts_fasync, // trigger asynchronously }
The complete structure also includes function pointers such as llseek and readdir, but because they are not used in this program, they are omitted or not written, and the kernel defaults them to NULL.
Process and key functions of touch screen driver
In this design, we use μClinux2.4 kernel. The main design idea of the driver program is: after the driver program is initialized, it enters an idle state and waits for the arrival of an interrupt. Once the pen is interrupted (pen_irq), it will enter the interrupt processing program to perform data sampling, conversion and transmission. At the same time, the program will identify and handle exceptions to various situations.
The touch screen software process is shown in Figure 3. In the driver, 7 different states of the touch screen are set, which are represented by numbers from -1 to 5 respectively. These 7 states constitute a touch screen state machine, and the system makes the next step according to the current state, such as shown in Table 1. The whole software design can be divided into 5 parts according to the function, namely initialization, device opening, read operation, interrupt processing and I/O control. Each part is described in detail below.
driver initialization
Register the device driver function with the kernel in mc68328digi_init(): err=misc_register(&mc68328_digi), set the current parameters of the touch screen in init_ts_settings(): kernel version number, pen movement judgment threshold, sampling time, jitter removal switch, jitter removal time These parameters are customized by the user according to their own LCD screen and accuracy requirements, and can also be set by the I/O control function ioctl() in the application program. This article will analyze the meaning of these parameters in the parameter analysis.
Turn on the device
In the ts_open() function, the driver registers the interrupt with the kernel. Interrupts can also be registered with the kernel when the system is initialized, but this is generally not recommended, because it may cause interrupt conflicts when there are many devices loaded. It is a better strategy to open a device and let the device occupy the interrupt. Registering the interrupt handler with the kernel mainly implements two functions, one is to register the interrupt number, and the other is to register the interrupt handler.
In this program, two interrupt handlers are registered with the kernel, namely:
request_irq(PEN_IRQ_NUM, handle_pen_irq, IRQ_FLG_STD,
“touch_screen”, NULL) and request_irq(SPI_IRQ_NUM, handle_spi_irq, IRQ_FLG_STD, “spi_irq”, NULL);
In the former, PEN_IRQ_NUM is the interrupt number, which can be specified or dynamically allocated. In this driver, the assigned interrupt number for the pen interrupt is 19; handle_pen_irq is the interrupt handling function, and IRQ_FLG_STD is an option when applying, which determines some features of the interrupt handler, which is occupied by the system here; touch_screen is the device name. In the latter, the program registers the SPI interrupt with the kernel to transfer data between the CPU and peripherals. The assigned interrupt number is 0, and handle_spi_irq is the SPI interrupt handler function.
In addition, in the touch screen driver initialization sub-function init_ts_drv(), the following work is done:
(1) Initialization of the touch screen state;
(2) Initialization of pen information (pen_values);
(3) Initialize the timer and set the timeout function handle_timeout();
(4) Initialize the register. Initialize the waiting queue. The waiting queue is a queue composed of processes waiting for touch events to occur. It includes head and tail pointers and a linked list of sleeping processes;
(5) Set the touch screen state to idle.
Since the initialization here will occupy a part of system resources, they are processed when the device is opened, rather than the initial device initialization part, which is also for the sake of saving resources.
Read function ts_read()
Once the user program calls read() to read the touch screen, the driver calls the entry point function ts_read() for processing. If no data arrives at this time, and the driver chooses a blocking operation, it will call interruptible_sleep_on (&queue->proc_list) to block the process, enter the waiting queue, and set the touch screen state to waiting; if a non-blocking operation is selected, the program will Return immediately when no data arrives, and then trigger fasync() asynchronously to notify the arrival of data.
In the process of waiting for the arrival of data, if there is a touch action (pen interrupt pen_irq), enter the interrupt handler. The data is sampled and transformed in the interrupt handler, and the current coordinate information is put into the queue. After the process is woken up (use wake_up_interruptible (&queue->proc_list) to wake up the process), the program takes the position coordinate information, event sequence information, etc. from the queue and puts it into the user space (put_user), so that it can be used by the user program to avoid This allows the user to deal directly with the hardware.
Driver’s interrupt handler
When a pen interrupt occurs, the program enters the interrupt handler function. In the interrupt handling function, two interrupts will be processed, which are the external touch interrupt (pen interrupt) and the SPI data conversion interrupt. The interrupt handling function corresponding to these two interrupts is the key to the software design of the touch screen.
Drivers use timers in interrupt handlers to handle time-related operations. Define the function set_timer_irq() as follows:
staticvoidset_timer_irq(structtimer_list *timer, intdelay) {
del_timer(timer);
timer->expires=jiffies+delay;
add_timer(timer);
}
jiffies is a variable that represents the number of clocks that the system has run since it was started, and delay is the set extension time (using the number of clocks as the counting unit). Once the number of clocks exceeds the set value, the timeout function is triggered, which is handle_timeout( ) in this program. The purpose of introducing a timer is twofold: one is to accurately control the time required for the system to eliminate signal jitter caused by level rise and fall, and the other is to effectively control the number of sampling coordinates without introducing a simple delay that takes up a lot of system resources function. The problem of using SPI interrupts to generate a large amount of coordinate data has no good solution in the literature, simply reducing the SPI clock frequency to take a smaller amount of data. The timer is introduced in this design, which can solve the above problems well.
In the handle_timeout() function, the program uses the conditional selection statement to judge the state value of the touch screen (ts_drv_state). If it is a non-Error state, enable SPI, enter handle_spi_irq(), and communicate with the ADS7843. In handle_spi_irq(), the program uses the conditional selection statement to perform data conversion operations according to the touch screen state value (ts_drv_state), and obtains the coordinates in the X and Y directions by sending the control word mentioned above to the touch screen control chip. The specific logic can be found in the program flow chart. Once a conversion is completed, the program will identify the nature of the click according to the click state information (state_counter). The determination method is relatively simple, and a conclusion can be drawn only by comparing the difference between the two sampling coordinates before and after with the moving threshold. In addition, signal error and coordinate change due to pen movement are also distinguished, and the discrimination threshold can be set by the user.
I/O control
All parameters of the hardware, including sampling time, jitter elimination switch, and jitter elimination time, can be set in the user program through the I/O control function ioctl() to avoid directly changing the driver every time, and recompile the kernel. time cost incurred. The definition of the I/O control function in this program is: staticintts_ioctl (structinode*inode, structfile*file, unsignedintcmd, unsignedlongarg); among them, the parameter cmd has two values, namely: TS_PARAMS_GET and TS_PARAMS_SET, which are used to indicate whether to obtain Parameters are still setting parameters. When the user calls this function, he only needs to assign value to this parameter according to the pre-agreed format, and then he can easily obtain or change the current parameter of the touch screen. arg is a pointer to the passed parameter.
in conclusion
After obtaining the original coordinates of the touch point (the value range is determined by the number of bits of the A/D converter selected), it is also necessary to convert according to the actual pixels of the LCD screen used to facilitate the subsequent development of the graphical interface. Considering the two adjacent moving thresholds, the coordinates of the touch screen are calculated according to the following formula:
Among them, XV is the X coordinate Display value of the touch point, XW is the measured value of the X coordinate of the touch point (original coordinate value), (1), (2), (3) are obtained when the touch screen is initialized, the method is to arbitrarily take the left side of the X direction of the touch screen One point on the side and one on the right side, take X△V=X△W=1, Xoffrer=0 as the initial value to measure to get three new parameters: X△V, X△W and Xoffrer (in actual use this work It belongs to the calibration zero offset), and then these three parameters will not change. For the original coordinate XW of any touch point measured each time, directly substitute the formula (4) to find the pixel display coordinate XV of the touch point. Among them, XV1 is the point coordinate display value on the left side of the touch screen; XV2 is the point coordinate display value on the right side of the touch screen; XW1 is the point coordinate measurement value on the left side of the touch screen; XW2 is the point coordinate measurement value on the right side of the touch screen.
This design uses MicroWindows as the user interface, customizes the coordinate area of each desktop icon, combines the sampling coordinates of the touch screen, determines whether it is within the coordinates of the icon area, and then makes corresponding event processing. For the development platform used in this design, the LCD screen is 320240 dot matrix, the physical size is: 80mm60mm, ADS7843 selects 12-bit conversion accuracy, and the theoretical resolution of the touch screen is 80/212=0.020mm, but due to level interference and touch action The actual accuracy cannot reach this value due to physical interference when it occurs. After testing, the click accuracy of the same point on our platform can reach 1.0mm. This driver can effectively distinguish click and movement signals. If it cooperates with handwriting recognition software, it can be used as the bottom driver of the handwriting board to realize handwriting input.
The Links: CM100DY-28H https://www.slw-ele.com/mg100h2ck1.html“> MG100H2CK1