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.
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
- Popular Resources
- Popular amplifiers
- MathWorks and NXP Collaborate to Launch Model-Based Design Toolbox for Battery Management Systems
- STMicroelectronics' advanced galvanically isolated gate driver STGAP3S provides flexible protection for IGBTs and SiC MOSFETs
- New diaphragm-free solid-state lithium battery technology is launched: the distance between the positive and negative electrodes is less than 0.000001 meters
- [“Source” Observe the Autumn Series] Application and testing of the next generation of semiconductor gallium oxide device photodetectors
- 采用自主设计封装,绝缘电阻显著提高!ROHM开发出更高电压xEV系统的SiC肖特基势垒二极管
- Will GaN replace SiC? PI's disruptive 1700V InnoMux2 is here to demonstrate
- From Isolation to the Third and a Half Generation: Understanding Naxinwei's Gate Driver IC in One Article
- The appeal of 48 V technology: importance, benefits and key factors in system-level applications
- Important breakthrough in recycling of used lithium-ion batteries
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- TI Reference Voltage (VREF) Application Design Tips
- The difference between multilayer PCB and LTCC
- The basis of the difference between TTL and CMOS
- About Puzhong Technology 51 microcontroller development board v3.0, LED part of the problem
- Understanding bandwidth
- Circuit output grounding problem.
- When AD software needs to drill vias to connect the network in the inner electrical layer segmentation, what is the minimum distance between the vias and the inner electrical layer segmentation edge?
- The United States is pressing forward: blacklisting 38 Huawei subsidiaries in an attempt to block Huawei's outsourcing of chips
- 【GD32450I-EVAL】+ 06SDRAM Introduction
- 【ST NUCLEO-H743ZI Review】(1)First impressions of ST NUCLEO-H743ZI