ucos II+ucGUI+s3c2410+LCD+触摸屏整合
LCD_SWAP_RB_0 1
2.触摸屏驱动:
触摸屏驱动计算出触摸屏的坐标(x,y),对dm2410实验板上的触摸屏,左下为原点,但不一定是(0,0)。两个函数:
1) 设置中断向量,开中断:
void SetTSInterrupt(void)
{
rADCDLY = (50000);
rADCCON = (114)|(ADCPRS6)|(73)|(02)|(01)|(0);
rADCTSC = (08)|(17)|(16)|(05)|(14)|(03)|(02)|(3);
pISR_ADC = (U32)TSIrqISR; //
rINTMSK = ~(BIT_ADC);
rINTSUBMSK = ~(BIT_SUB_TC);
}
2) 中断处理函数:
static void TSIrqISR(void)
{
int i;
U32 Pt[6];
rINTSUBMSK |= (BIT_SUB_ADC|BIT_SUB_TC);
if(rADCDAT0 0x8000)
{//抬起
isDown = 0;
rADCTSC = 0xff; // Set stylus down interrupt
TX = -1;
TY = -1; //抬起触笔时,TX,TY要值成不大于0的数
}
else //按下
{ isDown = 1;
rADCTSC=(08)|(07)|(06)|(15)|(14)|(13)|(02)|(1);
for(i=0;i
for(i=0;i5;i++) //5 times
{
rADCCON|=0x1; // Start X-position conversion
while(rADCCON 0x1); // Check if Enable_start is low
while(!(0x8000rADCCON)); // Check ECFLG
Pt[i]=(0x3ffrADCDAT0);
}
Pt[5]=(Pt[0]+Pt[1]+Pt[2]+Pt[3]+Pt[4])/5;//多次采样取平均值
TX = Pt[5];
rADCTSC=(08)|(07)|(16)|(15)|(04)|(13)|(02)|(2);
for(i=0;i
for(i=0;i5;i++) //5 times
{
rADCCON|=0x1; // Start Y-position conversion
while(rADCCON 0x1); // Check if Enable_start is low
while(!(0x8000rADCCON)); // Check ECFLG
Pt[i]=(0x3ffrADCDAT1);
}
Pt[5]=(Pt[0]+Pt[1]+Pt[2]+Pt[3]+Pt[4])/5;// 多次采样取平均值
TY = Pt[5];
rADCTSC=(18)|(17)|(16)|(05)|(14)|(03)|(02)|(3);
}
//cprintf(%d,%d\n,TX,TY);
OSMboxPost(TouchMbox, 0);//向处理触摸进程发消息
rSUBSRCPND |= BIT_SUB_TC;
rINTSUBMSK = ~(BIT_SUB_TC); // Unmask sub interrupt (TC)
ClearPending(BIT_ADC);
}
3) 需要的量:
#define LOOP 1
#define ADCPRS 0x27
int TX=0;//触摸坐标x
int TY=0;//触摸坐标y
extern OS_EVENT *TouchMbox;
int isDown;
4) 触摸屏校准:
Ucgui390中,带有一校准程序(于TOUCH_Calibrate.c中),可以改写为我所用(见下文)。
也可设置默认值,测出左下最小坐标minX,minY和右上最大坐标maxX,maxY,注意是触摸坐标,不是lcd坐标,如下填写配置文件GUITouchConf.h:
#define GUI_TOUCH_AD_LEFT minX
#define GUI_TOUCH_AD_TOP maxY
#define GUI_TOUCH_AD_RIGHT maxX
#define GUI_TOUCH_AD_BOTTOM minY
#define GUI_TOUCH_SWAP_XY 0
#define GUI_TOUCH_MIRROR_X 1
#define GUI_TOUCH_MIRROR_Y 1
#define TOUCH_NEED_CALIBRATE 0
3、如下填写GUIConf.h:
#define GUI_OS (1) /* Compile with multitasking support */
#define GUI_SUPPORT_TOUCH (1) /* Support a touch screen (req. win-manager) */
#define GUI_SUPPORT_UNICODE (1) /* Support mixed ASCII/UNICODE strings */
#define GUI_SUPPORT_CHINESE (1)
#define GUI_DEFAULT_FONT GUI_Font6x8
#define GUI_ALLOC_SIZE 12500 /* Size of dynamic memory ... For WM and memory devices*/
#define GUI_WINSUPPORT 1 /* Window manager package available */
#define GUI_SUPPORT_MEMDEV 1 /* Memory devices available */
#define GUI_SUPPORT_AA 1 /* Anti aliasing available */
4、ucgui与lcd驱动函数的连接,即修改LCDWin.c文件:
在LCDWin.c中,去掉无用的头文件包含。
#define SETPIXEL(x, y, c) LCD2410_SetPixel(x, y, c, LCD_DISPLAY_INDEX)
#define GETPIXEL(x, y) LCD2410_GetPixel(x,y, LCD_DISPLAY_INDEX)
即将“LCDSIM_XX”改成“LCD2410_XX”,这两个函数位于lcd驱动文件中。
……………………………
#define SETPIXEL(x, y, c) \
if (!_CheckBound(c)) { \
LCD2410_SetPixel(x, y, c, LCD_DISPLAY_INDEX); \
}
#else
#define SETPIXEL(x, y, c) LCD2410_SetPixel(x, y, c, LCD_DISPLAY_INDEX)
#endif
#define GETPIXEL(x, y) LCD2410_GetPixel(x,y,LCD_DISPLAY_INDEX)
……………………………
static void _XorPixel(int x, int y) {
unsigned int Index = LCD_L0_GetPixelIndex(x,y);
LCD2410_SetPixel(x, y, LCD_NUM_COLORS-1-Index, LCD_DISPLAY_INDEX);
}
……………………………
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)