STM32F7之ST-EMWIN入手stm32f7开发板已有数日了,经过两天的奋斗终于成功运行ST-EMWIN+RTOS。其实最方便快捷的办法是直接从st官网给的例程来修改就好了。想自己建工程的朋友就花点儿时间自己建工程吧。废话不多说了。。。。。
上面是整个工程包含的文件(注意:xbf是字库文件,放在是的卡中然后加载到系统中的)
这就是project里面的文件。
整个工程相对来说是比较大的
1.首先在GUIDEMO_START.C里面添加上
#include "ff.h"
#include "ff_gen_drv.h"
#include "sd_diskio.h"
#include "GUI.h"
#include "DIALOG.h"
#include "WM.h"
#include "BUTTON.h"
#include "CHECKBOX.h"
#include "DROPDOWN.h"
#include "EDIT.h"
#include "FRAMEWIN.h"
#include "LISTBOX.h"
#include "MULTIEDIT.h"
#include "RADIO.h"
#include "SLIDER.h"
#include "TEXT.h"
#include "PROGBAR.h"
#include "SCROLLBAR.h"
#include "LISTVIEW.h"
#include "GRAPH.h"
#include "MENU.h"
#include "MULTIPAGE.h"
#include "ICONVIEW.h"
#include "TREEVIEW.h"
#include "GUIDEMO.h"
//
为了方便此UI界面是移植安富莱智的,其实整个界面就是通过加载图片实现的。
WM_HWIN hWinInfo; /* 通过ICONVIEW所打开窗口的句柄 */
WM_HWIN hWinICON;
/* ICONVIEW控件句柄 */
WM_HWIN hWinMain; /* 主窗口句柄, ICONVIEW控件建立在这个窗口上面 */
uint8_t s_ucSelIconIndex = 0; /* 选择的ICON,默认不选择任何 */
#define MSG_SetENTER (GUI_ID_USER + 0x0E)
#define MSG_SetICONFocus (GUI_ID_USER + 0x0F)
#define MSG_Delect (GUI_ID_USER + 0x10)
//extern GUI_CONST_STORAGE GUI_FONT GUI_FontYahei;
extern GUI_CONST_STORAGE GUI_FONT GUI_FontYahei;
extern GUI_CONST_STORAGE GUI_BITMAP bma;
//引用外部定义
extern GUI_CONST_STORAGE GUI_BITMAP bmb;
extern GUI_CONST_STORAGE GUI_BITMAP bmc;
extern GUI_CONST_STORAGE GUI_BITMAP bmd;
extern GUI_CONST_STORAGE GUI_BITMAP bme;
extern GUI_CONST_STORAGE GUI_BITMAP bmf;
extern GUI_CONST_STORAGE GUI_BITMAP bmg;
extern GUI_CONST_STORAGE GUI_BITMAP bmh;
extern GUI_CONST_STORAGE GUI_BITMAP bmi;
extern GUI_CONST_STORAGE GUI_BITMAP bmj;
/* ????ICONVIEW????? */
typedef struct
{
const GUI_BITMAP * pBitmap;
const char * pText;
} BITMAP_ITEM;
GUI_CONST_STORAGE GUI_BITMAP bmTopLine = {
480, // xSize
44, // ySize
1920, // BytesPerLine
32, // BitsPerPixel
(unsigned char *)_acTopLine, // Pointer to picture data
NULL, // Pointer to palette
GUI_DRAW_BMP8888
};
/* 这里就是关键,从sd卡中加载字库 */
GUI_XBF_DATA XBF_Data;
GUI_FONT XBF_Font;
FIL Fontfile;
FRESULT result;
unsigned int mybr, mybw;
int t=2;
FATFS SDFatFs;
char SDPath[4];
static int _cbGetData(U32 Off, U16 NumBytes, void * pVoid, void * pBuffer)
{
FIL *FontFile;
/* ???? */
FontFile = (FIL *)pVoid;
/*
* ??????
*/
result =f_lseek(FontFile, Off);
if (result != FR_OK)
{
return 1;
}
/*
* ?????buffer
*/
result = f_read(FontFile, pBuffer, NumBytes, &mybr);
if (result != FR_OK)
{
return 1;
}
return 0;
}
static void _ShowXBF(void)
{
if(FATFS_LinkDriver(&SD_Driver, SDPath) == 0)
{
if(f_mount(&SDFatFs, (TCHAR const*)SDPath, 0) == FR_OK)
{
if(f_open(&Fontfile, "YAHE14.xbf", FA_OPEN_EXISTING | FA_READ | FA_OPEN_ALWAYS)!= FR_OK)
{
BSP_LED_On(LED1);//fail
}
}
}
if (result != FR_OK)
{
return;
}
/* ??XBF?? */
GUI_XBF_CreateFont(&XBF_Font,
&XBF_Data,
GUI_XBF_TYPE_PROP_AA4_EXT,
_cbGetData,
&Fontfile);
}
// FATFS_UnLinkDriver(SDPath);
/* ????ICONVIEW????? */
static const BITMAP_ITEM _aBitmapItem[] =
{
{&bma, "视频监控"},
{&bmb, "灯光控制"},
{&bmc, "智能门窗"},
{&bmd, "电器控制"},
{&bme, "信息查询"},
{&bmf, "安防报警"},
{&bmg, "背景音乐"},
{&bmh, "情景模式"},
{&bmi, "定时管理"},
{&bmj, "系统设置"},
};
/*********************************************************************
*
* Defines
*
**********************************************************************
*/
#define ID_WINDOW_0 (GUI_ID_USER + 0x00)
#define ID_FRAMEWIN_0 (GUI_ID_USER + 0x01)
#define ID_GRAPH_0 (GUI_ID_USER + 0x02)
#define ID_TEXT_0 (GUI_ID_USER + 0x03)
#define ID_TEXT_1 (GUI_ID_USER + 0x04)
#define ID_TEXT_2 (GUI_ID_USER + 0x05)
#define ID_TEXT_3 (GUI_ID_USER + 0x06)
#define ID_TEXT_4 (GUI_ID_USER + 0x07)
#define ID_TEXT_5 (GUI_ID_USER + 0x08)
#define ID_TEXT_6 (GUI_ID_USER + 0x09)
#define ID_TEXT_7 (GUI_ID_USER + 0x0A)
#define ID_TEXT_8 (GUI_ID_USER + 0x0B)
#define ID_TEXT_9 (GUI_ID_USER + 0x0C)
#define ID_TEXT_10 (GUI_ID_USER + 0x0D)
#define ID_TimerTime 1
// USER START (Optionally insert additional defines)
// USER END
/*********************************************************************
*
* Static data
*
**********************************************************************
*/
// USER START (Optionally insert additional static data)
// USER END
/*********************************************************************
*
* _aDialogCreate
*/
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] =
{
{ WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 480, 272, 0, 0x0, 0 },
{ TEXT_CreateIndirect, "智能家居", ID_TEXT_0, 130, 10, 200, 20, 0, 0x64, 0 },
};
static const GUI_WIDGET_CREATE_INFO _aDialogCreate1[] = {
{ FRAMEWIN_CreateIndirect, "Caption", 0, 0, 0, 480,272,0,0},
{ SLIDER_CreateIndirect, NULL, GUI_ID_SLIDER0, 115,56, 248,46, 0,0},
{ BUTTON_CreateIndirect, "BUTTON0", GUI_ID_BUTTON0, 115,143,248,32, 0,0}
};
void InitDialog(WM_MESSAGE * pMsg)
{
WM_HWIN hWin = pMsg->hWin;
_ShowXBF();
GUI_UC_SetEncodeUTF8();
TEXT_SetTextColor(WM_GetDialogItem(hWin,ID_TEXT_0), GUI_RED);
TEXT_SetFont(WM_GetDialogItem(hWin,ID_TEXT_0),&XBF_Font);
//这里就是从sd加载字体,并且对相应的字体进行设置
}
/*
*********************************************************************************************************
* ? ? ?: _cbCallback1
* ????: ????
* ? ?:pMsg ????
* ? ? ?:
*********************************************************************************************************
*/
static void _cbCallback1(WM_MESSAGE * pMsg)
{
int NCode, Id;
WM_HWIN hWin = pMsg->hWin;
switch (pMsg->MsgId)
{
case WM_PAINT:
break;
case WM_INIT_DIALOG:
// InitDialog(pMsg);
break;
case WM_KEY:
switch (((WM_KEY_INFO*)(pMsg->Data.p))->Key)
{
case GUI_KEY_ESCAPE:
GUI_EndDialog(hWin, 1);
break;
case GUI_KEY_ENTER:
GUI_EndDialog(hWin, 0);
break;
}
break;
case WM_NOTIFY_PARENT:
Id = WM_GetId(pMsg->hWinSrc);
NCode = pMsg->Data.v;
switch (Id)
{
case GUI_ID_OK:
if(NCode==WM_NOTIFICATION_RELEASED)
GUI_EndDialog(hWin, 0);
break;
case GUI_ID_CANCEL:
if(NCode==WM_NOTIFICATION_RELEASED)
GUI_EndDialog(hWin, 0);
break;
}
break;
default:
WM_DefaultProc(pMsg);
}
}
static void _cbDialog(WM_MESSAGE * pMsg)
{
//WM_HWIN hItem;
WM_MESSAGE pMsgInfo;
int NCode, Id;
switch (pMsg->MsgId)
{
case WM_PAINT:
GUI_DrawGradientH(0, 44, 240- 1, 272 - 44, 0xdda0dd, 0xe14169);
GUI_DrawGradientH(240, 44, 480-1, 272-44, 0xe14169, 0xdda0dd);
GUI_DrawBitmap(&bmButtonLine, 0, 272-44);
GUI_DrawBitmap(&bmTopLine, 0, 0);
break;
case WM_INIT_DIALOG:
// hItem = pMsg->hWin;
InitDialog(pMsg);
/* ???? */
// hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_0);
// TEXT_SetTextColor(hItem, GUI_WHITE);
//TEXT_SetFont(hItem, &GUI_FontRounded16);
//TEXT_SetText(hItem, "????STemWin???");
break;
case WM_TIMER:
WM_RestartTimer(pMsg->Data.v, 1000);
break;
/* 发送按下的消息 */
case MSG_SetENTER:
pMsgInfo.MsgId = WM_NOTIFY_PARENT;
pMsgInfo.hWinSrc = hWinICON;
pMsgInfo.Data.v = WM_NOTIFICATION_RELEASED;
WM_SendMessage(pMsg->hWin, &pMsgInfo);
break;
/* 设置ICON的聚焦 */
case MSG_SetICONFocus:
WM_SetFocus(hWinICON);
break;
/* 删除通过ICON创建的对话框 */
case MSG_Delect:
WM_DeleteWindow(hWinInfo);
break;
case WM_NOTIFY_PARENT:
Id = WM_GetId(pMsg->hWinSrc); /* Id of widget */
NCode = pMsg->Data.v; /* Notification code */
switch (Id)
{
/* 点击ICONVIEW上相应的图标,打开相应的窗口 */
case GUI_ID_ICONVIEW0:
switch (NCode)
{
case WM_NOTIFICATION_RELEASED:
s_ucSelIconIndex = ICONVIEW_GetSel(pMsg->hWinSrc);
switch( ICONVIEW_GetSel(pMsg->hWinSrc))
{
/* 视频监控 */
case 0:
hWinInfo = GUI_CreateDialogBox(_aDialogCreate1, GUI_COUNTOF(_aDialogCreate1), &_cbCallback1, 0, 0, 0);
break;
/* 灯光控制 */
case 1:
hWinInfo = GUI_CreateDialogBox(_aDialogCreate1, GUI_COUNTOF(_aDialogCreate1), &_cbCallback1, 0, 0, 0);
break;
/* 智能门窗 */
case 2:
hWinInfo = GUI_CreateDialogBox(_aDialogCreate1, GUI_COUNTOF(_aDialogCreate1), &_cbCallback1, 0, 0, 0);
break;
/* 电器控制 */
case 3:
hWinInfo = GUI_CreateDialogBox(_aDialogCreate1, GUI_COUNTOF(_aDialogCreate1), &_cbCallback1, 0, 0, 0);
break;
/* 信息查询 */
case 4:
hWinInfo = GUI_CreateDialogBox(_aDialogCreate1, GUI_COUNTOF(_aDialogCreate1), &_cbCallback1, 0, 0, 0);
break;
/* 安防报警 */
case 5:
hWinInfo = GUI_CreateDialogBox(_aDialogCreate1, GUI_COUNTOF(_aDialogCreate1), &_cbCallback1, 0, 0, 0);
break;
/* 背景音乐 */
case 6:
hWinInfo = GUI_CreateDialogBox(_aDialogCreate1, GUI_COUNTOF(_aDialogCreate1), &_cbCallback1, 0, 0, 0);
break;
/* 情景模式 */
case 7:
hWinInfo = GUI_CreateDialogBox(_aDialogCreate1, GUI_COUNTOF(_aDialogCreate1), &_cbCallback1, 0, 0, 0);
break;
/* 定时管理 */
case 8:
hWinInfo = GUI_CreateDialogBox(_aDialogCreate1, GUI_COUNTOF(_aDialogCreate1), &_cbCallback1, 0, 0, 0);
break;
/* 系统设置 */
case 9:
hWinInfo = GUI_CreateDialogBox(_aDialogCreate1, GUI_COUNTOF(_aDialogCreate1), &_cbCallback1, 0, 0, 0);
break;
default:
break;
}
break;
}
break;
}
break;
default:
WM_DefaultProc(pMsg);
}
}
void MainTask(void)
{
int i;
//WM_SetCreateFlags(WM_CF_MEMDEV);
//GUI_Init();
GUI_Clear();
WM_SetDesktopColor(GUI_BLUE);
FRAMEWIN_SetDefaultSkin(FRAMEWIN_SKIN_FLEX);
PROGBAR_SetDefaultSkin(PROGBAR_SKIN_FLEX);
FRAMEWIN_SetDefaultSkin(FRAMEWIN_SKIN_FLEX);
PROGBAR_SetDefaultSkin(PROGBAR_SKIN_FLEX);
BUTTON_SetDefaultSkin(BUTTON_SKIN_FLEX);
CHECKBOX_SetDefaultSkin(CHECKBOX_SKIN_FLEX);
DROPDOWN_SetDefaultSkin(DROPDOWN_SKIN_FLEX);
SCROLLBAR_SetDefaultSkin(SCROLLBAR_SKIN_FLEX);
SLIDER_SetDefaultSkin(SLIDER_SKIN_FLEX);
HEADER_SetDefaultSkin(HEADER_SKIN_FLEX);
RADIO_SetDefaultSkin(RADIO_SKIN_FLEX);
/* 使能UTF-8解码用于汉字显示 */
GUI_UC_SetEncodeUTF8();
hWinMain = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
/*在指定位置创建指定尺寸的ICONVIEW 小工具*/
hWinICON = ICONVIEW_CreateEx(20, /* 小工具的最左像素(在父坐标中)*/
45, /* 小工具的最上像素(在父坐标中)*/
440, /* 小工具的水平尺寸(单位:像素)*/
200, /* 小工具的垂直尺寸(单位:像素)*/
hWinMain, /* 父窗口的句柄。如果为0 ,则新小工具将成为桌面(顶级窗口)的子窗口 */
WM_CF_SHOW | WM_CF_HASTRANS, /* 窗口创建标记。为使小工具立即可见,通常使用 WM_CF_SHOW */
0,//ICONVIEW_CF_AUTOSCROLLBAR_V, /* 默认是0,如果不够现实可设置增减垂直滚动条 */
GUI_ID_ICONVIEW0, /* 小工具的窗口ID */
82, /* 图标的水平尺寸 */
80);/* 图标的垂直尺寸 */
/* 向ICONVIEW 小工具添加新图标 */
for (i = 0; i < GUI_COUNTOF(_aBitmapItem); i++)
{
ICONVIEW_AddBitmapItem(hWinICON, _aBitmapItem
.pBitmap, _aBitmapItem.pText);
}
/* 设置小工具的背景色 32 位颜色值的前8 位可用于alpha混合处理效果*/
ICONVIEW_SetBkColor(hWinICON, ICONVIEW_CI_SEL, GUI_WHITE | 0x80000000);
/* 设置字体 */
_ShowXBF();
GUI_Delay(8);
ICONVIEW_SetFont(hWinICON, &XBF_Font);//这里一定要设置为从sd card加载的字体
/* 设置图标在x 或y 方向上的间距。*/
ICONVIEW_SetSpace(hWinICON, GUI_COORD_Y, 10);
/* 设置对齐方式 在5.22版本中最新加入的 */
ICONVIEW_SetIconAlign(hWinICON, ICONVIEW_IA_HCENTER|ICONVIEW_IA_TOP);
WM_CreateTimer(WM_GetClientWindow(hWinMain), /* 接受信息的窗口的句柄 */
ID_TimerTime, /* 用户定义的Id。如果不对同一窗口使用多个定时器,此值可以设置为零。 */
20, /* 周期,此周期过后指定窗口应收到消息*/
0); /* 留待将来使用,应为0 */
/*******************************************华丽的分割线********************************************************/
上图啦。。。。。。。。。。。。这是通过软件模拟的,我是先通过软件模拟通过之后再一直到单片机,这样不用总是不停地下载程序来调试。
下面就是一步步从无到显示界面
最后还是要感谢eeword为我们提供的这次机会,让我们学到了很多东西。
再补充下我的字库使用fontcvdemon.exe生成的他可以生成.c/.xbf/.sif字体,图片的话就用bmpcvt.exe就可以转成.c文件了。
/**********************************THE END****************************************/
源码:http://pan.baidu.com/s/1bnbRwkB
本帖最后由 brantsun 于 2015-10-12 13:32 编辑