码迷,mamicode.com
首页 > Windows程序 > 详细

STM32F407+STemwin学习笔记之STemwin移植

时间:2018-04-15 21:06:38      阅读:2229      评论:0      收藏:0      [点我收藏+]

标签:触摸屏   fine   blank   into   bytes   测试程序   log   scree   结束   

原文链接: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/1rUxgjQwQPY0-m_AEOFXMrw 密码:fzp8),LCD的空工程(带有LCD画点,读点函数)。

开始移植

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

技术分享图片

打开目录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。

将留下的文件添加进工程,并包含头文件路径。
技术分享图片

留下的文件如图所示。

第二步,修改部分文件,

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

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

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

 1 #ifndef GUICONF_H
 2 #define GUICONF_H
 3 
 4 //Multi layer/display support
 5 #define GUI_NUM_LAYERS            2    // Maximum number of available layers
 6 
 7 //Multi tasking support
 8 #ifdef OS_SUPPORT
 9  #define GUI_OS                    (1)  // Compile with multitasking support
10 #else
11  #define GUI_OS                    (0)
12 #endif
13 
14 //Configuration of touch suppor
15 #ifndef   GUI_SUPPORT_TOUCH
16   #define GUI_SUPPORT_TOUCH       (1)  // Support touchscreen
17 #endif
18 
19 //Default font
20 #define GUI_DEFAULT_FONT          &GUI_Font6x8
21 
22 //Configuration of available packages
23 #define GUI_SUPPORT_MOUSE             (1)    /* Support a mouse */
24 #define GUI_WINSUPPORT                (1)    /* Use window manager */
25 #define GUI_SUPPORT_MEMDEV            (1)    /* Memory device package available */
26 #define GUI_SUPPORT_DEVICES           (1)    /* Enable use of device pointers */
27 
28 #endif  /* Avoid multiple inclusion */

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

 1 /*********************************************************************
 2 *
 3 *       _SetPixelIndex
 4 *
 5 * Purpose:
 6 *   Sets the index of the given pixel. The upper layers
 7 *   calling this routine make sure that the coordinates are in range, so
 8 *   that no check on the parameters needs to be performed.
 9 */
10 static void _SetPixelIndex(GUI_DEVICE * pDevice, int x, int y, int PixelIndex) {
11     //
12     // Convert logical into physical coordinates (Dep. on LCDConf.h)
13     //
14     #if (LCD_MIRROR_X == 1) || (LCD_MIRROR_Y == 1) || (LCD_SWAP_XY == 1)
15       int xPhys, yPhys;
16 
17       xPhys = LOG2PHYS_X(x, y);
18       yPhys = LOG2PHYS_Y(x, y);
19     #else
20       #define xPhys x
21       #define yPhys y
22     #endif
23     GUI_USE_PARA(pDevice);
24     GUI_USE_PARA(x);
25     GUI_USE_PARA(y);
26     GUI_USE_PARA(PixelIndex);
27     {
28         lcd_drawpoint(xPhys,yPhys,PixelIndex);  //2018/04/15-18:47:44  By Nick
29     }
30     #if (LCD_MIRROR_X == 0) && (LCD_MIRROR_Y == 0) && (LCD_SWAP_XY == 0)
31       #undef xPhys
32       #undef yPhys
33     #endif
34 }
35 
36 /*********************************************************************
37 *
38 *       _GetPixelIndex
39 *
40 * Purpose:
41 *   Returns the index of the given pixel. The upper layers
42 *   calling this routine make sure that the coordinates are in range, so
43 *   that no check on the parameters needs to be performed.
44 */
45 static unsigned int _GetPixelIndex(GUI_DEVICE * pDevice, int x, int y) {
46   unsigned int PixelIndex;
47     //
48     // Convert logical into physical coordinates (Dep. on LCDConf.h)
49     //
50     #if (LCD_MIRROR_X == 1) || (LCD_MIRROR_Y == 1) || (LCD_SWAP_XY == 1)
51       int xPhys, yPhys;
52 
53       xPhys = LOG2PHYS_X(x, y);
54       yPhys = LOG2PHYS_Y(x, y);
55     #else
56       #define xPhys x
57       #define yPhys y
58     #endif
59     GUI_USE_PARA(pDevice);
60     GUI_USE_PARA(x);
61     GUI_USE_PARA(y);
62     {
63         PixelIndex = lcd_read_gram(xPhys,yPhys);  //2018/04/15-18:47:29  By Nick
64     }
65     #if (LCD_MIRROR_X == 0) && (LCD_MIRROR_Y == 0) && (LCD_SWAP_XY == 0)
66       #undef xPhys
67       #undef yPhys
68     #endif
69   return PixelIndex;
70 }

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

 1 #include "Nick_lcd.h" 
 2 #include "GUI.h"
 3 #include "GUIDRV_FlexColor.h"
 4 
 5 
 6 u16 XSIZE_PHYS,YSIZE_PHYS,VXSIZE_PHYS,VYSIZE_PHYS;  //2018/04/15-18:48:10  By Nick
 7 
 8 #ifndef   GUICC_565
 9   #error Color conversion not defined!
10 #endif
11 #ifndef   GUIDRV_FLEXCOLOR
12   #error No display driver defined!
13 #endif
14 
15 void LCD_X_Config(void) {              //2018/04/15-18:48:24  By Nick
16     // Physical display size
17     XSIZE_PHYS  = lcddev.width;// To be adapted to x-screen size   240
18     YSIZE_PHYS  = lcddev.height; // To be adapted to y-screen size 320
19     VXSIZE_PHYS = XSIZE_PHYS;
20     VYSIZE_PHYS = YSIZE_PHYS;
21     GUI_DEVICE_CreateAndLink(&GUIDRV_Template_API,GUICC_M565,0,0);
22     LCD_SetSizeEx(0,XSIZE_PHYS,YSIZE_PHYS);
23     LCD_SetVSizeEx(0,VXSIZE_PHYS,VYSIZE_PHYS);
24 }
25 
26 
27 int LCD_X_DisplayDriver(unsigned LayerIndex, unsigned Cmd, void * pData) {
28   int r;
29   (void) LayerIndex;
30   (void) pData;
31   
32   switch (Cmd) {
33   case LCD_X_INITCONTROLLER: {
34     return 0;
35   }
36   default:
37     r = -1;
38   }
39   return r;
40 }

在此,修改已完成。

第三步,编写测试程序。

#include "stm32f4xx_conf.h"
#include "GUI.h"
#include "Nick_lcd.h"

int main(void)
{ 
    lcd_init(0);        //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",10,10); 
}

到此可以看到现象。如图

技术分享图片

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

 

STM32F407+STemwin学习笔记之STemwin移植

标签:触摸屏   fine   blank   into   bytes   测试程序   log   scree   结束   

原文地址:https://www.cnblogs.com/NickQ/p/8748011.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!