Development of touch screen driver on embedded Linux platform

Publisher:心若清泉Latest update time:2018-02-17 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

    introduction

    Touch screens are becoming more and more popular as input devices for embedded systems by various terminal product manufacturers due to their convenience, flexibility, space saving and intuitiveness. The Linux operating system is a popular choice for embedded systems because of its advantages of open source code and easy customization. This article will discuss in depth how to write a touch screen driver in the Linux operating system based on the construction of hardware.

    Introduction to SPI interface

    Serial Peripheral Interface SPI bus technology is a full-duplex, synchronous serial interface launched by Motorola. It provides a powerful four-wire interface (receive line, transmit line, clock line and slave chip select line).

    The slave and master devices of SPI share a clock line, and the clock is always sent from the master device. When 823e is in master mode, the chip select signal line is disabled. If it is in slave mode, its slave chip select line is enabled at a low level. In this example, 823e is the master device, so we also selected a GPIO (general purpose input and output port) of 823e as the chip select signal of the slave device. Most synchronous serial data converters are easy to connect to this interface, and their hardware functions are very powerful, so the software related to SPI is quite simple, giving the CPU more time to handle other matters.

    Touch screen hardware

    The touch screen input system consists of three parts: touch screen, touch screen control chip and data processor. Touch screens can be divided into five categories according to their technical principles: vector pressure sensing, resistive , capacitive , infrared and surface acoustic wave. Among them, resistive touch screens are more commonly used in embedded systems.

    The touch screen we chose is the resistive touch screen AMT9502 from AMD. The touch screen control chip is the analog-to-digital conversion chip ADS7846 from TI. This chip supports the SPI communication protocol, so we use the SPI interface of 823e to communicate with the ADS7846 chip. The analog signal obtained from the touch screen is input into the 823e as a data processor after passing through the analog-to-digital converter.

    software program

    823e communicates with the touch screen controller through the SPI interface, so the control of the touch screen is the operation of the SPI interface. After completing the writing of the SPI interface driver, it is possible to establish communication with the touch screen controller. After the Linux kernel has finished running, the SPI interface must be opened, and a portion of memory has been allocated for its use. At the same time, the SPI interrupt program has been added to the waiting queue. Once the SPI interface has an interrupt, the SPI interrupt service program is awakened and starts running. This part of the work is completed in the initialization function that runs during the system startup process. The following will discuss the writing of the initialization function in conjunction with the source code, among which two points will be discussed in detail.

    Use of m IC rocode

    Because the network parameter space of SCCx conflicts with the parameter space of SPI, if you want to use SCCx as a network port and SPI driver at the same time, you need to load microcode and relocate the parameter space of SPI. Micropatch is a file that loads microcode, and the microcode in this file can be downloaded from the official website of Motorola.

    CPM includes a part of bidirectional RAM port, called parameter RAM, which includes USB, SCC, SMC, SPI, I2C and I DMA channel operations. Among them, SPI and I2C parameter areas can be relocated to another 32-bit parameter area. After reading the following code carefully, you can understand how this process works:

    spi=(spi_t*)&cp->cp_dparam[PROFF_SPI];

    printk("thespiaddris%pn",spi);

    if((re LOC =spi->spi_rpbase))

    {

    spi=(spi_t*)&cp->cp_dpmem[spi->spi_rpbase];

    printk("MICROCODERELOCATIONPATCHn");

    }

    The purpose of the above code is to first check whether the microcode has been used, and then obtain the relocated pointer (the operations of loading microcode and relocation are completed in microcode.c).

    SPI Descriptor in RAM

    The descriptors of the SPI interface are stored in a buffer whose address is specified by the SPI buffer descriptor in the bidirectional RAM. The data to be sent is in the send buffer, and the received data will be stored in the send buffer. The buffer descriptor loop forms a loop that helps to gradually transmit (receive) the data to be sent (received). It is thanks to these buffer descriptors that the communication processing module can complete the communication and explain and handle errors.

    You can use a piece of code to see how the process of the above diagram is implemented in the initialization function:

    spi->spi_rbase=r_rbase=dp_addr;

    spi->spi_tbase=r_tbase=dp_addr+sizeof(cbd_t);

    /*Write the address of RXBDRING into POINTERTOSPIRXRING

    Write the address of TXBDRINT into POINTERTOSPITXRING*/

    spi->spi_rbptr=spi->spi_rbase;

    spi->spi_tbptr=spi->spi_tbase;

    /*The above two codes must be written, otherwise there will be errors in reading and writing./

    tbdf=(cbd_t*)&cp->cp_dpmem[r_tbase];

    rbdf=(cbd_t*)&cp->cp_dpmem[r_rbase];

    /*From this code, we can see that the address of RXBDRING is in the bidirectional RAM*/

    tbdf->cbd_sc&=~BD_SC_READY;

    rbdf->cbd_sc&=~BD_SC_EMPTY;

    /*Set the state of RING, and set the sent RING to the non-ready-to-send state.

    The received RING is set to the non-ready to receive state*/

    rxbuffer=m8xx_cpm_hostalloc(2);

    txbuffer = m8xx_cpm_hostalloc(2);/*get two spaces*/

    tbdf->cbd_bufaddr=__pa(txbuffer);

    rbdf->cbd_bufaddr=__pa(rxbuffer);

    /*Memory mapping; and set DATAPOINTER to the address of RXDATABUFFER*/

    The above code is completed in the initialization function. Once the initialization function works correctly, you can take the correct steps to communicate with the SPI port. After the above initialization is completed, the cpm_install_handler function must be called. The function of this function is to register the interrupt function into the kernel. Once the SPI port generates a hardware interrupt, the interrupt function is called. The writing of the interrupt function can be based on the different needs of different systems. In this example, we make it so that once the interrupt function is called, the data received by the SPI is read.

    Next, we will take how to send data as an example to analyze how to operate SPI port communication.

    Steps to send data

    In this example, the SPI interface is set to master mode. To start the data transfer process, the kernel writes the data to be transferred to a data buffer and then configures the buffer descriptor to achieve the purpose of the transfer. The following is a code for sending data, and the code explains the transmission process.

    MEMS et((void*)txbuffer,0,2);/*Clear buffer*/

    tbdf->cbd_sc=BD_SC_READY|BD_SC_LAST|BD_SC_WRAP;

    tbdf->cbd_datlen=2;

    /*Set the value of the status control register of the send buffer and the number of sent data*/

    rbdf->cbd_sc=BD_SC_EMPTY|BD_SC_WRAP;

    rbdf->cbd_datlen=0;

    /*Since no data is intended to be received, the number is 0*/

    cp->cp_spmode=0x777f;

    cp->cp_spie = 0xff;

    cp->cp_spim=0x37;

    /*Set the value of the SPI interface register to send data and set the SPI interface

    The master or slave mode must be set in the send function, otherwise, data cannot be sent*/

    cp->cp_spcom|=0x80;/*Start sending data*/

    udelay(1000);/*Must wait, otherwise the value of the buffer status control register cannot be read correctly*/

    if((tbdf->cbd_sc&0x8000))

    printk("spiwriteerror!");

    m EMS et((void*)rxbuffer,0,2);

    The most important thing in data communication is timing, and the correct timing can only be obtained through repeated experiments. Figure 3 is the logic diagram obtained during the experiment (test results of Agilent's 1672G logic analyzer). Among them, CS is the chip select signal, CK is the clock signal, and DO is the data sent by 823e. You can use a logic analyzer to read whether the obtained data is consistent with the data sent by the device. Correct communication can only be achieved after a long period of debugging.

    Operation of ADS7846

    According to the user manual of ADS7846, the driver must establish communication with ADS7846 during initialization. Therefore, 823e must first send a command to ADS7846 and establish communication after receiving a reply from ADS7846. The driver calls the read and write functions of SPI to implement operations on ADS7846.


Reference address:Development of touch screen driver on embedded Linux platform

Previous article:Development of a fault monitoring system for embedded radar transmitters
Next article:Introduction to Embedded System Design Technology

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

DC motor drive based on 51 single chip microcomputer (L298)
L298 is a product of SGS. L298N is a 15-pixel monolithic integrated circuit with high voltage, high current and four-channel drive. L298N is designed to receive DTL or TTL logic levels, drive inductive loads (such as relays, DC and stepper motors) and switch power transistors. It contains a 4-channel logic drive circui
[Microcontroller]
linux i2c device test, i2c-dev driver test code
embed-linux version:linux-2.6.39-exp vmware-linux:ubuntu14.04 hardware: core chip at91sam9x25 cross-compile:arm-none-linux-gnueabi-gcc 4.5.2 code: #include stdio.h #include stdlib.h #include unistd.h #include sys/ioctl.h #include sys/types.h #include sys/stat.h #include fcntl.h //#include sys/select.h #include sys/tim
[Microcontroller]
8051/2 MCU basics LED flashing, buzzer, digital tube driver, independent button, interrupt, timer interrupt, serial communication
The road from software to hardware is always difficult. I have been learning various circuit knowledge for more than three months, and now I have finally got the hang of it. AT 8051/2 1. Drive LED to flash 2. Drive the buzzer to sound 3. Drive common anode, single digital tube, 0-9 change (MPX1-CA) - use 8 resistors
[Microcontroller]
8051/2 MCU basics LED flashing, buzzer, digital tube driver, independent button, interrupt, timer interrupt, serial communication
A simple input subsystem program for Linux driver
In the brief analysis of the input subsystem of the Linux driver, we have analyzed the composition of the input subsystem. It is composed of the device layer, the core layer, and the event layer. The core layer provides some functions common to the device layer and the event layer, such as registration functions, un
[Microcontroller]
A simple input subsystem program for Linux driver
STM32L0 Development Notes 9: Manually add driver files
    We can generate project code through STM32CubeMX, but what if our project has been built, or we start a new project design on the existing project and need to add a new driver? This article explores the solution.     1. The driver path of STM32CubeMX is shown in the figure below. If we want to add any driver, we c
[Microcontroller]
tiny4412 serial port driver analysis nine --- shell terminal
Development board: tiny4412ADK+S700 4GB Flash Host: Wind7 64-bit Virtual machine: Vmware+Ubuntu12_04 u-boot:U-Boot 2010.12 Linux kernel version: linux-3.0.31 Android version: android-4.1.2     Above we know how /dev/ttySACx is generated. In addition, we can also see that there are device nodes /dev/console and /dev/tt
[Microcontroller]
"Driver separation" design idea of ​​microcontroller firmware
Today I have found with you a common design method of separating applications and drivers. It is still worth using for some current high-performance MCUs. However, it is not recommended for MCUs whose original main frequency is not high enough and whose performance is not strong enough. After all, this The design stil
[Microcontroller]
Analysis of typical new energy vehicle drive motor system
The motor, also known as the "drive motor", is an electrical device that converts electrical energy into mechanical energy and can generate kinetic energy from mechanical energy to drive other devices. The drive motor is one of the core components of the new energy vehicle drive system and is responsible for providi
[Embedded]
Analysis of typical new energy vehicle drive motor system
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号