Touch support in VTFT XPT2046 touch controller

Post your requests and ideas on the future development of Visual TFT Software.
Author
Message
KevinA
Posts: 60
Joined: 22 Mar 2010 18:46

Touch support in VTFT XPT2046 touch controller

#1 Post by KevinA » 04 Apr 2014 21:53

I went to create a project and found there is only two touch controllers being supported in VTFT and one is ONLY for ARM.
STMPE610 and TSC2006 ARM only
A search on Ebay shows nothing for the VTFT supported controllers but a search for XPT2046 shows a lot of product both for the chips and displays with the chip.

So my wish is for support for ALL your sold compilers for support of the XPT2046 touch controller

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: Touch support in VTFT XPT2046 touch controller

#2 Post by filip » 07 Apr 2014 14:56

Hi,

Thank you for your suggestion, I will pass it to our developers.

Regards,
Filip.

Jardik
Posts: 60
Joined: 06 Jan 2010 18:28

Re: Touch support in VTFT XPT2046 touch controller

#3 Post by Jardik » 01 Sep 2015 21:41

Hello filip and KevinA,

here is code for Mikrobasic Pro for PIC32 and Visual TFT for Touch screen controler XPT2046:

--------------------------------------------------------------------

module xpt2046
' Use HW spi2 modul
dim Xcoord as word external
Ycoord as word external
PenDown as byte external


dim SPI_TP_CS as sbit at LATD8_bit
SPI_TP_CS_Direction as sbit at TRISD8_bit
SPI_TP_IRQ as sbit at PORTD.B11
SPI_TP_IRQ_Direction as sbit at TRISD11_bit



dim xvysl as word
yvysl as word
xnativ as word
ynativ as word

sub procedure SPI_TP_Init()
sub procedure SPI_TP_Check()
sub function SPI_TP_Read_Once(dim address as char) as word
sub function SPI_TP_Get_Coordinates() as char
sub procedure SPI_TP_Info(dim sloupec as word,dim radek as word,dim barva as word)

implements

sub procedure SPI_TP_Init()
SPI_TP_CS_Direction = 0
SPI_TP_IRQ_Direction = 1


SPI_TP_CS = 0
SPI2_Init_Advanced(_SPI_MASTER, _SPI_8_BIT, 1024, _SPI_SS_DISABLE, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_IDLE_2_ACTIVE)

SPI_TP_IRQ_Direction = 1

SPI_TP_CS = 1

Xcoord = 0
Ycoord = 0


end sub



sub function SPI_TP_Read_Once(dim address as char) as word
dim hodnota as word

SPI2_Write(address)

hodnota = SPI2_Read(0)
hodnota = hodnota << 8
hodnota = hodnota + SPI2_Read(0)
hodnota = hodnota >> 3 ' Prise en charge CLK pendant BUSY
result = hodnota

end sub

sub function SPI_TP_Get_Coordinates() as char
dim x as word
y as word
dim x_min as word
x_max as word
y_min as word
y_max as word
dim x_div as float
y_div as float
'char debug_text[100]
x_min = 200
x_max = 3900
y_min = 200
y_max = 3900




SPI_TP_CS = 0


x = SPI_TP_Read_Once(0xD0)
y = SPI_TP_Read_Once(0x90)

SPI_TP_CS = 1


'sprintf(debug_text, "X = %u ; Y = %u", x, y);
'UART4_Write_Text(debug_text);
'UART4_Write(13);
'UART4_Write(10);
ynativ=y
xnativ=x

if (x = 0) or (x = 4095) or (y = 0) or (y = 4095) then
result= 1
exit
end if



if x < x_min then
x = x_min
end if
if x > x_max then
x = x_max
end if

if y < y_min then
y = y_min
end if
if y > y_max then
y = y_max
end if
x = x-x_min
y = y-y_min

x_div = x_max
x_div = x_div - x_min
x_div = x_div / 800
y_div = y_max
y_div = y_div - y_min
y_div = y_div / 480

x = x / x_div
y = y / y_div

xvysl = x
yvysl = y

result= 0
end sub



sub procedure SPI_TP_Check()
if SPI_TP_IRQ = 0 then
if SPI_TP_Get_Coordinates() = 0 then

TFT_Dot(Xvysl, Yvysl, CL_white)
TFT_Dot(Xvysl + 1, Yvysl, CL_white)
TFT_Dot(Xvysl, Yvysl + 1, CL_white)
TFT_Dot(Xvysl + 1, Yvysl + 1, CL_white)

delay_ms(200) ' Anti rebond

TFT_Dot(Xvysl, Yvysl, CL_BLACK)
TFT_Dot(Xvysl + 1, Yvysl, CL_BLACK)
TFT_Dot(Xvysl, Yvysl + 1, CL_BLACK)
TFT_Dot(Xvysl + 1, Yvysl + 1, CL_BLACK)
end if





end if




end sub

sub procedure SPI_TP_Info(dim sloupec as word,dim radek as word,dim barva as word)


dim txt65buf as string[5]
dim txt66buf as string[5]
dim txt67buf as string[14]
if SPI_TP_IRQ = 0 then
txt67buf=""
txt66buf=""
txt65buf=""
WordToStr(xnativ, txt65buf)
WordToStr(ynativ, txt66buf)
txt67buf=txt65buf+","+txt66buf
TFT_Set_Pen(CL_black, 1)
TFT_Write_Text(txt67buf, sloupec, radek)
' TFT_Set_Pen(CL_white, 12)
TFT_Set_Brush(1, 1, 0, LEFT_TO_RIGHT, CL_white, CL_white)
TFT_Rectangle(sloupec, radek, sloupec+50, radek+12)
' TFT_Line(sloupec, radek, sloupec+55, radek)
end if





end sub



end.

----------------------------------------------------------------------------------------------------

SUB Check_TP() for VISUAL TFT

sub procedure Check_TP()
if SPI_TP_IRQ = 0 then
' After a PRESS is detected read X-Y and convert it to 128x64 space
if (SPI_TP_Get_Coordinates=0) then
Process_TP_Press(Xvysl, Yvysl)
if PenDown = 0 then
PenDown = 1
Process_TP_Down(Xvysl, Yvysl)
end if
end if
else
if PenDown = 1 then
PenDown = 0
Process_TP_Up(Xvysl, Yvysl)
end if
end if
end sub






And finally, a question for filip:

Once you are finished module and procedure for Visual TFT, when finally you integrate touch controler XPT2046 in Visual TFT or expand library Touch TFT panel for compiler MIKROE on this controler ???



It is very annoying after each change in Visual TFT rewrite automatic insertion routine !!!!


Thank you

User avatar
aleksa.jovanovic
Posts: 526
Joined: 30 Jun 2015 08:48

Re: Touch support in VTFT XPT2046 touch controller

#4 Post by aleksa.jovanovic » 02 Sep 2015 14:14

Hi,

You can place your code in the events code, then press save in the compiler. This will keep the visual TFT from erasing it every time that you compile.
However the calling for your driver, which is placed in the driver, or main, or wherever else, will probably be erased and will need to be rewritten when you compile again in visual TFT.

Best regards,
Aleksa

Jardik
Posts: 60
Joined: 06 Jan 2010 18:28

Re: Touch support in VTFT XPT2046 touch controller

#5 Post by Jardik » 02 Sep 2015 20:14

Hello,

And when you integrate into the Visual Controller XPT2046 TFT ???

The hardest work - functional code is complete. The only thing left to integrate into the Visual TFT. It must do Mikroe team.

Tell us any specific binding deadline integration ???


Thank you

User avatar
aleksa.jovanovic
Posts: 526
Joined: 30 Jun 2015 08:48

Re: Touch support in VTFT XPT2046 touch controller

#6 Post by aleksa.jovanovic » 03 Sep 2015 08:42

Hi,

I can't tell you at this point when it will be.
It is on our software team to do list and there is no specific date listed there.

Best regards,
Aleksa

Csucsu
Posts: 4
Joined: 30 Dec 2017 20:37

Re: Touch support in VTFT XPT2046 touch controller

#7 Post by Csucsu » 01 Jan 2018 11:50

Dear All,

I have a same problem (I want to use XPT2046 with mikroC PRO for dsPIC/PIC24 compiler).

So last day I think it's easy :shock: I disabling the touch functions in VTFT project settings and use own TP driver for XPT2046.
But in this case I dont know how can I passing TP coordinates to graphic driver.
And I lost functionalities of events.

My idea:
Because impossible to fulfill all wishes.
Please enable in VTFT to insert my own TP code!

Best Regards, and Happy new year.

Csucsu

User avatar
dusan.poluga
mikroElektronika team
Posts: 780
Joined: 02 Feb 2017 14:21

Re: Touch support in VTFT XPT2046 touch controller

#8 Post by dusan.poluga » 03 Jan 2018 10:47

Hi,

Thank you for your suggestion.
I will transfer your request to the developers for consideration.

Best Regards,
Dusan Poluga.

ahmed.hasib
Posts: 71
Joined: 11 Jul 2015 17:59

Re: Touch support in VTFT XPT2046 touch controller

#9 Post by ahmed.hasib » 23 Dec 2018 22:30

Hi,
i tried to use the code for XPT2046 with PIC32MZ2048EFG144 but not working. Can anyone give me an example or demo?
i use MikroBasic for PIC32.

ahmed.hasib
Posts: 71
Joined: 11 Jul 2015 17:59

Re: Touch support in VTFT XPT2046 touch controller

#10 Post by ahmed.hasib » 01 Mar 2019 20:58

Can somebody help me to use this code without VTFT?

User avatar
stefan.filipovic
mikroElektronika team
Posts: 1135
Joined: 18 Dec 2018 10:30

Re: Touch support in VTFT XPT2046 touch controller

#11 Post by stefan.filipovic » 08 Mar 2019 15:58

Hi Ahmed,

Unfortunately, the XPT2046 touch controller has not supported by our compilers and tools yet.
I'll forward your request to our developers, they will take it into consideration.

Kind regards,
Stefan Filipović

ahmed.hasib
Posts: 71
Joined: 11 Jul 2015 17:59

Re: Touch support in VTFT XPT2046 touch controller

#12 Post by ahmed.hasib » 08 Mar 2019 21:34

Hi Stefan,
Thanks.
i tried to use the ADC in PIC32MZ2048EFG144 but i have compiling error in Mikrobasic PIC32

AD1CAL1 = DEVADC1 " Copy the configuration data to the
AD1CAL2 = DEVADC2 " AD1CALx special function registers.
AD1CAL3 = DEVADC3
AD1CAL4 = DEVADC4
AD1CAL5 = DEVADC5

Could you please help me?

User avatar
stefan.filipovic
mikroElektronika team
Posts: 1135
Joined: 18 Dec 2018 10:30

Re: Touch support in VTFT XPT2046 touch controller

#13 Post by stefan.filipovic » 11 Mar 2019 14:55

Hi Ahmed,

PIC32MZ EC devices require calibration values be copied into the AD1CALx registers before turning on the ADC. These values come from the DEVADCx registers.
PIC32MZ EF devices do not require this step, and the corresponding registers are not available.

This is the reason why you got errors in compiling.

Kind regards,
Stefan Filipović

ahmed.hasib
Posts: 71
Joined: 11 Jul 2015 17:59

Re: Touch support in VTFT XPT2046 touch controller

#14 Post by ahmed.hasib » 15 Mar 2019 18:25

Hi Stefan,
Thank you for your reply.
i tried to use the TP_TFT as below code "also project attached" but i got strange readings.
could you help me please?

Code: Select all

PROGRAM MYPROJECT

' DECLARATIONS SECTION 
' TFT MODULE CONNECTIONS
DIM TFT_DATAPORT AS WORD  AT LATH
    TFT_RST AS SBIT  AT LATG14_BIT
    TFT_RS AS SBIT  AT LATG9_BIT
    TFT_CS AS SBIT  AT LATG1_BIT
    TFT_RD AS SBIT  AT LATG12_BIT
    TFT_WR AS SBIT  AT LATG13_BIT
    TFT_DATAPORT_DIRECTION AS WORD  AT TRISH
    TFT_RST_DIRECTION AS SBIT  AT TRISG14_BIT
    TFT_RS_DIRECTION AS SBIT  AT TRISG9_BIT
    TFT_CS_DIRECTION AS SBIT  AT TRISG1_BIT
    TFT_RD_DIRECTION AS SBIT  AT TRISG12_BIT
    TFT_WR_DIRECTION AS SBIT  AT TRISG13_BIT
' END TFT MODULE CONNECTIONS

' TOUCH PANEL MODULE CONNECTIONS
DIM DRIVEX_LEFT AS SBIT AT LATC4_BIT        '' XL ADC READ
DIM DRIVEX_RIGHT AS SBIT AT LATC1_BIT       '' XR DRIVE
DIM DRIVEY_UP AS SBIT AT LATC3_BIT          '' YUP ADC READ
DIM DRIVEY_DOWN AS SBIT AT LATC2_BIT        '' YDN DRIVE
DIM DRIVEX_LEFT_DIRECTION AS SBIT AT TRISC4_BIT
DIM DRIVEX_RIGHT_DIRECTION AS SBIT AT TRISC1_BIT
DIM DRIVEY_UP_DIRECTION AS SBIT AT TRISC3_BIT
DIM DRIVEY_DOWN_DIRECTION AS SBIT AT TRISC2_BIT
' END TOUCH PANEL MODULE CONNECTIONS

DIM X_MIN,X_MAX,Y_MIN,Y_MAX, XCOORD, YCOORD AS WORD
DIM X_MIN_VAL,X_MAX_VAL,Y_MIN_VAL,Y_MAX_VAL, XCOORD_VAL, YCOORD_VAL AS CHAR[5]

SUB PROCEDURE INIT()
  TFT_SET_DEFAULT_MODE()     ' SET TFT IN DEFAULT MODE
  TFT_INIT_SSD1963(800,480)         ' INITIALIZE TFT DISPLAY
  TP_TFT_SET_DEFAULT_MODE()
  TP_TFT_INIT(800, 480, 19, 20 )                                  ' INITIALIZE TOUCH PANEL
  TP_TFT_SET_ADC_THRESHOLD(900)
  TFT_FILL_SCREEN(CL_WHITE)
  TFT_SET_PEN(CL_RED,5)
  TFT_SET_FONT(@TFT_DEFAULTFONT, CL_BLUE, FO_HORIZONTAL)
  
  ''ADC INIT
  ADC1_INIT_ADVANCED(_ADC_REF_VREF_AVSS)
  DELAY_MS(50)
  TRISH=0     '' TFT PORT AS OUTPUT
  DELAY_MS(50)
END SUB

SUB PROCEDURE CALIBRATE()

  TFT_WRITE_TEXT("TOUCH SELECTED CORNERS FOR CALIBRATION", 230, 240)
  DELAY_MS(1000)
  
  TFT_CIRCLE(780,20,20)
  TFT_WRITE_TEXT("FIRST HERE", 730, 40)

  TP_TFT_CALIBRATE_MIN()                      ' CALIBRATION OF BOTTOM LEFT CORNER
  DELAY_MS(2000)

  TFT_CIRCLE(20,460,20)
  TFT_WRITE_TEXT("NOW HERE", 45, 450)

  TP_TFT_CALIBRATE_MAX()                       ' CALIBRATION OF BOTTOM LEFT CORNER
  DELAY_MS(2000)
  TP_TFT_GET_CALIBRATION_CONSTS(@X_MIN, @X_MAX, @Y_MIN, @Y_MAX) ' GET CALIBRATION CONSTANTS
  
 WORDTOSTR(X_MIN,X_MIN_VAL)
 WORDTOSTR(X_MAX,X_MAX_VAL)
 WORDTOSTR(Y_MIN,Y_MIN_VAL)
 WORDTOSTR(Y_MAX,Y_MAX_VAL)

 TFT_WRITE_TEXT("X_MIN:",10,10)
 TFT_WRITE_TEXT("X_MAX:",10,40)
 TFT_WRITE_TEXT("Y_MIN:",10,70)
 TFT_WRITE_TEXT("Y_MAX:",10,100)

 TFT_WRITE_TEXT(X_MIN_VAL,60,10)
 TFT_WRITE_TEXT(X_MAX_VAL,60,40)
 TFT_WRITE_TEXT(Y_MIN_VAL,60,70)
 TFT_WRITE_TEXT(Y_MAX_VAL,60,100)
 
END SUB

MAIN:
' MAIN PROGRAM
  INIT()
  DELAY_MS(50)
  
  CALIBRATE()

  WHILE TRUE
  TP_TFT_GET_COORDINATES(@XCOORD, @YCOORD)
  WORDTOSTR(XCOORD,XCOORD_VAL)
  WORDTOSTR(YCOORD,YCOORD_VAL)
  TFT_WRITE_TEXT("XCOORD:",10,130)
  TFT_WRITE_TEXT("YCOORD:",10,160)
  TFT_WRITE_TEXT(XCOORD_VAL,60,130)
  TFT_WRITE_TEXT(YCOORD_VAL,60,160)
  DELAY_MS(200)
  WEND

END.
Attachments
TP TFT.rar
(222 KiB) Downloaded 112 times

User avatar
stefan.filipovic
mikroElektronika team
Posts: 1135
Joined: 18 Dec 2018 10:30

Re: Touch support in VTFT XPT2046 touch controller

#15 Post by stefan.filipovic » 18 Mar 2019 16:21

Hi Ahmed,

Could you please tell me how can I reproduce the same issue?
Which development board and display you are using?

You should use ANSEL registers to set pins as digital.
According to the datasheet of this MCU:
"The ANSELx register has a default value of 0xFFFF; therefore, all pins that share analog functions are analog (not digital) by default."

Kind regards,
Stefan Filipović

Post Reply

Return to “Visual TFT Wish List”