1. 程式人生 > >STM32F407+STemwin學習筆記之STemwin移植

STM32F407+STemwin學習筆記之STemwin移植

byte 裸機 測試程序 AC class create temp png check

原文鏈接: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移植