[信息] uCOSIII uCGUI STM32 平台移植

[复制链接]
 楼主| internally 发表于 2019-6-18 09:25 | 显示全部楼层 |阅读模式
在写了uCOS-III移植后,一直想把GUI移植上去。经过不断的努力,有了不错的进展。下面对移植过程进行详解,以方便大家共同学习。
         我用的是uCGUI3.98版,在网上找了很久, 可是还不是完整版的。没办法,算是比较全的了,只好先用着。官方是4.03版的但是没有源码,是以库的形式。在搞开发的时候, 可以用官方提供的VC工程去开发,可以省去大量烧写芯片的时间。 我用vs2008测试过可以正常运行。

 楼主| internally 发表于 2019-6-18 09:25 | 显示全部楼层
一、环境:

         软件:

STM32F10x 3.5固件库。
MDK4.23 编译器。
uCos-III v3.03。      
uCGUI v3.98。
         硬件:

神舟三号开发板STM30F103ZE芯;
3.2寸屏320*240。
SPI接口的触摸板。
 楼主| internally 发表于 2019-6-18 09:26 | 显示全部楼层
二、资料

这是我搜集到的资料,都存现在网盘上了。现在115不好用了,只好换百度。

ucGUI中文手册.pdf

http://pan.baidu.com/share/link?shareid=25403&uk=118334538

UCGUI3.98源码.rar

http://pan.baidu.com/share/link?shareid=25407&uk=118334538

官方UCGUI4.04, 及说明书

http://pan.baidu.com/share/link?shareid=25413&uk=118334538

http://pan.baidu.com/share/link?shareid=25415&uk=118334538



下面上两个版本空的工程:

    FWLib3.5+uCOSIII3.03

         http://pan.baidu.com/share/link?shareid=25418&uk=118334538

         FWLib2.0+uCOSIII3.03

         http://pan.baidu.com/share/link?shareid=25419&uk=118334538

         提示:
              1、下文的移植都是在FWLib3.5+uCOSIII3.03这个工程上进行的。
              2、这两个工程STM32F固件没有完整添加,在用到哪个功能就添加哪个(减少编译量)。
 楼主| internally 发表于 2019-6-18 09:27 | 显示全部楼层
在移植前最好看过一遍uCGUI中文手册,这样可以有个初步了解,和操作使用。

建立工程时用他推崇的结构:
196275d083de4d971c.png

内容介绍:
113045d083dfa96f4c.png
 楼主| internally 发表于 2019-6-18 09:28 | 显示全部楼层
三、开始准备移植文件:

新建文件夹uCGUI

1、复制UCGUI3.98源码\uC-GUI-V3-98\Micrium\Software\uC-GUI\Start整个GUI和 Config文件夹到uCGUI。
2、复制UCGUI3.98源码\uC-GUI-V3-98\Micrium\Software\uC-GUI\Sample\GUI_X 下GUI_X_Touch.c,GUI_X_uCOS.c两个文件到uCGUI中,因为有触摸功能和uCOS系统。
3、复制UCGUI3.98源码\uC-GUI-V3-98\Micrium\Software\uC-GUI\Sample下整个GUIDemo文件夹到uCGUI。
4、在uCGUI文件夹下新建LCDDriver文件夹,把自己lcd的驱动程序写入其中。我新建的ili9320.c 和ili9320.h两个文件。需要写哪什么驱动函数,后面做详细的介绍。
366755d083e32ec376.png
到此文件的准备就完成了,开始向程序中添加。
 楼主| internally 发表于 2019-6-18 09:29 | 显示全部楼层
本帖最后由 internally 于 2019-6-18 09:31 编辑

四、添加到工程
我还是直接上图,添加哪些文件。
747735d083e5bb8b7b.png
62325d083e628cc35.png
249835d083e69ecfaf.png
948995d083e715ab65.png

直接添加所有Dome中的文件。
759565d083e83e6eb8.png
添加所有GUI子文件。太多了,还是用CTRL+A吧,不然手都要点麻!
 楼主| internally 发表于 2019-6-18 09:30 | 显示全部楼层

940475d083ea59cd95.png
重要的一步,让添加的文件可直接索引到。

好了,所有文件都添加到工程中了。下面是最后重要的一步,对文件进行修改。
 楼主| internally 发表于 2019-6-18 09:31 | 显示全部楼层
五、移植修改文件

LCD的驱动,这一步也关系到LCD显示的成功于否,主要要写三个函数:

void LCDxxx_Init(void);  //LCD硬件初始化

u16 LCDxxx _GetPoint(u16 x,u16 y);  //获取(x,y)坐标的像素点

void LCDxxx _SetPoint(u16 x,u16 y,u16 point);  //把像素点写入(x,y)坐标点

这三个函数以定要再在自己的开发板上测试好了,再复制过来。LCDxxx函数名可自定义。只要这三个函数没有问题,移植就成功一大半了

我的是:

void ili9320_Initializtion(void);

u16 ili9320_GetPoint(u16 x,u16 y);

void ili9320_SetPoint(u16 x,u16 y,u16 point);



写好后,在uCGUI\GUI\LCDDriver下找到LCDTemplate.c文件。

找到LCD_L0_SetPixelIndex 添加ili9320_SetPoint函数;

找到 LCD_L0_GetPixelIndex添加ili9320_GetPoint函数。

如下代码:
  1. /*********************************************************************
  2. *
  3. *       Exported functions
  4. *
  5. **********************************************************************
  6. */

  7. /*********************************************************************
  8. *
  9. *       LCD_L0_SetPixelIndex
  10. *
  11. * Purpose:
  12. *   Sets the index of the given pixel. The upper layers
  13. *   calling this routine make sure that the coordinates are in range, so
  14. *   that no check on the parameters needs to be performed.
  15. */
  16. void LCD_L0_SetPixelIndex(int x, int y, int PixelIndex) {
  17.   int xPhys = 0;
  18.   int yPhys = 0;
  19.   GUI_USE_PARA(x);
  20.   GUI_USE_PARA(y);
  21.   GUI_USE_PARA(PixelIndex);
  22.   /* Convert logical into physical coordinates (Dep. on LCDConf.h) */
  23.   #if LCD_SWAP_XY | LCD_MIRROR_X| LCD_MIRROR_Y
  24.     xPhys = LOG2PHYS_X(x, y);
  25.     yPhys = LOG2PHYS_Y(x, y);
  26.   #else
  27.     xPhys = x;
  28.     yPhys = y;
  29.   #endif
  30.   /* Write into hardware ... Adapt to your system */
  31.   {
  32.     ili9320_SetPoint(xPhys, yPhys, PixelIndex);/* ... */
  33.   }
  34. }

  35. /*********************************************************************
  36. *
  37. *       LCD_L0_GetPixelIndex
  38. *
  39. * Purpose:
  40. *   Returns the index of the given pixel. The upper layers
  41. *   calling this routine make sure that the coordinates are in range, so
  42. *   that no check on the parameters needs to be performed.
  43. */
  44. unsigned int LCD_L0_GetPixelIndex(int x, int y) {
  45.   int xPhys = 0;
  46.   int yPhys = 0;
  47.   LCD_PIXELINDEX PixelIndex;

  48.   GUI_USE_PARA(x);
  49.   GUI_USE_PARA(y);
  50.   /* Convert logical into physical coordinates (Dep. on LCDConf.h) */
  51.   #if LCD_SWAP_XY | LCD_MIRROR_X| LCD_MIRROR_Y
  52.     xPhys = LOG2PHYS_X(x, y);
  53.     yPhys = LOG2PHYS_Y(x, y);
  54.   #else
  55.     xPhys = x;
  56.     yPhys = y;
  57.   #endif
  58.   /* Read from hardware ... Adapt to your system */
  59.   {
  60.     PixelIndex = ili9320_GetPoint(xPhys, yPhys);/* ... */
  61.   }
  62.   return PixelIndex;
  63. }
 楼主| internally 发表于 2019-6-18 09:32 | 显示全部楼层
在uCGUI\Config找到三个配置文件。
LCDConf.h
在pdf的第20章有详细介绍
905805d083f163f25e.png
先设定这几个必需的。

初始化宏定义

驱动如果是自己写的需要以下宏定义

#define LCD_CONTROLLER      -1

#define LCD_INIT_CONTROLLER()  ili9320_Initializtion();

GUIConf.h

可以用默认配置

GUITouchConf.h
先用默认值,等运行Dome后,有个校准,获得校准值,再进行修改。
参图:
209705d083f3ed3201.png
 楼主| internally 发表于 2019-6-18 09:33 | 显示全部楼层
GUI_X_Touch.c文件修改

主要添加读X轴和Y轴的AD值。如果和我用同样的开发板,可以用如下代码。
  1. GUI_X_Touch.c
  2.   1 /*
  3.   2 *********************************************************************************************************
  4.   3 *                                             uC/GUI V3.98
  5.   4 *                        Universal graphic software for embedded applications
  6.   5 *
  7.   6 *                       (c) Copyright 2002, Micrium Inc., Weston, FL
  8.   7 *                       (c) Copyright 2002, SEGGER Microcontroller Systeme GmbH
  9.   8 *
  10.   9 *              礐/GUI is protected by international copyright laws. Knowledge of the
  11. 10 *              source code may not be used to write a similar product. This file may
  12. 11 *              only be used in accordance with a license and should not be redistributed
  13. 12 *              in any way. We appreciate your understanding and fairness.
  14. 13 *
  15. 14 ----------------------------------------------------------------------
  16. 15 File        : GUI_TOUCH_X.C
  17. 16 Purpose     : Config / System dependent externals for GUI
  18. 17 ---------------------------END-OF-HEADER------------------------------
  19. 18 */
  20. 19
  21. 20
  22. 21 #include "GUI.h"
  23. 22 #include "GUI_X.h"
  24. 23 #include "ili9320.h"
  25. 24 #include "bsp.h"
  26. 25
  27. 26 //#define NEW8989_LCD      // 如果触摸屏的触摸与指针的移动方向是反的请注释掉该宏定义
  28. 27
  29. 28 unsigned short int X,Y;
  30. 29
  31. 30 void GUI_TOUCH_X_ActivateX(void) {
  32. 31 }
  33. 32
  34. 33 void GUI_TOUCH_X_ActivateY(void) {
  35. 34 }
  36. 35
  37. 36
  38. 37 int  GUI_TOUCH_X_MeasureX(void)
  39. 38 {
  40. 39     unsigned char t=0,t1,count=0;
  41. 40     unsigned short int databuffer[10]={5,7,9,3,2,6,4,0,3,1};//数据组
  42. 41     unsigned short temp=0,X=0;   
  43. 42      
  44. 43     while(/*GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_0)==0&&*/count<10)//循环读数10次
  45. 44     {            
  46. 45 #ifndef NEW8989_LCD
  47. 46         databuffer[count]=TPReadX();
  48. 47 #else
  49. 48         databuffer[count]=TPReadY();
  50. 49 #endif
  51. 50         count++;
  52. 51     }  
  53. 52     if(count==10)//一定要读到10次数据,否则丢弃
  54. 53     {  
  55. 54         do//将数据X升序排列
  56. 55         {   
  57. 56             t1=0;         
  58. 57             for(t=0;t<count-1;t++)
  59. 58             {
  60. 59                 if(databuffer[t]>databuffer[t+1])//升序排列
  61. 60                 {
  62. 61                     temp=databuffer[t+1];
  63. 62                     databuffer[t+1]=databuffer[t];
  64. 63                     databuffer[t]=temp;
  65. 64                     t1=1;
  66. 65                 }  
  67. 66             }
  68. 67         }while(t1);                                 
  69. 68         X=(databuffer[3]+databuffer[4]+databuffer[5]+databuffer[6])>>2;      
  70. 69     }
  71. 70 #ifndef NEW8989_LCD
  72. 71     return(X);
  73. 72 #else
  74. 73     return((X>100)?(X-100): 0);
  75. 74 #endif
  76. 75  
  77. 76 }
  78. 77
  79. 78 int  GUI_TOUCH_X_MeasureY(void) {
  80. 79       unsigned char t=0,t1,count=0;
  81. 80     unsigned short int databuffer[10]={5,7,9,3,2,6,4,0,3,1};//数据组
  82. 81     unsigned short temp=0,Y=0;   
  83. 82  
  84. 83     while(/*GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_0)==0&&*/count<10)    //循环读数10次
  85. 84     {            
  86. 85 #ifndef NEW8989_LCD
  87. 86         databuffer[count]=TPReadY();
  88. 87 #else
  89. 88         databuffer[count]=TPReadX();
  90. 89 #endif
  91. 90         count++;  
  92. 91     }  
  93. 92     if(count==10)//一定要读到10次数据,否则丢弃
  94. 93     {  
  95. 94         do//将数据X升序排列
  96. 95         {   
  97. 96             t1=0;         
  98. 97             for(t=0;t<count-1;t++)
  99. 98             {
  100. 99                 if(databuffer[t]>databuffer[t+1])//升序排列
  101. 100                 {
  102. 101                     temp=databuffer[t+1];
  103. 102                     databuffer[t+1]=databuffer[t];
  104. 103                     databuffer[t]=temp;
  105. 104                     t1=1;
  106. 105                 }  
  107. 106             }
  108. 107         }while(t1);                                 
  109. 108         Y=(databuffer[3]+databuffer[4]+databuffer[5]+databuffer[6])>>2;      
  110. 109     }
  111. 110 #ifndef NEW8989_LCD
  112. 111     return(Y);
  113. 112 #else
  114. 113     Y = 4095-Y;
  115. 114     return((Y>100)?(Y-100): 0);
  116. 115 #endif
  117. 116 }
  118. 117
  119. 118
 楼主| internally 发表于 2019-6-18 09:33 | 显示全部楼层
GUI_X_uCOS.c文件如下替换
  1. GUI_X_uCOS.c
  2.   1 /*
  3.   2 *********************************************************************************************************
  4.   3 *                                                uC/GUI
  5.   4 *                        Universal graphic software for embedded applications
  6.   5 *
  7.   6 *                       (c) Copyright 2002, Micrium Inc., Weston, FL
  8.   7 *                       (c) Copyright 2002, SEGGER Microcontroller Systeme GmbH
  9.   8 *
  10.   9 *              礐/GUI is protected by international copyright laws. Knowledge of the
  11. 10 *              source code may not be used to write a similar product. This file may
  12. 11 *              only be used in accordance with a license and should not be redistributed
  13. 12 *              in any way. We appreciate your understanding and fairness.
  14. 13 *
  15. 14 ---Author-Explanation
  16. 15 *
  17. 16 * 1.00.00 020519 JJL    First release of uC/GUI to uC/OS-II interface
  18. 17 *
  19. 18 *
  20. 19 * Known problems or limitations with current version
  21. 20 *
  22. 21 *    None.
  23. 22 *
  24. 23 *
  25. 24 * Open issues
  26. 25 *
  27. 26 *    None
  28. 27 *********************************************************************************************************
  29. 28 */
  30. 29
  31. 30 #include "os.h"
  32. 31 #include "os_Cfg_app.h"
  33. 32 #include "GUI_Private.H"
  34. 33 #include "stdio.H"
  35. 34
  36. 35
  37. 36 /*
  38. 37 *********************************************************************************************************
  39. 38 *                                         GLOBAL VARIABLES
  40. 39 *********************************************************************************************************
  41. 40 */
  42. 41
  43. 42 static  int        KeyPressed;
  44. 43 static  char       KeyIsInited;
  45. 44
  46. 45 static  OS_SEM      dispSem;
  47. 46 static  OS_SEM      eventSem;
  48. 47 static  OS_SEM      keySem;
  49. 48
  50. 49 /*
  51. 50 *********************************************************************************************************
  52. 51 *                                        TIMING FUNCTIONS
  53. 52 *
  54. 53 * Notes: Some timing dependent routines of uC/GUI require a GetTime and delay funtion.
  55. 54 *        Default time unit (tick), normally is 1 ms.
  56. 55 *********************************************************************************************************
  57. 56 */
  58. 57
  59. 58 int GUI_X_GetTime(void)
  60. 59 {
  61. 60     OS_ERR err;
  62. 61     
  63. 62     return ((int)OSTimeGet( (OS_ERR *)&err));
  64. 63 }
  65. 64
  66. 65 void GUI_X_Delay(int period)
  67. 66 {
  68. 67     OS_TICK  ticks;
  69. 68     OS_ERR err;
  70. 69     
  71. 70     ticks = period * OS_CFG_TICK_RATE_HZ / 1000;
  72. 71     OSTimeDly(  (OS_TICK    )ticks,
  73. 72                 (OS_OPT        )OS_OPT_TIME_DLY,
  74. 73                 (OS_ERR     *)&err);
  75. 74 }
  76. 75
  77. 76
  78. 77 /*
  79. 78 *********************************************************************************************************
  80. 79 *                                          GUI_X_ExecIdle()
  81. 80 *********************************************************************************************************
  82. 81 */
  83. 82 /*WM空闲时调用*/
  84. 83 void GUI_X_ExecIdle(void)
  85. 84 {
  86. 85     OS_ERR err;
  87. 86     
  88. 87     OSTimeDly(  (OS_TICK    )50,
  89. 88                 (OS_OPT     )OS_OPT_TIME_DLY,
  90. 89                 (OS_ERR     *)&err);
  91. 90 }
  92. 91
  93. 92
  94. 93 /*
  95. 94 *********************************************************************************************************
  96. 95 *                                    MULTITASKING INTERFACE FUNCTIONS
  97. 96 *
  98. 97 * Note(1): 1) The following routines are required only if uC/GUI is used in a true multi task environment,
  99. 98 *             which means you have more than one thread using the uC/GUI API.  In this case the #define
  100. 99 *             GUI_OS 1   needs to be in GUIConf.h
  101. 100 *********************************************************************************************************
  102. 101 */
  103. 102
  104. 103 void GUI_X_InitOS (void)
  105. 104 {
  106. 105     OS_ERR err;
  107. 106     
  108. 107     OSSemCreate(    (OS_SEM     *)&dispSem, //建立一个互斥型信号量
  109. 108                     (CPU_CHAR   *)"dispSem",
  110. 109                     (OS_SEM_CTR )1,
  111. 110                     (OS_ERR     *)&err   );
  112. 111     
  113. 112     OSSemCreate(    (OS_SEM     *)&eventSem,
  114. 113                     (CPU_CHAR   *)"eventSem",
  115. 114                     (OS_SEM_CTR )1,
  116. 115                     (OS_ERR     *)&err   );
  117. 116 }
  118. 117
  119. 118
  120. 119 void GUI_X_Lock(void)
  121. 120 {
  122. 121     OS_ERR err;
  123. 122     CPU_TS ts;
  124. 123     
  125. 124     OSSemPend(  (OS_SEM     *)&dispSem,
  126. 125                 (OS_TICK    )0,
  127. 126                 (OS_OPT        )OS_OPT_PEND_BLOCKING,
  128. 127                 (CPU_TS     *)&ts,
  129. 128                 (OS_ERR     *)&err);
  130. 129 }
  131. 130
  132. 131
  133. 132 void GUI_X_Unlock(void)
  134. 133 {
  135. 134     OS_ERR err;
  136. 135     
  137. 136     OSSemPost(  (OS_SEM     *)&dispSem,
  138. 137                 (OS_OPT        )OS_OPT_POST_1,
  139. 138                 (OS_ERR     *)&err);
  140. 139 }
  141. 140
  142. 141
  143. 142 U32 GUI_X_GetTaskId(void)
  144. 143 {
  145. 144   return ((U32)(OSTCBCurPtr->Prio));
  146. 145 }
  147. 146
  148. 147 /*
  149. 148 *********************************************************************************************************
  150. 149 *                                        GUI_X_WaitEvent()
  151. 150 *                                        GUI_X_SignalEvent()
  152. 151 *********************************************************************************************************
  153. 152 */
  154. 153
  155. 154
  156. 155 void GUI_X_WaitEvent(void)
  157. 156 {
  158. 157     OS_ERR err;
  159. 158     CPU_TS ts;
  160. 159     
  161. 160     OSSemPend(  (OS_SEM     *)&eventSem,
  162. 161                 (OS_TICK    )0,
  163. 162                 (OS_OPT        )OS_OPT_PEND_BLOCKING,
  164. 163                 (CPU_TS     *)&ts,
  165. 164                 (OS_ERR     *)&err);
  166. 165 }
  167. 166
  168. 167
  169. 168 void GUI_X_SignalEvent(void)
  170. 169 {
  171. 170     OS_ERR err;
  172. 171
  173. 172     OSSemPost(  (OS_SEM     *)&eventSem,
  174. 173                 (OS_OPT        )OS_OPT_POST_1,
  175. 174                 (OS_ERR     *)&err);
  176. 175 }
  177. 176
  178. 177 /*
  179. 178 *********************************************************************************************************
  180. 179 *                                      KEYBOARD INTERFACE FUNCTIONS
  181. 180 *
  182. 181 * Purpose: The keyboard routines are required only by some widgets.
  183. 182 *          If widgets are not used, they may be eliminated.
  184. 183 *
  185. 184 * Note(s): If uC/OS-II is used, characters typed into the log window will be placed    in the keyboard buffer.
  186. 185 *          This is a neat feature which allows you to operate your target system without having to use or
  187. 186 *          even to have a keyboard connected to it. (useful for demos !)
  188. 187 *********************************************************************************************************
  189. 188 */
  190. 189
  191. 190 static void CheckInit(void)
  192. 191 {
  193. 192     if(KeyIsInited==DEF_FALSE)
  194. 193     {
  195. 194         KeyIsInited = DEF_TRUE;
  196. 195         GUI_X_Init();
  197. 196     }
  198. 197 }
  199. 198
  200. 199
  201. 200 /*被GUI_Init()调用,用来初始化一些GUI运行之前需要用的硬件,如键盘或者鼠标之类的.如果不需要的话,可以为空*/
  202. 201 void GUI_X_Init(void)
  203. 202 {
  204. 203     OS_ERR err;
  205. 204     
  206. 205     OSSemCreate(    (OS_SEM     *)&keySem,
  207. 206                     (CPU_CHAR   *)"keySem",
  208. 207                     (OS_SEM_CTR )0,
  209. 208                     (OS_ERR     *)&err   );
  210. 209 }
  211. 210
  212. 211
  213. 212 int GUI_X_GetKey(void)
  214. 213 {
  215. 214     int r;
  216. 215     r = KeyPressed;
  217. 216     CheckInit();
  218. 217     KeyPressed = 0;
  219. 218     return (r);
  220. 219 }
  221. 220
  222. 221
  223. 222 int GUI_X_WaitKey(void)
  224. 223 {
  225. 224     int  r;
  226. 225     OS_ERR err;
  227. 226     CPU_TS ts;
  228. 227     
  229. 228     CheckInit();
  230. 229     if(KeyPressed==0)
  231. 230     {
  232. 231         OSSemPend(  (OS_SEM     *)&keySem,      //等待信号量
  233. 232                     (OS_TICK    )0,
  234. 233                     (OS_OPT     )OS_OPT_PEND_BLOCKING,
  235. 234                     (CPU_TS     *)&ts,
  236. 235                     (OS_ERR     *)&err);
  237. 236     }
  238. 237     r= KeyPressed;
  239. 238     KeyPressed = 0;
  240. 239     return (r);
  241. 240 }
  242. 241
  243. 242
  244. 243 void GUI_X_StoreKey(int k)
  245. 244 {
  246. 245     OS_ERR err;
  247. 246     
  248. 247     KeyPressed = k;
  249. 248     OSSemPost(  (OS_SEM     *)&keySem,      //释放信号量
  250. 249                 (OS_OPT     )OS_OPT_POST_1,
  251. 250                 (OS_ERR     *)&err);
  252. 251 }
  253. 252
  254. 253 void GUI_X_Log(const char *s)
  255. 254 {
  256. 255     GUI_USE_PARA(s);
  257. 256 }
  258. 257
  259. 258 void GUI_X_Warn(const char *s)
  260. 259 {
  261. 260     GUI_USE_PARA(s);
  262. 261 }
  263. 262
  264. 263 void GUI_X_ErrorOut(const char *s)
  265. 264 {
  266. 265     GUI_USE_PARA(s);
  267. 266 }
 楼主| internally 发表于 2019-6-18 09:34 | 显示全部楼层
在BSP.c文件中添加触摸板SPI接口程序。修改后如下:
  1. BSP.C
  2.   1 /*
  3.   2 ********************************************************************************
  4.   3 *                                  uC/OS-III
  5.   4 *                           
  6.   5 *                              ARM Cortex-M3 Port
  7.   6 *
  8.   7 * File          : Config.C
  9.   8 * Version       : V1.0
  10.   9 * By            : 王宏强
  11. 10 *
  12. 11 * For           : Stm32f10x
  13. 12 * Mode          : Thumb2
  14. 13 * Toolchain     :
  15. 14 *                     RealView Microcontroller Development Kit (MDK)
  16. 15 *                     Keil uVision
  17. 16 * Description   : STM32F10x 内部 系统的配置
  18. 17 *
  19. 18 *                    1,系统中断优先级模式设置
  20. 19 *                    2,系统程序启动指定
  21. 20 *                    3,系统时钟计时器配置
  22. 21 *                    4,芯片引脚初始化
  23. 22 *                    
  24. 23 * Date          : 2012.05.22
  25. 24 *******************************************************************************/
  26. 25
  27. 26 #include "misc.h"
  28. 27 #include "stm32f10x_gpio.h"
  29. 28 #include "stm32f10x_rcc.h"
  30. 29 #include "stm32f10x_iwdg.h"
  31. 30 #include "stm32f10x_spi.h"
  32. 31 #include "bsp.h"
  33. 32
  34. 33
  35. 34 GPIO_InitTypeDef GPIO_InitStructure;
  36. 35
  37. 36 /*******************************************************************************
  38. 37 * Function Name  : GPIO_Configuration
  39. 38 * Description    : Configures the different GPIO ports.
  40. 39 * Input          : None
  41. 40 * Output         : None
  42. 41 * Return         : None
  43. 42 *******************************************************************************/
  44. 43 void GPIO_Configuration(void)
  45. 44 {
  46. 45 #ifdef USE_STM3210B_EVAL
  47. 46     /* Enable the USART2 Pins Software Remapping */
  48. 47     GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);
  49. 48 #endif
  50. 49
  51. 50     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
  52. 51                      RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD |
  53. 52                      RCC_APB2Periph_GPIOE, ENABLE);
  54. 53
  55. 54     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
  56. 55     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
  57. 56     GPIO_Init(GPIOA, &GPIO_InitStructure);
  58. 57     GPIO_Init(GPIOB, &GPIO_InitStructure);
  59. 58     GPIO_Init(GPIOC, &GPIO_InitStructure);
  60. 59     GPIO_Init(GPIOD, &GPIO_InitStructure);
  61. 60     GPIO_Init(GPIOE, &GPIO_InitStructure);
  62. 61
  63. 62     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
  64. 63                          RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD |
  65. 64                          RCC_APB2Periph_GPIOE, DISABLE);  
  66. 65
  67. 66 }
  68. 67
  69. 68
  70. 69 /*******************************************************************************
  71. 70 * Function Name  : Delay
  72. 71 * Description    : Inserts a delay time.
  73. 72 * Input          : nCount: specifies the delay time length.
  74. 73 * Output         : None
  75. 74 * Return         : None
  76. 75 *******************************************************************************/
  77. 76 //void Delay(volatile CPU_INT32U nCount)
  78. 77 //{
  79. 78 //  for(; nCount != 0; nCount--);
  80. 79 //}
  81. 80
  82. 81 /*******************************************************************************
  83. 82 函 数 名:void IWDG_Init(void)
  84. 83 功能描述:看门狗初始化                        
  85. 84 入口参数:                           
  86. 85 返回参数:
  87. 86 创建时间: 2011.6.24
  88. 87 ********************************************************************************/
  89. 88 void IWDG_Init(void)
  90. 89 {
  91. 90     IWDG_WriteAccessCmd( IWDG_WriteAccess_Enable );
  92. 91     IWDG_SetPrescaler( IWDG_Prescaler_64);    //最小
  93. 92     IWDG_SetReload( 0x138);        //40KHz内部时钟 (1/40000 * 64 * 0x138 = 0.5s)
  94. 93     IWDG_WriteAccessCmd( IWDG_WriteAccess_Disable );
  95. 94     IWDG_Enable();
  96. 95     IWDG_ReloadCounter();
  97. 96 }
  98. 97
  99. 98 /*******************************************************************************
  100. 99 * Function Name :void SysTickInit(void)
  101. 100 * Description   :系统定时器时间配置
  102. 101 * Input         :
  103. 102 * Output        :
  104. 103 * Other         :时基为1ms
  105. 104 * Date          :2011.11.03  12:59:13
  106. 105 *******************************************************************************/
  107. 106 void SysTickInit(void)
  108. 107 {
  109. 108     SysTick_Config(SystemCoreClock / 1000);            //uCOS时基1ms
  110. 109 }
  111. 110
  112. 111 /*******************************************************************************
  113. 112 * Function Name :void InterruptOrder(void)
  114. 113 * Description   :中断向量,优先级
  115. 114 * Input         :
  116. 115 * Output        :
  117. 116 * Other         :
  118. 117 * Date          :2011.10.27  11:50:05
  119. 118 *******************************************************************************/
  120. 119 void NVIC_Configuration(void)
  121. 120 {
  122. 121     NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4);//优先级设置  全为抢占式优先级
  123. 122 }
  124. 123
  125. 124
  126. 125 /*******************************************************************************
  127. 126 * Function Name :void SystemConfig(void)
  128. 127 * Description   :系统时间戳 初始化
  129. 128 * Input         :
  130. 129 * Output        :
  131. 130 * Other         :
  132. 131 * Date          :2012.6.15  13:14:59
  133. 132 *******************************************************************************/
  134. 133 #if (CPU_CFG_TS_TMR_EN == DEF_ENABLED)
  135. 134 void  CPU_TS_TmrInit (void)
  136. 135 {
  137. 136 }
  138. 137 #endif
  139. 138
  140. 139
  141. 140 /*******************************************************************************
  142. 141 * Function Name :void SystemConfig(void)
  143. 142 * Description   :读时间戳 计数值
  144. 143 * Input         :读到的计数值
  145. 144 * Output        :
  146. 145 * Other         :
  147. 146 * Date          :2012.6.15  13:14:59
  148. 147 *******************************************************************************/
  149. 148 #if (CPU_CFG_TS_TMR_EN == DEF_ENABLED)
  150. 149 CPU_TS_TMR  CPU_TS_TmrRd (void)
  151. 150 {
  152. 151     return (SysTick->VAL);
  153. 152 }
  154. 153 #endif
  155. 154
  156. 155 /*******************************************************************************
  157. 156 * Function Name :void SystemConfig(void)
  158. 157 * Description   :系统初始化
  159. 158 * Input         :
  160. 159 * Output        :
  161. 160 * Other         :
  162. 161 * Date          :2011.10.27  13:14:59
  163. 162 *******************************************************************************/
  164. 163 void BspInit(void)
  165. 164 {
  166. 165     NVIC_Configuration();    //中断优先级设置
  167. 166     GPIO_Configuration();    //端口初始化,所有端口关
  168. 167     SPI_Config();           //触摸接口初始化
  169. 168 }
  170. 169
  171. 170 void led_init(void)
  172. 171 {
  173. 172     GPIO_InitTypeDef GPIO_InitStructure;
  174. 173     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOF, ENABLE);
  175. 174     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 |  GPIO_Pin_12 | GPIO_Pin_13;
  176. 175     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  177. 176     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
  178. 177     GPIO_Init(GPIOA, &GPIO_InitStructure);
  179. 178
  180. 179     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8;
  181. 180     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  182. 181     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
  183. 182     GPIO_Init(GPIOF, &GPIO_InitStructure);
  184. 183 }
  185. 184
  186. 185
  187. 186
  188. 187 void led_on(CPU_INT32U n)
  189. 188 {
  190. 189     switch (n)
  191. 190     {
  192. 191         case LED_0:
  193. 192         GPIO_SetBits(GPIOD, GPIO_Pin_2);
  194. 193         break;
  195. 194         case LED_1:
  196. 195         GPIO_SetBits(GPIOD, GPIO_Pin_3);
  197. 196         break;
  198. 197         case LED_2:
  199. 198         GPIO_SetBits(GPIOD, GPIO_Pin_4);
  200. 199         break;
  201. 200         case LED_3:
  202. 201         GPIO_SetBits(GPIOF, GPIO_Pin_6);
  203. 202         break;
  204. 203         case LED_4:
  205. 204         GPIO_SetBits(GPIOF, GPIO_Pin_7);
  206. 205         break;
  207. 206         case LED_5:
  208. 207         GPIO_SetBits(GPIOF, GPIO_Pin_8);
  209. 208         break;
  210. 209         default:
  211. 210         break;
  212. 211     }
  213. 212 }
  214. 213
  215. 214
  216. 215 void led_off(CPU_INT32U n)
  217. 216 {
  218. 217     switch (n)
  219. 218     {
  220. 219         case LED_0:
  221. 220         GPIO_ResetBits(GPIOD, GPIO_Pin_2);
  222. 221         break;
  223. 222         case LED_1:
  224. 223         GPIO_ResetBits(GPIOD, GPIO_Pin_3);
  225. 224         break;
  226. 225         case LED_2:
  227. 226         GPIO_ResetBits(GPIOD, GPIO_Pin_4);
  228. 227         break;
  229. 228         case LED_3:
  230. 229         GPIO_ResetBits(GPIOF, GPIO_Pin_6);
  231. 230         break;
  232. 231         case LED_4:
  233. 232         GPIO_ResetBits(GPIOF, GPIO_Pin_7);
  234. 233         break;
  235. 234         case LED_5:
  236. 235         GPIO_ResetBits(GPIOF, GPIO_Pin_8);
  237. 236         break;
  238. 237         default:
  239. 238         break;
  240. 239     }
  241. 240 }
  242. 241 /*
  243. 242  T_CS PA4
  244. 243  SPI1_SCK PA5
  245. 244  SPI1_MISO PA6
  246. 245 SPI1_MOSI PA7
  247. 246    T_BUSY PA8
  248. 247 */
  249. 248 void SPI_Config(void)
  250. 249 {
  251. 250     GPIO_InitTypeDef  GPIO_InitStructure;
  252. 251     SPI_InitTypeDef   SPI_InitStructure;
  253. 252     
  254. 253     //GPIOA Periph clock enable
  255. 254     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
  256. 255     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);   
  257. 256     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE);
  258. 257     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF,ENABLE);
  259. 258     //SPI1 Periph clock enable
  260. 259     // RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1,ENABLE);
  261. 260     //SPI2 Periph clock enable
  262. 261     RCC_APB1PeriphClockCmd( RCC_APB1Periph_SPI2, ENABLE ) ;
  263. 262     
  264. 263     //Configure SPI2 pins: SCK, MISO and MOSI
  265. 264     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15;
  266. 265     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  267. 266     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;   //复用推挽输出
  268. 267     GPIO_Init(GPIOB,&GPIO_InitStructure);  
  269. 268     /*
  270. 269     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5|GPIO_Pin_7;
  271. 270     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  272. 271     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;   //推挽输出
  273. 272     GPIO_Init(GPIOA,&GPIO_InitStructure);     
  274. 273     
  275. 274     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
  276. 275     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  277. 276     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;   //上拉输入
  278. 277     GPIO_Init(GPIOA,&GPIO_InitStructure);     */
  279. 278     
  280. 279     //Configure PF10 pin: TP_CS pin
  281. 280     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
  282. 281     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  283. 282     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;     //推挽输出
  284. 283     GPIO_Init(GPIOB,&GPIO_InitStructure);
  285. 284     
  286. 285     //Configure PA8 pin: TP_BUSY pin
  287. 286     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
  288. 287     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  289. 288     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;     //上拉输入
  290. 289     GPIO_Init(GPIOE,&GPIO_InitStructure);
  291. 290     
  292. 291     /* Configure PE.06 as input floating For TP_IRQ*/
  293. 292     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
  294. 293     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  295. 294     GPIO_Init(GPIOE,&GPIO_InitStructure);
  296. 295     
  297. 296     // SPI1 Config  
  298. 297     SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
  299. 298     SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
  300. 299     SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
  301. 300     SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
  302. 301     SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
  303. 302     SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;   //SPI_NSS_Hard
  304. 303     SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_64;
  305. 304     SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
  306. 305     SPI_InitStructure.SPI_CRCPolynomial = 7;
  307. 306     SPI_Init(SPI2,&SPI_InitStructure);
  308. 307     
  309. 308     // SPI1 enable  
  310. 309     SPI_Cmd(SPI2,ENABLE);  
  311. 310 }
  312. 311
  313. 312
  314. 313 unsigned char SPI_WriteByte(unsigned char data)
  315. 314 {
  316. 315     unsigned char Data = 0;
  317. 316     
  318. 317     //Wait until the transmit buffer is empty
  319. 318     while(SPI_I2S_GetFlagStatus(SPI2,SPI_I2S_FLAG_TXE)==RESET);
  320. 319     // Send the byte  
  321. 320     SPI_I2S_SendData(SPI2,data);
  322. 321     
  323. 322     //Wait until a data is received
  324. 323     while(SPI_I2S_GetFlagStatus(SPI2,SPI_I2S_FLAG_RXNE)==RESET);
  325. 324     // Get the received data
  326. 325     Data = SPI_I2S_ReceiveData(SPI2);
  327. 326     
  328. 327     // Return the shifted data
  329. 328     return Data;
  330. 329 }  
  331. 330 void SpiDelay(unsigned int DelayCnt)
  332. 331 {
  333. 332  unsigned int i;
  334. 333  for(i=0;i<DelayCnt;i++);
  335. 334 }
  336. 335
  337. 336 u16 TPReadX(void)
  338. 337 {
  339. 338     u16 x=0;
  340. 339     TP_CS();
  341. 340     SpiDelay(10);
  342. 341     SPI_WriteByte(0x90);
  343. 342     SpiDelay(10);
  344. 343     x=SPI_WriteByte(0x00);
  345. 344     x<<=8;
  346. 345     x+=SPI_WriteByte(0x00);
  347. 346     SpiDelay(10);
  348. 347     TP_DCS();
  349. 348     x = x>>3;
  350. 349     return (x);
  351. 350 }
  352. 351
  353. 352 u16 TPReadY(void)
  354. 353 {
  355. 354     u16 y=0;
  356. 355     TP_CS();
  357. 356     SpiDelay(10);
  358. 357     SPI_WriteByte(0xD0);
  359. 358     SpiDelay(10);
  360. 359     y=SPI_WriteByte(0x00);
  361. 360     y<<=8;
  362. 361     y+=SPI_WriteByte(0x00);
  363. 362     SpiDelay(10);
  364. 363     TP_DCS();
  365. 364     y = y>>3;
  366. 365     return (y);
  367. 366 }
 楼主| internally 发表于 2019-6-18 09:34 | 显示全部楼层
向工程中添加两个stm32f10x_fsmc.c,stm32f10x_spi.c这两个文件。

好了,大部分的准备工作都好了, 再在让新建一个任务来运行Dome中的MainTask();在任务3中调用GUI_TOUCH_Exec();
  1. APP.C
  2.   1 /*-------------------------------------------------------------------------
  3.   2
  4.   3                             软件主体
  5.   4
  6.   5     
  7.   6 -------------------------------------------------------------------------*/
  8.   7
  9.   8 #include "bsp.h"
  10.   9 #include "App.h"
  11. 10
  12. 11 extern void MainTask(void);
  13. 12 extern void GUI_TOUCH_Exec(void);
  14. 13
  15. 14 static  OS_TCB      taskStartTCB;
  16. 15 static  CPU_STK     taskStartStk[STARTUP_TASK_STK_SIZE];         //启动任务的程序空间
  17. 16
  18. 17 static  OS_TCB      task1TCB;
  19. 18 static  CPU_STK     task1Stk[TASK1_STK_SIZE];
  20. 19
  21. 20 static  OS_TCB      task2TCB;
  22. 21 static  CPU_STK     task2Stk[TASK2_STK_SIZE];
  23. 22
  24. 23 static  OS_TCB      task3TCB;
  25. 24 static  CPU_STK     task3Stk[TASK3_STK_SIZE];
  26. 25
  27. 26 static  OS_TCB      dispTCB;
  28. 27 static  CPU_STK     dispStk[TASK4_STK_SIZE];
  29. 28
  30. 29 static  volatile    OS_SEM taskSem;
  31. 30
  32. 31
  33. 32
  34. 33 /*******************************************************************************
  35. 34 * Function Name :void TaskStart(void)
  36. 35 * Description   :任务启动
  37. 36 * Input         :
  38. 37 * Output        :
  39. 38 * Other         :
  40. 39 * Date          :2012.04.18  11:48:23
  41. 40 *******************************************************************************/
  42. 41 static void TaskStart(void)
  43. 42 {
  44. 43     OS_ERR         err;
  45. 44     
  46. 45     led_init();
  47. 46     SysTickInit();
  48. 47     
  49. 48     
  50. 49     OSTaskCreate(   (OS_TCB     *)&task1TCB,
  51. 50                     (CPU_CHAR   *)"Task1",
  52. 51                     (OS_TASK_PTR)Task1,
  53. 52                     (void       *)0,
  54. 53                     (OS_PRIO    )TASK1_PRIO,
  55. 54                     (CPU_STK    *)&task1Stk[0],
  56. 55                     (CPU_STK_SIZE)TASK1_STK_SIZE / 10,
  57. 56                     (CPU_STK_SIZE)TASK1_STK_SIZE,
  58. 57                     (OS_MSG_QTY )0,
  59. 58                     (OS_TICK    )0,
  60. 59                     (void       *)0,
  61. 60                     (OS_OPT     )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
  62. 61                     (OS_ERR     *)&err);
  63. 62     
  64. 63     OSTaskCreate(   (OS_TCB     *)&task2TCB,
  65. 64                     (CPU_CHAR   *)"Task2",
  66. 65                     (OS_TASK_PTR)Task2,
  67. 66                     (void       *)0,
  68. 67                     (OS_PRIO    ) TASK2_PRIO,
  69. 68                     (CPU_STK    *)&task2Stk[0],
  70. 69                     (CPU_STK_SIZE)TASK2_STK_SIZE / 10,
  71. 70                     (CPU_STK_SIZE)TASK2_STK_SIZE,
  72. 71                     (OS_MSG_QTY )0,
  73. 72                     (OS_TICK    )0,
  74. 73                     (void       *)0,
  75. 74                     (OS_OPT     )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
  76. 75                     (OS_ERR     *)&err);   
  77. 76     
  78. 77     
  79. 78     OSTaskCreate(   (OS_TCB     *)&task3TCB,
  80. 79                     (CPU_CHAR   *)"Task3",
  81. 80                     (OS_TASK_PTR)Task3,
  82. 81                     (void       *)0,
  83. 82                     (OS_PRIO    )TASK3_PRIO,
  84. 83                     (CPU_STK    *)&task3Stk[0],
  85. 84                     (CPU_STK_SIZE)TASK3_STK_SIZE / 10,
  86. 85                     (CPU_STK_SIZE)TASK3_STK_SIZE,
  87. 86                     (OS_MSG_QTY )0,
  88. 87                     (OS_TICK    )0,
  89. 88                     (void       *)0,
  90. 89                     (OS_OPT     )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
  91. 90                     (OS_ERR     *)&err);
  92. 91  
  93. 92      OSTaskCreate(  (OS_TCB     *)&dispTCB,
  94. 93                     (CPU_CHAR   *)"LCD display",
  95. 94                     (OS_TASK_PTR)MainTask,
  96. 95                     (void       *)0,
  97. 96                     (OS_PRIO    )Disp_PRIO,
  98. 97                     (CPU_STK    *)&dispStk[0],
  99. 98                     (CPU_STK_SIZE)TASK4_STK_SIZE / 10,
  100. 99                     (CPU_STK_SIZE)TASK4_STK_SIZE,
  101. 100                     (OS_MSG_QTY )0,
  102. 101                     (OS_TICK    )0,
  103. 102                     (void       *)0,
  104. 103                     (OS_OPT     )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
  105. 104                     (OS_ERR     *)&err);   
  106. 105     
  107. 106     OSSemCreate(    (OS_SEM     *)&taskSem,
  108. 107                     (CPU_CHAR   *)"taskSem",
  109. 108                     (OS_SEM_CTR )0,
  110. 109                     (OS_ERR     *)err);
  111. 110     
  112. 111     OSTaskDel(      (OS_TCB     *)&taskStartTCB,
  113. 112                     (OS_ERR     *)&err);
  114. 113 }
  115. 114
  116. 115 static void Task1(void *p_arg)
  117. 116 {
  118. 117     OS_ERR err;
  119. 118     
  120. 119     while (1)
  121. 120     {
  122. 121         led_on(LED_4);
  123. 122         OSTimeDly(  (OS_TICK    )200,
  124. 123                     (OS_OPT     )OS_OPT_TIME_DLY,
  125. 124                     (OS_ERR     *)&err);
  126. 125         
  127. 126         led_off(LED_4);
  128. 127         OSTimeDly(  (OS_TICK    )200,
  129. 128                     (OS_OPT     )OS_OPT_TIME_DLY,
  130. 129                     (OS_ERR     *)&err);
  131. 130         
  132. 131         OSSemPost(  (OS_SEM     *)&taskSem,
  133. 132                     (OS_OPT     )OS_OPT_POST_ALL,
  134. 133                     (OS_ERR     *)&err);
  135. 134     }
  136. 135 }
  137. 136
  138. 137 static void Task2(void *p_arg)
  139. 138 {
  140. 139     OS_ERR err;
  141. 140
  142. 141     while (1)
  143. 142     {
  144. 143         led_on(LED_5);
  145. 144         OSSemPend(  (OS_SEM     *)&taskSem,
  146. 145                     (OS_TICK    )10000,
  147. 146                     (OS_OPT     )OS_OPT_PEND_BLOCKING,
  148. 147                     (CPU_TS     *)0,
  149. 148                     (OS_ERR     *)&err);
  150. 149         
  151. 150         led_off(LED_5);
  152. 151         OSSemPend(  (OS_SEM     *)&taskSem,
  153. 152                     (OS_TICK    )10000,
  154. 153                     (OS_OPT     )OS_OPT_PEND_BLOCKING,
  155. 154                     (CPU_TS     *)0,
  156. 155                     (OS_ERR     *)&err);
  157. 156     }
  158. 157 }
  159. 158
  160. 159 static void Task3(void *p_arg)
  161. 160 {
  162. 161     OS_ERR err;
  163. 162     static int tasCon = 0;
  164. 163     while (1)
  165. 164     {      
  166. 165         GUI_TOUCH_Exec();
  167. 166         OSTimeDly(  (OS_TICK    )10,
  168. 167                     (OS_OPT     )OS_OPT_TIME_DLY,
  169. 168                     (OS_ERR     *)&err);
  170. 169         
  171. 170         OSTimeDly(  (OS_TICK    )10,
  172. 171                     (OS_OPT     )OS_OPT_TIME_DLY,
  173. 172                     (OS_ERR     *)&err);
  174. 173
  175. 174         if ((tasCon++ % 50) < 25)
  176. 175             led_on(LED_3);
  177. 176         else
  178. 177             led_off(LED_3);
  179. 178     }      
  180. 179 }
  181. 180
  182. 181
  183. 182 void KernelMain(void)
  184. 183 {
  185. 184     OS_ERR err;
  186. 185
  187. 186     CPU_Init();
  188. 187     OSInit(         (OS_ERR        *)&err);
  189. 188
  190. 189     OSTaskCreate(   (OS_TCB     *)&taskStartTCB,
  191. 190                     (CPU_CHAR   *)"Task Start",
  192. 191                     (OS_TASK_PTR)TaskStart,
  193. 192                     (void       *)0,
  194. 193                     (OS_PRIO    ) STARTUP_TASK_PRIO,
  195. 194                     (CPU_STK    *)&taskStartStk[0],
  196. 195                     (CPU_STK_SIZE)STARTUP_TASK_STK_SIZE / 10,
  197. 196                     (CPU_STK_SIZE)STARTUP_TASK_STK_SIZE,
  198. 197                     (OS_MSG_QTY )0,
  199. 198                     (OS_TICK    )0,
  200. 199                     (void       *)0,
  201. 200                     (OS_OPT     )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
  202. 201                     (OS_ERR     *)&err);   
  203. 202     
  204. 203     OSStart(        (OS_ERR        *)&err);
  205. 204 }
 楼主| internally 发表于 2019-6-18 09:35 | 显示全部楼层
设定优先级 和分配空间。任务3分配350个字节,MainTask分配500个字节

优先级设定触摸版 比MainTask()高就可以了。

需要注意一个问题,GUI中用到了获取获取时基计数器的值。而时基计数器是在优先级为10的任务中进行刷新的。所以必需把         MainTask()任务的优先级比10优先级低。

         还有一个解决办法:修改时基计数器任务的优先级,在uCOS-III\uCOS-III文件os_cfg_app.h

OS_CFG_TMR_TASK_PRIO

OS_CFG_TICK_TASK_PRIO      



到此就可以进行编译了。

几分钟的等待,下载~~~
 楼主| internally 发表于 2019-6-18 09:36 | 显示全部楼层
每次编译的时间实在是太长了。这样咱们把源代码生成库,再进行编译。如下图:
787775d083fdb19195.png
再编译生成
到Obj文件夹下到Project.lib 找到,改下名子GUI3_98.lib
把工程中的uCGUI/lib里的所有文件删除,用GUI3_98.lib替换。
再切换回来
685715d083ff553f37.png
424585d083ffd455b9.png
再编译, 是不是非常快了。

注意:在对LCD配置变更时,需要重新制作.lib库。
 楼主| internally 发表于 2019-6-18 09:37 | 显示全部楼层
以下两个连接是编译完成后的工程。

FWLib3.5+uCOSIII3.03+uCGUI3.98(源文件版).rar

http://pan.baidu.com/share/link?shareid=25616&uk=118334538

FWLib3.5+uCOSIII3.03+uCGUI3.98(库形式版).rar

http://pan.baidu.com/share/link?shareid=25619&uk=118334538

 楼主| internally 发表于 2019-6-18 09:38 | 显示全部楼层
总结:

在移植的过程中主要讲述了三点

三个LCD的驱动函数。
GUI程序在uCOS-III优先级的选择。
GUI库的制作。
好了,就这些了,后期还会慢慢更新最新版。希望以上对新学习uCGUI的朋友有所帮助。

下面传几个Dome的照片。
224375d084057bec35.png
592145d0840613d555.png
189975d08406990394.png
160215d08407193283.png
321625d08407baf939.png

视频http://www.tudou.com/programs/view/Ut-yCR2jTs0/
yediezeus 发表于 2019-6-18 09:38 | 显示全部楼层
o(╥﹏╥)o
xiaoqizi 发表于 2019-7-8 09:32 | 显示全部楼层
图片效果不错
观海 发表于 2019-7-8 10:52 | 显示全部楼层
非常感谢楼主分享
您需要登录后才可以回帖 登录 | 注册

本版积分规则

15

主题

315

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部