Touch screen driver solution based on Linux system

Publisher:快乐旅行Latest update time:2012-11-22 Source: 维库电子Keywords:Linux Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

introduction

As an input device, the touch screen has the advantages of being durable, fast in response, space-saving, and easy to communicate. It provides a simple, convenient, and natural way of human-computer interaction and is currently widely used in industrial control, electronic inquiry, and consumer electrical products.

Linux is one of the most popular operating systems at present. It has a large number of users in the desktop system and server fields. It has the advantages of open source code, rich hardware support, high portability, etc. It is also favored in the embedded field. Linux divides the driver into three types according to different devices: character device driver, block device driver, and network device driver. The Linux input subsystem u is an abstraction of the implementation method of character type input device driver. It is a kernel driver model that uniformly processes scattered and various types of input devices. The input subsystem has the advantages of high efficiency, no bugs and reusability. This article discusses the touch screen driver based on the Linux input subsystem in depth.

1 Hardware Platform

S3C2440 is an MCU launched by Samsung using the ARM920t core. It integrates a rich set of peripherals, including a 4-wire resistive touch screen controller and an 8-channel multiplexed ADC.

The touch screen consists of a touch detection component and a touch screen controller, which corresponds to the external circuit of the four-wire resistive touch screen of the S3C2440 platform and the A/D conversion control part of the S3C2440 chip. The external circuit of the four-wire resistive touch screen controls the on-off status of the upper and lower conductive layers and how to obtain the voltage. After obtaining the voltage, the A/D in the S3C2440 chip converts the analog quantity into a digital quantity. The A/D converter of the S3C2440 chip has 8 input channels, and the conversion result is a 10-bit digital number. The conversion process is automatically implemented inside the chip. The conversion result is taken from the register, and the coordinates of the touch point can be directly obtained after a certain conversion. The ADC and touch screen interface provided by the S3C2440 are shown in Figure 1. The touch screen is directly connected to the pins XP, XM, YP and YM. The on-off of the two conductive layers of the touch screen is controlled by the XP, XM, YP and YM4 pins. By reading and writing the specified special register, the touch screen controller of the S3C2440 will automatically control the touch screen interface to open or close, and complete the collection of contact data according to the specified operation mode.

Figure 1 S3C2440ADC and touch screen interface structure

2. Introduction to the Input Subsystem Architecture

Device drivers play an important role in the Linux kernel. They are implemented as kernel modules and can be loaded and unloaded dynamically. The implementation of Linux device drivers only requires the initialization of key data structures and the writing of callback functions according to a set of relevant data structures and driver interface standards provided by the kernel. The kernel provides the cdev data structure and file_operations structure and operation methods for character device drivers. To implement character device drivers, you only need to complete the initialization of cdev, the implementation of the operation functions in file_operations, and register with the kernel.

The Linux input subsystem is an abstraction of input devices with different physical forms but similar functions. It is an encapsulation of the character device driver interface in the kernel. The input subsystem consists of the device driver layer, the core layer, and the event processing layer. The device driver layer provides read and write access to the hardware registers and converts the response of the underlying hardware to the user input access into standard input events, which are submitted to the event processing layer through the core layer; the core layer provides a programming interface to the device driver layer and also provides a programming interface to the event processing layer; the event processing layer provides a unified interface for accessing devices and event processing submitted by the driver layer for user space applications. When designing a driver based on the input subsystem, it is necessary to implement the driver of the device driver layer and the driver of the event processing layer. The input subsystem provides a standard event interface for the touch screen in the event processing layer, so it is only necessary to complete the driver of the device driver layer, that is, the operation of the hardware registers and the submission of input event information. The implementation process of the device driver layer driver based on the input subsystem is as follows:

1) In the driver module loading function, the input device is set to support events of the input subsystem; the Linux kernel uses input_dev to represent an input device. For the touch screen, the evbit[0] of the input_dev instance is set to support synchronization (EN_SYN), key (EN_KEY) and absolute coordinate (EV_ABS) events.

2) Register the input device to the input subsystem through the input_register_device0 function provided by the kernel.

3) When an input operation occurs, the input device submits the event and the corresponding key value or coordinate status information. The touch screen uses the general input event driver Evdev provided by the input subsystem to package the event information into the Input_event type for reporting.

3 Implementation of Linux touch screen driver

3.1 Touch screen contact data collection

The S3C2440 touch screen controller has four working modes. The selection of the touch screen controller working mode and the collection of touch screen contact data are completed by reading and writing ADCTSC, ADCDA, ADCDATl and ADCDLY registers. Due to the randomness of the touch action time, the interrupt working mode is selected during the driver design. Set the ADCTSC register to 0xD3 to make the touch screen controller enter the waiting interrupt mode, and set the ADCDLY sampling delay time. When the touch screen is pressed, the touch screen controller will generate an INT_TC interrupt: in the ⅡTC interrupt handler, set the ADCTSC register to 0x0C, the touch screen controller switches to the automatic X/Y coordinate conversion mode, and automatically converts the x, y coordinate values ​​corresponding to the contact point, and writes them to the ADCDAT0 register and ADCDTA1 register respectively. The INTADC interrupt is issued to indicate that the ADC conversion is completed; enter the INT_ADC interrupt handler to read the coordinate data in the ADCDAT0 register and ADCDTA1 register and perform the corresponding conversion. After data collection, reset the ADCTSC register to 0xD3 to make the touch screen controller enter the waiting interrupt mode, waiting for the touch screen to be pressed.

3.2 Driver initialization module

The Linux driver is loaded and run as a kernel module. Implement the driver loading function s3c2440ts_init() and register with the kernel through module_init (s3c2440ts_init). The driver loading function mainly completes: enabling the clock required by ADC, mapping 10 addresses, initializing registers related to ADC and touch screen controller, applying for INT_TS and INT_ADC interrupts, initializing input devices, and registering input devices to the input subsystem. The key code is as follows:

3.3 Interrupt Handler and Event Reporting

When the user presses, lifts, and drags the touch screen, the interrupt INT_TS is triggered, and the kernel enters the interrupt processing function tc_irq0 for interrupt processing. In tcirq0, the ADC-LOCK lock mechanism is used to ensure that only one driver uses the ADC interrupt line. By reading the ADCDAT0 and ADCDAT1 registers, the state of the touch operation is determined. When the touch pen is pressed, ts_timer_fireO is called for data conversion. When the data conversion is completed, the INT_ADC interrupt is generated, and the kernel enters the interrupt processing function adc-irqO. adc_irq() completes the contact information collection and calls ts_timer_fire() for event reporting. The event reporting process is shown in Figure 2.

Figure 2 Incident reporting process

ts_timer_fire0 is mainly used to report the contact coordinate information to the application layer. updown and count are static global variables. The updown contact state, count represents the number of ADC conversions within 1 jiffies. When count is 0, the automatic X/Y axis coordinate conversion mode is set. After the conversion is completed, the corresponding INT_ADC interrupt notification is generated to complete the conversion. When count is not 0, the input_report_abs() function reports the X, Y absolute coordinate events to the input subsystem, and the inputreport_key() function reports the corresponding button pressed event on the touch screen. The input subsystem uses inputsync() to form an evdev packet of the reported events and sends it out through /dev/input/eventX. The application can obtain the event information by reading /dev/input/eventX. The key code is as follows:

4 Conclusion

With the rapid development of information technology, embedded technology is becoming more and more closely related to people's lives. As a new type of input device, touch screens are becoming more and more popular due to their advantages such as light weight, small footprint, convenience and flexibility. They have even been widely used in the industrial field, improving the level of industrial control automation in my country. To give full play to the advantages of touch screens, driver design in embedded systems is crucial. When implementing touch screen drivers based on the input subsystem in embedded Linux, the standard event interface provided by the Linux input subsystem is used to simplify the driver design. The focus of driver design becomes the hardware operation and function implementation related to the touch screen controller, which fully reflects the high reproducibility of the Linux kernel code and has a certain reference role in the design of drivers for other types of input devices.

Keywords:Linux Reference address:Touch screen driver solution based on Linux system

Previous article:Display Technology of Digital Storage Oscilloscope Based on FPGA
Next article:Design of an Active Power Factor Correction Circuit and Control Method

Recommended ReadingLatest update time:2024-11-16 17:36

Access control monitoring system software design based on ARM9 and Linux
Access control, also known as access management control system, is a digital management system for managing people's access. At present, with the development of industrial automation and people's increasing demand for applications, access control monitoring systems have been increasingly used, but traditional acce
[Security Electronics]
Access control monitoring system software design based on ARM9 and Linux
s3c6410 linux gadget hid driver
The kernel I use is linux2.6.38. At the beginning, the development board can be used as a USB flash drive, but when using the HID function, the following problems occur: g_hid gadget: hid_setup crtl_request : bRequestType:0x21 bRequest:0xa Value:0x0 g_hid gadget: Unknown request 0xa s3c-hsotg s3
[Microcontroller]
UBIFS file system construction and configuration (Micro2440 + Linux 2.6.39)
1. UBIFS file system configuration a) Kernel configuration         After 2.6.27, ubifs has been integrated into the kernel tree. The 2.6.39 kernel used in this document has already included the relevant code for UBIFS, so you can directly perform make menuconfig configuration.         Device Drivers ---        
[Microcontroller]
UBIFS file system construction and configuration (Micro2440 + Linux 2.6.39)
Linux system installation under SmartArm3250
I am currently researching the Linux driver for SmartArm3250, so first I have to install (also known as download) the Linux system on the development board. I followed the steps in the book and encountered some minor problems. After many experiments and summaries, I can now install the Linux system skillfully. Here is
[Microcontroller]
Novice self-study ARM: Programming under Linux to obtain system time and set time
There are several programmatic ways to get the time: 1 #include stdio.h #include time.h main(){ time_t t; struct tm *p; time(&t); p=gmtime(&t); printf("Year :%d\n",1900+p- tm_year); printf("Month :%d\n",1+p- tm_mon); printf("Day :%d\n",p- tm_mday); printf("Hour :%d\n",p- tm_hour); printf("Minute:%d\n",p-
[Microcontroller]
Design of vehicle navigation system based on embedded LINUX
1 Introduction The continuous improvement of the technical level of vehicle-mounted electronic equipment has become one of the important signs of the development of modern automobiles, and vehicle-mounted navigation equipment is an important part of it. It should display the data communication system, audio and vide
[Microcontroller]
Design of vehicle navigation system based on embedded LINUX
Implementation of Serial Peripheral Interface SPI Based on S3C2410 and Embedded Driver under Linux
    Serial peripheral interface SPI (serial peripheral interface) bus technology is a synchronous serial interface introduced by Motorola. It allows the CPU to communicate with peripheral interface devices such as TTL shift registers, A/D or D/A converters, real-time clocks (RTO), memories, and LCD and LED display dri
[Microcontroller]
Implementation of Serial Peripheral Interface SPI Based on S3C2410 and Embedded Driver under Linux
Design of magnetic field measurement system based on embedded Linux
1 Introduction With the development of science and technology, embedded operating systems play an important role in more and more fields, and have become one of the symbols of product technology level. Among them, Linux is widely used in instrument measurement equipment because of its openness, multi-user, multi-taskin
[Test Measurement]
Design of magnetic field measurement system based on embedded Linux
Latest Power Management Articles
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号