#include "GUI.h"
int main(int argc, char* argv[])
{
char c;
printf("this is ucgui-linux test!
");
GUI_Init();
GUI_SetBkColor(GUI_BLUE);
GUI_Clear();
GUI_SetColor(GUI_WHITE);
GUI_SetTextAlign(GUI_TA_HCENTER);
GUI_SetFont(&GUI_Font16B_ASCII);
GUI_DispStringAt("hello world, ucgui-linux",240,100);
GUI_DrawCircle(100,100,50);//画圆
printf("system pause
");
while ((c = getchar()) != '
');
system("pause");
return 0;
}
先来张运行成功的截图:
又发现ucGUI一个强大功能,竟可以windows上设计界面自动生成代码,带仿真执行功能。附图:是不是很赞,这是minigui远远不能及的....
连带电脑上的代码编写仿真环境都有,
进入正题,移植minigui,
很好移植,把底层调用的几个函数,用linux上的frambuffer实现就可以了。
具体文件是LCDDummy.c那么文件 里的LCD_L0_Init(void),LCD_L0_SetPixelIndex,LCD_L0_GetPixelIndex,这三个函数,实现这三个函数。
/*********************************************
*
* LCD_L0_Init
*
**********************************************
Purpose:
Initialises the LCD-controller.
*/
int LCD_L0_Init(void) {
return fb_init();
}/*********************************************
*
* LCD_L0_SetPixelIndex
*
**********************************************
Purpose:
Sets the index of the given pixel. The upper layers of emWin
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) {
/* Convert logical into physical coordinates (Dep. on LCDConf.h) */
#if LCD_SWAP_XY | LCD_MIRROR_X| LCD_MIRROR_Y
int xPhys = LOG2PHYS_X(x, y);
int yPhys = LOG2PHYS_Y(x, y);
#else
#define xPhys x
#define yPhys y
#endif
/* Write into hardware ... Adapt to your system */
{
/* ... */
fb_setpixel(480, 272, xPhys, yPhys, PixelIndex);
}
}
/*********************************************
*
* LCD_L0_GetPixelIndex
*
**********************************************
Purpose:
Returns the index of the given pixel. The upper layers of emWin
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;
/* Convert logical into physical coordinates (Dep. on LCDConf.h) */
#if LCD_SWAP_XY | LCD_MIRROR_X| LCD_MIRROR_Y
int xPhys = LOG2PHYS_X(x, y);
int yPhys = LOG2PHYS_Y(x, y);
#else
#define xPhys x
#define yPhys y
#endif
/* Read from hardware ... Adapt to your system */
{
PixelIndex = 0;/* ... */
PixelIndex = fb_readpixel(480, 272, xPhys, yPhys);
}
return PixelIndex;
}
#include #include #include #include #include #include #include #include #include #include #include #include #include static unsigned char* npu8_fbmem;
static int ns32_fb;
static unsigned int nu32_screensize;
static void* _fb_mmap(int fd, unsigned int screensize)
{
caddr_t fbmem;
if ((fbmem = mmap(0, screensize, PROT_READ | PROT_WRITE,
MAP_SHARED, fd, 0)) == MAP_FAILED) {
perror(__func__);
return (void *) (-1);
}
return fbmem;
}
static int _fb_munmap(void *start, size_t length)
{
return (munmap(start, length));
}
static int _fb_stat(int fd, unsigned int *width, unsigned int *height, unsigned int *depth)
{
//struct fb_fix_screeninfo fb_finfo;
struct fb_var_screeninfo fb_vinfo;
//if (ioctl(fd, FBIOGET_FSCREENINFO, &fb_finfo)) {
// perror(__func__);
// return -1;
//}
if (ioctl(fd, FBIOGET_VSCREENINFO, &fb_vinfo)) {
perror(__func__);
return -1;
}
*width = fb_vinfo.xres;
*height = fb_vinfo.yres;
*depth = fb_vinfo.bits_per_pixel;
return 0;
}
int fb_init(void)
{
unsigned int fbw, fbh, fbd;
ns32_fb = open("/dev/fb0", O_RDWR);
if(ns32_fb<0){
printf("can not open fb0
");
return -1;
}
if( _fb_stat(ns32_fb, &fbw, &fbh, &fbd) < 0 ) return -1;
printf("%d, %d, %d
", fbw, fbh, fbd);
nu32_screensize = fbw * fbh * fbd / 8;
npu8_fbmem = _fb_mmap(ns32_fb, nu32_screensize);
return 0;
}
void fb_deinit(void)
{
close(ns32_fb);
_fb_munmap(npu8_fbmem, nu32_screensize);
}
int fb_setpixel(int width, int height, int x, int y, unsigned short color)
{
if ((x > width) || (y > height))
return -1;
unsigned short *dst = ((unsigned short *)npu8_fbmem + y * width + x);
*dst = color;
return 0;
}
unsigned short fb_readpixel(int width, int height, int x, int y)
{
if ((x > width) || (y > height)) return -1;
unsigned short *dst = ((unsigned short *)npu8_fbmem + y * width + x);
return *dst;
}
最后,要在linux上编译,写个makefile吧,简单省事。写完后配置下工具链直接make即可。
########################################
##makefile
########################################
#****************************************************************************
# Cross complie path
#****************************************************************************
#CHAIN_ROOT=/home/yangyongzhen/imax283/ctools/gcc-4.4.4-glibc-2.11.1-multilib-1.0/arm-fsl-linux-gnueabi/bin
#CROSS_COMPILE=$(CHAIN_ROOT)/arm-none-linux-gnueabi-
CROSS_COMPILE =
CC := $(CROSS_COMPILE)gcc
CXX := $(CROSS_COMPILE)g++
AS := $(CROSS_COMPILE)as
AR := $(CROSS_COMPILE)ar
LD := $(CROSS_COMPILE)ld
RANLIB := $(CROSS_COMPILE)ranlib
OBJDUMP:= $(CROSS_COMPILE)objdump
OBJCOPY:= $(CROSS_COMPILE)objcopy
STRIP := $(CROSS_COMPILE)strip
#****************************************************************************
# Source files
#****************************************************************************
SRC_C=$(shell find . -name "*.c")
OBJ_C=$(patsubst %.c, %.o, $(SRC_C))
SRCS := $(SRC_C) $(SRC_C)
OBJS := $(OBJ_C)
#****************************************************************************
# Flags
#****************************************************************************
CFLAGS= -I./GUI_X -I./GUI/Core -I./GUI/WM -I./GUI/Widget
LDSCRIPT=
LDFLAGS=
#****************************************************************************
# Targets of the build
#****************************************************************************
TARGET := libucgui
.PHONY: clean
all: prebuild $(TARGET).a
#****************************************************************************
# TARGET
#****************************************************************************
prebuild:
@echo Building lib...
$(TARGET).a : $(OBJS)
@echo Generating lib...
ar crv $(TARGET).a $(OBJS)
cp $(TARGET).a ../
@echo OK!
%.o : %.c
$(CC) -c $(CFLAGS) $< -o $@
clean:
@echo The following files:
rm -f $(TARGET) *.a
find . -name "*.[od]" |xargs rm
@echo Removed!