Design of touch screen driver based on Qt/Embeded in embedded Linux

Publisher:电子设计探索者Latest update time:2012-04-19 Source: 中国仪器仪表Keywords:Linux  Qt  Embeded Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Embedded Linux has attracted the attention of embedded system developers with its open source, kernel robustness and stability, scalability, and support and maintenance from professional commercial companies and the world's top free software developers. It has become the new favorite of embedded operating systems. Touch screens are widely used because of their friendly human-computer interaction, simple and flexible operation, and fast input speed, which greatly simplifies the input of embedded systems. This article introduces the design of touch screen driver based on Qt/Embedded on the embedded Linux system platform. This solution has been successfully used in engineering machinery safety instrument and power quality monitoring instrument projects, realizing the support of GUI (Graphical User Interface) interface for touch screens, and can be customized according to different touch screens.

1. Introduction to Qt/Embedded
Qt/Embedded is a development library for GUI and application development for embedded systems released by the famous Trolltech company. It is a comprehensive C++ graphical interface application development framework that inherits all standard APIs of Qt, provides a more compact window generation system than Xlib and XWindows systems, and directly operates FrameBuffer (see Figure 1). The fully modular design and efficient compilation system reduce memory consumption, making Qt/Embedded a powerful and comprehensive GUI development tool in embedded environments. Due to the powerful functions of Qt/Embedded, it is widely used in various fields, from consumer electronics (mobile phones, PDAs, set-top boxes) to industrial control (medical imaging equipment, mobile information systems).

2. Device driver basics under Linux
The Linux system mainly divides devices into three types: character devices, block devices, and network interfaces. Each module usually implements one of these types, and the corresponding modules can be divided into three types: character modules, block modules, and network modules. However, this classification method is not very strict. Programmers can construct a large module to implement different types of device drivers in it. In order to achieve good scalability and extensibility, it is usually necessary to create a different module for each function.

A character device is a device that can be accessed as a byte stream, and this feature is implemented by a character device driver. It usually needs to implement at least the open, close, read, and write system calls. Character devices can be accessed through file system nodes, such as character terminals (/dev/console) and serial ports (/dev/ttyS0). Block devices are also accessed through file system nodes under the /dev directory. Block devices can hold file systems. Linux allows applications to read and write block devices like character devices, and can pass any number of bytes of data at a time. Therefore, the difference between block devices and character devices is only the way the kernel manages data internally. That is, the interfaces between the kernel and the driver are different. In addition, the interface of the block device must support mounting the file system.

A network interface is a device that can exchange data with other hosts. It is driven by the network subsystem in the kernel and is responsible for sending and receiving data packets. It does not need to understand how each transaction is mapped to the actual transmitted data packets.

There are other types of driver modules in Linux that use the common services provided by the kernel to handle specific types of devices. So we can communicate with Universal Serial Bus (USB) modules, serial port modules, etc.

In this system, the controller converts the original voltage signal collected by the touch screen into coordinate data through a dedicated A/D, and transmits it to the embedded system through the RS-232 bus (see Figure 2). The Linux system uses the serial port module provided by the kernel to process the touch screen device, and stores the device in the /dev directory in the form of a file /dev/ttyS0, providing system calls such as open, read, write, and close. We only need to operate the serial port device like operating an ordinary data file, and send the coordinate data of the touch screen to the upper Qt/Embedded application layer.

3. Driver of touch screen under Qt
The signals related to user input events in Qt/Embedded are based on the interface call of the underlying input device, which is generally implemented by I/O reading and writing of device files. Most of these drivers have been encapsulated into the Qt library to form corresponding device driver interfaces, such as display card drivers, mice, keyboards, serial ports and parallel ports. The abstract base class of the mouse device is QWSMouse Handler, from which some specific implementation classes of mouse devices are derived. In the 3.3.4 version series of Qt/Embedded, the derived structure of mouse devices is shown in Figure 3.

Figure 3 Derived structure diagram of mouse devices (gray wireframe indicates that the class structure can be omitted)

The loading method of mouse devices is similar to that of KeyBoard devices. When the system constructs a QWSServer object, it calls the member function QWSServer:: openMouse. The program then calls QmouseDriverFactory::create() or QmouseDriverPlugin:: create() in the QWSServer:: openMouse function. This function obtains the device type and device node of the mouse device based on the Linux system environment variable QWS_MOUSE_PROTO. It opens and returns the base class pointer QWSMouseHandler of the corresponding device to the system. The system operates the specific subclass device pointer QWSCustomMouseHandler derived from the base class. [page]

The functions of touch screen and mouse devices are basically the same. Therefore, in the Qt library, the touch screen is generally simulated as a mouse device to implement the operation of the touch screen device. However, since the underlying interfaces of the touch screen and the mouse are different, the upper interface will be inconsistent. For example, the absolute position information is almost never obtained from the mouse driver interface, and only the relative movement amount is generally read. In addition, the acceleration of the mouse movement also needs to be taken into account, while the touch screen interface is almost entirely absolute position information and pressure information. In view of such differences, Qt/Embedded also distinguishes and abstracts the interface part of the same type of device, which is specifically implemented in the QmouseDriverInterface class.

In this system, the Linux system reads the coordinate data of the touch screen from the COM1 port, but because it is inconsistent with the underlying interface of the touch screen, it is necessary to add the QWSCustomMouseHandler program interface class to control the touch screen. Looking at the Qt/Embedded source code qwsmouselinuxtp_qws.cpp and qwsmousevr41xx_qws.cpp, it can be seen that Qt provides driver interface classes for linuxtp and vr41xx touch screens. If these two touch screen interfaces are used, you can directly add the configuration option -qt-mouse- when executing Qt's configure configuration. Since our touch screen is not one of the above two, a driver interface needs to be added.

From the derived structure of the mouse device driver class above, we can know that to add a driver interface, we must first generate the corresponding QWSCustomMouseHandler object according to the corresponding device name by calling the QmouseDriverFactory or QmouseDriverPlugin class. These specific device driver interface classes are derived from the QWSMouseHandler class and inherit the QWSMouseHandler class. Then the system calls QWSCustomMouseHandler:: readMouseData (), and the acquired touch screen positioning and status information are directly sent to the QWSMouseHandler class, the abstract layer of the mouse device driver class. Qt/Embedded uses the QWSMouseHandler class to operate the mouse device.

There are two ways to add device driver interface classes: one is to generate the corresponding QWSCustomMouseHandler by calling QmouseDriverFactory, and the other is to generate the corresponding QWSCustomMouseHandler by QmouseDriverPlugin. We adopt the first solution and modify the original interface qwsmouselinuxtp_qws.cpp to suit the new touch screen device driver interface.

First, we modify qwsmouselinuxtp_qws.cpp, first change the TS_EVENT structure to the data structure of the corresponding device, and then change the device file node opened in the QWSLinuxTPMouseHandlerPrivate function from /dev/ts to our own device file /dev/ttyS1. Then modify the readMouseData() function, read the device file according to our own data structure, and pass it to the QPoint class to locate the mouse or convert it to the mouse button state. The operation of this function can refer to the mouse driver source code under Windows.

In fact, after this modification, the touch screen device can be used normally, but in order to use the mouse and touch screen operations on this system platform at the same time, two steps must be completed: one is to correctly set the QWS_MOUSE_PROTO environment variable. Reading the QWSServer:: openMouse () function in qwindowsystem_qws.cpp, we can know that this environment variable can set multiple devices [: ] at the same time, and multiple devices are separated by spaces. Therefore, QWS_MOUSE_PROTO="Auto LinuxTP" can be set. Qt/Embedded generates the corresponding mouse and touch screen driver interfaces through this environment variable to operate the device. Then modify the source code of the mouse driver interface class of Qt/Embedded. Since the touch screen uses the system serial port, and Qt/Embedded automatically searches for the mouse interface and finds that the serial port is working, it will treat it as a mouse device for operation, which causes a device conflict. Therefore, we need to remove the sub-driver of the serial mouse in the qmousepc_qws.cpp file, find the code in the function QWSPcMouseHandlerPrivate::openDevices() as follows, and comment it out.

else if (driver=="Microsoft") {
QString dev=device.isEmpty()? QString("/dev/ttyS0") : device;
fd = open ( dev.latin1 (), O_RDWR | O_NDELAY );
if ( fd >= 0 )
sub[nsub++] = newQWSPcMouseSubHandler_ms(fd);
} else if (driver=="MouseSystems"){
QStringdev=device.isEmpty()?QString("/dev/ttyS0"). : device;
fd = open ( dev.latin1 (), O_RDWR | O_NDELAY );
if ( fd >= 0 ) sub[nsub++] = new QWSPcMouseSubHandler_mous esystems (fd);
}

Regarding the calibration of the touch screen, read the qwsmouselinuxtp_qws.h file (the code is as follows), and you can see that the coordinate calibration has been implemented in QWSMouseLinuxTPHandler. Generally, you can directly read the position and status of the coordinates.
class QWSLinuxTPMouseHandler:
public QWSCalibratedMouseHandler
{
};
Finally, you only need to add the option -qt-mouse- to the configure of Qt/Embedded installation and recompile. The application on the Qt/Embedded platform can provide support for the touch screen according to customized requirements.

4. Conclusion

This solution uses the same framework as the common mouse driver under Qt, with a simple design and clear organization. It has been successfully applied to the power quality monitor platform, and has stable operation, accurate positioning, and sensitive response. The friendly GUI interface and convenient human-computer interface make the power quality monitor more attractive. At the same time, the advantages of open source code are fully reflected in this solution. By reading a lot of source code, you can fully understand the software working mechanism and customize it according to user requirements to make a product that is truly suitable for users.

Keywords:Linux  Qt  Embeded Reference address:Design of touch screen driver based on Qt/Embeded in embedded Linux

Previous article:Design of remote meter reading system based on CAN/RS485 double-layer network
Next article:Design of Multi-protocol Router Based on Embedded Linux Platform

Recommended ReadingLatest update time:2024-11-16 21:31

OK6410A development board (eight) 2 linux-5.11 OK6410A linux development environment construction
Code : https://github.com/lisider/linux/tree/ok6410a-linux-5.11 Submit id : 4459e78a4d845f08286623b98546bcefbb45ddb9 defconfig : arch/arm/configs/ok6410A_sdboot_mini_net_defconfig To achieve u-boot tftp uImage  uImage network mounted root file system 1 TFTP server and client installation 2 NFS Server Installa
[Microcontroller]
Porting Linux-3.4.2 to TQ2440
Development Environment Host development environment: Ubuntu 12.04 BootLoader: u-boot-2012.04.01 kernel:linux-3.4.2 CPU: s3c2440 Development board: TQ2440 step I have previously ported the linux-2.6.30.4 kernel, and this time I will try to port a higher version of the kernel, Linux-3.4.2 1. Download kernel source
[Microcontroller]
Porting Linux-3.4.2 to TQ2440
S3C6410 WATCHDOG TIMER (watchdog timer) driver under Linux (3)
The previous two articles analyzed the driver architecture of the watchdog timer, and the other one analyzed the probe function corresponding to the platform device. Although the corresponding remove function was not analyzed, it is actually the same as other platform device drivers, doing the opposite of the probe fu
[Microcontroller]
S3C6410 WATCHDOG TIMER (watchdog timer) driver under Linux (3)
The transplantation process of Linux operating system on S3C2410 development board
The integration of ARM9S3C2410 microprocessor and Linux is getting closer and closer, and it is gradually being widely used in the embedded field. Currently, the combination of S3C2410 and Linux can be seen in portable consumer electronics, wireless devices, automobiles, networks, storage products, etc. The S3C2410
[Microcontroller]
The transplantation process of Linux operating system on S3C2410 development board
Today I used crosstool to create an arm-linux cross-compilation toolchain
Today I used crosstool to create an arm-linux cross-compilation toolchain, and successfully compiled and ran u-boot-1.3.0. Learn about crosstool at http://www.kegel.com/crosstool/. The cross-compilation toolchain version to be created is 3.3.2. The specific steps are as follows: Download crosstool-0.43.tar.gz mkdi
[Microcontroller]
arm-linux-gcc4.4.3 compiles the s3c2410 platform linux kernel
1. First download the linux kernel: linux-2.6.14.tar.bz2 Download address: http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.14.tar.bz2 2. Unzip linux-2.6.14.tar.bz2: tar -jxvf linux-2.6.14.tar.bz2 3. Configure the Makefile: 1. Open the Makefile in the source code root directory: gedit Makefile Modify the Makefil
[Microcontroller]
Development of Linux Driver Based on S3C2410
1. Establishment of development environment In embedded systems, due to the limited resources of the target machine, the driver and application are usually compiled on the host, and then communicate with the target machine through serial port, Ethernet, emulator or other communication means. In order to facilitate the
[Microcontroller]
ARM-Linux uses SD card root file system
Therefore, we instruct students to use JPT-7 module to run GPS application in arm-Linux. Nand Flash space is too small, and the board used often cannot burn the root file system. So we decide to use SD card to run the root file system. 1. Format the SD card on the PC To operate the SD card using an
[Microcontroller]
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号