Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2290180
  • 博文数量: 218
  • 博客积分: 5767
  • 博客等级: 大校
  • 技术积分: 5883
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-01 14:44
文章存档

2012年(53)

2011年(131)

2009年(1)

2008年(33)

分类:

2008-05-03 17:30:25

1.编写驱动,主要为Lcd驱动和触摸屏驱动:
 lcd驱动实现画点函数LCD2410_SetPixel(x,y,c)。对dm2410实验板上的lcd,左上为原点(0,0)
 触摸屏驱动计算出触摸屏的坐标(x,y),对dm2410实验板上的触摸屏,左下为原点,但不一定是(0,0)

2.触摸屏校准:
 测出左下最小坐标minX,minY和右上最大坐标maxX,maxY
 如下填写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

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            22500  /* 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

4.如下填写LCDConf.h:
#define LCD_XSIZE      (800)   /* X-resolution of LCD, Logical coor. */
#define LCD_YSIZE      (480)   /* Y-resolution of LCD, Logical coor. */

#define LCD_BITSPERPIXEL (16)
#define LCD_CONTROLLER  1
#define LCD_SWAP_RB_0 1

5.ucgui与lcd驱动函数的连接:
在LCDWin.c中,去掉无用的头文件包含。
#define SETPIXEL(x, y, c) LCD2410_SetPixel(x, y, c)
#define GETPIXEL(x, y)    LCD2410_GetPixel(x,y)
即将“LCDSIM_XX”改成“LCD2410_XX”,这两个函数位于lcd驱动文件中。

6.某些编译器不会初始化全局变量,因此做如下事:
1)修改如下函数为:(位于GUICore.c)
static void _InitContext(GUI_CONTEXT* pContext) {
 
 memset(pContext,0,sizeof(GUI_CONTEXT));//add
 
  #if GUI_SUPPORT_MEMDEV
    GUI_SelectLCD();
  #else
    LCD_SetClipRectMax();//LCD_L0_GetRect
  #endif
  pContext->pLCD_HL      = &LCD_HL_APIList;
  pContext->pAFont       = GUI_DEFAULT_FONT;
  pContext->pClipRect_HL = &GUI_Context.ClipRect;
  pContext->PenSize      = 1;
  pContext->DrawMode = GUI_DRAWMODE_NORMAL;//add
  pContext->TextMode = GUI_TEXTMODE_NORMAL;//add
  pContext->TextAlign = GUI_TA_LEFT|GUI_TA_TOP;//add
 
  pContext->AA_HiResEnable = 0;//add
 
  /* Variables in WM module */
  #if GUI_WINSUPPORT
    pContext->hAWin    = WM_GetDesktopWindow();
  #endif
  /* Variables in GUI_AA module */
  pContext->AA_Factor = 3;
  LCD_SetBkColor(GUI_DEFAULT_BKCOLOR);
  LCD_SetColor(GUI_DEFAULT_COLOR);
}
2)自己编写如下函数:
void MyInit()
{
  IsInitialized = 0;//MemDev
  _IsInited = 0;//Win
  WM__CreateFlags = 0;
 
  GUI_CURSOR_pfTempHide = NULL;
  GUI_Context.hDevData = 0;
 
  WM__hCapture=0;
  WM__hWinFocus=0;
 
  WM_pfPollPID = 0;
  WM_pfHandlePID = 0;
 
  GUI_pfTimerExec = 0;
 
  _KeyMsgCnt = 0;
}
该函数应在GUI_Init()调用之前调用。

7.由于没有加入ucos操作系统,自己编写如下函数模拟延时:

int ost = 0;
void My_X_Delay(int p)
{
 int i = 0;
 int j=0;
 for(i=0; i  for(j=0; j 
 ost += p;
}
void MyDly(int Period)
{
 
  int EndTime;
  int tRem; /* remaining Time */
  ost = 0;
  EndTime = ost + Period;
  while (tRem = EndTime - ost, tRem>0) {
    GUI_Exec();
    My_X_Delay((tRem >100) ? 100 : tRem);
  }
}
因此将示例中的GUI_Delay(x)该为MyDly(x).

8.修改如下函数,接入lcd的初始化:(位于LCD.c)
int  LCD_Init(void) {
  int r;
  GUI_DEBUG_LOG("\nLCD_Init...");
  LCD_SetClipRectMax();
  if ((r = LCD2410_Init()) != 0) //LCD2410_Init(),设置lcd寄存器
    return r;
#if LCD_NUM_DISPLAYS > 1
  if ((r = LCD_L0_1_Init()) != 0)
    return r;
#endif
    LCD_InitLUT();
/* Clear video memory */
  LCD_SetDrawMode(GUI_DRAWMODE_REV);
  LCD_FillRect(0,0, GUI_XMAX, GUI_YMAX);
  LCD_SetDrawMode(0);
/* Switch LCD on */
  LCD_On();
  return 0;
}

9.如下修改GUI_X.c:
int GUI_X_GetTime(void)
{
 return 0;
// return OSTimeGet();
}

void GUI_X_Delay(int ms)
{
// OSTimeDly(ms);
 int i=0;
 for(i=0; i  ;
}
void GUI_X_ExecIdle(void) {
 GUI_X_Delay(1);
}
void GUI_X_Unlock(void)
{
// OSSemPost(DispSem);
}
void GUI_X_Lock(void)
{
// U8 err;
// OSSemPend(DispSem, 0, &err);
}

U32 GUI_X_GetTaskId(void)
{
// if(bGUIInitialized){
//  return ((INT32U)(OSTCBCur->OSTCBPrio)); /* < 64(è???ó??è??) */
// }
// else{
 return 100; /* ??òa±£?¤>64?′?é */
// }
}

void GUI_X_InitOS(void)
{
// DispSem = OSSemCreate(1);
}
void GUI_X_ErrorOut(const char *s){}

void GUI_X_Warn(const char *s){}

/*********************************************************************
*
*       GUI_X_Init()
*
* Note:
*     GUI_X_Init() is called from GUI_Init is a possibility to init
*     some hardware which needs to be up and running before the GUI.
*     If not required, leave this routine blank.
*/

void GUI_X_Init(void) {
 SetTsInterrupt(); //此处接入触摸屏的中断设置
 GUI_TOUCH_SetDefaultCalibration();//关键函数
}
int  GUI_TOUCH_X_MeasureX(void) {
 return TX;

int  GUI_TOUCH_X_MeasureY(void){
 return TY;
}

void GUI_TOUCH_X_ActivateX(void) {} 
void GUI_TOUCH_X_ActivateY(void) {}
void GUI_X_Log(const char *s)   {}

10.为了响应触摸屏,做如下事:
1)在触摸屏中断中,获得触摸坐标后,应调用如下函数:
       GUI_TOUCH_Exec();
2)如下修改函数 GUI_TOUCH_Exec(),注释掉错误部分:
void GUI_TOUCH_Exec(void) {
  #ifndef WIN32
  static U8 ReadState;
  int x,y;
  /* calculate Min / Max values */
  if (xyMinMax[GUI_COORD_X].Min < xyMinMax[GUI_COORD_X].Max) {
    xMin = xyMinMax[GUI_COORD_X].Min;
    xMax = xyMinMax[GUI_COORD_X].Max;
  } else {
    xMax = xyMinMax[GUI_COORD_X].Min;
    xMin = xyMinMax[GUI_COORD_X].Max;
  }
  if (xyMinMax[GUI_COORD_Y].Min < xyMinMax[GUI_COORD_Y].Max) {
    yMin = xyMinMax[GUI_COORD_Y].Min;
    yMax = xyMinMax[GUI_COORD_Y].Max;
  } else {
    yMax = xyMinMax[GUI_COORD_Y].Min;
    yMin = xyMinMax[GUI_COORD_Y].Max;
  }
  /* Execute the state machine which reads the touch */
  //switch (ReadState) {
  //case 0:
    yPhys = TOUCH_X_MeasureY();
   // TOUCH_X_ActivateY();  /* Prepare X- measurement */
  //  ReadState++;
  //  break;
  //default:
    xPhys = TOUCH_X_MeasureX();
  //  TOUCH_X_ActivateX();  /* Prepare Y- measurement */
    /* Convert values into logical values */
      #if !GUI_TOUCH_SWAP_XY   /* Is X/Y swapped ? */
        x = xPhys;
        y = yPhys;
      #else
        x = yPhys;
        y = xPhys;
      #endif

    if ((x xMax)  | (y yMax)) {
      GUI_TOUCH_StoreUnstable(-1,-1);
    } else {
      x = AD2X(x);
      y = AD2Y(y);
      GUI_TOUCH_StoreUnstable(x,y);
    }
    /* Reset state machine */
    //ReadState=0;
   // break;
  //}
  #endif /* WIN32 */
}

画点效率有待改进...........................

阅读(2588) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~