4520|5

553

帖子

3

TA的资源

纯净的硅(初级)

楼主
 

STM32F769I-DISCO评测【7】——将STemwin移植到 STM32F769I-DISCO上 [复制链接]

移植之前先上一张效果图,开发板第一次显示这张图片的时候确实很开心,因为这是第一次接触emwin。移植过程是参考的正点原子的emwin的移植手册,手册上是以767为蓝本而写的。看看我们应该怎么把emwin移植到我们的769上。





移植前的准备工作:
1、一个带lcd驱动的可以编译通过的MDK5.14以上版本(其他版本我没有试过)的工程。(我的工程文件太大,无法上传附件)
2、STemwin的源文件
3、DSP库,这个在HAL的库里有。(本次的程序并没有用到DSP库)

一、找到DSP库的位置
文件位置:STM32Cube_FW_F7_V1.5.0\Drivers\CMSIS



二、找到stemwin源文件位置

文件位置:STM32Cube_FW_F7_V1.5.0\Middlewares\ST\STemWin



三、开始移植

1、在我的工程文件夹下新建一个DSP_LIB的文件夹,然后将我们可能会用到的dsp库复制的这个文件夹中,文件目录:STM32Cube_FW_F7_V1.5.0\Drivers\CMSIS\Lib\ARM,里面有6个dsp库,我们只选择最后一个复制到我们的DSP_LIB文件夹下,因为其他的我们都用不到。



然后将文件夹添加到我们的MDK工程,添加后如下图所示:


如果要使用DSP库,还需要添加四个宏:
__CC_ARM,ARM_MATH_MATRIX_CHECK,ARM_MATH_ROUNDING,__FPU_RPESENT=1



到此为止,dsp就已经添加进工程中了。

2、添加STemWin源文件到工程中。

STemwin包含6个文件夹:


我们在工程目录下新建EMWIN文件夹,然后将STEMWIN源码添加到文件夹中,再向工程中添加STTEMWIN和相关头文件:


删掉一些不用的文件夹:


Lib文件夹下只保留2个文件,其余的都删掉:


完成以上操作就可以进行编译了,编译会提示错误,提示LCDConf.h没有定义,然后我们新建一个LCDConf.h文件放到STEMWIN源码目录下的Config文件夹下然后添加到工程,LCDConf.h文件里不需要写任何内容,再编译应该没有这个错误,可能会还有其他错误,根据具体情况修改错误,直到编译通过。
(说明:在这个过程中我遇到了很多错误,主要是2个方面的错误:1、分给GUI的内存太大,超出了769芯片的内存,会报一大堆乱七八糟的错误,解决方法只需要减小分给GUI的内存即可;2、提示GUI_X_Config()重定义,解决方法是从工程中移除LCDConf_Lin_Template.c文件,切记工程中不要添加LCDConf_Lin_Template.c文件)


3、修改工程文件

1)修改GUIConfig.h文件如下:
(红色为修改的地方)
  1. /*********************************************************************
  2. *          Portions COPYRIGHT 2016 STMicroelectronics                *
  3. *          Portions SEGGER Microcontroller GmbH & Co. KG             *
  4. *        Solutions for real time microcontroller applications        *
  5. **********************************************************************
  6. *                                                                    *
  7. *        (c) 1996 - 2015  SEGGER Microcontroller GmbH & Co. KG       *
  8. *                                                                    *
  9. *        Internet: www.segger.com    Support:  support@segger.com    *
  10. *                                                                    *
  11. **********************************************************************

  12. ** emWin V5.32 - Graphical user interface for embedded applications **
  13. All  Intellectual Property rights  in the Software belongs to  SEGGER.
  14. emWin is protected by  international copyright laws.  Knowledge of the
  15. source code may not be used to write a similar product.  This file may
  16. only be used in accordance with the following terms:

  17. The  software has  been licensed  to STMicroelectronics International
  18. N.V. a Dutch company with a Swiss branch and its headquarters in Plan-
  19. les-Ouates, Geneva, 39 Chemin du Champ des Filles, Switzerland for the
  20. purposes of creating libraries for ARM Cortex-M-based 32-bit microcon_
  21. troller products commercialized by Licensee only, sublicensed and dis_
  22. tributed under the terms and conditions of the End User License Agree_
  23. ment supplied by STMicroelectronics International N.V.
  24. Full source code is available at: www.segger.com

  25. We appreciate your understanding and fairness.
  26. ----------------------------------------------------------------------
  27. File        : GUIConf.h
  28. Purpose     : Configures emWins abilities, fonts etc.
  29. ----------------------------------------------------------------------
  30. */

  31. /**
  32.   ******************************************************************************
  33.   * @attention
  34.   *
  35.   * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  36.   * You may not use this file except in compliance with the License.
  37.   * You may obtain a copy of the License at:
  38.   *
  39.   *        http://www.st.com/software_license_agreement_liberty_v2
  40.   *
  41.   * Unless required by applicable law or agreed to in writing, software
  42.   * distributed under the License is distributed on an "AS IS" BASIS,
  43.   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  44.   * See the License for the specific language governing permissions and
  45.   * limitations under the License.
  46.   *
  47.   ******************************************************************************
  48.   */

  49. #ifndef GUICONF_H
  50. #define GUICONF_H

  51. /*********************************************************************
  52. *
  53. *       Multi layer/display support
  54. */
  55. #define GUI_NUM_LAYERS            2    // Maximum number of available layers

  56. /*********************************************************************
  57. *
  58. *       Multi tasking support
  59. */
  60. #ifdef OS_SUPPORT
  61. #<font color="Red">define GUI_OS                    (0)</font>  // Compile with multitasking support
  62. #else
  63. #define GUI_OS                    (0)
  64. #endif

  65. /*********************************************************************
  66. *
  67. *       Configuration of touch support
  68. */
  69. #ifndef   GUI_SUPPORT_TOUCH
  70.   #define<font color="Red"> GUI_SUPPORT_TOUCH       (0) </font> // Support touchscreen
  71. #endif

  72. /*********************************************************************
  73. *
  74. *       Default font
  75. */
  76. #define GUI_DEFAULT_FONT          &GUI_Font6x8

  77. /*********************************************************************
  78. *
  79. *         Configuration of available packages
  80. */
  81. #define GUI_SUPPORT_MOUSE             (1)    /* Support a mouse */
  82. #define GUI_WINSUPPORT                (1)    /* Use window manager */
  83. #define GUI_SUPPORT_MEMDEV            (1)    /* Memory device package available */
  84. #define GUI_SUPPORT_DEVICES           (1)    /* Enable use of device pointers */

  85. #endif  /* Avoid multiple inclusion */
复制代码

2)修改GUIConfig.c文件如下:

  1. /*********************************************************************
  2. *          Portions COPYRIGHT 2016 STMicroelectronics                *
  3. *          Portions SEGGER Microcontroller GmbH & Co. KG             *
  4. *        Solutions for real time microcontroller applications        *
  5. **********************************************************************
  6. *                                                                    *
  7. *        (c) 1996 - 2015  SEGGER Microcontroller GmbH & Co. KG       *
  8. *                                                                    *
  9. *        Internet: www.segger.com    Support:  support@segger.com    *
  10. *                                                                    *
  11. **********************************************************************

  12. ** emWin V5.32 - Graphical user interface for embedded applications **
  13. All  Intellectual Property rights  in the Software belongs to  SEGGER.
  14. emWin is protected by  international copyright laws.  Knowledge of the
  15. source code may not be used to write a similar product.  This file may
  16. only be used in accordance with the following terms:

  17. The  software has  been licensed  to STMicroelectronics International
  18. N.V. a Dutch company with a Swiss branch and its headquarters in Plan-
  19. les-Ouates, Geneva, 39 Chemin du Champ des Filles, Switzerland for the
  20. purposes of creating libraries for ARM Cortex-M-based 32-bit microcon_
  21. troller products commercialized by Licensee only, sublicensed and dis_
  22. tributed under the terms and conditions of the End User License Agree_
  23. ment supplied by STMicroelectronics International N.V.
  24. Full source code is available at: www.segger.com

  25. We appreciate your understanding and fairness.
  26. ----------------------------------------------------------------------
  27. File        : GUIConf.c
  28. Purpose     : Display controller initialization
  29. ---------------------------END-OF-HEADER------------------------------
  30. */

  31. /**
  32.   ******************************************************************************
  33.   * @attention
  34.   *
  35.   * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  36.   * You may not use this file except in compliance with the License.
  37.   * You may obtain a copy of the License at:
  38.   *
  39.   *        http://www.st.com/software_license_agreement_liberty_v2
  40.   *
  41.   * Unless required by applicable law or agreed to in writing, software
  42.   * distributed under the License is distributed on an "AS IS" BASIS,
  43.   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  44.   * See the License for the specific language governing permissions and
  45.   * limitations under the License.
  46.   *
  47.   ******************************************************************************
  48.   */

  49. #include "GUI.h"

  50. /*********************************************************************
  51. *
  52. *       Defines
  53. *
  54. **********************************************************************
  55. */
  56. //
  57. // Define the available number of bytes available for the GUI
  58. //
  59. //#define GUI_NUMBYTES  0x200000
  60. <font color="Red">#define GUI_NUMBYTES  1024*5//</font>这就是分给GUI的内存,这个不能太大,否则会报错
  61. /*********************************************************************
  62. *
  63. *       Public code
  64. *
  65. **********************************************************************
  66. */
  67. /*********************************************************************
  68. *
  69. *       GUI_X_Config
  70. *
  71. * Purpose:
  72. *   Called during the initialization process in order to set up the
  73. *   available memory for the GUI.
  74. */
  75. void GUI_X_Config(void) {
  76.   //
  77.   // 32 bit aligned memory area
  78.   //
  79.   static U32 aMemory[GUI_NUMBYTES / 4];
  80.   //
  81.   // Assign memory to emWin
  82.   //
  83.   GUI_ALLOC_AssignMemory(aMemory, GUI_NUMBYTES);
  84.   //
  85.   // Set default font
  86.   //
  87.   GUI_SetDefaultFont(GUI_FONT_6X8);
  88. }

  89. /*************************** End of file ****************************/
复制代码

3)修改GUIDRV_Template.c文件

  1. /*********************************************************************
  2. *          Portions COPYRIGHT 2016 STMicroelectronics                *
  3. *          Portions SEGGER Microcontroller GmbH & Co. KG             *
  4. *        Solutions for real time microcontroller applications        *
  5. **********************************************************************
  6. *                                                                    *
  7. *        (c) 1996 - 2015  SEGGER Microcontroller GmbH & Co. KG       *
  8. *                                                                    *
  9. *        Internet: www.segger.com    Support:  support@segger.com    *
  10. *                                                                    *
  11. **********************************************************************

  12. ** emWin V5.32 - Graphical user interface for embedded applications **
  13. All  Intellectual Property rights  in the Software belongs to  SEGGER.
  14. emWin is protected by  international copyright laws.  Knowledge of the
  15. source code may not be used to write a similar product.  This file may
  16. only be used in accordance with the following terms:

  17. The  software has  been licensed  to STMicroelectronics International
  18. N.V. a Dutch company with a Swiss branch and its headquarters in Plan-
  19. les-Ouates, Geneva, 39 Chemin du Champ des Filles, Switzerland for the
  20. purposes of creating libraries for ARM Cortex-M-based 32-bit microcon_
  21. troller products commercialized by Licensee only, sublicensed and dis_
  22. tributed under the terms and conditions of the End User License Agree_
  23. ment supplied by STMicroelectronics International N.V.
  24. Full source code is available at: www.segger.com

  25. We appreciate your understanding and fairness.
  26. ----------------------------------------------------------------------
  27. File        : GUIDRV_Template.c
  28. Purpose     : Template driver, could be used as starting point for new
  29.               simple display drivers supporting only one color depth.
  30. ---------------------------END-OF-HEADER------------------------------
  31. */

  32. /**
  33.   ******************************************************************************
  34.   * @attention
  35.   *
  36.   * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  37.   * You may not use this file except in compliance with the License.
  38.   * You may obtain a copy of the License at:
  39.   *
  40.   *        http://www.st.com/software_license_agreement_liberty_v2
  41.   *
  42.   * Unless required by applicable law or agreed to in writing, software
  43.   * distributed under the License is distributed on an "AS IS" BASIS,
  44.   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  45.   * See the License for the specific language governing permissions and
  46.   * limitations under the License.
  47.   *
  48.   ******************************************************************************
  49.   */

  50. #include <stddef.h>

  51. #include "LCD_Private.h"
  52. #include "GUI_Private.h"
  53. #include "LCD_ConfDefaults.h"
  54. <font color="Red">#include "stm32f769i_discovery_lcd.h"</font>

  55. /*********************************************************************
  56. *
  57. *       Defines
  58. *
  59. **********************************************************************
  60. */
  61. /*********************************************************************
  62. *
  63. *       Macros for MIRROR_, SWAP_ and LUT_
  64. */
  65. #if (!defined (LCD_LUT_COM) && !defined(LCD_LUT_SEG))
  66.   #if   (!LCD_MIRROR_X && !LCD_MIRROR_Y && !LCD_SWAP_XY)
  67.     #define LOG2PHYS_X(x, y) x
  68.     #define LOG2PHYS_Y(x, y) y
  69.   #elif (!LCD_MIRROR_X && !LCD_MIRROR_Y &&  LCD_SWAP_XY)
  70.     #define LOG2PHYS_X(x, y) y
  71.     #define LOG2PHYS_Y(x, y) x
  72.   #elif (!LCD_MIRROR_X &&  LCD_MIRROR_Y && !LCD_SWAP_XY)
  73.     #define LOG2PHYS_X(x, y) x
  74.     #define LOG2PHYS_Y(x, y) LCD_YSIZE - 1 - (y)
  75.   #elif (!LCD_MIRROR_X &&  LCD_MIRROR_Y &&  LCD_SWAP_XY)
  76.     #define LOG2PHYS_X(x, y) y
  77.     #define LOG2PHYS_Y(x, y) LCD_XSIZE - 1 - (x)
  78.   #elif ( LCD_MIRROR_X && !LCD_MIRROR_Y && !LCD_SWAP_XY)
  79.     #define LOG2PHYS_X(x, y) LCD_XSIZE - 1 - (x)
  80.     #define LOG2PHYS_Y(x, y) y
  81.   #elif ( LCD_MIRROR_X && !LCD_MIRROR_Y &&  LCD_SWAP_XY)
  82.     #define LOG2PHYS_X(x, y) LCD_YSIZE - 1 - (y)
  83.     #define LOG2PHYS_Y(x, y) x
  84.   #elif ( LCD_MIRROR_X &&  LCD_MIRROR_Y && !LCD_SWAP_XY)
  85.     #define LOG2PHYS_X(x, y) LCD_XSIZE - 1 - (x)
  86.     #define LOG2PHYS_Y(x, y) LCD_YSIZE - 1 - (y)
  87.   #elif ( LCD_MIRROR_X &&  LCD_MIRROR_Y &&  LCD_SWAP_XY)
  88.     #define LOG2PHYS_X(x, y) LCD_YSIZE - 1 - (y)
  89.     #define LOG2PHYS_Y(x, y) LCD_XSIZE - 1 - (x)
  90.   #endif
  91. #else
  92.   #if   ( defined (LCD_LUT_COM) && !defined(LCD_LUT_SEG))
  93.     #define LOG2PHYS_X(x, y) x
  94.     #define LOG2PHYS_Y(x, y) LCD__aLine2Com0[y]
  95.   #elif (!defined (LCD_LUT_COM) &&  defined(LCD_LUT_SEG))
  96.     #define LOG2PHYS_X(x, y) LCD__aCol2Seg0[x]
  97.     #define LOG2PHYS_Y(x, y) y
  98.   #elif ( defined (LCD_LUT_COM) &&  defined(LCD_LUT_SEG))
  99.     #define LOG2PHYS_X(x, y) LCD__aCol2Seg0[x]
  100.     #define LOG2PHYS_Y(x, y) LCD__aLine2Com0[y]
  101.   #endif
  102. #endif

  103. /*********************************************************************
  104. *
  105. *       Types
  106. *
  107. **********************************************************************
  108. */
  109. typedef struct {
  110.   U32 VRAMAddr;
  111.   int xSize, ySize;
  112.   int vxSize, vySize;
  113.   int vxSizePhys;
  114.   int BitsPerPixel;
  115. } DRIVER_CONTEXT_TEMPLATE;

  116. /*********************************************************************
  117. *
  118. *       Static functions
  119. *
  120. **********************************************************************
  121. */
  122. /*********************************************************************
  123. *
  124. *       _SetPixelIndex
  125. *
  126. * Purpose:
  127. *   Sets the index of the given pixel. The upper layers
  128. *   calling this routine make sure that the coordinates are in range, so
  129. *   that no check on the parameters needs to be performed.
  130. */
  131. static void _SetPixelIndex(GUI_DEVICE * pDevice, int x, int y, int PixelIndex) {
  132.     //
  133.     // Convert logical into physical coordinates (Dep. on LCDConf.h)
  134.     //
  135.     #if (LCD_MIRROR_X == 1) || (LCD_MIRROR_Y == 1) || (LCD_SWAP_XY == 1)
  136.       int xPhys, yPhys;

  137.       xPhys = LOG2PHYS_X(x, y);
  138.       yPhys = LOG2PHYS_Y(x, y);
  139.     #else
  140.       #define xPhys x
  141.       #define yPhys y
  142.     #endif
  143.     GUI_USE_PARA(pDevice);
  144.     GUI_USE_PARA(x);
  145.     GUI_USE_PARA(y);
  146.     GUI_USE_PARA(PixelIndex);
  147.     {
  148.       //
  149.       // Write into hardware ... Adapt to your system
  150.       //
  151.       // TBD by customer...
  152.       //
  153.         <font color="Red">BSP_LCD_DrawPixel(x, y, PixelIndex);</font>

  154.                
  155.     }
  156.     #if (LCD_MIRROR_X == 0) && (LCD_MIRROR_Y == 0) && (LCD_SWAP_XY == 0)
  157.       #undef xPhys
  158.       #undef yPhys
  159.     #endif
  160. }

  161. /*********************************************************************
  162. *
  163. *       _GetPixelIndex
  164. *
  165. * Purpose:
  166. *   Returns the index of the given pixel. The upper layers
  167. *   calling this routine make sure that the coordinates are in range, so
  168. *   that no check on the parameters needs to be performed.
  169. */
  170. static unsigned int _GetPixelIndex(GUI_DEVICE * pDevice, int x, int y) {
  171.   unsigned int PixelIndex;
  172.     //
  173.     // Convert logical into physical coordinates (Dep. on LCDConf.h)
  174.     //
  175.     #if (LCD_MIRROR_X == 1) || (LCD_MIRROR_Y == 1) || (LCD_SWAP_XY == 1)
  176.       int xPhys, yPhys;

  177.       xPhys = LOG2PHYS_X(x, y);
  178.       yPhys = LOG2PHYS_Y(x, y);
  179.     #else
  180.       #define xPhys x
  181.       #define yPhys y
  182.     #endif
  183.     GUI_USE_PARA(pDevice);
  184.     GUI_USE_PARA(x);
  185.     GUI_USE_PARA(y);
  186.     {
  187.       //
  188.       // Write into hardware ... Adapt to your system
  189.       //
  190.       // TBD by customer...
  191.       //
  192.                 <font color="Red">PixelIndex = BSP_LCD_ReadPixel(x, y);
  193.     //  PixelIndex = 0;</font>
  194.     }
  195.     #if (LCD_MIRROR_X == 0) && (LCD_MIRROR_Y == 0) && (LCD_SWAP_XY == 0)
  196.       #undef xPhys
  197.       #undef yPhys
  198.     #endif
  199.   return PixelIndex;
  200. }

  201. /*********************************************************************
  202. *
  203. *       _XorPixel
  204. */
  205. static void _XorPixel(GUI_DEVICE * pDevice, int x, int y) {
  206.   LCD_PIXELINDEX PixelIndex;
  207.   LCD_PIXELINDEX IndexMask;

  208.   PixelIndex = _GetPixelIndex(pDevice, x, y);
  209.   IndexMask  = pDevice->pColorConvAPI->pfGetIndexMask();
  210.   _SetPixelIndex(pDevice, x, y, PixelIndex ^ IndexMask);
  211. }

  212. /*********************************************************************
  213. *
  214. *       _FillRect
  215. */
  216. static void _FillRect(GUI_DEVICE * pDevice, int x0, int y0, int x1, int y1) {
  217.   LCD_PIXELINDEX PixelIndex;
  218.   int x;

  219.   PixelIndex = LCD__GetColorIndex();
  220.   if (GUI_pContext->DrawMode & LCD_DRAWMODE_XOR) {
  221.     for (; y0 <= y1; y0++) {
  222.       for (x = x0; x <= x1; x++) {
  223.         _XorPixel(pDevice, x, y0);
  224.       }
  225.     }
  226.   } else {
  227. //    for (; y0 <= y1; y0++) {
  228. //      for (x = x0; x <= x1; x++) {
  229. //        _SetPixelIndex(pDevice, x, y0, PixelIndex);
  230. //      }
  231. //    }
  232.           <font color="Red">BSP_LCD_FillRect(x0, y0, x1-x0, y1-y0);</font>
  233.   }
  234. }

  235. /*********************************************************************
  236. *
  237. *       _DrawHLine
  238. */
  239. static void _DrawHLine(GUI_DEVICE * pDevice, int x0, int y, int x1) {
  240.   _FillRect(pDevice, x0, y, x1, y);
  241. }

  242. /*********************************************************************
  243. *
  244. *       _DrawVLine, not optimized
  245. */
  246. static void _DrawVLine(GUI_DEVICE * pDevice, int x, int y0, int y1) {
  247.   _FillRect(pDevice, x, y0, x, y1);
  248. }

  249. /*********************************************************************
  250. *
  251. *       Draw Bitmap 1 BPP
  252. */
  253. static void _DrawBitLine1BPP(GUI_DEVICE * pDevice, int x, int y, U8 const GUI_UNI_PTR * p, int Diff, int xsize, const LCD_PIXELINDEX * pTrans) {
  254.   LCD_PIXELINDEX IndexMask, Index0, Index1, Pixel;

  255.   Index0 = *(pTrans + 0);
  256.   Index1 = *(pTrans + 1);
  257.   x += Diff;
  258.   switch (GUI_pContext->DrawMode & (LCD_DRAWMODE_TRANS | LCD_DRAWMODE_XOR)) {
  259.   case 0:
  260.     do {
  261.       _SetPixelIndex(pDevice, x++, y, (*p & (0x80 >> Diff)) ? Index1 : Index0);
  262.       if (++Diff == 8) {
  263.         Diff = 0;
  264.         p++;
  265.       }
  266.     } while (--xsize);
  267.     break;
  268.   case LCD_DRAWMODE_TRANS:
  269.     do {
  270.       if (*p & (0x80 >> Diff))
  271.         _SetPixelIndex(pDevice, x, y, Index1);
  272.       x++;
  273.       if (++Diff == 8) {
  274.         Diff = 0;
  275.         p++;
  276.       }
  277.     } while (--xsize);
  278.     break;
  279.   case LCD_DRAWMODE_XOR | LCD_DRAWMODE_TRANS:
  280.   case LCD_DRAWMODE_XOR:
  281.     IndexMask = pDevice->pColorConvAPI->pfGetIndexMask();
  282.     do {
  283.       if (*p & (0x80 >> Diff)) {
  284.         Pixel = _GetPixelIndex(pDevice, x, y);
  285.         _SetPixelIndex(pDevice, x, y, Pixel ^ IndexMask);
  286.       }
  287.       x++;
  288.       if (++Diff == 8) {
  289.         Diff = 0;
  290.         p++;
  291.       }
  292.     } while (--xsize);
  293.     break;
  294.   }
  295. }

  296. /*********************************************************************
  297. *
  298. *       Draw Bitmap 2 BPP
  299. */
  300. static void  _DrawBitLine2BPP(GUI_DEVICE * pDevice, int x, int y, U8 const GUI_UNI_PTR * p, int Diff, int xsize, const LCD_PIXELINDEX * pTrans) {
  301.   LCD_PIXELINDEX Pixels, PixelIndex;
  302.   int CurrentPixel, Shift, Index;

  303.   Pixels = *p;
  304.   CurrentPixel = Diff;
  305.   x += Diff;
  306.   switch (GUI_pContext->DrawMode & (LCD_DRAWMODE_TRANS | LCD_DRAWMODE_XOR)) {
  307.   case 0:
  308.     if (pTrans) {
  309.       do {
  310.         Shift = (3 - CurrentPixel) << 1;
  311.         Index = (Pixels & (0xC0 >> (6 - Shift))) >> Shift;
  312.         PixelIndex = *(pTrans + Index);
  313.         _SetPixelIndex(pDevice, x++, y, PixelIndex);
  314.         if (++CurrentPixel == 4) {
  315.           CurrentPixel = 0;
  316.           Pixels = *(++p);
  317.         }
  318.       } while (--xsize);
  319.     } else {
  320.       do {
  321.         Shift = (3 - CurrentPixel) << 1;
  322.         Index = (Pixels & (0xC0 >> (6 - Shift))) >> Shift;
  323.         _SetPixelIndex(pDevice, x++, y, Index);
  324.         if (++CurrentPixel == 4) {
  325.           CurrentPixel = 0;
  326.           Pixels = *(++p);
  327.         }
  328.       } while (--xsize);
  329.     }
  330.     break;
  331.   case LCD_DRAWMODE_TRANS:
  332.     if (pTrans) {
  333.       do {
  334.         Shift = (3 - CurrentPixel) << 1;
  335.         Index = (Pixels & (0xC0 >> (6 - Shift))) >> Shift;
  336.         if (Index) {
  337.           PixelIndex = *(pTrans + Index);
  338.           _SetPixelIndex(pDevice, x, y, PixelIndex);
  339.         }
  340.         x++;
  341.         if (++CurrentPixel == 4) {
  342.           CurrentPixel = 0;
  343.           Pixels = *(++p);
  344.         }
  345.       } while (--xsize);
  346.     } else {
  347.       do {
  348.         Shift = (3 - CurrentPixel) << 1;
  349.         Index = (Pixels & (0xC0 >> (6 - Shift))) >> Shift;
  350.         if (Index) {
  351.           _SetPixelIndex(pDevice, x, y, Index);
  352.         }
  353.         x++;
  354.         if (++CurrentPixel == 4) {
  355.           CurrentPixel = 0;
  356.           Pixels = *(++p);
  357.         }
  358.       } while (--xsize);
  359.     }
  360.     break;
  361.   }
  362. }

  363. /*********************************************************************
  364. *
  365. *       Draw Bitmap 4 BPP
  366. */
  367. static void  _DrawBitLine4BPP(GUI_DEVICE * pDevice, int x, int y, U8 const GUI_UNI_PTR * p, int Diff, int xsize, const LCD_PIXELINDEX * pTrans) {
  368.   LCD_PIXELINDEX Pixels, PixelIndex;
  369.   int CurrentPixel, Shift, Index;

  370.   Pixels = *p;
  371.   CurrentPixel = Diff;
  372.   x += Diff;
  373.   switch (GUI_pContext->DrawMode & (LCD_DRAWMODE_TRANS | LCD_DRAWMODE_XOR)) {
  374.   case 0:
  375.     if (pTrans) {
  376.       do {
  377.         Shift = (1 - CurrentPixel) << 2;
  378.         Index = (Pixels & (0xF0 >> (4 - Shift))) >> Shift;
  379.         PixelIndex = *(pTrans + Index);
  380.         _SetPixelIndex(pDevice, x++, y, PixelIndex);
  381.         if (++CurrentPixel == 2) {
  382.           CurrentPixel = 0;
  383.           Pixels = *(++p);
  384.         }
  385.       } while (--xsize);
  386.     } else {
  387.       do {
  388.         Shift = (1 - CurrentPixel) << 2;
  389.         Index = (Pixels & (0xF0 >> (4 - Shift))) >> Shift;
  390.         _SetPixelIndex(pDevice, x++, y, Index);
  391.         if (++CurrentPixel == 2) {
  392.           CurrentPixel = 0;
  393.           Pixels = *(++p);
  394.         }
  395.       } while (--xsize);
  396.     }
  397.     break;
  398.   case LCD_DRAWMODE_TRANS:
  399.     if (pTrans) {
  400.       do {
  401.         Shift = (1 - CurrentPixel) << 2;
  402.         Index = (Pixels & (0xF0 >> (4 - Shift))) >> Shift;
  403.         if (Index) {
  404.           PixelIndex = *(pTrans + Index);
  405.           _SetPixelIndex(pDevice, x, y, PixelIndex);
  406.         }
  407.         x++;
  408.         if (++CurrentPixel == 2) {
  409.           CurrentPixel = 0;
  410.           Pixels = *(++p);
  411.         }
  412.       } while (--xsize);
  413.     } else {
  414.       do {
  415.         Shift = (1 - CurrentPixel) << 2;
  416.         Index = (Pixels & (0xF0 >> (4 - Shift))) >> Shift;
  417.         if (Index) {
  418.           _SetPixelIndex(pDevice, x, y, Index);
  419.         }
  420.         x++;
  421.         if (++CurrentPixel == 2) {
  422.           CurrentPixel = 0;
  423.           Pixels = *(++p);
  424.         }
  425.       } while (--xsize);
  426.     }
  427.     break;
  428.   }
  429. }

  430. /*********************************************************************
  431. *
  432. *       Draw Bitmap 8 BPP
  433. */
  434. static void  _DrawBitLine8BPP(GUI_DEVICE * pDevice, int x, int y, U8 const GUI_UNI_PTR * p, int xsize, const LCD_PIXELINDEX * pTrans) {
  435.   LCD_PIXELINDEX Pixel;

  436.   switch (GUI_pContext->DrawMode & (LCD_DRAWMODE_TRANS | LCD_DRAWMODE_XOR)) {
  437.   case 0:
  438.     if (pTrans) {
  439.       for (; xsize > 0; xsize--, x++, p++) {
  440.         Pixel = *p;
  441.         _SetPixelIndex(pDevice, x, y, *(pTrans + Pixel));
  442.       }
  443.     } else {
  444.       for (; xsize > 0; xsize--, x++, p++) {
  445.         _SetPixelIndex(pDevice, x, y, *p);
  446.       }
  447.     }
  448.     break;
  449.   case LCD_DRAWMODE_TRANS:
  450.     if (pTrans) {
  451.       for (; xsize > 0; xsize--, x++, p++) {
  452.         Pixel = *p;
  453.         if (Pixel) {
  454.           _SetPixelIndex(pDevice, x, y, *(pTrans + Pixel));
  455.         }
  456.       }
  457.     } else {
  458.       for (; xsize > 0; xsize--, x++, p++) {
  459.         Pixel = *p;
  460.         if (Pixel) {
  461.           _SetPixelIndex(pDevice, x, y, Pixel);
  462.         }
  463.       }
  464.     }
  465.     break;
  466.   }
  467. }

  468. /*********************************************************************
  469. *
  470. *       Draw Bitmap 16 BPP, not optimized
  471. *
  472. * Purpose:
  473. *   Drawing of 16bpp high color bitmaps.
  474. *   Only required for 16bpp color depth of target. Should be removed otherwise.
  475. */
  476. static void _DrawBitLine16BPP(GUI_DEVICE * pDevice, int x, int y, U16 const GUI_UNI_PTR * p, int xsize) {
  477.   for (;xsize > 0; xsize--, x++, p++) {
  478.     _SetPixelIndex(pDevice, x, y, *p);
  479.   }
  480. }

  481. /*********************************************************************
  482. *
  483. *       Draw Bitmap 32 BPP, not optimized
  484. *
  485. * Purpose:
  486. *   Drawing of 32bpp true color bitmaps.
  487. *   Only required for 32bpp color depth of target. Should be removed otherwise.
  488. */
  489. static void _DrawBitLine32BPP(GUI_DEVICE * pDevice, int x, int y, U32 const GUI_UNI_PTR * p, int xsize) {
  490.   for (;xsize > 0; xsize--, x++, p++) {
  491.     _SetPixelIndex(pDevice, x, y, *p);
  492.   }
  493. }

  494. /*********************************************************************
  495. *
  496. *       _DrawBitmap
  497. */
  498. static void _DrawBitmap(GUI_DEVICE * pDevice, int x0, int y0,
  499.                        int xSize, int ySize,
  500.                        int BitsPerPixel,
  501.                        int BytesPerLine,
  502.                        const U8 GUI_UNI_PTR * pData, int Diff,
  503.                        const LCD_PIXELINDEX * pTrans) {
  504.   int i;

  505.   switch (BitsPerPixel) {
  506.   case 1:
  507.     for (i = 0; i < ySize; i++) {
  508.       _DrawBitLine1BPP(pDevice, x0, i + y0, pData, Diff, xSize, pTrans);
  509.       pData += BytesPerLine;
  510.     }
  511.     break;
  512.   case 2:
  513.     for (i = 0; i < ySize; i++) {
  514.       _DrawBitLine2BPP(pDevice, x0, i + y0, pData, Diff, xSize, pTrans);
  515.       pData += BytesPerLine;
  516.     }
  517.     break;
  518.   case 4:
  519.     for (i = 0; i < ySize; i++) {
  520.       _DrawBitLine4BPP(pDevice, x0, i + y0, pData, Diff, xSize, pTrans);
  521.       pData += BytesPerLine;
  522.     }
  523.     break;
  524.   case 8:
  525.     for (i = 0; i < ySize; i++) {
  526.       _DrawBitLine8BPP(pDevice, x0, i + y0, pData, xSize, pTrans);
  527.       pData += BytesPerLine;
  528.     }
  529.     break;
  530.   //
  531.   // Only required for 16bpp color depth of target. Should be removed otherwise.
  532.   //
  533.   case 16:
  534.     for (i = 0; i < ySize; i++) {
  535.       _DrawBitLine16BPP(pDevice, x0, i + y0, (const U16 *)pData, xSize);
  536.       pData += BytesPerLine;
  537.     }
  538.     break;
  539.   //
  540.   // Only required for 32bpp color depth of target. Should be removed otherwise.
  541.   //
  542.   case 32:
  543.     for (i = 0; i < ySize; i++) {
  544.       _DrawBitLine32BPP(pDevice, x0, i + y0, (const U32 *)pData, xSize);
  545.       pData += BytesPerLine;
  546.     }
  547.     break;
  548.   }
  549. }

  550. /*********************************************************************
  551. *
  552. *       _InitOnce
  553. *
  554. * Purpose:
  555. *   Allocates a fixed block for the context of the driver
  556. *
  557. * Return value:
  558. *   0 on success, 1 on error
  559. */
  560. static int _InitOnce(GUI_DEVICE * pDevice) {
  561.   DRIVER_CONTEXT_TEMPLATE * pContext;

  562.   if (pDevice->u.pContext == NULL) {
  563.     pDevice->u.pContext = GUI_ALLOC_GetFixedBlock(sizeof(DRIVER_CONTEXT_TEMPLATE));
  564.     pContext = (DRIVER_CONTEXT_TEMPLATE *)pDevice->u.pContext;
  565.     pContext->BitsPerPixel = LCD__GetBPP(pDevice->pColorConvAPI->pfGetIndexMask());
  566.   }
  567.   return pDevice->u.pContext ? 0 : 1;
  568. }

  569. /*********************************************************************
  570. *
  571. *       _GetDevProp
  572. */
  573. static I32 _GetDevProp(GUI_DEVICE * pDevice, int Index) {
  574.   DRIVER_CONTEXT_TEMPLATE * pContext;

  575.   pContext = (DRIVER_CONTEXT_TEMPLATE *)pDevice->u.pContext;
  576.   switch (Index) {
  577.   case LCD_DEVCAP_XSIZE:
  578.     return pContext->xSize;
  579.   case LCD_DEVCAP_YSIZE:
  580.     return pContext->ySize;
  581.   case LCD_DEVCAP_VXSIZE:
  582.     return pContext->vxSize;
  583.   case LCD_DEVCAP_VYSIZE:
  584.     return pContext->vySize;
  585.   case LCD_DEVCAP_BITSPERPIXEL:
  586.     return pContext->BitsPerPixel;
  587.   case LCD_DEVCAP_NUMCOLORS:
  588.     return 0;
  589.   case LCD_DEVCAP_XMAG:
  590.     return 1;
  591.   case LCD_DEVCAP_YMAG:
  592.     return 1;
  593.   case LCD_DEVCAP_MIRROR_X:
  594.     return 0;
  595.   case LCD_DEVCAP_MIRROR_Y:
  596.     return 0;
  597.   case LCD_DEVCAP_SWAP_XY:
  598.     return 0;
  599.   }
  600.   return -1;
  601. }

  602. /*********************************************************************
  603. *
  604. *       _GetDevData
  605. */
  606. static void * _GetDevData(GUI_DEVICE * pDevice, int Index) {
  607.   GUI_USE_PARA(pDevice);
  608.   #if GUI_SUPPORT_MEMDEV
  609.     switch (Index) {
  610.     case LCD_DEVDATA_MEMDEV:
  611.       return (void *)&GUI_MEMDEV_DEVICE_16; // TBD: Has to be adapted to the right memory device depending on the used color depth!
  612.     }
  613.   #else
  614.     GUI_USE_PARA(Index);
  615.   #endif
  616.   return NULL;
  617. }

  618. /*********************************************************************
  619. *
  620. *       _GetRect
  621. */
  622. static void _GetRect(GUI_DEVICE * pDevice, LCD_RECT * pRect) {
  623.   DRIVER_CONTEXT_TEMPLATE * pContext;

  624.   pContext = (DRIVER_CONTEXT_TEMPLATE *)pDevice->u.pContext;
  625.   pRect->x0 = 0;
  626.   pRect->y0 = 0;
  627.   pRect->x1 = pContext->vxSize - 1;
  628.   pRect->y1 = pContext->vySize - 1;
  629. }

  630. /*********************************************************************
  631. *
  632. *       _SetOrg
  633. */
  634. static void _SetOrg(GUI_DEVICE * pDevice, int x, int y) {
  635.   LCD_X_SETORG_INFO Data = {0};

  636.   Data.xPos = x;
  637.   Data.yPos = y;
  638.   LCD_X_DisplayDriver(pDevice->LayerIndex, LCD_X_SETORG, (void *)&Data);
  639. }

  640. /*********************************************************************
  641. *
  642. *       Static code: Functions available by _GetDevFunc()
  643. *
  644. **********************************************************************
  645. */
  646. /*********************************************************************
  647. *
  648. *       _SetVRAMAddr
  649. */
  650. static void _SetVRAMAddr(GUI_DEVICE * pDevice, void * pVRAM) {
  651.   DRIVER_CONTEXT_TEMPLATE * pContext;
  652.   LCD_X_SETVRAMADDR_INFO Data = {0};

  653.   _InitOnce(pDevice);
  654.   if (pDevice->u.pContext) {
  655.     pContext = (DRIVER_CONTEXT_TEMPLATE *)pDevice->u.pContext;
  656.     pContext->VRAMAddr = (U32)pVRAM;
  657.     Data.pVRAM = pVRAM;
  658.     LCD_X_DisplayDriver(pDevice->LayerIndex, LCD_X_SETVRAMADDR, (void *)&Data);
  659.   }
  660. }

  661. /*********************************************************************
  662. *
  663. *       _SetVSize
  664. */
  665. static void _SetVSize(GUI_DEVICE * pDevice, int xSize, int ySize) {
  666.   DRIVER_CONTEXT_TEMPLATE * pContext;

  667.   _InitOnce(pDevice);
  668.   if (pDevice->u.pContext) {
  669.     pContext = (DRIVER_CONTEXT_TEMPLATE *)pDevice->u.pContext;
  670.     pContext->vxSize = xSize;
  671.     pContext->vySize = ySize;
  672.     pContext->vxSizePhys = xSize;
  673.   }
  674. }

  675. /*********************************************************************
  676. *
  677. *       _SetSize
  678. */
  679. static void _SetSize(GUI_DEVICE * pDevice, int xSize, int ySize) {
  680.   DRIVER_CONTEXT_TEMPLATE * pContext;
  681.   LCD_X_SETSIZE_INFO Data = {0};

  682.   _InitOnce(pDevice);
  683.   if (pDevice->u.pContext) {
  684.     pContext = (DRIVER_CONTEXT_TEMPLATE *)pDevice->u.pContext;
  685.     pContext->vxSizePhys = (pContext->vxSizePhys == 0) ? xSize : pContext->vxSizePhys;
  686.     pContext->xSize = xSize;
  687.     pContext->ySize = ySize;
  688.     Data.xSize = xSize;
  689.     Data.ySize = ySize;
  690.     LCD_X_DisplayDriver(pDevice->LayerIndex, LCD_X_SETSIZE, (void *)&Data);
  691.   }
  692. }
  693. /*********************************************************************
  694. *
  695. *       _Init
  696. */
  697. static int  _Init(GUI_DEVICE * pDevice) {
  698.   int r;

  699.   r = _InitOnce(pDevice);
  700.   r |= LCD_X_DisplayDriver(pDevice->LayerIndex, LCD_X_INITCONTROLLER, NULL);
  701.   return r;
  702. }

  703. /*********************************************************************
  704. *
  705. *       _On
  706. */
  707. static void _On (GUI_DEVICE * pDevice) {
  708.   LCD_X_DisplayDriver(pDevice->LayerIndex, LCD_X_ON, NULL);
  709. }

  710. /*********************************************************************
  711. *
  712. *       _Off
  713. */
  714. static void _Off (GUI_DEVICE * pDevice) {
  715.   LCD_X_DisplayDriver(pDevice->LayerIndex, LCD_X_OFF, NULL);
  716. }

  717. /*********************************************************************
  718. *
  719. *       _SetLUTEntry
  720. */
  721. static void _SetLUTEntry(GUI_DEVICE * pDevice, U8 Pos, LCD_COLOR Color) {
  722.   LCD_X_SETLUTENTRY_INFO Data = {0};

  723.   Data.Pos   = Pos;
  724.   Data.Color = Color;
  725.   LCD_X_DisplayDriver(pDevice->LayerIndex, LCD_X_SETLUTENTRY, (void *)&Data);
  726. }

  727. /*********************************************************************
  728. *
  729. *       _GetDevFunc
  730. */
  731. static void (* _GetDevFunc(GUI_DEVICE ** ppDevice, int Index))(void) {
  732.   GUI_USE_PARA(ppDevice);
  733.   switch (Index) {
  734.   case LCD_DEVFUNC_SET_VRAM_ADDR:
  735.     return (void (*)(void))_SetVRAMAddr;
  736.   case LCD_DEVFUNC_SET_VSIZE:
  737.     return (void (*)(void))_SetVSize;
  738.   case LCD_DEVFUNC_SET_SIZE:
  739.     return (void (*)(void))_SetSize;
  740.   case LCD_DEVFUNC_INIT:
  741.     return (void (*)(void))_Init;
  742.   case LCD_DEVFUNC_ON:
  743.     return (void (*)(void))_On;
  744.   case LCD_DEVFUNC_OFF:
  745.     return (void (*)(void))_Off;
  746.   case LCD_DEVFUNC_SETLUTENTRY:
  747.     return (void (*)(void))_SetLUTEntry;
  748.   }
  749.   return NULL;
  750. }

  751. /*********************************************************************
  752. *
  753. *       Public data
  754. *
  755. **********************************************************************
  756. */
  757. /*********************************************************************
  758. *
  759. *       GUI_DEVICE_API structure
  760. */
  761. const GUI_DEVICE_API GUIDRV_Template_API = {
  762.   //
  763.   // Data
  764.   //
  765.   DEVICE_CLASS_DRIVER,
  766.   //
  767.   // Drawing functions
  768.   //
  769.   _DrawBitmap,
  770.   _DrawHLine,
  771.   _DrawVLine,
  772.   _FillRect,
  773.   _GetPixelIndex,
  774.   _SetPixelIndex,
  775.   _XorPixel,
  776.   //
  777.   // Set origin
  778.   //
  779.   _SetOrg,
  780.   //
  781.   // Request information
  782.   //
  783.   _GetDevFunc,
  784.   _GetDevProp,
  785.   _GetDevData,
  786.   _GetRect,
  787. };

  788. /*************************** End of file ****************************/
复制代码


4)修改LCDConf_FlexColor_Template.c文件

/*********************************************************************
*          Portions COPYRIGHT 2016 STMicroelectronics                *
*          Portions SEGGER Microcontroller GmbH & Co. KG             *
*        Solutions for real time microcontroller applications        *
**********************************************************************
*                                                                    *
*        (c) 1996 - 2015  SEGGER Microcontroller GmbH & Co. KG       *
*                                                                    *
*        Internet: www.segger.com    Support:  support@segger.com    *
*                                                                    *
**********************************************************************

** emWin V5.32 - Graphical user interface for embedded applications **
All  Intellectual Property rights  in the Software belongs to  SEGGER.
emWin is protected by  international copyright laws.  Knowledge of the
source code may not be used to write a similar product.  This file may
only be used in accordance with the following terms:

The  software has  been licensed  to STMicroelectronics International
N.V. a Dutch company with a Swiss branch and its headquarters in Plan-
les-Ouates, Geneva, 39 Chemin du Champ des Filles, Switzerland for the
purposes of creating libraries for ARM Cortex-M-based 32-bit microcon_
troller products commercialized by Licensee only, sublicensed and dis_
tributed under the terms and conditions of the End User License Agree_
ment supplied by STMicroelectronics International N.V.
Full source code is available at: www.segger.com

We appreciate your understanding and fairness.
----------------------------------------------------------------------
File        : LCDConf_FlexColor_Template.c
Purpose     : Display controller configuration (single layer)
---------------------------END-OF-HEADER------------------------------
*/

/**
  ******************************************************************************
  * @attention
  *
  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  * You may not use this file except in compliance with the License.
  * You may obtain a copy of the License at:
  *
  *        http://www.st.com/software_license_agreement_liberty_v2
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  *
  ******************************************************************************
  */

#include "GUI.h"
#include "GUIDRV_FlexColor.h"

/*********************************************************************
*
*       Layer configuration (to be modified)
*
**********************************************************************
*/

//
// Physical display size
//
#define XSIZE_PHYS  800 // To be adapted to x-screen size
#define YSIZE_PHYS  480 // To be adapted to y-screen size


/*********************************************************************
*
*       Configuration checking
*
**********************************************************************
*/
#ifndef   VXSIZE_PHYS
  #define VXSIZE_PHYS XSIZE_PHYS
#endif
#ifndef   VYSIZE_PHYS
  #define VYSIZE_PHYS YSIZE_PHYS
#endif
#ifndef   XSIZE_PHYS
  #error Physical X size of display is not defined!
#endif
#ifndef   YSIZE_PHYS
  #error Physical Y size of display is not defined!
#endif
#ifndef   GUICC_565
  #error Color conversion not defined!
#endif
#ifndef   GUIDRV_FLEXCOLOR
  #error No display driver defined!
#endif

/*********************************************************************
*
*       Local functions
*
**********************************************************************
*/
/*********************************************************************
*
*       Public functions
*
**********************************************************************
*/
/*********************************************************************
*
*       LCD_X_Config
*
* Function description:
*   Called during the initialization process in order to set up the
*   display driver configuration.
*
*/
void LCD_X_Config(void) {

GUI_DEVICE_CreateAndLink(&GUIDRV_Template_API, GUICC_8888, 0, 0);
  //
  // Display driver configuration, required for Lin-driver
  //
  LCD_SetSizeEx (0, XSIZE_PHYS , YSIZE_PHYS);
  LCD_SetVSizeEx(0, VXSIZE_PHYS, VYSIZE_PHYS);  //

}

/*********************************************************************
*
*       LCD_X_DisplayDriver
*
* Function description:
*   This function is called by the display driver for several purposes.
*   To support the according task the routine needs to be adapted to
*   the display controller. Please note that the commands marked with
*   'optional' are not cogently required and should only be adapted if
*   the display controller supports these features.
*
* Parameter:
*   LayerIndex - Index of layer to be configured
*   Cmd        - Please refer to the details in the switch statement below
*   pData      - Pointer to a LCD_X_DATA structure
*
* Return Value:
*   < -1 - Error
*     -1 - Command not handled
*      0 - Ok
*/
int LCD_X_DisplayDriver(unsigned LayerIndex, unsigned Cmd, void * pData) {
  int r;
  (void) LayerIndex;
  (void) pData;
  
  switch (Cmd) {
  case LCD_X_INITCONTROLLER: {
    //
    // Called during the initialization process in order to set up the
    // display controller and put it into operation. If the display
    // controller is not initialized by any external routine this needs
    // to be adapted by the customer...
    //
    // ...
    return 0;
  }
  default:
    r = -1;
  }
  return r;
}

/*************************** End of file ****************************/

5)编写测试代码用于测试
main.c文件如下:

  1. /**
  2.   ******************************************************************************
  3.   * @file    ADC/ADC_TemperatureSensor/Src/main.c
  4.   * @author  MCD Application Team
  5.   * [url=home.php?mod=space&uid=252314]@version[/url] V1.1.0
  6.   * [url=home.php?mod=space&uid=311857]@date[/url]    23-September-2016
  7.   * [url=home.php?mod=space&uid=159083]@brief[/url]   This example describes how to use the Temperature Sensor to
  8.   *          calculate the junction temperature of the device.
  9.   ******************************************************************************
  10.   * @attention
  11.   *
  12.   * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
  13.   *
  14.   * Redistribution and use in source and binary forms, with or without modification,
  15.   * are permitted provided that the following conditions are met:
  16.   *   1. Redistributions of source code must retain the above copyright notice,
  17.   *      this list of conditions and the following disclaimer.
  18.   *   2. Redistributions in binary form must reproduce the above copyright notice,
  19.   *      this list of conditions and the following disclaimer in the documentation
  20.   *      and/or other materials provided with the distribution.
  21.   *   3. Neither the name of STMicroelectronics nor the names of its contributors
  22.   *      may be used to endorse or promote products derived from this software
  23.   *      without specific prior written permission.
  24.   *
  25.   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  26.   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  27.   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  28.   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  29.   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  30.   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  31.   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  32.   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  33.   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  34.   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35.   *
  36.   ******************************************************************************
  37.   */

  38. /* Includes ------------------------------------------------------------------*/
  39. #include "main.h"
  40. #include "GUI.h"
  41. /** @addtogroup STM32F7xx_HAL_Examples
  42.   * @{
  43.   */

  44. /** @addtogroup ADC_TemperatureSensor
  45.   * @{
  46.   */

  47. /* Private typedef -----------------------------------------------------------*/
  48. /* Private define ------------------------------------------------------------*/
  49. #define TEMP_REFRESH_PERIOD   1000    /* Internal temperature refresh period */
  50. #define MAX_CONVERTED_VALUE   4095    /* Max converted value */
  51. #define AMBIENT_TEMP            25    /* Ambient Temperature */
  52. #define VSENS_AT_AMBIENT_TEMP  760    /* VSENSE value (mv) at ambient temperature */
  53. #define AVG_SLOPE               25    /* Avg_Solpe multiply by 10 */
  54. #define VREF                  3300
  55. /* Private macro -------------------------------------------------------------*/
  56. /* Private variables ---------------------------------------------------------*/
  57. /* ADC handler declaration */
  58. ADC_HandleTypeDef    AdcHandle;
  59. /* Variable used to get converted value */
  60. __IO int32_t ConvertedValue = 0;
  61. int32_t JTemp = 0x0;

  62. /* Private function prototypes -----------------------------------------------*/
  63. void SystemClock_Config(void);
  64. static void LCD_Config(void);
  65. static void ADC_Config(void);
  66. static void Error_Handler(void);
  67. static void MPU_Config(void);
  68. static void CPU_CACHE_Enable(void);

  69. /* Private functions ---------------------------------------------------------*/

  70. /**
  71.   * @brief  Main program.
  72.   * @param  None
  73.   * @retval None
  74.   */
  75. int main(void)
  76. {
  77.   char desc[50];
  78. __HAL_RCC_CRC_CLK_ENABLE();
  79.   /* Configure the MPU attributes as Write Through */
  80.   MPU_Config();

  81.   /* Enable the CPU Cache */
  82.   CPU_CACHE_Enable();

  83.   /* STM32F7xx HAL library initialization:
  84.        - Configure the Flash prefetch
  85.        - Systick timer is configured by default as source of time base, but user
  86.          can eventually implement his proper time base source (a general purpose
  87.          timer for example or other time source), keeping in mind that Time base
  88.          duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and
  89.          handled in milliseconds basis.
  90.        - Set NVIC Group Priority to 4
  91.        - Low Level Initialization
  92.      */
  93.   HAL_Init();

  94.   /* Configure the system clock to 200 MHz */
  95.   SystemClock_Config();

  96.   /* Configure LED1 and LED2 */
  97.   BSP_LED_Init(LED1);
  98.   BSP_LED_Init(LED2);
  99.   
  100.   /*##-1- Configure the LCD peripheral #########################################*/
  101.   LCD_Config();
  102.   
  103.   /*##-2- Configure the ADC peripheral #########################################*/
  104.   //ADC_Config();
  105.   
  106.   /*##-3- Start the conversion process #######################################*/
  107.   //HAL_ADC_Start_DMA(&AdcHandle, (uint32_t*)&ConvertedValue, 1);

  108.        
  109.        
  110.         GUI_Init();
  111.         GUI_SetBkColor(GUI_BLUE);
  112.         GUI_SetColor(GUI_YELLOW);
  113.         GUI_Clear();
  114.                
  115. //        GUI_SetFont(&GUI_Font32B_ASCII);
  116. //        GUI_DispStringAt("Hello World",0,0);
  117. //       
  118. //        GUI_SetFont(&GUI_Font32B_ASCII);
  119. //        GUI_DispStringAt("STemWin",40,40);
  120.         GUI_SetFont(&GUI_Font8_ASCII);
  121.         GUI_DispString("STemWin5.32\r\n");
  122.         GUI_SetFont(&GUI_Font10S_ASCII);
  123.         GUI_DispString("STemWin5.32\r\n");
  124.         GUI_SetFont(&GUI_Font10_ASCII);
  125.         GUI_DispString("STemWin5.32\r\n");
  126.         GUI_SetFont(&GUI_Font13_ASCII);
  127.         GUI_DispString("STemWin5.32\r\n");       
  128.        
  129.         GUI_SetFont(&GUI_Font13B_ASCII);
  130.         GUI_DispString("STemWin5.32\r\n");
  131.         GUI_SetFont(&GUI_Font13H_ASCII);
  132.         GUI_DispString("STemWin5.32\r\n");
  133.         GUI_SetFont(&GUI_Font13HB_ASCII);
  134.         GUI_DispString("STemWin5.32\r\n");
  135.         GUI_SetFont(&GUI_Font16_ASCII);
  136.         GUI_DispString("STemWin5.32\r\n");
  137.        
  138.                 GUI_SetFont(&GUI_Font16B_ASCII);
  139.         GUI_DispString("STemWin5.32\r\n");
  140.         GUI_SetFont(&GUI_Font20_ASCII);
  141.         GUI_DispString("STemWin5.32\r\n");
  142.         GUI_SetFont(&GUI_Font20B_ASCII);
  143.         GUI_DispString("STemWin5.32\r\n");
  144.         GUI_SetFont(&GUI_Font24_ASCII);
  145.         GUI_DispString("STemWin5.32\r\n");
  146.        
  147.                         GUI_SetFont(&GUI_Font24B_ASCII);
  148.         GUI_DispString("STemWin5.32\r\n");
  149.         GUI_SetFont(&GUI_Font32_ASCII);
  150.         GUI_DispString("STemWin5.32\r\n");
  151.         GUI_SetFont(&GUI_Font32B_ASCII);
  152.         GUI_DispString("STemWin5.32\r\n");
  153.        
  154.         GUI_DispStringHCenterAt("EEworld!!",400,240);
  155.         GUI_DispStringHCenterAt("xinmeng_wit.2016/12/29",500,340);
  156.         GUI_FillCircle(400,240,50);
  157.        

  158.   /* Infinite loop */
  159.   while (1)
  160.   {
  161.           
  162.   }
  163. }

  164. /**
  165.   * @brief  System Clock Configuration
  166.   *         The system Clock is configured as follow :
  167.   *            System Clock source            = PLL (HSE)
  168.   *            SYSCLK(Hz)                     = 200000000
  169.   *            HCLK(Hz)                       = 200000000
  170.   *            AHB Prescaler                  = 1
  171.   *            APB1 Prescaler                 = 4
  172.   *            APB2 Prescaler                 = 2
  173.   *            HSE Frequency(Hz)              = 25000000
  174.   *            PLL_M                          = 25
  175.   *            PLL_N                          = 400
  176.   *            PLL_P                          = 2
  177.   *            PLL_Q                          = 9
  178.   *            PLL_R                          = 7
  179.   *            VDD(V)                         = 3.3
  180.   *            Main regulator output voltage  = Scale1 mode
  181.   *            Flash Latency(WS)              = 7
  182.   * @param  None
  183.   * @retval None
  184.   */
  185. void SystemClock_Config(void)
  186. {
  187.   RCC_ClkInitTypeDef RCC_ClkInitStruct;
  188.   RCC_OscInitTypeDef RCC_OscInitStruct;
  189.   HAL_StatusTypeDef ret = HAL_OK;

  190.   /* Enable HSE Oscillator and activate PLL with HSE as source */
  191.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  192.   RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  193.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  194.   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  195.   RCC_OscInitStruct.PLL.PLLM = 25;
  196.   RCC_OscInitStruct.PLL.PLLN = 400;
  197.   RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  198.   RCC_OscInitStruct.PLL.PLLQ = 9;
  199.   RCC_OscInitStruct.PLL.PLLR = 7;
  200.   
  201.   ret = HAL_RCC_OscConfig(&RCC_OscInitStruct);
  202.   if(ret != HAL_OK)
  203.   {
  204.     while(1) { ; }
  205.   }
  206.   
  207.   /* Activate the OverDrive to reach the 216 MHz Frequency */  
  208.   ret = HAL_PWREx_EnableOverDrive();
  209.   if(ret != HAL_OK)
  210.   {
  211.     while(1) { ; }
  212.   }
  213.   
  214.   /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */
  215.   RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
  216.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  217.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  218.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;  
  219.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
  220.   
  221.   ret = HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_7);
  222.   if(ret != HAL_OK)
  223.   {
  224.     while(1) { ; }
  225.   }  
  226. }

  227. /**
  228.   * @brief  Configure the LCD for display.
  229.   * @param  None
  230.   * @retval None
  231.   */
  232. static void LCD_Config(void)
  233. {
  234.   uint32_t  lcd_status = LCD_OK;
  235.       
  236.   /* Initialize the LCD */
  237.   lcd_status = BSP_LCD_Init();
  238.   while(lcd_status != LCD_OK);
  239.   
  240.   BSP_LCD_LayerDefaultInit(0, LCD_FB_START_ADDRESS);
  241.   
  242.   /* Clear the LCD */
  243.   BSP_LCD_Clear(LCD_COLOR_BLUE);
  244. BSP_LCD_SetTextColor(LCD_COLOR_BLUE);
  245. //        BSP_LCD_SetBackColor(LCD_COLOR_BLUE);
  246.   /* Set LCD Example description */
  247. //  BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
  248. //  BSP_LCD_SetFont(&Font12);
  249. //  BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()- 20, (uint8_t *)"Copyright (c) STMicroelectronics 2016", CENTER_MODE);
  250.         //  BSP_LCD_SetTextColor(LCD_COLOR_BLUE);
  251. //  BSP_LCD_FillRect(0, 0, BSP_LCD_GetXSize(), 120);
  252. //  BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
  253. //  BSP_LCD_SetBackColor(LCD_COLOR_BLUE);
  254. //  BSP_LCD_SetFont(&Font24);
  255. //  BSP_LCD_DisplayStringAt(0, 10, (uint8_t *)"ADC_TemperatureSensor", CENTER_MODE);
  256. //  BSP_LCD_SetFont(&Font16);
  257. //  BSP_LCD_DisplayStringAt(0, 60, (uint8_t *)"This example shows how to measure the Junction", CENTER_MODE);
  258. //  BSP_LCD_DisplayStringAt(0, 75, (uint8_t *)"Temperature of the device via an Internal", CENTER_MODE);
  259. //  BSP_LCD_DisplayStringAt(0, 90, (uint8_t *)"Sensor and display the Value on the LCD", CENTER_MODE);

  260. //  BSP_LCD_SetTextColor(LCD_COLOR_BLACK);
  261. //  BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
  262. //  BSP_LCD_SetFont(&Font24);
  263. }

  264. /**
  265.   * @brief  Configure the ADC.
  266.   * @param  None
  267.   * @retval None
  268.   */
  269. static void ADC_Config(void)
  270. {
  271.   ADC_ChannelConfTypeDef sConfig;
  272.   
  273.   /* Configure the ADC peripheral */
  274.   AdcHandle.Instance          = ADC1;
  275.   
  276.   AdcHandle.Init.ClockPrescaler        = ADC_CLOCKPRESCALER_PCLK_DIV4;
  277.   AdcHandle.Init.Resolution            = ADC_RESOLUTION_12B;
  278.   AdcHandle.Init.ScanConvMode          = DISABLE;                       /* Sequencer disabled (ADC conversion on only 1 channel: channel set on rank 1) */
  279.   AdcHandle.Init.ContinuousConvMode    = ENABLE;                        /* Continuous mode enabled to have continuous conversion */
  280.   AdcHandle.Init.DiscontinuousConvMode = DISABLE;                       /* Parameter discarded because sequencer is disabled */
  281.   AdcHandle.Init.NbrOfDiscConversion   = 0;
  282.   AdcHandle.Init.ExternalTrigConvEdge  = ADC_EXTERNALTRIGCONVEDGE_NONE;        /* Conversion start not trigged by an external event */
  283.   AdcHandle.Init.ExternalTrigConv      = ADC_EXTERNALTRIGCONV_T1_CC1;
  284.   AdcHandle.Init.DataAlign             = ADC_DATAALIGN_RIGHT;
  285.   AdcHandle.Init.NbrOfConversion       = 1;
  286.   AdcHandle.Init.DMAContinuousRequests = ENABLE;
  287.   AdcHandle.Init.EOCSelection          = DISABLE;

  288.   if (HAL_ADC_Init(&AdcHandle) != HAL_OK)
  289.   {
  290.     /* ADC initialization Error */
  291.     Error_Handler();
  292.   }

  293.   /* Configure ADC Temperature Sensor Channel */
  294.   sConfig.Channel = ADC_CHANNEL_TEMPSENSOR;
  295.   sConfig.Rank = 1;
  296.   sConfig.SamplingTime = ADC_SAMPLETIME_56CYCLES;
  297.   sConfig.Offset = 0;

  298.   if (HAL_ADC_ConfigChannel(&AdcHandle, &sConfig) != HAL_OK)
  299.   {
  300.     /* Channel Configuration Error */
  301.     Error_Handler();
  302.   }
  303. }

  304. /**
  305.   * @brief  This function is executed in case of error occurrence.
  306.   * @param  None
  307.   * @retval None
  308.   */
  309. static void Error_Handler(void)
  310. {
  311.   while (1)
  312.   {
  313.     /* LED1 blinks */
  314.     BSP_LED_Toggle(LED1);
  315.     HAL_Delay(20);
  316.   }
  317. }

  318. #ifdef  USE_FULL_ASSERT

  319. /**
  320.   * @brief  Reports the name of the source file and the source line number
  321.   *         where the assert_param error has occurred.
  322.   * @param  file: pointer to the source file name
  323.   * @param  line: assert_param error line source number
  324.   * @retval None
  325.   */
  326. void assert_failed(uint8_t *file, uint32_t line)
  327. {
  328.   /* User can add his own implementation to report the file name and line number,
  329.      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

  330.   /* Infinite loop */
  331.   while (1)
  332.   {
  333.   }
  334. }

  335. #endif

  336. /**
  337.   * @brief  Configure the MPU attributes as Write Through for SRAM1/2.
  338.   * @note   The Base Address is 0x20010000 since this memory interface is the AXI.
  339.   *         The Region Size is 256KB, it is related to SRAM1 and SRAM2  memory size.
  340.   * @param  None
  341.   * @retval None
  342.   */
  343. static void MPU_Config(void)
  344. {
  345.   MPU_Region_InitTypeDef MPU_InitStruct;
  346.   
  347.   /* Disable the MPU */
  348.   HAL_MPU_Disable();

  349.   /* Configure the MPU attributes as WT for SRAM */
  350.   MPU_InitStruct.Enable = MPU_REGION_ENABLE;
  351.   MPU_InitStruct.BaseAddress = 0x20010000;
  352.   MPU_InitStruct.Size = MPU_REGION_SIZE_256KB;
  353.   MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
  354.   MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
  355.   MPU_InitStruct.IsCacheable = MPU_ACCESS_CACHEABLE;
  356.   MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
  357.   MPU_InitStruct.Number = MPU_REGION_NUMBER0;
  358.   MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
  359.   MPU_InitStruct.SubRegionDisable = 0x00;
  360.   MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;

  361.   HAL_MPU_ConfigRegion(&MPU_InitStruct);

  362.   /* Enable the MPU */
  363.   HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);
  364. }

  365. /**
  366.   * @brief  CPU L1-Cache enable.
  367.   * @param  None
  368.   * @retval None
  369.   */
  370. static void CPU_CACHE_Enable(void)
  371. {
  372.   /* Enable I-Cache */
  373.   SCB_EnableICache();

  374.   /* Enable D-Cache */
  375.   SCB_EnableDCache();
  376. }

  377. /**
  378.   * @}
  379.   */

  380. /**
  381.   * @}
  382.   */

  383. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
复制代码

另外,还有最重要的一点要修改,就是颜色的格式需要加入一个宏GUI_USE_ARGB,,因为我们的开发板使用的是ARGB格式,并非常用的rgb565格式。至于为什么要添加这个宏,可以在GUI.h文件里看出来:




完成以上修改就可以编译下载到开发板上运行了,



运行结果::







点击此处,查看STM32F769I开发板官方资源。
此帖出自stm32/stm8论坛

最新回复

有点乱!!!,哈哈哈,  详情 回复 发表于 2017-1-4 16:13
点赞 关注
 

回复
举报

2

帖子

0

TA的资源

一粒金砂(初级)

沙发
 
前排留名
此帖出自stm32/stm8论坛
 
 

回复

4177

帖子

9

TA的资源

五彩晶圆(高级)

板凳
 
不错,emwin的这个移植还是挺详细的。楼主的移植步骤值得参考。哈哈
此帖出自stm32/stm8论坛

点评

多谢捧场  详情 回复 发表于 2016-12-30 16:46
 
 

回复

553

帖子

3

TA的资源

纯净的硅(初级)

4
 
huaiqiao 发表于 2016-12-30 15:21
不错,emwin的这个移植还是挺详细的。楼主的移植步骤值得参考。哈哈

多谢捧场
此帖出自stm32/stm8论坛
 
 
 

回复

116

帖子

2

TA的资源

一粒金砂(中级)

5
 
只打包过程文件和修改到的原文件,不打包库,就可以上传了。 没有库就没那么大了
此帖出自stm32/stm8论坛
 
个人签名熙熙攘攘的世界,我们不懈前行......
 
 

回复

1706

帖子

4

TA的资源

纯净的硅(初级)

6
 
有点乱!!!,哈哈哈,
此帖出自stm32/stm8论坛
 
 
 

回复
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/6 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表