GUI移植总结

GUI移植总结

一:移除源GUI文件中的编译文件
把uc-gui-v3-90a目录中的start这个目录拷贝出来,删除这个目录下的application、output、systen和其他一些不是目录的文件,之后这个文件就剩下config和gui这两个目录,然后分别进入这两个目录及子目录删除里面的编译文件(不是以.c.h结尾的文件),剩下的文件就是我们所要移植的文件,这时我们可以在与gui和config目录下建立一个应用程序文件夹(将来我们的应用程序都放到此文件夹里面).
二:编写makefile文件
在linux下编译程序是用make指令,make指令执行是需要makefile文件的,makefile文件分为两种:(一)递归makefile,(二)非递归makefile,递归的需要在每一个目录下提供一个makefile文件,非递归的只需要在主目录下提供一个makefile文件,然后在子目录中提供装载文件就可以了,在这里我采用的是非递归makefile.下面分别是我用的makefile和装载文件(主要的部分都有注释)
makefile:
# $(call source-to-object,source-file-list)
source-to-object = $(subst .c,.o,$(filter %.c,$1))
//将c文件转换为目标文件的函数
# $(subdirectory)
subdirectory = $(patsubst %/module.mk,%,$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
//求子目录
libraries :=
sources :=

# $(call make-library,library-name,source-file-list)
define make-libray
$1:$(call source-to-object,$2)
$(AR) $(ARFLAGS) $@ $^
endef
//此函数我在编译的时候没有调用
modules := ./GUI/AntiAlias ./GUI/ConvertColor ./GUI/ConvertMono ./GUI/Core ./GUI/Font ./GUI/JPEG ./GUI/LCDDriver ./GUI/MultiLayer /
./GUI/Widget ./GUI/WM ./appsrc
#modules := ./GUIL ./appsrc  
programs :=


objects = $(call source-to-object,$(sources))
dependencies = $(subst .o,.d,$(objects))

#include_dirs := GUIL Config
include_dirs := Config GUI/Core GUI/Widget GUI/WM
///头文件所在的目录
CC := ppc_4xx-gcc
指定编译器
CPPFLAGS += $(addprefix -I ,$(include_dirs))
///指定编译器搜索头文件的路径
#CPPFLAGS += -IGUI/Core -IConfig -IGUI/JPEG -IGUI/Widget -IGUI/WM -Iappsrc
VPATH = appsrc GUI/AntiAlias GUI/ConvertColor GUI/ConvertMono GUI/Core GUI/Font /
GUI/JPEG GUI/LCDDriver GUI/MultiLayer GUI/Widget GUI/WM
指定编译器搜索文件的路径
vpath %.h $(include_dirs)
///这个也是指定搜索头文件的路径可以不要
MV := mv -f
RM := rm -f
SED := sed
///定义指令变量
all:

#include GUIL/module.mk
#include appsrc/module.mk
include $(addsuffix /module.mk,$(modules))
/装载子目录的装载文件
.PHONY: all
all: $(programs)

.PHONY: clean
clean:
$(RM) $(objects) $(programs) $(libraries) $(dependencies)

ifneq "$(MAKECMDGOALS)" "clean"
 -include $(dependencies)
endif
///建立文件的依存关系
%.d: %.c
$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -M $< | /
$(SED) 's,/($(notdir $*)/.o/) *:,$(dir $@)/1 $@: ,' > $@.tmp
$(MV) $@.tmp $@

应用程序目录装载文件:
local_pgm  := $(subdirectory)/play1 ///生成的应用程序
local_src  := $(wildcard $(subdirectory)/*.c) //当前目录下的c文件

programs   += $(local_pgm) 
libraries += $(subdirectory)/ucgui.a

$(local_pgm): $(local_src) $(subdirectory)/ucgui.a
$(CC) $(CPPFLAGS) $^ -lm -o $@
///编译生成可执行程序
$(subdirectory)/ucgui.a: $(call source-to-object,$(sources))
$(AR) $(ARFLAGS) $@ $^
//把ucgui编译成程序库
gui核心程序子目录装载文件:
local_src := $(wildcard $(subdirectory)/*.c)
sources    += $(local_src)
//搜索子目录下的c文件并把他添加到总文件变量中

三:修改ucgui核心文件的驱动部分和配置部分
(一)修改文件的配置部分;
在config目录下有三个配置文件:guiconf/guitouchconf/lcdconf,其中guiconf是关于系统功能的配置在这里我用的是默认的功能也就没有配置,guitouchconf是触摸平配置在这里我没有用到也没有修改,其lcdconf文件我进行了修改,其修改如下我在修改的地方加了说明:
----------------------------------------------------------------------
*/

#ifndef LCDCONF_H
#define LCDCONF_H

//char *BIG_LCD_PTR;
/*********************************************************************
*
*                   General configuration of LCD
*
**********************************************************************
*/

#define LCD_XSIZE      (320)   /* X-resolution of LCD, Logical coor. */
#define LCD_YSIZE      (240)   /* Y-resolution of LCD, Logical coor. */

#define LCD_BITSPERPIXEL (1) //每个像素所需求的数据位数

#define LCD_CONTROLLER (0) //gui所用到的控制其,我在这里用的是0是我自己定义的,我的显示屏驱动是freambuffer,在他的自带驱动里面没有这样的驱动,我是通过修改他的一个亚驱动而提供的驱动

/*********************************************************************
*
*                   Full bus configuration
*
**********************************************************************
*/
#define LCD_BUSWIDTH (8)
#define LCD_READ_REG(Off)            //因为是freambuffer驱动所以不需要这两个
#define LCD_WRITE_REG(Off,data)      //函数去配置控制芯片的寄存器

/*********************************************************************
*
*                   Define contents of registers
*
**********************************************************************
*/


/*********************************************************************
*
*                   Init sequence for 16 bit access
*
**********************************************************************
*/

/*#if !LCD_SWAP_BYTE_ORDER
 #define LCD_WRITE_REGLH(Adr, d0, d1) LCD_WRITE_REG(Adr, ((d0)<<8) | (d1))
#else
 #define LCD_WRITE_REGLH(Adr, d0, d1) LCD_WRITE_REG(Adr, ((d1)<<8) | (d0))
#endif */
//上面的两个函数是提供读写显示屏数据用的
#define LCD_INIT_CONTROLLER()
//因为freambuffer已经初始化好了显示屏在这里就不需用这个函数了  
#endif /* LCDCONF_H */
(二)驱动程序的修改
驱动程序是通过修改lcddummy.c这个文件而成的,其修改后的文件如下所示:(在修改的地方我加了注释)
*/
#include
#include
#include
#include
#include
#include
#include
#include "LCD_Private.h"      /* private modul definitions & config */
#include "GUI_Private.h"
#include "GUIDebug.h"
#include "LCDConf.h"
#define XY2OFFSET(x,y) ((x >> 3) + y * ((LCD_XSIZE + 7) >> 3))
//上面的宏是计算位置所在的字节
#if (LCD_CONTROLLER == 0) / //这个与配置里面的修改相呼应
   && (!defined(WIN32) | defined(LCD_SIMCONTROLLER))

/*********************************************************************
*
*       Defines
*
**********************************************************************
*/

#ifndef LCD_INIT_CONTROLLER
 #define LCD_INIT_CONTROLLER()
#endif

/*********************************************************************
*
*       Macros for MIRROR_, SWAP_ and LUT_
*/
#if (!defined (LCD_LUT_COM) && !defined(LCD_LUT_SEG))
 #if   (!LCD_MIRROR_X && !LCD_MIRROR_Y && !LCD_SWAP_XY)
   #define LOG2PHYS_X(x, y) x
   #define LOG2PHYS_Y(x, y) y
 #elif (!LCD_MIRROR_X && !LCD_MIRROR_Y &&  LCD_SWAP_XY)
   #define LOG2PHYS_X(x, y) y
   #define LOG2PHYS_Y(x, y) x
 #elif (!LCD_MIRROR_X &&  LCD_MIRROR_Y && !LCD_SWAP_XY)
   #define LOG2PHYS_X(x, y) x
   #define LOG2PHYS_Y(x, y) LCD_YSIZE - 1 - (y)
 #elif (!LCD_MIRROR_X &&  LCD_MIRROR_Y &&  LCD_SWAP_XY)
   #define LOG2PHYS_X(x, y) y
   #define LOG2PHYS_Y(x, y) LCD_XSIZE - 1 - (x)
 #elif ( LCD_MIRROR_X && !LCD_MIRROR_Y && !LCD_SWAP_XY)
   #define LOG2PHYS_X(x, y) LCD_XSIZE - 1 - (x)
   #define LOG2PHYS_Y(x, y) y
 #elif ( LCD_MIRROR_X && !LCD_MIRROR_Y &&  LCD_SWAP_XY)
   #define LOG2PHYS_X(x, y) LCD_YSIZE - 1 - (y)
   #define LOG2PHYS_Y(x, y) x
 #elif ( LCD_MIRROR_X &&  LCD_MIRROR_Y && !LCD_SWAP_XY)
   #define LOG2PHYS_X(x, y) LCD_XSIZE - 1 - (x)
   #define LOG2PHYS_Y(x, y) LCD_YSIZE - 1 - (y)
 #elif ( LCD_MIRROR_X &&  LCD_MIRROR_Y &&  LCD_SWAP_XY)
   #define LOG2PHYS_X(x, y) LCD_YSIZE - 1 - (y)
   #define LOG2PHYS_Y(x, y) LCD_XSIZE - 1 - (x)
 #endif
#else
 #if   ( defined (LCD_LUT_COM) && !defined(LCD_LUT_SEG))
   #define LOG2PHYS_X(x, y) x
   #define LOG2PHYS_Y(x, y) LCD__aLine2Com0[y]
 #elif (!defined (LCD_LUT_COM) &&  defined(LCD_LUT_SEG))
   #define LOG2PHYS_X(x, y) LCD__aCol2Seg0[x]
   #define LOG2PHYS_Y(x, y) y
 #elif ( defined (LCD_LUT_COM) &&  defined(LCD_LUT_SEG))
   #define LOG2PHYS_X(x, y) LCD__aCol2Seg0[x]
   #define LOG2PHYS_Y(x, y) LCD__aLine2Com0[y]
 #endif
#endif

unsigned char *BIG_LCD_PTR;
char LCD_READ_MEM(unsigned short off)
{
char temp;
temp = *(BIG_LCD_PTR + off);
return(temp);
}
void LCD_WRITE_MEM(unsigned short off,char data)
{
*(BIG_LCD_PTR + off) = data;
}

//
/*********************************************************************
*
*       Static functions
*
**********************************************************************
*/

/*********************************************************************
*
*       Draw Bitmap 1 BPP
*/
static void  _DrawBitLine1BPP(int x, int y, U8 const GUI_UNI_PTR *p, int Diff, int xsize, const LCD_PIXELINDEX*pTrans) {
 LCD_PIXELINDEX Index0 = 0; ///此处修改位黑白色模式
 LCD_PIXELINDEX Index1 = 1;///
 x += Diff;
 switch (GUI_Context.DrawMode & (LCD_DRAWMODE_TRANS | LCD_DRAWMODE_XOR)) {
   case 0:
     do {
         LCD_L0_SetPixelIndex(x++, y, ((*p) & (0x80 >> Diff)) ? Index1 : Index0);    
 if (++Diff == 8) {
           Diff = 0;
 p++;
 }
 } while (--xsize);
     break;
   case LCD_DRAWMODE_TRANS:
     do {
   if ((*p) & (0x80 >> Diff))
         LCD_L0_SetPixelIndex(x, y, Index1);
       x++;
 if (++Diff == 8) {
         Diff = 0;
 p++;
 }
 } while (--xsize);
     break;
   case LCD_DRAWMODE_XOR:;
     do {
   if ((*p) & (0x80 >> Diff)) {
         int Pixel = LCD_L0_GetPixelIndex(x, y);
         LCD_L0_SetPixelIndex(x, y, LCD_NUM_COLORS - 1 - Pixel);
       }
       x++;
 if (++Diff == 8) {
         Diff = 0;
 p++;
 }
 } while (--xsize);
     break;
}
}

/*********************************************************************
*
*       Draw Bitmap 2 BPP
*/
#if (LCD_MAX_LOG_COLORS > 2)
static void  _DrawBitLine2BPP(int x, int y, U8 const GUI_UNI_PTR * p, int Diff, int xsize, const LCD_PIXELINDEX * pTrans) {
 LCD_PIXELINDEX Pixels = *p;
 int CurrentPixel = Diff;
 x += Diff;
 switch (GUI_Context.DrawMode & (LCD_DRAWMODE_TRANS | LCD_DRAWMODE_XOR)) {
   case 0:
     if (pTrans) {
       do {
         int Shift = (3 - CurrentPixel) << 1;
         int Index = (Pixels & (0xC0 >> (6 - Shift))) >> Shift;
         LCD_PIXELINDEX PixelIndex = *(pTrans + Index);
         LCD_L0_SetPixelIndex(x++, y, PixelIndex);
         if (++CurrentPixel == 4) {
           CurrentPixel = 0;
           Pixels = *(++p);
         }
   } while (--xsize);
     } else {
       do {
         int Shift = (3 - CurrentPixel) << 1;
         int Index = (Pixels & (0xC0 >> (6 - Shift))) >> Shift;
         LCD_L0_SetPixelIndex(x++, y, Index);
         if (++CurrentPixel == 4) {
           CurrentPixel = 0;
           Pixels = *(++p);
         }
   } while (--xsize);
     }
     break;
   case LCD_DRAWMODE_TRANS:
     if (pTrans) {
       do {
         int Shift = (3 - CurrentPixel) << 1;
         int Index = (Pixels & (0xC0 >> (6 - Shift))) >> Shift;
         if (Index) {
           LCD_PIXELINDEX PixelIndex = *(pTrans + Index);
           LCD_L0_SetPixelIndex(x, y, PixelIndex);
         }
         x++;
         if (++CurrentPixel == 4) {
           CurrentPixel = 0;
           Pixels = *(++p);
         }
   } while (--xsize);
     } else {
       do {
         int Shift = (3 - CurrentPixel) << 1;
         int Index = (Pixels & (0xC0 >> (6 - Shift))) >> Shift;
         if (Index) {
           LCD_L0_SetPixelIndex(x, y, Index);
         }
         x++;
         if (++CurrentPixel == 4) {
           CurrentPixel = 0;
           Pixels = *(++p);
         }
   } while (--xsize);
     }
     break;
 }
}
#endif

/*********************************************************************
*
*       Draw Bitmap 4 BPP
*/
#if (LCD_MAX_LOG_COLORS > 4)
static void  _DrawBitLine4BPP(int x, int y, U8 const GUI_UNI_PTR * p, int Diff, int xsize, const LCD_PIXELINDEX * pTrans) {
 LCD_PIXELINDEX Pixels = *p;
 int CurrentPixel = Diff;
 x += Diff;
 switch (GUI_Context.DrawMode & (LCD_DRAWMODE_TRANS | LCD_DRAWMODE_XOR)) {
   case 0:
     if (pTrans) {
       do {
         int Shift = (1 - CurrentPixel) << 2;
         int Index = (Pixels & (0xF0 >> (4 - Shift))) >> Shift;
         LCD_PIXELINDEX PixelIndex = *(pTrans + Index);
         LCD_L0_SetPixelIndex(x++, y, PixelIndex);
         if (++CurrentPixel == 2) {
           CurrentPixel = 0;
           Pixels = *(++p);
         }
   } while (--xsize);
     } else {
       do {
         int Shift = (1 - CurrentPixel) << 2;
         int Index = (Pixels & (0xF0 >> (4 - Shift))) >> Shift;
         LCD_L0_SetPixelIndex(x++, y, Index);
         if (++CurrentPixel == 2) {
           CurrentPixel = 0;
           Pixels = *(++p);
         }
   } while (--xsize);
     }
     break;
   case LCD_DRAWMODE_TRANS:
     if (pTrans) {
       do {
         int Shift = (1 - CurrentPixel) << 2;
         int Index = (Pixels & (0xF0 >> (4 - Shift))) >> Shift;
         if (Index) {
           LCD_PIXELINDEX PixelIndex = *(pTrans + Index);
           LCD_L0_SetPixelIndex(x, y, PixelIndex);
         }
         x++;
         if (++CurrentPixel == 2) {
           CurrentPixel = 0;
           Pixels = *(++p);
         }
   } while (--xsize);
     } else {
       do {
         int Shift = (1 - CurrentPixel) << 2;
         int Index = (Pixels & (0xF0 >> (4 - Shift))) >> Shift;
         if (Index) {
           LCD_L0_SetPixelIndex(x, y, Index);
         }
         x++;
         if (++CurrentPixel == 2) {
           CurrentPixel = 0;
           Pixels = *(++p);
         }
   } while (--xsize);
     }
     break;
 }
}
#endif

/*********************************************************************
*
*       Draw Bitmap 8 BPP
*/
#if (LCD_MAX_LOG_COLORS > 16)
static void  _DrawBitLine8BPP(int x, int y, U8 const GUI_UNI_PTR * p, int xsize, const LCD_PIXELINDEX * pTrans) {
 LCD_PIXELINDEX Pixel;
 switch (GUI_Context.DrawMode & (LCD_DRAWMODE_TRANS | LCD_DRAWMODE_XOR)) {
   case 0:
     if (pTrans) {
       for (; xsize > 0; xsize--, x++, p++) {
         Pixel = *p;
         LCD_L0_SetPixelIndex(x, y, *(pTrans + Pixel));
       }
     } else {
       for (; xsize > 0; xsize--, x++, p++) {
         LCD_L0_SetPixelIndex(x, y, *p);
       }
     }
     break;
   case LCD_DRAWMODE_TRANS:
     if (pTrans) {
       for (; xsize > 0; xsize--, x++, p++) {
         Pixel = *p;
         if (Pixel) {
           LCD_L0_SetPixelIndex(x, y, *(pTrans + Pixel));
         }
       }
     } else {
       for (; xsize > 0; xsize--, x++, p++) {
         Pixel = *p;
         if (Pixel) {
           LCD_L0_SetPixelIndex(x, y, Pixel);
         }
       }
     }
     break;
 }
}
#endif

/*********************************************************************
*
*       Draw Bitmap 16 BPP
*/
#if (LCD_BITSPERPIXEL > 8)
static void  DrawBitLine16BPP(int x, int y, U16 const GUI_UNI_PTR * p, int xsize, const LCD_PIXELINDEX * pTrans) {
 LCD_PIXELINDEX pixel;
 if ((GUI_Context.DrawMode & LCD_DRAWMODE_TRANS) == 0) {
   if (pTrans) {
     for (; xsize > 0; xsize--, x++, p++) {
       pixel = *p;
       LCD_L0_SetPixelIndex(x, y, *(pTrans + pixel));
     }
   } else {
     for (;xsize > 0; xsize--, x++, p++) {
       LCD_L0_SetPixelIndex(x, y, *p);
     }
   }
 } else {
   if (pTrans) {
     for (; xsize > 0; xsize--, x++, p++) {
       pixel = *p;
       if (pixel) {
         LCD_L0_SetPixelIndex(x, y, *(pTrans + pixel));
       }
     }
   } else {
     for (; xsize > 0; xsize--, x++, p++) {
       pixel = *p;
       if (pixel) {
         LCD_L0_SetPixelIndex(x, y, pixel);
       }
     }
   }
 }
}
#endif
//
void GUI_SetPixel(int x,int y,int pColor) 写一个像素的函数
{
U8 Mask = 1 << (7 - (x & 7));
U16 Adr = ((x >> 3) + (y * 40));
U8 CacheByte = LCD_READ_MEM(Adr);
if (pColor)
CacheByte |= Mask;
else
CacheByte &= ~Mask;
LCD_WRITE_MEM(Adr,CacheByte);
}
/
unsigned int GUI_GetPixel(int x,int y) //读一个像素值的函数
{
U8 Mask = 1 << (7 - (x & 7));
U16 Adr = ((x >> 3) + (y * 40));
U8 CacheByte = LCD_READ_MEM(Adr);
if(CacheByte & Mask)
{
return 1;
}
else
{
return 0;
}
}
/*********************************************************************
*
*       Exported functions
*
**********************************************************************
*/

/*********************************************************************
*
*       LCD_L0_SetPixelIndex
*
* Purpose:
*   Sets the index of the given pixel. The upper layers
*   calling this routine make sure that the coordinates are in range, so
*   that no check on the parameters needs to be performed.
*/
void LCD_L0_SetPixelIndex(int x, int y, int PixelIndex) {
GUI_SetPixel(x,y,PixelIndex); 
}
///修改此函数与我们的驱动相适应
/*********************************************************************
*
*       LCD_L0_GetPixelIndex
*
* Purpose:
*   Returns the index of the given pixel. The upper layers
*   calling this routine make sure that the coordinates are in range, so
*   that no check on the parameters needs to be performed.
*/
unsigned int LCD_L0_GetPixelIndex(int x, int y) {
 LCD_PIXELINDEX PixelIndex;
 PixelIndex = GUI_GetPixel(x,y);
 return PixelIndex;
}
///修改此函数与我们的驱动相适应
/*********************************************************************
*
*       LCD_L0_XorPixel
*/
void LCD_L0_XorPixel(int x, int y) {
 LCD_PIXELINDEX PixelIndex = LCD_L0_GetPixelIndex(x, y);
 LCD_L0_SetPixelIndex(x, y, LCD_NUM_COLORS - PixelIndex - 1);
}

/*********************************************************************
*
*       LCD_L0_DrawHLine
*/
void LCD_L0_DrawHLine  (int x0, int y,  int x1) {
 if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR) {
   for (; x0 <= x1; x0++) {
     LCD_L0_XorPixel(x0, y);
   }
 } else {
   for (; x0 <= x1; x0++) {
     LCD_L0_SetPixelIndex(x0, y, LCD_COLORINDEX);
   }
 }
}

/*********************************************************************
*
*       LCD_L0_DrawVLine
*/
void LCD_L0_DrawVLine  (int x, int y0,  int y1) {
 if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR) {
   for (; y0 <= y1; y0++) {
     LCD_L0_XorPixel(x, y0);
   }
 } else {
   for (; y0 <= y1; y0++) {
     LCD_L0_SetPixelIndex(x, y0, LCD_COLORINDEX);
   }
 }
}

/*********************************************************************
*
*       LCD_L0_FillRect
*/
void LCD_L0_FillRect(int x0, int y0, int x1, int y1) {
 for (; y0 <= y1; y0++) {
   LCD_L0_DrawHLine(x0, y0, x1);
 }
}

/*********************************************************************
*
*       LCD_L0_DrawBitmap
*/
void LCD_L0_DrawBitmap(int x0, int y0,
                      int xsize, int ysize,
                      int BitsPerPixel,
                      int BytesPerLine,
                      const U8 GUI_UNI_PTR * pData, int Diff,
                      const LCD_PIXELINDEX* pTrans)
{
 int i;
 /* Use _DrawBitLineXBPP */
 for (i=0; i    switch (BitsPerPixel) {
   case 1:
     _DrawBitLine1BPP(x0, i + y0, pData, Diff, xsize, pTrans);
     break;
   #if (LCD_MAX_LOG_COLORS > 2)
     case 2:
       _DrawBitLine2BPP(x0, i + y0, pData, Diff, xsize, pTrans);
       break;
   #endif
   #if (LCD_MAX_LOG_COLORS > 4)
     case 4:
       _DrawBitLine4BPP(x0, i + y0, pData, Diff, xsize, pTrans);
       break;
   #endif
   #if (LCD_MAX_LOG_COLORS > 16)
     case 8:
       _DrawBitLine8BPP(x0, i + y0, pData, xsize, pTrans);
       break;
   #endif
   #if (LCD_BITSPERPIXEL > 8)
     case 16:
       DrawBitLine16BPP(x0, i + y0, (const U16 *)pData, xsize, pTrans);
       break;
   #endif
   }
   pData += BytesPerLine;
 }
}

/*********************************************************************
*
*       LCD_L0_SetOrg
*/
void LCD_L0_SetOrg(int x, int y) {
 GUI_USE_PARA(x);
 GUI_USE_PARA(y);
}

/*********************************************************************
*
*       LCD_On / LCD_Off
*/
void LCD_On (void) {
#ifdef LCD_ON
 LCD_ON();
#endif
}

void LCD_Off (void) {
#ifdef LCD_OFF
 LCD_OFF();
#endif
}

/*********************************************************************
*
*       LCD_L0_Init
*
* Purpose:
*   Initialises the LCD-controller.
*/
int  LCD_L0_Init(void) {
 int lcdfd;
 int i,j;
 LCD_INIT_CONTROLLER();
 lcdfd = open("/dev/fb0",O_RDWR); //打开freambuffer设备
if(lcdfd<0)
{
printf("open file failed/n");
return -1;
}
BIG_LCD_PTR = mmap(NULL,9600,PROT_READ|PROT_WRITE,MAP_SHARED,lcdfd,0);
//进行内存映射
if((BIG_LCD_PTR==NULL)||((int)BIG_LCD_PTR == -1))
{
printf("mmap failed/n");
close(lcdfd);
return -1;
}
memset(BIG_LCD_PTR,0x00,9600);
//初始化屏幕背景
//LCD_L0_DrawVLine (160,5,238);
/*while(1)
{
for(i=1;i<235;i++)
{
GUI_SetPixel(160,i,1);

}
sleep(2);
memset(BIG_LCD_PTR,0x00,9600);
sleep(2);
}*/
 return 0;
}

/*********************************************************************
*
*       LCD_L0_SetLUTEntry
*/
void LCD_L0_SetLUTEntry(U8 Pos, LCD_COLOR Color) {
 GUI_USE_PARA(Pos);
 GUI_USE_PARA(Color);
}

#else

void LCDDummy_c(void);
void LCDDummy_c(void) { } /* avoid empty object files */

#endif /* (LCD_CONTROLLER undefined) */
把这些修改完之后在我们的应用文件夹下编写一个测试程序后就可以用我们刚才写的makefile进行编译了,编译完成后会生成可执行文件,此时可把生成的可执行文件在我们的开发板上执行以验证我们移植的成败,在此时我们的移植还不能够显示汉字,我们为了显示汉字我们还要修改GUI/core/guichar.c和GUI/core/gui.h文件,然后添加中文汉字库文件,
其guichar.c文件修改后如下:(在关键的部位我会加以详细的说明)
/*
*********************************************************************************************************
*                                                uC/GUI
*                        Universal graphic software for embedded applications
*
*                       (c) Copyright 2002, Micrium Inc., Weston, FL
*                       (c) Copyright 2002, SEGGER Microcontroller Systeme GmbH
*
*              礐/GUI is protected by international copyright laws. Knowledge of the
*              source code may not be used to write a similar product. This file may
*              only be used in accordance with a license and should not be redistributed
*              in any way. We appreciate your understanding and fairness.
*
----------------------------------------------------------------------
File        : GUIChar.C
Purpose     : Implementation of character and string services
---------------------------END-OF-HEADER------------------------------
*/


#include           /* needed for definition of NULL */
#include
#include
#include
#include
#include
#include
#include
#include "GUI_Private.h"

#define HZSIZEX (16)
#define HZSIZEY(16)

//增加汉字库支持所做修改, 2005-06-12 15:31:20
//#include "HZ.h"

///
/**********************************************************
*
*        Public code
*
***********************************************************
*/


/***********************************************************
*
*       GUI_DispChar
*/

void GL_DispChar(U16 c) {
 /* check for control characters */
 if (c == '/n') {
   GUI_DispNextLine();
 } else {
   if (c != '/r') {
     GUI_Context.pAFont->pfDispChar(c);
   }
 }
}


/*************** GUI_GetStringDistX ****************************
This routine is used to calculate the length of a string in pixels.
*/

int GUI_GetLineDistX(const char GUI_UNI_PTR *s, int Len) {
 int Dist =0;
 if (s) {
   if (GUI_Context.pAFont->pafEncode) {
     return GUI_Context.pAFont->pafEncode->pfGetLineDistX(s, Len);
   }
#if (GUI_SUPPORT_UNICODE)
   {
     U8 c0;
     char UCActive=0;
     while (((c0=*(U8*)s) !=0) && Len >0) {
       s++; Len--;
       if (UCActive) {
         if (c0 == GUI_UC_ENDCHAR)
           UCActive = 0;
         else {
           U8  c1 = *(U8*)s++;
           Len--;
           Dist += GUI_GetCharDistX(GUI_DB2UC(c0, c1));
         }
       } else { /* Unicode not active */
         if (c0 == GUI_UC_STARTCHAR)
           UCActive = 1;
         else
           Dist += GUI_GetCharDistX(c0);
       }
     }
   }
#else
   while (--Len>=0) {
     Dist += GUI_GetCharDistX(*(U8*)s++);
   }
#endif
 }
 return Dist;
}
***************************add**********************

//static FILE handle;
//static FILE* handle;

/*int OpenHZ(const char *Hz16Path)
{
return (handle=fopen(Hz16Path,"rb"));
}*/

/*void OpenHZ(const char *Hz16Path)
{
handle=fopen(Hz16Path,"rb");
}
int CloseHZ()
{

if (handle<0) return -1;
else return fclose (handle);
}

int GetBit(unsigned char c,int n)
{
return((c>>n)&1);
}

int WriteHZ (int x, int y,char *p,int color)
{
 U16 c1,c2,rec;
 long l;
 char pixeldata[32];

 int BytesPerLine;
 printf("jin ru xie han zi/n");
 GUI_DRAWMODE DrawMode = GUI_Context.TextMode;
 GUI_DRAWMODE OldDrawMode;

 if (handle<0 ) return 0;
 if (p==NULL) return 0;
 //p[0] = 0xb9;
 //p[1] = 0xfa;
 //c1=(p[0]-0xa0)&0x07f;
 //c2=(p[1]-0xa0)&0x07f;
 c1=(p[0]);//-0xa1);
 c2=(p[1]);//-0xa1);
 rec=c1*94+c2;
 l=rec*32;

 //lseek(handle,l,SEEK_SET);
 //read(handle,pixeldata,32);
 fseek(handle,l,SEEK_SET);
 fread(pixeldata,sizeof(char),32,handle);

/* 2005-06-17 9:09:08
 fseek(handle,l,SEEK_SET);
 fread(pixeldata,32, 1, handle);*/

/* BytesPerLine = 2;
 OldDrawMode  = LCD_SetDrawMode(DrawMode);
 LCD_DrawBitmap (GUI_Context.DispPosX, GUI_Context.DispPosY,
 HZSIZEX,HZSIZEY,
 1, 1,
 1,            /*Bits per Pixel */
/*  BytesPerLine,
 (U8*)pixeldata,
//  NULL  /* no palette means default palette */
//  &LCD_BKCOLORINDEX  /* no palette means default palette */
//  );
 /* Fill empty pixel lines */
 /*
 if (GUI_Context.pAFont->YDist > GUI_Context.pAFont->YSize) {
   int YMag = GUI_Context.pAFont->YMag;
   int YDist = GUI_Context.pAFont->YDist * YMag;
   int YSize = GUI_Context.pAFont->YSize * YMag;
   if (DrawMode != LCD_DRAWMODE_TRANS) {
   LCD_COLOR OldColor = GUI_GetColor();
   GUI_SetColor(GUI_GetBkColor());
   LCD_FillRect(GUI_Context.DispPosX,
GUI_Context.DispPosY + YSize,
GUI_Context.DispPosX + pCharInfo->XSize,
GUI_Context.DispPosY + YDist);
   GUI_SetColor(OldColor);
 }
 */
/* LCD_SetDrawMode(OldDrawMode); /* Restore draw mode */
/* GUI_Context.DispPosX += HZSIZEX;
 return 1;
}
*/

*********************************end***********

/*************** GUI_GetLineLen ****************************
Returns the number of characters in a string
Note: The return value can be used as offset into the
string, which means that double characters count double
*/

int GUI__GetLineLen(const char GUI_FAR *s, int MaxLen) {
 int Len =0;
 if (!s)
   return 0;
 if (GUI_Context.pAFont->pafEncode) {
   return GUI_Context.pAFont->pafEncode->pfGetLineLen(s, MaxLen);
 }
#if (GUI_SUPPORT_UNICODE)
 {
   U8 c0;
   char UCActive=0;
   while (((c0=*(U8*)s) !=0) && Len < MaxLen) {
     s++;
     if (UCActive) {
       switch (c0) {
       case GUI_UC_ENDCHAR: UCActive = 0; break;
       default: Len++; s++;
       }
     } else { /* Unicode not active */
       switch (c0) {
       case GUI_UC_STARTCHAR: UCActive = 1; break;
       case '/n': return Len;
       case '/r': return Len;
       }
     }
     Len++;
   }
 }
#else
 for (;Len    U8 Data = *(U8*)s++;
   if ((Data == 0) || (Data == '/n'))
     break;
 }
#endif
 return Len;
}


/**********************************************************************
*
*       "GET"   routines    (information retrieval)
*
***********************************************************************

These routines all return a value like selected font, current display
position in x/y direction, window size in x/y direction,
font size and matrix in x/y.
The routines prefixed with GUI_ can be called from the application
program or emWin internally, while the routines without that prefix
are not supposed to be called from outside emWin.
The main reason is that GUI_LOCK has to be called before these
values can be reliably retrieved in a multitasking environment.

*/

/*------------------------------------------------------------------
 GUI_GetYAdjust  --- returns adjustment in vertical (Y) direction
                 The return value needs to be subtracted from
                 the y-position of the character
*/

int GUI_GetYAdjust(void) {
 switch (GUI_Context.TextAlign&GUI_TA_VERTICAL) {
case GUI_TA_BOTTOM:
return GUI_Context.pAFont->YSize-1;
case GUI_TA_VCENTER:
return GUI_Context.pAFont->YSize/2;
case GUI_TA_BASELINE:
return GUI_Context.pAFont->YSize/2;
}
 return 0;
}

/*
       *******************************************
       *                                         *
       *        Get Font Spacing routines        *
       *                                         *
       *******************************************
*/

int GUI_GetFontDistY(void) {
 int r;
 GUI_LOCK();
 r = GUI_Context.pAFont->YDist * GUI_Context.pAFont->YMag;
 GUI_UNLOCK();
 return r;
}


/*
       *******************************************
       *                                         *
       *        Get Char spacing routines        *
       *                                         *
       *******************************************
*/

int GUI_GetCharDistX(U16 c) {
 int r;
 GUI_LOCK();
 r = GUI_Context.pAFont->pfGetCharDistX(c);
 GUI_UNLOCK();
 return r;
}


/*
     *********************************
     *                               *
     *       Linefeed                *
     *                               *
     *********************************

*/
void GUI_DispNextLine(void) {
 GUI_Context.DispPosY +=GUI_GetFontDistY();
 GUI_Context.DispPosX = GUI_Context.LBorder;
}

/*
       ************************************************************
       *                                                          *
       *             Set the write position                       *
       *                                                          *
       ************************************************************

Sets the write position. The routines routine 1 if it is clear that
the current write position is in an area outside the current window
and will therefor not be GL_DispChar(c0);written.


/*
********************************************************
*
*                Display line
*
********************************************************
*/

void GL_DispLine(const char GUI_FAR *s, int Len, const GUI_RECT *pRect) {
 /*
   Check if we have anything to do at all ...
   If the window manager has already set the clipping rect, it does not
   make sense to due this. So it makes sense only if
   a) The window manager is not used (-> Configuration)
     or
   b) The window manager is inactive (-> Memory device active)
 */
 if (GUI_Context.pClipRect_HL) {
   if (GUI_RectsIntersect(GUI_Context.pClipRect_HL, pRect) == 0)
     return;
 }
 if (GUI_Context.pAFont->pafEncode) {
   GUI_Context.pAFont->pafEncode->pfDispLine(s, Len);
   return;
 }
#if (GUI_SUPPORT_UNICODE)
 {
   U8 c0;
   char UCActive=0;
   while (--Len >=0) {
     c0=*(U8*)s++;
     if (UCActive) {
       if (c0 == GUI_UC_ENDCHAR)
         UCActive = 0;
       else {
         U8  c1 = *(U8*)s++;
         Len--;
         GL_DispChar (GUI_DB2UC(c0, c1));
       }
     } else { /* Unicode not active */
       if (c0 == GUI_UC_STARTCHAR)
         UCActive = 1;
       else
{
 GL_DispChar(c0); /
 }
     }
   }
 }
#else
 {
 U8 c0;
 while (--Len >=0) {  
 c0=*(U8*)s++;
 GL_DispChar(c0);
 }
 }
#endif
}
//此函数就是显示汉字的基本函数

void GUI__DispLine(const char GUI_FAR *s, int Len, const GUI_RECT* pr) {
 GUI_RECT r;
 r = *pr;
 #if GUI_WINSUPPORT
 WM_ADDORG(r.x0,r.y0);
 WM_ADDORG(r.x1,r.y1);
 WM_ITERATE_START(&r) {
 #endif
    GUI_Context.DispPosX = r.x0;
    GUI_Context.DispPosY = r.y0;
 ///* Do the actual drawing via routine call. */
    GL_DispLine(s, Len, &r);
 #if GUI_WINSUPPORT
 } WM_ITERATE_END();
 WM_SUBORG(GUI_Context.DispPosX, GUI_Context.DispPosY);
 #endif
}

***************************************add
void zhuanhuan(const char *srcptr,char *dptr)
{
int len;
len = 0;
while(*srcptr)
{
if(((*srcptr) & 0xe0) == 0xe0)
{
char temp,temp1;
temp = 0;
temp1 = 0;
*(dptr + len) = 0x1a;
len++;
temp |= (*srcptr) & 0x0f;
temp1 = (*(srcptr+1)) & 0x3f;
temp = temp << 4;
temp |= ((temp1 >> 2) & 0x0f);
*(dptr + len) = temp;
len++;
temp = (*(srcptr + 2) & 0x3f);
temp1 = ((temp1 & 0x03) << 6);
temp1 |= temp;
*(dptr + len) = temp1;
len++;
*(dptr + len) = 0xe2;
len++;
srcptr += 3;
}
else if(((*srcptr) & 0xc0) == 0xc0)
{
char temp,temp1;
*(dptr + len) = 0x1a;
len++;
temp = (*srcptr) & 0x1f;
temp1 = (*(srcptr+1) & 0x3f);
*(dptr + len) = (temp >> 2) & 0x07;
len++;
*(dptr + len) = (temp1 | ((temp & 0x03) << 6));
len++;
*(dptr + len) = 0xe2;
len++;
srcptr += 2;
}
else
{
*(dptr + len) = *srcptr;
len++;
srcptr += 1;
}
}
}
//
//编码转换函数


/********************************************************************
*
*                Display String
*
*********************************************************************
*/

void GUI_DispString(const char GUI_FAR *s1) {
 int xAdjust, yAdjust, xOrg;
 int FontSizeY;
/
 char *s;
 char *stemp;
 int len1;
 len1 = strlen(s1);
 s = (char*)malloc(len1+10);
 if(s == NULL)
   {
    printf("malloc failed/n");
    exit(0);
   }
 stemp = s;
 zhuanhuan(s1,s);
/
上面两个杠线之间的部分是进行码值转换用的,在linux中文本的汉字编码是unicode码中的UTF8编码要把他转换成字库需要的UCS2编码,其转换函数是上面的zhuanhuan()函数
 if (!s)
   return;
 GUI_LOCK();
 FontSizeY = GUI_Context.pAFont->YDist;
 xOrg = GUI_Context.DispPosX;
/* Adjust vertical position */
 yAdjust = GUI_GetYAdjust();
 GUI_Context.DispPosY -= yAdjust;
 for (; *s; s++) {
   GUI_RECT r;
   int LineLen= GUI__GetLineLen(s,0x7fff);
   int xLineSize = GUI_GetLineDistX(s, LineLen);
 /* Check if x-position needs to be changed due to h-alignment */
   switch (GUI_Context.TextAlign & GUI_TA_HORIZONTAL) {
   case GUI_TA_CENTER: xAdjust= xLineSize/2; break;
   case GUI_TA_RIGHT:  xAdjust= xLineSize; break;
   default:            xAdjust= 0;
   }
   r.x0 = GUI_Context.DispPosX -= xAdjust;
   r.x1 = r.x0 + xLineSize-1;    
   r.y0 = GUI_Context.DispPosY;
   r.y1 = r.y0 + FontSizeY-1;    
   GUI__DispLine(s, LineLen, &r);
   GUI_Context.DispPosY = r.y0;
   s += LineLen;
   if ((*s=='/n') || (*s=='/r')) {
     switch (GUI_Context.TextAlign & GUI_TA_HORIZONTAL) {
     case GUI_TA_CENTER:
     case GUI_TA_RIGHT:
       GUI_Context.DispPosX = xOrg;
       break;
     default:
       GUI_Context.DispPosX = GUI_Context.LBorder;
       break;
     }
     if (*s=='/n')
       GUI_Context.DispPosY += GUI_GetFontDistY();
   } else {
     GUI_Context.DispPosX = r.x0+xLineSize;
   }
   if (*s==0)    /* end of string (last line) reached ? */
     break;
 }
 GUI_Context.DispPosY += yAdjust;
 GUI_Context.TextAlign &= ~GUI_TA_HORIZONTAL;
 GUI_UNLOCK();
 free(stemp);
}
此函数在源文件中是没有的他是在guidispstring.c文件中编写的,在这里我是在这里实现的所以我们要删除guidispstring.c文件以免造成编译冲突.
然后我们在font文件夹里面添加我们的中文字库的c文件,此c文件是有tool文件夹里面的ucgui-fontconvert-mody文件夹里面的工具生成的,把生成的这个文件复制到font目录下,然后在gui.h文件中添加我们的字库就可以了,在以后的应用程序中先定义这个字库后就可以在程序中直接显示中文了,到此我们的移植已经完成了.


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值