Mini2440 bare metal programming -------- touch screen driver

Publisher:SparklingSoulLatest update time:2021-10-20 Source: eefocusKeywords:mini2440 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The mini2440 is connected to a resistive touch screen, which is based on AD conversion. That is, when a certain position is pressed, the voltage at that point will change. The voltage can be used to determine which point is pressed, and the arm can get the coordinates of this point. Because the touch screen and the LCD are two devices, the coordinates obtained by the touch screen generally cannot correspond to the coordinates on the LCD, so we need to manually calibrate them in the program (although they do not correspond, the relationship between them is linear, so by sampling three points, the coefficients can be determined.)


s3c2440 does not support interrupt nesting.


The arm is connected to the touch screen through four wires: tsxptsxm and tsyptsym. There is a sentence in the data sheet: When Touch Screen device is used; XM or PM is only connected ground for Touch Screen I/F. S3C2440 has a total of 4 touch screen interface modes, among which the automatic (continuous) XY coordinate conversion mode and wait for interrupt mode are what we use.


(1) Waiting for interrupt mode is to generate an interrupt when the stylus falls. In this mode, the value of the A/D touch screen control register ADCTSC should be 0xD3. After the system responds to the interrupt, the measurement mode of the XY coordinates must be no operation mode, that is, the lower two bits of the register ADCTSC must be cleared.


(2) Automatic (continuous) XY coordinate conversion mode is that the system converts the X-axis coordinate and Y-axis coordinate of the contact in sequence, where the X-axis coordinate value is written to the lower 10 bits of register ADCDAT0, and the Y-axis coordinate is written to the lower 10 bits of register ADCDAT1. In this mode, the system will also generate an interrupt signal.


In general, to realize the touch screen function, it is first set to wait for interrupt mode. After the int_tc interrupt is generated, it is set to automatic (continuous) XY coordinate conversion mode in the interrupt function to read the coordinate values ​​of the touch points in sequence.


There are two interrupts related to the touch screen function: int_adc and int_tc. These two interrupt sources belong to subinterrupt source, both of which belong to int_adc. Therefore, when configuring interrupts, you need to configure them according to the configuration method of sub interrupt sources. Among them, int_tc is generated when the touch screen is pressed or released. Only one of the events can be detected at a time. To detect whether the touch screen is pressed or released, we need to set the 8th bit of the ADCTSC register. int_adc is generated after the ad conversion is completed.


The third bit of the ADCTSC register can select the enable of the pull-up resistor. In the waiting interrupt mode, the pull-up resistor must be valid. After the interrupt is triggered, the pull-up resistor must be invalid. The second bit of the ADCTSC register is used to select the automatic (continuous) XY coordinate conversion mode. The lower two bits of the stylus lift/drop interrupt status register ADCUPDN can determine the state of the stylus causing the interrupt. The A/D delay register ADCDLY can set the delay length from the start of the interrupt to the actual start of the A/D conversion. Its clock source frequency is 3.68MHz.


The process of implementing the touch screen function is as follows:


1. Set the touch screen to wait for interrupt mode and configure ADCTSC to generate an interrupt when the touch screen is pressed.


2. After the interrupt is generated, it proves that the touch screen is pressed. Modify ADCTSC and ADCCON in the interrupt function and configure the touch screen for continuous conversion. At the same time, the int_adc interrupt should be blocked. Because we are in the interrupt function, we use the while loop to detect the srcpnd and subsrcpnd registers to detect whether the interrupt of adc conversion completion has been generated. That is, the interrupt is blocked, but by detecting whether the interrupt is generated, we can determine whether the adc conversion is completed.


3. After the adc conversion is completed, extract the desired data. Then configure ADCSTC to generate an interrupt when the touch screen is released, and continue to mask the interrupt. By detecting srcpnd and subsrcpnd, it is determined whether an interrupt is generated when the touch screen is released. When the touch screen is detected to be released, the interrupt function ends.


Of course, I think it is also possible to use other methods to achieve this, for example, after detecting that the touch screen is pressed, the interrupt function ends. In other words, it is also feasible to implement the above three steps in three interrupt functions respectively.



In addition, regarding the calibration of the touch screen, Mr. Zhao's method is reproduced as follows:


The more common calibration method is the three-point calibration method, and its principle is:


       Assume that the coordinates of each point PD on the LCD are [XD, YD], and the coordinates of each point PT on the touch screen are [XT, YT]. To convert the coordinates on the touch screen to the coordinates on the LCD, the following formula is required for conversion:


XD=A×XT+B×YT+C


YD=D×XT+E×YT+F


Because there are a total of six parameters (A, B, C, D, E, F), only three sampling points are needed to obtain these six parameters. Once these six parameters are determined, as long as the coordinate point PT on any touch screen is given and substituted into this formula, the coordinate PD of the corresponding pixel point on the LCD can be obtained. The specific solution process will not be explained in detail, only the final result is given. The three sampling points on the LCD are known to be: PD0, PD1, PD2, and the three points on the touch screen they correspond to are: PT0, PT1, PT2. The final results of the six parameters A, B, C, D, E, F are all fractions, and they all have a common denominator, which is:


K = (XT0-XT2) × (YT1-YT2) - (XT1-XT2) × (YT0-YT2)


The six parameters are:


              A=[(XD0-XD2)×(YT1-YT2)-(XD1-XD2)×(YT0-YT2)] / K


              B=[(XT0-XT2)×(XD1-XD2)-(XD0-XD2)×(XT1-XT2)] / K


              C=[YT0×(XT2×XD1-XT1×XD2)+YT1×(XT0×XD2-XT2×XD0)+YT2×(XT1×XD0-XT0×XD1)] / K


              D=[(YD0-YD2)×(YT1-YT2)-(YD1-YD2)×(YT0-YT2)] / K


              E=[(XT0-XT2)×(YD1-YD2)-(YD0-YD2)×(XT1-XT2)] / K


              F=[YT0×(XT2×YD1-XT1×YD2)+YT1×(XT0×YD2-XT2×YD0)+YT2×(XT1×YD0-XT0×YD1)] / K


The specific operation is to first display three points on the LCD, and then after the user clicks on these three points, collect the actual coordinates and theoretical coordinates of the three points, so that the above parameters can be calculated.



Attached below is my code.


static void __irq touchscreen_irq(void)

{

   int xdata, ydata;

   rADCTSC = (1<<3)|(1<<2); //Pull-up resistor is invalid, automatic continuous XY coordinate conversion mode is turned on

       rADCDLY = 40000; //delay

      

       rADCCON|=0x1; //Start A/D conversion

 

       while(rADCCON & 0x1); //Check if A/D conversion has started

       while(!(rADCCON & 0x8000)); //Wait for the end of A/D conversion

             

       while(!(rSRCPND & (BIT_ADC))) ; //Judge the suspension bit of A/D interrupt

 

       xdata=(rADCDAT0&0x3ff); //Read the X-axis coordinate

   ydata=(rADCDAT1&0x3ff); //Read Y-axis coordinates

 

   uart_printf("xdata = %x, ydata = %x adcdata0 = %x ", xdata, ydata, rADCDAT0);

   

       rSUBSRCPND|=BIT_SUB_TC;

   ClearPending(BIT_ADC);

                     

       rADCTSC = 0xd3; // Set the wait interrupt mode again, this time to determine whether the stylus is lifted

       rADCTSC = rADCTSC|(1<<8); //Set the stylus lift interrupt

 

       while(1) //Wait for the stylus to be lifted

       {

              if(rSUBSRCPND & (0x1<<9)) //Check A/D touch screen interrupt suspension

              {

                     break; //If the stylus is lifted, then jump out of the loop

              }

       }    

    uart_printf("adcdata0 = %x ", rADCDAT0);

rSUBSRCPND = 1<<9;

ClearPending(BIT_ADC); 

uart_printf("irq finishrn");

rADCTSC=0xd3; //important here

}

 

 

void touchscreen_init(void)

{

rADCDLY=50000; //Set delay

    rADCCON=(1<<14)+(9<<6); //Set A/D prescaler

 

    rADCTSC=0xd3; //Set the touch screen to wait for interrupt mode.

 

    pISR_ADC = (U32)touchscreen_irq;

 

rINTSUBMSK &= ~(BIT_SUB_TC);

rSUBSRCPND = 1<<9;

ClearPending(BIT_ADC);

EnableIrq(BIT_ADC);

}

void touchscreen_test(void) 

{

   touchscreen_init();

}

Keywords:mini2440 Reference address:Mini2440 bare metal programming -------- touch screen driver

Previous article:S3C2440 (4.3-inch) LCD driver level analysis (16)
Next article:ARM processor architecture------implementation of nested interrupts

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号