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.
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
- Popular Resources
- Popular amplifiers
- Siemens Motion Control Technology and Engineering Applications (Tongxue, edited by Wu Xiaojun)
- Modern Product Design Guide
- Modern arc welding power supply and its control
- Small AC Servo Motor Control Circuit Design (by Masaru Ishijima; translated by Xue Liang and Zhu Jianjun, by Masaru Ishijima, Xue Liang, and Zhu Jianjun)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- 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
- Share a book about Cortex M3 core
- MicroPython v1.10 released
- Fudan Micro FM33LC046N Evaluation + ADC Collection Alarm
- MSP430FR235x-based pulse oximeter system solution
- CCS compilation error: Solution for missing header file
- Help chip F28377D to establish SYS/BIOS routines
- LWIP uses UDP to send data continuously
- It was very popular in the past, and now it is back, how should this button position be designed?
- Implementing USB source code with Verilog (FPGA)
- How good is Hangshun's chip? Let's see if Huawei 5G uses its chip