原文链接:http://www.cnblogs.com/NickQ/p/8748011.html

环境:keil5.20  STM32F407ZGT6  LCD(320*240)  STemwin:STemWin_Library_V1.1.2

准备:

STemWIn在裸机上的移植,需要准备STemwin的库( STemwin:STemWin_Library_V1.1.2.rar  链接:https://pan.baidu.com/s/1ekMm-X7RG5JK185GnV9fFw

提取码:peup ),LCD的空工程(带有LCD画点,读点函数)。

开始移植

第一步:解压STemWin_Library_V1.1.2.rar,目录结构如下

STM32F407+STemwin学习笔记之STemwin移植-LMLPHP

打开目录STemWin_Library_V1.1.2\Libraries\STemWinLibrary522,复制Config,inc,OS,LIB四个目录到工程文件夹中

删除Config中LCDConf_Lin_Template.c,LCDConf_Lin_Template.h文件。

根据需要保留LIB中文件,删除其他文件。此处使用CM4内核的F407,Keil IDE,保留STemWin522_CM4_Keil.lib。

根据是否使用OS,保留OS文件夹中相应文件。此处不使用OS,保留GUI_X.c。

将留下的文件添加进工程,并包含头文件路径。
STM32F407+STemwin学习笔记之STemwin移植-LMLPHP

留下的文件如图所示。

第二步,修改部分文件,

修改GUIConf.c   修改分配给GUI的内存大小,此处为16K

 // Define the available number of bytes available for the GUI
#define GUI_NUMBYTES 0x4000 //16KB 2018/04/15-17:52:54 By Nick

修改GUIConf.h   配置GUI相关功能

 #ifndef GUICONF_H
#define GUICONF_H //Multi layer/display support
#define GUI_NUM_LAYERS 2 // Maximum number of available layers //Multi tasking support
#ifdef OS_SUPPORT
#define GUI_OS (1) // Compile with multitasking support
#else
#define GUI_OS (0)
#endif //Configuration of touch suppor
#ifndef GUI_SUPPORT_TOUCH
#define GUI_SUPPORT_TOUCH (1) // Support touchscreen
#endif //Default font
#define GUI_DEFAULT_FONT &GUI_Font6x8 //Configuration of available packages
#define GUI_SUPPORT_MOUSE (1) /* Support a mouse */
#define GUI_WINSUPPORT (1) /* Use window manager */
#define GUI_SUPPORT_MEMDEV (1) /* Memory device package available */
#define GUI_SUPPORT_DEVICES (1) /* Enable use of device pointers */ #endif /* Avoid multiple inclusion */

修改GUIDRV_Template.c   修改画点和读点函数,注意要引入自己的LCD头文件

 /*********************************************************************
*
* _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.
*/
static void _SetPixelIndex(GUI_DEVICE * pDevice, int x, int y, int PixelIndex) {
//
// Convert logical into physical coordinates (Dep. on LCDConf.h)
//
#if (LCD_MIRROR_X == 1) || (LCD_MIRROR_Y == 1) || (LCD_SWAP_XY == 1)
int xPhys, yPhys; xPhys = LOG2PHYS_X(x, y);
yPhys = LOG2PHYS_Y(x, y);
#else
#define xPhys x
#define yPhys y
#endif
GUI_USE_PARA(pDevice);
GUI_USE_PARA(x);
GUI_USE_PARA(y);
GUI_USE_PARA(PixelIndex);
{
lcd_drawpoint(xPhys,yPhys,PixelIndex); //2018/04/15-18:47:44 By Nick
}
#if (LCD_MIRROR_X == 0) && (LCD_MIRROR_Y == 0) && (LCD_SWAP_XY == 0)
#undef xPhys
#undef yPhys
#endif
} /*********************************************************************
*
* _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.
*/
static unsigned int _GetPixelIndex(GUI_DEVICE * pDevice, int x, int y) {
unsigned int PixelIndex;
//
// Convert logical into physical coordinates (Dep. on LCDConf.h)
//
#if (LCD_MIRROR_X == 1) || (LCD_MIRROR_Y == 1) || (LCD_SWAP_XY == 1)
int xPhys, yPhys; xPhys = LOG2PHYS_X(x, y);
yPhys = LOG2PHYS_Y(x, y);
#else
#define xPhys x
#define yPhys y
#endif
GUI_USE_PARA(pDevice);
GUI_USE_PARA(x);
GUI_USE_PARA(y);
{
PixelIndex = lcd_read_gram(xPhys,yPhys); //2018/04/15-18:47:29 By Nick
}
#if (LCD_MIRROR_X == 0) && (LCD_MIRROR_Y == 0) && (LCD_SWAP_XY == 0)
#undef xPhys
#undef yPhys
#endif
return PixelIndex;
}

修改 GUIDRV_FlexColor.c文件  配置屏幕尺寸(此处为320*240),可以用宏,Nick在此不用宏的原因是方便LCD初始化函数自动识别屏幕后,传递给GUI

 #include "Nick_lcd.h"
#include "GUI.h"
#include "GUIDRV_FlexColor.h" u16 XSIZE_PHYS,YSIZE_PHYS,VXSIZE_PHYS,VYSIZE_PHYS; //2018/04/15-18:48:10 By Nick #ifndef GUICC_565
#error Color conversion not defined!
#endif
#ifndef GUIDRV_FLEXCOLOR
#error No display driver defined!
#endif void LCD_X_Config(void) { //2018/04/15-18:48:24 By Nick
// Physical display size
XSIZE_PHYS = lcddev.width;// To be adapted to x-screen size 240
YSIZE_PHYS = lcddev.height; // To be adapted to y-screen size 320
VXSIZE_PHYS = XSIZE_PHYS;
VYSIZE_PHYS = YSIZE_PHYS;
GUI_DEVICE_CreateAndLink(&GUIDRV_Template_API,GUICC_M565,,);
LCD_SetSizeEx(,XSIZE_PHYS,YSIZE_PHYS);
LCD_SetVSizeEx(,VXSIZE_PHYS,VYSIZE_PHYS);
} int LCD_X_DisplayDriver(unsigned LayerIndex, unsigned Cmd, void * pData) {
int r;
(void) LayerIndex;
(void) pData; switch (Cmd) {
case LCD_X_INITCONTROLLER: {
return ;
}
default:
r = -;
}
return r;
}

在此,修改已完成。

第三步,编写测试程序。

#include "stm32f4xx_conf.h"
#include "GUI.h"
#include "Nick_lcd.h" int main(void)
{
lcd_init(); //LCD初始化
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_CRC,ENABLE);//使能CRC时钟,否则STemWin不能使用
GUI_Init(); GUI_SetColor(GUI_RED);
GUI_SetBkColor(GUI_BLUE);
GUI_SetFont(&GUI_Font24_ASCII);
GUI_Clear();
GUI_DispStringAt("Hello World",,);
}

到此可以看到现象。如图

STM32F407+STemwin学习笔记之STemwin移植-LMLPHP

当然,到此STemwin移植就结束了。下一篇将添加触摸屏点击功能。

05-22 18:36