• «
  • 1
  • 2
  • »
  • Pages: 1/2     Go
主题 : UCOS加上触摸屏支持[源代码+说明]友善QQ2440测试通过~ 复制链接 | 浏览器收藏 | 打印
eCGUI-微型嵌入式GUI/
级别: 新手上路
UID: 1604
精华: 0
发帖: 4
金钱: 40 两
威望: 16 点
贡献值: 0 点
综合积分: 8 分
注册时间: 2008-09-13
最后登录: 2011-06-15
楼主  发表于: 2009-12-01 18:55

 UCOS加上触摸屏支持[源代码+说明]友善QQ2440测试通过~

管理提醒: 本帖被 qq2440 从 QQ2440技术交流专区 移动到本区(2009-12-27)
S3C2410/S3C2440 ADC和触摸屏接口有 等待中断模式 的特性。所以需要编写一个中断函数,来完成ADC数据的读取。
以下代码均在友善提供的ucos移植版上测试通过~
有兴趣的朋友,可以直接下载bin文件实际进行测试,基于eCGUI图形系统的简单演示,支持触摸屏矫正。
链接:http://www.ecgui.com/download/qq2440ucos2.bin
使用ADS1.2编译,请使用DNW下载~

增加两个文件touch.c  和touch.h ,再修改ucos中的uCos2\S3C2440\source\main.c 文件,找到MainTask主函数,
修改部分如下:

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();// 初始化触摸屏
        OS_EXIT_CRITICAL();
//后续部分省略
/*****************************************************************/

以下贴出touch.c 和touch.h 的完整代码,touch.h 中的一些定义可以在2440addr.h等头文件中找到,
但是为了实现模块化,单独编译,就把需要的定义收集在touch.h里了~


/******  touch.h -start*******/
/*
Touch support for ecgui
ecCGUI是一个微型嵌入式图形界面系统,支持linux,dos,ucos等系统,支持常用GUI控件,
体积小巧 大小在 100KB~180KB!
特性: 多窗口支持| 完全中文输入/显示| 多数常用GUI控件| 99.9% ANSI C 编写| 已成功移植 DOS,Linux,uc/OS-II| 组件式 API(易用,高效)
更多信息: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 screen 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是一个微型嵌入式图形界面系统,支持linux,dos,ucos等系统,支持常用GUI控件,
体积小巧 大小在 100KB~180KB!
特性: 多窗口支持| 完全中文输入/显示| 多数常用GUI控件| 99.9% ANSI C 编写| 已成功移植 DOS,Linux,uc/OS-II| 组件式 API(易用,高效)
更多信息: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;//触摸坐标x
int TY=0;//触摸坐标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<0>?-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)
    {//抬起
        _touch_key = 0;
        rADCTSC &= 0xff;    // Set stylus down interrupt
    }
    else //按下
    {          _touch_key = 1;
        rADCTSC=(0<<8)|(0<<7)|(0<<6)|(1<<5)|(1<<4)|(1<<3)|(0<<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&rADCDAT0);
        }
        Pt[5]=(Pt[0]+Pt[1]+Pt[2]+Pt[3]+Pt[4])/5;//多次采样取平均值
        TX = Pt[5];
        rADCTSC=(0<<8)|(0<<7)|(1<<6)|(1<<5)|(0<<4)|(1<<3)|(0<<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&rADCDAT1);
        }
        Pt[5]=(Pt[0]+Pt[1]+Pt[2]+Pt[3]+Pt[4])/5;// 多次采样取平均值

        TY = Pt[5];
               rADCTSC=(1<<8)|(1<<7)|(1<<6)|(0<<5)|(1<<4)|(0<<3)|(0<<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 *********************** */
会当凌绝顶,一览众山小!
级别: 总版主
UID: 2
精华: 17
发帖: 1655
金钱: 13860 两
威望: 5369 点
贡献值: 17 点
综合积分: 3650 分
注册时间: 2008-01-01
最后登录: 2024-02-17
1楼  发表于: 2009-12-01 19:07
支持
描述:qq2440ucos2.bin
附件: qq2440ucos2.bin (289 K) 下载次数:361
友善之臂淘宝直销店:http://shop34928758.taobao.com

手机:13560352861(杨工),QQ:10108270
级别: 新手上路
UID: 11395
精华: 0
发帖: 3
金钱: 15 两
威望: 3 点
贡献值: 0 点
综合积分: 6 分
注册时间: 2009-12-06
最后登录: 2010-05-23
2楼  发表于: 2010-03-26 19:58
lz,你好。
我也在做ucos+触摸屏的项目,ucos就直接用的是友善提供的移植版本。触摸屏驱动也是用的友善提供的。但是好像将二者合一时,触摸屏中断貌似出现了问题,其中断服务程序工作出现了异常。你能否赐教?讲讲你的经验?
级别: 新手上路
UID: 33730
精华: 0
发帖: 11
金钱: 60 两
威望: 12 点
贡献值: 0 点
综合积分: 22 分
注册时间: 2010-12-05
最后登录: 2011-04-20
3楼  发表于: 2010-12-06 16:42
好东西啊
级别: 新手上路
UID: 2797
精华: 0
发帖: 24
金钱: 135 两
威望: 35 点
贡献值: 0 点
综合积分: 48 分
注册时间: 2008-12-09
最后登录: 2011-06-29
4楼  发表于: 2010-12-21 13:43
haohao
级别: 新手上路
UID: 45535
精华: 0
发帖: 4
金钱: 20 两
威望: 4 点
贡献值: 0 点
综合积分: 8 分
注册时间: 2011-05-05
最后登录: 2011-06-06
5楼  发表于: 2011-05-05 20:39
貌似有点乱
级别: 新手上路
UID: 48796
精华: 0
发帖: 16
金钱: 80 两
威望: 16 点
贡献值: 0 点
综合积分: 32 分
注册时间: 2011-06-04
最后登录: 2011-08-20
6楼  发表于: 2011-06-28 14:49
能否将源码传一下啊,我的只能返回一次中断,怎么回事啊!请楼主请教一二。
级别: 新手上路
UID: 18656
精华: 0
发帖: 23
金钱: 120 两
威望: 24 点
贡献值: 0 点
综合积分: 46 分
注册时间: 2010-04-11
最后登录: 2011-10-11
7楼  发表于: 2011-07-16 11:52
加上 中断,我的UCOS跑不起来了,不知道什么原因
级别: 新手上路
UID: 53668
精华: 0
发帖: 9
金钱: 45 两
威望: 9 点
贡献值: 0 点
综合积分: 18 分
注册时间: 2011-08-12
最后登录: 2017-09-13
8楼  发表于: 2011-08-12 22:03
中断怎么加啊,我像楼主上那样试了,也不行啊,像时钟节拍那样写中断,也不行啊.
liu_jianchu@126.com, 请指教
级别: 新手上路
UID: 59073
精华: 0
发帖: 7
金钱: 35 两
威望: 7 点
贡献值: 0 点
综合积分: 14 分
注册时间: 2011-11-18
最后登录: 2011-11-24
9楼  发表于: 2011-11-18 16:29
再学习
  • «
  • 1
  • 2
  • »
  • Pages: 1/2     Go