移植ucgui到s3c2410十大步
1.編寫驅(qū)動(dòng),主要為L(zhǎng)cd驅(qū)動(dòng)和觸摸屏驅(qū)動(dòng):
lcd驅(qū)動(dòng)實(shí)現(xiàn)畫點(diǎn)函數(shù)LCD2410_SetPixel(x,y,c)。對(duì)dm2410實(shí)驗(yàn)板上的lcd,左上為原點(diǎn)(0,0)
觸摸屏驅(qū)動(dòng)計(jì)算出觸摸屏的坐標(biāo)(x,y),對(duì)dm2410實(shí)驗(yàn)板上的觸摸屏,左下為原點(diǎn),但不一定是(0,0)
2.觸摸屏校準(zhǔn):
測(cè)出左下最小坐標(biāo)minX,minY和右上最大坐標(biāo)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驅(qū)動(dòng)函數(shù)的連接:
在LCDWin.c中,去掉無(wú)用的頭文件包含。
#define SETPIXEL(x, y, c) LCD2410_SetPixel(x, y, c)
#define GETPIXEL(x, y) LCD2410_GetPixel(x,y)
即將“LCDSIM_XX”改成“LCD2410_XX”,這兩個(gè)函數(shù)位于lcd驅(qū)動(dòng)文件中。
6.某些編譯器不會(huì)初始化全局變量,因此做如下事:
1)修改如下函數(shù)為:(位于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)自己編寫如下函數(shù):
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;
}
該函數(shù)應(yīng)在GUI_Init()調(diào)用之前調(diào)用。
7.由于沒有加入ucos操作系統(tǒng),自己編寫如下函數(shù)模擬延時(shí):
int ost = 0;
void My_X_Delay(int p)
{
int i = 0;
int j=0;
for(i=0; i
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.修改如下函數(shù),接入lcd的初始化:(位于LCD.c)
int LCD_Init(void) {
int r;
GUI_DEBUG_LOG("nLCD_Init...");
LCD_SetClipRectMax();
if ((r = LCD2410_Init()) != 0) //LCD2410_Init(),設(shè)置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(); //此處接入觸摸屏的中斷設(shè)置
GUI_TOUCH_SetDefaultCalibration();//關(guān)鍵函數(shù)
}
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.為了響應(yīng)觸摸屏,做如下事:
1)在觸摸屏中斷中,獲得觸摸坐標(biāo)后,應(yīng)調(diào)用如下函數(shù):
GUI_TOUCH_Exec();
2)如下修改函數(shù) 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
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 */
}
注:若發(fā)現(xiàn)顯示較慢,看看是否開啟了Cache。也可適當(dāng)修改DrawBitmap函數(shù)。