Ucos Plus touch screen support [source code + Instructions]arm9-2440 test Pass ~

Source: Internet
Author: User
Tags volatile

s3c2410/s3c2440 ADC and touch-screen interfaces have the characteristics of waiting for interrupt mode. So you need to write an interrupt function to complete the reading of ADC data.
The following code is tested through the friendly Ucos transplant version ~
Interested friends, you can download the bin file to actually test, based on the Ecgui graphics system simple demo, support touch screen correction.
Link: http://www.ecgui.com/download/qq2440ucos2.bin
Use ADS1.2 to compile, please use DNW download ~

Add two files touch.c and touch.h, and then modify the Ucos2/s3c2440/source/main.c file in Ucos to find the Maintask main function,
The revised section reads as follows:

int lcd_tourch_init (void);
void Maintask (void *pdata)//main Task create Taks0 and Task1
{

#if Os_critical_method = = 3/* Allocate storage for CPU status register */
OS_CPU_SR Cpu_sr;
#endif
Os_enter_critical ();

Timer0init ();//initial Timer0 for ucos time tick
Isrinit (); Initial interrupt Prio or enable or disable
Gui_init ();
Lcd_tourch_init ()//Initialize touch screen
Os_exit_critical ();
Subsequent sections omit
/*****************************************************************/

The complete code for TOUCH.C and TOUCH.H is posted below, and some of the definitions in TOUCH.H can be found in 2440addr.h header files.
But in order to achieve modularity, separate compilation, the need to define the definition in the TOUCH.H ~


/****** touch.h-start*******/
/*
Touch Support for Ecgui
Eccgui is a micro-embedded graphical interface system, supporting Linux,dos,ucos and other systems, support common GUI controls,
Small size in 100kb~180kb.
Features: Multi-window Support | Full Chinese input/display | Most common GUI controls | 99.9% ANSI C Write | Successfully transplanted dos,linux,uc/os-ii| Component API (easy to use, efficient)
More information: http://www.ecgui.com
Email:ecgui.com@gmail.com

Code from Files:touchpanel.c,2440addr.h,option.h,def.h
*/

Def.h
#define U32 unsigned int
#define U16 unsigned short
#define S32 INT
#define S16 Short int
#define U8 unsigned char
#define S8 Char

#define BYTE Char
#define WORD Short
#define DWORD INT
#define UINT U32
#define LPSTR U8 *

#define TRUE 1
#define FALSE 0
#ifndef _g_touch_h
#define _g_touch_h

#define OK 1
#define FAIL 0


#define REQCNT 30
#define ADCPRS 9//yh 0627
#define LOOP 1


Option.h
#define _isr_startaddress 0X33FFFF00

2440addr.h ADC
#define RADCCON (* (volatile unsigned *) 0x58000000)//ADC control
#define RADCTSC (* (volatile unsigned *) 0x58000004)//ADC Touch screens Control
#define RADCDLY (* (volatile unsigned *) 0x58000008)//adc start or Interval Delay
#define RADCDAT0 (* (volatile unsigned *) 0x5800000c)//ADC conversion Data 0
#define RADCDAT1 (* (volatile unsigned *) 0x58000010)//ADC conversion Data 1
#define RADCUPDN (* (volatile unsigned *) 0x58000014)//stylus Up/down interrupt Status

#define PISR_ADC (* (unsigned *) (_isr_startaddress+0x9c))

INTERRUPT
#define RSRCPND (* (volatile unsigned *) 0x4a000000)//interrupt request status
#define RINTMOD (* (volatile unsigned *) 0x4a000004)//interrupt mode control
#define RINTMSK (* (volatile unsigned *) 0x4a000008)//interrupt Mask Control
#define RPRIORITY (* (volatile unsigned *) 0x4a00000c)//IRQ priority control
#define RINTPND (* (volatile unsigned *) 0x4a000010)//interrupt request status
#define RINTOFFSET (* (volatile unsigned *) 0x4a000014)//interruot Request Source Offset
#define RSUBSRCPND (* (volatile unsigned *) 0x4a000018)//sub source pending
#define RINTSUBMSK (* (volatile unsigned *) 0x4a00001c)//interrupt Sub Mask

#define BIT_ADC (0X1<<31)
#define BIT_ADC (0X1<<30)
#define BIT_SUB_ADC (0X1<<10)
#define BIT_SUB_TC (0X1<<9)
#define BIT_ALLMSK (0xFFFFFFFF)

int _touch_init (void);
int _touch_exit (void);
int _touch_read (int *x,int *y,int *key);
int lcd_tourch_init (void);

#endif//_g_touch_h


/************* touch.c ************/
/*
Touch Support for Ecgui
Eccgui is a micro-embedded graphical interface system, supporting Linux,dos,ucos and other systems, support common GUI controls,
Small size in 100kb~180kb.
Features: Multi-window Support | Full Chinese input/display | Most common GUI controls | 99.9% ANSI C Write | Successfully transplanted dos,linux,uc/os-ii| Component API (easy to use, efficient)
More information: http://www.ecgui.com
Email:ecgui.com@gmail.com
Code from Files:touchpanel.c,2440addr.h,option.h
*/

Need TOUCH.H


int _touch_count=0;
volatile int _touch_xdata=0, _touch_ydata=0,_touch_key=0;


int tx=0;//Touch coordinates x
int ty=0;//Touch coordinates y


int _touch_init (void)
{

return 1;
}

int _touch_exit (void)
{

return 1;
}
void uart_printf (const char *fmt,...);

/*
(912,127) _____ (921,897)
| |
| |
| |
| |
(130,136) ___ (135,899)

=> x <->y

(127,912) _____ (897,921)
| |
| |
| |
| |
(130,136) _____ (899,135)
*/
int _touch_b[2],_touch_k[2];

#define ABS (a) (A&LT;0&GT;?-A:A)

int _touch_txy[4]={127,921,899,135};
int _touch_sxy[4]={0,0,240,320};

void _touch_setbk (int txy[4],int sxy[4])
{
int tw,sw,th,sh;
Tw= (txy[0]-txy[2]);
tw=tw<0?0-tw:tw;
Sw= (sxy[0]-sxy[2]) *100;
sw=sw<0?0-sw:sw;
_TOUCH_K[0]=SW/TW;
uart_printf ("%d/%d=%d/n", sw,tw,_touch_k[0]);
Th= (Txy[1]-txy[3]);
th=th<0?0-th:th;
Sh= (sxy[1]-sxy[3]) *100;
sh=sh<0?0-sh:sh;
_touch_k[1]=sh/th;

uart_printf ("%d/%d=%d/n", sh,th,_touch_k[1]);
}

int _touch_x (int tx)
{
int x;
x=tx-127;
X*=_TOUCH_K[0];
return (X/100);
}

int _touch_y (int ty)
{
int y;
Y=921-ty;
Y*=_TOUCH_K[1];
return (Y/100);
}

int _touch_read (int *x,int *y,int *key)
{
*x=_touch_x (TY);
*y=_touch_y (TX);
*key=_touch_key;
return 0;
}


* ******************* Touch Support-start *********************** * *

#define REQCNT 30
#define ADCPRS 9//yh 0627
#define LOOP 1

void __irq ost_adctsauto (void);
static void Tsirqisr (void);
__inline void clearpending (int bit)
{
Register I;
RSRCPND = bit;
RINTPND = bit;
i = RINTPND;
}

int ost_count=0;
volatile int ost_xdata, ost_ydata;

int lcd_tourch_init (void)
{

_TOUCH_SETBK (_TOUCH_TXY,_TOUCH_SXY);

radcdly=50000; Normal Conversion Mode delay about (1/3.6864m) *50000=13.56ms
Radccon= (1<<14) + (adcprs<<6); Adcprs En, Adcprs Value

uart_printf ("ADC touch screen test/n");

Radctsc=0xd3; Wfait,xp_pu,xp_dis,xm_dis,yp_dis,ym_en

PISR_ADC = (int) Ost_adctsauto;
PISR_ADC = (int) Tsirqisr;
Rintmsk &=~BIT_ADC; ADC touch screen Mask bit clear
Rintsubmsk &=~ (BIT_SUB_TC);

return 0;
}


static void Tsirqisr (void)
{
int i,j;
U32 Pt[6];
Rintsubmsk |= (bit_sub_adc| BIT_SUB_TC);
if (RADCDAT0 & 0x8000)
{//Lift up
_touch_key = 0;
RADCTSC &= 0xFF; Set Stylus Down Interrupt
}
else//Press
{_touch_key = 1;
radctsc= (0<<8) | (0<<7) | (0<<6) | (1<<5) | (1<<4) | (1<<3) | (0&LT;&LT;2) | (1);
for (i=0;i<loop;i++); Delay to set up the next channel
for (j=0;j<5;j++)//5 times
{
radccon|=0x1; Start x-position Conversion
while (Radccon & 0x1); Check if Enable_start is low
while (!) (   0x8000&radccon)); Check ECFLG
Pt[j]= (0X3FF&AMP;RADCDAT0);
}
Pt[5]= (pt[0]+pt[1]+pt[2]+pt[3]+pt[4])/5;//multiple sampling takes average
TX = pt[5];
radctsc= (0<<8) | (0<<7) | (1<<6) | (1<<5) | (0<<4) | (1<<3) | (0&LT;&LT;2) | (2);
for (i=0;i<loop;i++); Delay to set up the next channel
for (j=0;j<5;j++)//5 times
{
radccon|=0x1; Start y-position Conversion
while (Radccon & 0x1); Check if Enable_start is low
while (!) (   0x8000&radccon)); Check ECFLG
Pt[j]= (0X3FF&AMP;RADCDAT1);
}
Pt[5]= (pt[0]+pt[1]+pt[2]+pt[3]+pt[4])/5;//multiple sampling takes average

TY = pt[5];
radctsc= (1<<8) | (1<<7) | (1<<6) | (0<<5) | (1<<4) | (0<<3) | (0&LT;&LT;2) | (3);
}
uart_printf ("%d,%d-> (%d,%d)/n", tx,ty,_touch_x (TY), _touch_y (TX));
RSUBSRCPND |= BIT_SUB_TC;
Rintsubmsk &= ~ (BIT_SUB_TC); Unmask Sub Interrupt (TC)
Clearpending (BIT_ADC);
}


* ******************* Touch support-end *********************** * *

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.