编译环境:ADS1.2
开发板:TQ2440
主要参考这篇文章:stm32-UCGUI-完美移植
ucGUI版本:3.90 ucGUI3.90下载地址:UCGUI最新3.90版源码
屏幕:联想VGA电脑屏幕,最大分辨率1024x768
(1)解压源码,将Sample/GUI_X/GUI_X.c复制到Start/Config里面,然后将Start/Config和Start/GUI复制到工程文件夹ucGUI里面,然后拖动到ucGUI文件夹到工程里面,文件比较多,加载了十几秒
(2)然后打开GUIConf.h配置
#define GUI_OS (0) //没有ucos
#define GUI_SUPPORT_TOUCH (0) //没有触摸屏
#define GUI_SUPPORT_UNICODE (0) //没有中文
#define GUI_DEFAULT_FONT &GUI_Font8x16//字体宽8高16
#define GUI_ALLOC_SIZE 1024*1024 //动态内存大小1MB,用于WM和Memory设备
#define GUI_WINSUPPORT 1 //窗口管理器要
#define GUI_SUPPORT_MEMDEV 1 //内存设备要
#define GUI_SUPPORT_AA 1 //抗锯齿要
(3)然后打开LCDConf.h配置
#define LCD_XSIZE (640) //屏幕宽
#define LCD_YSIZE (480) //屏幕高
#define LCD_BITSPERPIXEL (16) //RGB565
#define LCD_FIXEDPALETTE (565)
#define LCD_SWAP_RB 1//红蓝色反转
#define LCD_CONTROLLER -1//无控制器
#define LCD_SWAP_BYTE_ORDER 0//为了去掉warning
extern void screen_Init(void);
#define LCD_INIT_CONTROLLER() screen_Init(); //屏幕初始化函数,需要根据自己的板子写
(4)然后打开GUI/LCDDriver/LCDDummy.c修改
(5)修改LCD_L0_SetPixelIndex函数
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 */
{
putPixel(x,y,PixelIndex);//就添加这一句,在x,y位置用颜色pixelIndex画像素,需要实现putPixel
}
}
(6)修改 LCD_L0_GetPixelIndex函数
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 = getPixel(x,y);/* 就修改这一句,需要实现getPixel*/
}
return PixelIndex;
}
(7)还有就是CORE/LCD.h中基本数据类型,注意一下
(8)编译后会出现错误:
Error : L6218E: Undefined symbol main (referred from kernel.o).
百度了一下,说只需要添加个int main(){}空函数即可,不知道为什么,总之我的板子的汇编是跳到Main()函数的,所以在Main入口函数文件里添加个int main(){}即可
(9)添加测试代码
void Main(void){
GUI_Init();
GUI_DispString("hello world!\n");
}
int main(){}
就可以在屏幕0,0开始处打印hello world
(10)添加对话框测试代码,从别的地方搬来的:
#include "GUI.h"
#include "WM.h"
#include "DIALOG_Intern.h"
#include "FRAMEWIN.h"
#include "TEXT.h"
#include "LISTBOX.h"
/*********************************************************************
*
对话框可以基于阻塞(使用GUI_ExecDialogBox())或非阻塞(使用GUI_CreateDialogBox())
方式创建。必须首先定义一个资源表,以指定在对话框中所要包括的所有小工具。下面的示例说明了创
建资源表的方法:
对话框中所要包括的任何小工具都必须使用<WIDGET>_CreateIndirect()函数来间接创建。
*/
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
{ FRAMEWIN_CreateIndirect, "Dialog", 0, 10, 10, 180, 230, FRAMEWIN_CF_MOVEABLE, 0 },
{ BUTTON_CreateIndirect, "OK", GUI_ID_OK, 100, 5, 60, 20 },
{ BUTTON_CreateIndirect, "Cancel", GUI_ID_CANCEL, 100, 30, 60, 20 },
{ TEXT_CreateIndirect, "LText", 0, 10, 55, 48, 15, TEXT_CF_LEFT },
{ TEXT_CreateIndirect, "RText", 0, 10, 80, 48, 15, TEXT_CF_RIGHT },
{ EDIT_CreateIndirect, NULL, GUI_ID_EDIT0, 60, 55, 100, 15, 0, 50 },
{ EDIT_CreateIndirect, NULL, GUI_ID_EDIT1, 60, 80, 100, 15, 0, 50 },
{ TEXT_CreateIndirect, "Hex", 0, 10, 100, 48, 15, TEXT_CF_RIGHT },
{ EDIT_CreateIndirect, NULL, GUI_ID_EDIT2, 60, 100, 100, 15, 0, 6 },
{ TEXT_CreateIndirect, "Bin", 0, 10, 120, 48, 15, TEXT_CF_RIGHT },
{ EDIT_CreateIndirect, NULL, GUI_ID_EDIT3, 60, 120, 100, 15 },
{ LISTBOX_CreateIndirect, NULL, GUI_ID_LISTBOX0,10, 10, 48, 40 },
{ CHECKBOX_CreateIndirect, NULL, GUI_ID_CHECK0, 10, 140, 0, 0 },
{ CHECKBOX_CreateIndirect, NULL, GUI_ID_CHECK1, 30, 140, 0, 0 },
{ SLIDER_CreateIndirect, NULL, GUI_ID_SLIDER0, 60, 140, 100, 20 },
{ SLIDER_CreateIndirect, NULL, GUI_ID_SLIDER1, 10, 170, 150, 30 }
};
/*********************************************************************
*
对话框过程函数
上述示例使用如下所示的空白对话框过程函数创建。在创建任何对话框过程函数时,该基本模板都将
作为起始点:
*/
static void _cbCallback(WM_MESSAGE * pMsg) {
switch (pMsg->MsgId) {
default:
WM_DefaultProc(pMsg);
}
}
/*********************************************************************
*
* MainTask
*/
void Fun(void) {
//对于该示例,对话框显示时会有下列代码行:
GUI_ExecDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate),&_cbCallback, 0, 0, 0);
}
/*
创建对话框后,所有资源表中的小工具都将可见。尽管这些小工具在上面的屏幕截图中可见,但它们
是以 “空”的形式出现的。这是因为对话框过程函数尚未包含初始化单个元素的代码。小工具的初始
值、由它们所引起的行为以及它们之间的交互作用都需要在对话框过程中进行定义。
*/
void Main(void){
GUI_Init();
Fun();
}
int main(){}
(11)效果图:
(12)触摸屏,汉字,鼠标以后再说