S3C2416 bare metal development series 13_capacitive screen driver implementation

Publisher:紫菜包饭Latest update time:2016-12-12 Source: eefocusKeywords:S3C2416 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

In the human-computer interaction system, input devices such as keyboards and touch screens are an indispensable part. For consumer electronics such as mobile phones and tablets, touch screens have been widely used due to their very good user experience. Here, the author briefly introduces the application of s3c2416 IIC interface capacitive touch screen.

Android and iOS used in mobile phones and tablets, most operating systems (or graphics systems) do not support multi-point touch very well. This mode of pulling the interrupt signal line low when there is touch and pulling the interrupt signal line high when there is no touch will be very well applied to these software. The trigger mode is that when there is touch, the driver chip will generate an interrupt signal at a certain frequency to report the coordinate position of the touch point. Usually, this reporting frequency is about 100HZ (the driver chip is solidified). If the reporting frequency is too low, it may cause point loss. This can ensure the recognition of multiple touch points. At present, mainstream mobile phones and tablets all use this working method to obtain the coordinate position of multi-point touch.

The capacitive screen module of the author adopts the IIC interface. Therefore, the implementation of the s3c2416 capacitive screen driver needs to be based on the IIC driver in the previous chapter. In the capacitive screen test code, an example of 5-point touch canvas is given, and 5 fingers can be used to draw on the canvas at the same time. The touch screen module code test in this chapter requires the support of the startup code, IIC interface module, and RGB screen driver module in the previous chapter.

The tp_ft5206.c module is implemented as follows:

#include "s3c2416.h"

#include "IIC.h"

#include "tp_ft5206.h"

#include "Exception.h"

 

volatile unsigned char  TP_Press;

static void TP_EINT8_15_IRQ()

{  

    if (rEINTPEND & (1<<12)) { //EINT12 interrupt processing

        rEINTMASK |= (1 << 12); // EINT12 interrupt disable  

        rEINTPEND |= (1 << 12); // Clear interrupt flag

        TP_Press = 1; // Indicates that the touch screen is pressed

    }

   

    rSRCPND1 |= (1 << INT_EINT8_15);//Clear pending bit

    rINTPND1 |= (1 << INT_EINT8_15);

 

}

 

static void Delay_ms(unsigned int nCount)

{

//Delay 1ms, total delay nCount(R0) ms

    __asm__ __volatile__ (

        "0:\n\t"   

        "ldr  r1, =100000\n\t"  // Arm clock为400M     

        "1:\n\t"

        "subs r1, r1, #1\n\t"  // 一个Arm clock

        "bne 1b\n\t" // Jump will clear the pipeline, 3 Arm clocks

        "subs %0, %0, #1\n\t" // The caller ensures that nCount is not 0

        "bne  0b\n\t"

        : : "r"(nCount):"r1"

    );

}

 

// Write Length bytes of data to the internal address WriteAddr of the capacitive touch screen. The data location is in pData.

intTP_WriteBytes(unsigned char WriteAddr, unsigned char *pData,

             int Length)

{  

    //Call IIC write to continuously write to a certain address inside the capacitive screen

    return IIC_WriteBytes(TP_SlaveAddr,WriteAddr, pData, Length);

}

 

//Continuously read Length bytes of data from the internal address ReadAddr of the capacitive touch screen, and save the data in pData

intTP_ReadBytes(unsigned char ReadAddr, unsigned char *pData,

             int Length)

{

    // Call the IIC interface to read continuously a certain address inside the capacitive screen

    return IIC_ReadBytes(TP_SlaveAddr, ReadAddr,pData, Length);

}

 

void TP_Reset()

{

    rGPFDAT &= ~(1 << 5); // Pull the reset line low

    Delay_ms(20);

    rGPFDAT |= (1 << 5);

    Delay_ms(200);

}

 

void TP_Init()

{

    rGPGUDP &= ~(0x3 << 8); //GPG4 (EINT12) as capacitive screen interrupt input

    rGPGUDP |= (0x2 << 8); // TP_INT GPG4 pull-up  

    rGPGCON &= ~(0x3 << 8);

    rGPGCON |= (0x2 << 8); // GPG4 is configured as EINT12

   

    rGPFUDP &= ~(0x3 << 10); //GPF5 is used as reset control signal

    rGPFUDP |= (0x2 << 10); // TP_RST GPF5 pull-up 

    rGPFCON &= ~(0x3 << 10);

    rGPFCON |= (0x1 << 10); // GPF5 is configured as output

   

    TP_Reset(); //TP reset

    //TP external interrupt entry function is added to the vector table

    IRQ_Register(INT_EINT8_15, TP_EINT8_15_IRQ);

    rEXTINT1 &= ~(0x7 << 16);

    rEXTINT1 |= (0x2 << 16); // EINT12 falling edge trigger

    rINTMOD1 &= ~(1 << INT_EINT8_15);// EINT8_15 IRQ

    rINTMSK1 &= ~(1 << INT_EINT8_15); // EINT8_15 enables interrupt

    rEINTMASK &= ~(1 << 12); // EINT12 enable interrupt 

}

 

The contents of the module header file are as follows:

#ifndef__TP_FT5206_H__

#define__TP_FT5206_H__

 

#ifdef__cplusplus

extern"C" {

#endif

 

// TP IIC 7-bit slave address

#define TP_SlaveAddr    0x38

   

#define TOUCH1_XH       0x03

#define TOUCH1_XL       0x04

#define TOUCH1_YH       0x05

#define TOUCH1_YL       0x06

#define ID_G_MODE       0xA4

 

extern void TP_Reset(void);

extern void TP_Init(void); 

extern int TP_WriteBytes(unsigned char WriteAddr,

                   unsigned char *pData, int Length);

extern int TP_ReadBytes(unsigned char ReadAddr,

                 unsigned char *pData, int Length);

extern volatile unsigned char TP_Press;

   

#ifdef__cplusplus

}

#endif

#endif/*__TP_FT5206_H__*/

 

The effect of drawing a line with five fingers touching at the same time:

http://pan.baidu.com/s/1i37NU2x


Keywords:S3C2416 Reference address:S3C2416 bare metal development series 13_capacitive screen driver implementation

Previous article:S3C2416 bare metal development series 14_Transplantation of UCGUI under GCC (1)
Next article:S3C2416 bare metal development series 12_IIC driver implementation

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
Guess you like

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号