[触摸板源码]uCGUI在STM32 + uCOS-III平台移植 [复制链接]查看:4656回复:0

1#

在写了uCOS-III移植后,一直想把GUI移植上去。经过不断的努力,有了不错的进展。下面对移植过程进行详解,以方便大家共同学习。

         我用的是uCGUI3.98版,在网上找了很久, 可是还不是完整版的。没办法,算是比较全的了,只好先用着。官方是4.03版的但是没有源码,是以库的形式。在搞开发的时候, 可以用官方提供的VC工程去开发,可以省去大量烧写芯片的时间。 我用vs2008测试过可以正常运行。


一、环境:

         软件:


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

         硬件:


  • 神舟三号开发板STM30F103ZE芯;
  • 3.2寸屏320*240。
  • SPI接口的触摸板。

二、资料

这是我搜集到的资料,都存现在网盘上了。现在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

         提示:


  • 下文的移植都是在FWLib3.5+uCOSIII3.03这个工程上进行的。
  • 这两个工程STM32F固件没有完整添加,在用到哪个功能就添加哪个(减少编译量)。


         在移植前最好看过一遍uCGUI中文手册,这样可以有个初步了解,和操作使用。

建立工程时用他推崇的结构:

         图1


内容介绍:

图2


三、开始准备移植文件:

新建文件夹uCGUI

图3

到此文件的准备就完成了,开始向程序中添加。


四、添加到工程

我还是直接上图,添加哪些文件。

图4

图5

图6

图7

直接添加所有Dome中的文件。

图8

添加所有GUI子文件。太多了,还是用CTRL+A吧,不然手都要点麻!

图9

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

好了,所有文件都添加到工程中了。下面是最后重要的一步,对文件进行修改。


五、移植修改文件

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 *10 *       LCD_L0_SetPixelIndex11 *12 * Purpose:13 *   Sets the index of the given pixel. The upper layers14 *   calling this routine make sure that the coordinates are in range, so15 *   that no check on the parameters needs to be performed.16 */17 void LCD_L0_SetPixelIndex(int x, int y, int PixelIndex) {18   int xPhys = 0;19   int yPhys = 0; 20   GUI_USE_PARA(x);21   GUI_USE_PARA(y);22   GUI_USE_PARA(PixelIndex);23   /* Convert logical into physical coordinates (Dep. on LCDConf.h) */24   #if LCD_SWAP_XY | LCD_MIRROR_X| LCD_MIRROR_Y25     xPhys = LOG2PHYS_X(x, y);26     yPhys = LOG2PHYS_Y(x, y);27   #else28     xPhys = x;29     yPhys = y;30   #endif31   /* Write into hardware ... Adapt to your system */32   {33     ili9320_SetPoint(xPhys, yPhys, PixelIndex);/* ... */34   }35 }36 37 /*********************************************************************38 *39 *       LCD_L0_GetPixelIndex40 *41 * Purpose:42 *   Returns the index of the given pixel. The upper layers43 *   calling this routine make sure that the coordinates are in range, so44 *   that no check on the parameters needs to be performed.45 */46 unsigned int LCD_L0_GetPixelIndex(int x, int y) {47   int xPhys = 0;48   int yPhys = 0;49   LCD_PIXELINDEX PixelIndex;50 51   GUI_USE_PARA(x);52   GUI_USE_PARA(y);53   /* Convert logical into physical coordinates (Dep. on LCDConf.h) */54   #if LCD_SWAP_XY | LCD_MIRROR_X| LCD_MIRROR_Y55     xPhys = LOG2PHYS_X(x, y);56     yPhys = LOG2PHYS_Y(x, y);57   #else58     xPhys = x;59     yPhys = y;60   #endif61   /* Read from hardware ... Adapt to your system */62   {63     PixelIndex = ili9320_GetPoint(xPhys, yPhys);/* ... */64   }65   return PixelIndex;66 }



在uCGUI\Config找到三个配置文件。

LCDConf.h

在pdf的第20章有详细介绍

图10

先设定这几个必需的。

初始化宏定义

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

#define LCD_CONTROLLER      -1

#define LCD_INIT_CONTROLLER()  ili9320_Initializtion();


GUIConf.h

可以用默认配置


GUITouchConf.h

先用默认值,等运行Dome后,有个校准,获得校准值,再进行修改。

参图:


GUI_X_Touch.c文件修改

主要添加读X轴和Y轴的AD值。如果和我用同样的开发板,可以用如下代码。


  1 /*  2 *********************************************************************************************************  3 *                                             uC/GUI V3.98  4 *                        Universal graphic software for embedded applications  5 *  6 *                       (c) Copyright 2002, Micrium Inc., Weston, FL  7 *                       (c) Copyright 2002, SEGGER Microcontroller Systeme GmbH  8 *  9 *              礐/GUI is protected by international copyright laws. Knowledge of the 10 *              source code may not be used to write a similar product. This file may 11 *              only be used in accordance with a license and should not be redistributed 12 *              in any way. We appreciate your understanding and fairness. 13 * 14 ---------------------------------------------------------------------- 15 File        : GUI_TOUCH_X.C 16 Purpose     : Config / System dependent externals for GUI 17 ---------------------------END-OF-HEADER------------------------------ 18 */ 19 20 21 #include "GUI.h" 22 #include "GUI_X.h" 23 #include "ili9320.h" 24 #include "bsp.h" 25 26 //#define NEW8989_LCD      // 如果触摸屏的触摸与指针的移动方向是反的请注释掉该宏定义 27 28 unsigned short int X,Y; 29 30 void GUI_TOUCH_X_ActivateX(void) { 31 } 32 33 void GUI_TOUCH_X_ActivateY(void) { 34 } 35 36 37 int  GUI_TOUCH_X_MeasureX(void) 38 { 39     unsigned char t=0,t1,count=0; 40     unsigned short int databuffer[10]={5,7,9,3,2,6,4,0,3,1};//数据组 41     unsigned short temp=0,X=0;     42       43     while(/*GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_0)==0&&*/count<10)//循环读数10次 44     {             45 #ifndef NEW8989_LCD 46         databuffer[count]=TPReadX(); 47 #else 48         databuffer[count]=TPReadY(); 49 #endif 50         count++; 51     }   52     if(count==10)//一定要读到10次数据,否则丢弃 53     {   54         do//将数据X升序排列 55         {     56             t1=0;           57             for(t=0;t<count-1;t++) 58             { 59                 if(databuffer[t]>databuffer[t+1])//升序排列 60                 { 61                     temp=databuffer[t+1]; 62                     databuffer[t+1]=databuffer[t]; 63                     databuffer[t]=temp; 64                     t1=1; 65                 }   66             } 67         }while(t1);                                 68         X=(databuffer[3]+databuffer[4]+databuffer[5]+databuffer[6])>>2;       69     } 70 #ifndef NEW8989_LCD 71     return(X); 72 #else 73     return((X>100)?(X-100): 0); 74 #endif 75   76 } 77 78 int  GUI_TOUCH_X_MeasureY(void) { 79       unsigned char t=0,t1,count=0; 80     unsigned short int databuffer[10]={5,7,9,3,2,6,4,0,3,1};//数据组 81     unsigned short temp=0,Y=0;     82   83     while(/*GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_0)==0&&*/count<10)    //循环读数10次 84     {             85 #ifndef NEW8989_LCD 86         databuffer[count]=TPReadY(); 87 #else 88         databuffer[count]=TPReadX(); 89 #endif 90         count++;   91     }   92     if(count==10)//一定要读到10次数据,否则丢弃 93     {   94         do//将数据X升序排列 95         {     96             t1=0;           97             for(t=0;t<count-1;t++) 98             { 99                 if(databuffer[t]>databuffer[t+1])//升序排列100                 {101                     temp=databuffer[t+1];102                     databuffer[t+1]=databuffer[t];103                     databuffer[t]=temp;104                     t1=1; 105                 }  106             }107         }while(t1);                                 108         Y=(databuffer[3]+databuffer[4]+databuffer[5]+databuffer[6])>>2;      109     }110 #ifndef NEW8989_LCD111     return(Y); 112 #else113     Y = 4095-Y;114     return((Y>100)?(Y-100): 0); 115 #endif116 }117 118                                                                                                                                                                                                                                                                                                                                                                                                                                                              



GUI_X_uCOS.c文件如下替换


  1 /*  2 *********************************************************************************************************  3 *                                                uC/GUI  4 *                        Universal graphic software for embedded applications  5 *  6 *                       (c) Copyright 2002, Micrium Inc., Weston, FL  7 *                       (c) Copyright 2002, SEGGER Microcontroller Systeme GmbH  8 *  9 *              礐/GUI is protected by international copyright laws. Knowledge of the 10 *              source code may not be used to write a similar product. This file may 11 *              only be used in accordance with a license and should not be redistributed 12 *              in any way. We appreciate your understanding and fairness. 13 * 14 ---Author-Explanation 15 * 16 * 1.00.00 020519 JJL    First release of uC/GUI to uC/OS-II interface 17 * 18 * 19 * Known problems or limitations with current version 20 * 21 *    None. 22 * 23 * 24 * Open issues 25 * 26 *    None 27 ********************************************************************************************************* 28 */ 29 30 #include "os.h" 31 #include "os_Cfg_app.h" 32 #include "GUI_Private.H" 33 #include "stdio.H" 34 35 36 /* 37 ********************************************************************************************************* 38 *                                         GLOBAL VARIABLES 39 ********************************************************************************************************* 40 */ 41 42 static  int        KeyPressed; 43 static  char       KeyIsInited; 44 45 static  OS_SEM      dispSem; 46 static  OS_SEM      eventSem; 47 static  OS_SEM      keySem; 48 49 /* 50 ********************************************************************************************************* 51 *                                        TIMING FUNCTIONS 52 * 53 * Notes: Some timing dependent routines of uC/GUI require a GetTime and delay funtion. 54 *        Default time unit (tick), normally is 1 ms. 55 ********************************************************************************************************* 56 */ 57 58 int GUI_X_GetTime(void) 59 { 60     OS_ERR err; 61     62     return ((int)OSTimeGet( (OS_ERR *)&err)); 63 } 64 65 void GUI_X_Delay(int period) 66 { 67     OS_TICK  ticks; 68     OS_ERR err; 69     70     ticks = period * OS_CFG_TICK_RATE_HZ / 1000; 71     OSTimeDly(  (OS_TICK    )ticks, 72                 (OS_OPT        )OS_OPT_TIME_DLY, 73                 (OS_ERR     *)&err); 74 } 75 76 77 /* 78 ********************************************************************************************************* 79 *                                          GUI_X_ExecIdle() 80 ********************************************************************************************************* 81 */ 82 /*WM空闲时调用*/ 83 void GUI_X_ExecIdle(void) 84 { 85     OS_ERR err; 86     87     OSTimeDly(  (OS_TICK    )50, 88                 (OS_OPT     )OS_OPT_TIME_DLY, 89                 (OS_ERR     *)&err); 90 } 91 92 93 /* 94 ********************************************************************************************************* 95 *                                    MULTITASKING INTERFACE FUNCTIONS 96 * 97 * Note(1): 1) The following routines are required only if uC/GUI is used in a true multi task environment, 98 *             which means you have more than one thread using the uC/GUI API.  In this case the #define 99 *             GUI_OS 1   needs to be in GUIConf.h100 *********************************************************************************************************101 */102 103 void GUI_X_InitOS (void)104 { 105     OS_ERR err;106     107     OSSemCreate(    (OS_SEM     *)&dispSem, //建立一个互斥型信号量108                     (CPU_CHAR   *)"dispSem", 109                     (OS_SEM_CTR )1, 110                     (OS_ERR     *)&err   );111     112     OSSemCreate(    (OS_SEM     *)&eventSem,113                     (CPU_CHAR   *)"eventSem", 114                     (OS_SEM_CTR )1, 115                     (OS_ERR     *)&err   );116 }117 118 119 void GUI_X_Lock(void)120 { 121     OS_ERR err;122     CPU_TS ts;123     124     OSSemPend(  (OS_SEM     *)&dispSem, 125                 (OS_TICK    )0, 126                 (OS_OPT        )OS_OPT_PEND_BLOCKING, 127                 (CPU_TS     *)&ts, 128                 (OS_ERR     *)&err);129 }130 131 132 void GUI_X_Unlock(void)133 { 134     OS_ERR err;135     136     OSSemPost(  (OS_SEM     *)&dispSem, 137                 (OS_OPT        )OS_OPT_POST_1, 138                 (OS_ERR     *)&err);139 }140 141 142 U32 GUI_X_GetTaskId(void)143 { 144   return ((U32)(OSTCBCurPtr->Prio));145 }146 147 /*148 *********************************************************************************************************149 *                                        GUI_X_WaitEvent()150 *                                        GUI_X_SignalEvent()151 *********************************************************************************************************152 */153 154 155 void GUI_X_WaitEvent(void)156 {157     OS_ERR err;158     CPU_TS ts;159     160     OSSemPend(  (OS_SEM     *)&eventSem, 161                 (OS_TICK    )0, 162                 (OS_OPT        )OS_OPT_PEND_BLOCKING, 163                 (CPU_TS     *)&ts, 164                 (OS_ERR     *)&err);165 }166 167 168 void GUI_X_SignalEvent(void)169 {170     OS_ERR err;171 172     OSSemPost(  (OS_SEM     *)&eventSem, 173                 (OS_OPT        )OS_OPT_POST_1, 174                 (OS_ERR     *)&err);175 }176 177 /*178 *********************************************************************************************************179 *                                      KEYBOARD INTERFACE FUNCTIONS180 *181 * Purpose: The keyboard routines are required only by some widgets.182 *          If widgets are not used, they may be eliminated.183 *184 * Note(s): If uC/OS-II is used, characters typed into the log window will be placed    in the keyboard buffer. 185 *          This is a neat feature which allows you to operate your target system without having to use or 186 *          even to have a keyboard connected to it. (useful for demos !)187 *********************************************************************************************************188 */189 190 static void CheckInit(void)191 {192     if(KeyIsInited==DEF_FALSE)193     {194         KeyIsInited = DEF_TRUE;195         GUI_X_Init();196     }197 }198 199 200 /*被GUI_Init()调用,用来初始化一些GUI运行之前需要用的硬件,如键盘或者鼠标之类的.如果不需要的话,可以为空*/201 void GUI_X_Init(void)202 {203     OS_ERR err;204     205     OSSemCreate(    (OS_SEM     *)&keySem,206                     (CPU_CHAR   *)"keySem", 207                     (OS_SEM_CTR )0, 208                     (OS_ERR     *)&err   );209 }210 211 212 int GUI_X_GetKey(void)213 {214     int r;215     r = KeyPressed;216     CheckInit();217     KeyPressed = 0;218     return (r);219 }220 221 222 int GUI_X_WaitKey(void)223 {224     int  r;225     OS_ERR err;226     CPU_TS ts;227     228     CheckInit();229     if(KeyPressed==0)230     {231         OSSemPend(  (OS_SEM     *)&keySem,      //等待信号量232                     (OS_TICK    )0, 233                     (OS_OPT     )OS_OPT_PEND_BLOCKING, 234                     (CPU_TS     *)&ts, 235                     (OS_ERR     *)&err);236     }237     r= KeyPressed;238     KeyPressed = 0;239     return (r);240 }241 242 243 void GUI_X_StoreKey(int k)244 {245     OS_ERR err;246     247     KeyPressed = k;248     OSSemPost(  (OS_SEM     *)&keySem,      //释放信号量249                 (OS_OPT     )OS_OPT_POST_1, 250                 (OS_ERR     *)&err);251 }252 253 void GUI_X_Log(const char *s) 254 { 255     GUI_USE_PARA(s); 256 }257 258 void GUI_X_Warn(const char *s) 259 {260     GUI_USE_PARA(s); 261 }262 263 void GUI_X_ErrorOut(const char *s)264 { 265     GUI_USE_PARA(s); 266 }



在BSP.c文件中添加触摸板SPI接口程序。修改后如下:


  1 /*  2 ********************************************************************************  3 *                                  uC/OS-III  4 *                              5 *                              ARM Cortex-M3 Port  6 *  7 * File          : Config.C  8 * Version       : V1.0  9 * By            : 王宏强 10 * 11 * For           : Stm32f10x 12 * Mode          : Thumb2 13 * Toolchain     : 14 *                     RealView Microcontroller Development Kit (MDK) 15 *                     Keil uVision 16 * Description   : STM32F10x 内部 系统的配置 17 * 18 *                    1,系统中断优先级模式设置 19 *                    2,系统程序启动指定 20 *                    3,系统时钟计时器配置 21 *                    4,芯片引脚初始化 22 *                     23 * Date          : 2012.05.22 24 *******************************************************************************/ 25 26 #include "misc.h" 27 #include "stm32f10x_gpio.h" 28 #include "stm32f10x_rcc.h" 29 #include "stm32f10x_iwdg.h" 30 #include "stm32f10x_spi.h" 31 #include "bsp.h" 32 33 34 GPIO_InitTypeDef GPIO_InitStructure; 35 36 /******************************************************************************* 37 * Function Name  : GPIO_Configuration 38 * Description    : Configures the different GPIO ports. 39 * Input          : None 40 * Output         : None 41 * Return         : None 42 *******************************************************************************/ 43 void GPIO_Configuration(void) 44 { 45 #ifdef USE_STM3210B_EVAL 46     /* Enable the USART2 Pins Software Remapping */ 47     GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE); 48 #endif 49 50     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | 51                      RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | 52                      RCC_APB2Periph_GPIOE, ENABLE); 53 54     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All; 55     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; 56     GPIO_Init(GPIOA, &GPIO_InitStructure); 57     GPIO_Init(GPIOB, &GPIO_InitStructure); 58     GPIO_Init(GPIOC, &GPIO_InitStructure); 59     GPIO_Init(GPIOD, &GPIO_InitStructure); 60     GPIO_Init(GPIOE, &GPIO_InitStructure); 61 62     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | 63                          RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | 64                          RCC_APB2Periph_GPIOE, DISABLE);   65 66 } 67 68 69 /******************************************************************************* 70 * Function Name  : Delay 71 * Description    : Inserts a delay time. 72 * Input          : nCount: specifies the delay time length. 73 * Output         : None 74 * Return         : None 75 *******************************************************************************/ 76 //void Delay(volatile CPU_INT32U nCount) 77 //{ 78 //  for(; nCount != 0; nCount--); 79 //} 80 81 /******************************************************************************* 82 函 数 名:void IWDG_Init(void) 83 功能描述:看门狗初始化                         84 入口参数:                             85 返回参数: 86 创建时间: 2011.6.24 87 ********************************************************************************/ 88 void IWDG_Init(void) 89 { 90     IWDG_WriteAccessCmd( IWDG_WriteAccess_Enable ); 91     IWDG_SetPrescaler( IWDG_Prescaler_64);    //最小 92     IWDG_SetReload( 0x138);        //40KHz内部时钟 (1/40000 * 64 * 0x138 = 0.5s) 93     IWDG_WriteAccessCmd( IWDG_WriteAccess_Disable ); 94     IWDG_Enable(); 95     IWDG_ReloadCounter(); 96 } 97 98 /******************************************************************************* 99 * Function Name :void SysTickInit(void)100 * Description   :系统定时器时间配置101 * Input         :102 * Output        :103 * Other         :时基为1ms104 * Date          :2011.11.03  12:59:13105 *******************************************************************************/106 void SysTickInit(void)107 {108     SysTick_Config(SystemCoreClock / 1000);            //uCOS时基1ms109 }110 111 /*******************************************************************************112 * Function Name :void InterruptOrder(void)113 * Description   :中断向量,优先级114 * Input         :115 * Output        :116 * Other         :117 * Date          :2011.10.27  11:50:05118 *******************************************************************************/119 void NVIC_Configuration(void)120 {121     NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4);//优先级设置  全为抢占式优先级122 }123 124 125 /*******************************************************************************126 * Function Name :void SystemConfig(void)127 * Description   :系统时间戳 初始化128 * Input         :129 * Output        :130 * Other         :131 * Date          :2012.6.15  13:14:59132 *******************************************************************************/133 #if (CPU_CFG_TS_TMR_EN == DEF_ENABLED)134 void  CPU_TS_TmrInit (void)135 {136 }137 #endif138 139 140 /*******************************************************************************141 * Function Name :void SystemConfig(void)142 * Description   :读时间戳 计数值143 * Input         :读到的计数值144 * Output        :145 * Other         :146 * Date          :2012.6.15  13:14:59147 *******************************************************************************/148 #if (CPU_CFG_TS_TMR_EN == DEF_ENABLED)149 CPU_TS_TMR  CPU_TS_TmrRd (void)150 {151     return (SysTick->VAL);152 }153 #endif154 155 /*******************************************************************************156 * Function Name :void SystemConfig(void)157 * Description   :系统初始化158 * Input         :159 * Output        :160 * Other         :161 * Date          :2011.10.27  13:14:59162 *******************************************************************************/163 void BspInit(void)164 {165     NVIC_Configuration();    //中断优先级设置166     GPIO_Configuration();    //端口初始化,所有端口关167     SPI_Config();           //触摸接口初始化168 }169 170 void led_init(void)171 {172     GPIO_InitTypeDef GPIO_InitStructure;173     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOF, ENABLE);174     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 |  GPIO_Pin_12 | GPIO_Pin_13;175     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;176     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;177     GPIO_Init(GPIOA, &GPIO_InitStructure);178 179     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8;180     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;181     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;182     GPIO_Init(GPIOF, &GPIO_InitStructure);183 }184 185 186 187 void led_on(CPU_INT32U n)188 {189     switch (n)190     {191         case LED_0:192         GPIO_SetBits(GPIOD, GPIO_Pin_2);193         break;194         case LED_1:195         GPIO_SetBits(GPIOD, GPIO_Pin_3);196         break;197         case LED_2:198         GPIO_SetBits(GPIOD, GPIO_Pin_4);199         break;200         case LED_3:201         GPIO_SetBits(GPIOF, GPIO_Pin_6);202         break;203         case LED_4:204         GPIO_SetBits(GPIOF, GPIO_Pin_7);205         break;206         case LED_5:207         GPIO_SetBits(GPIOF, GPIO_Pin_8);208         break;209         default:210         break;211     }212 }213 214 215 void led_off(CPU_INT32U n)216 {217     switch (n)218     {219         case LED_0:220         GPIO_ResetBits(GPIOD, GPIO_Pin_2);221         break;222         case LED_1:223         GPIO_ResetBits(GPIOD, GPIO_Pin_3);224         break;225         case LED_2:226         GPIO_ResetBits(GPIOD, GPIO_Pin_4);227         break;228         case LED_3:229         GPIO_ResetBits(GPIOF, GPIO_Pin_6);230         break;231         case LED_4:232         GPIO_ResetBits(GPIOF, GPIO_Pin_7);233         break;234         case LED_5:235         GPIO_ResetBits(GPIOF, GPIO_Pin_8);236         break;237         default:238         break;239     }240 }241 /*242 T_CS PA4243 SPI1_SCK PA5244 SPI1_MISO PA6245 SPI1_MOSI PA7246    T_BUSY PA8247 */248 void SPI_Config(void) 249 { 250     GPIO_InitTypeDef  GPIO_InitStructure; 251     SPI_InitTypeDef   SPI_InitStructure; 252     253     //GPIOA Periph clock enable254     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE); 255     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);   256     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE);257     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF,ENABLE);258     //SPI1 Periph clock enable 259     // RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1,ENABLE); 260     //SPI2 Periph clock enable 261     RCC_APB1PeriphClockCmd( RCC_APB1Periph_SPI2, ENABLE ) ;262     263     //Configure SPI2 pins: SCK, MISO and MOSI 264     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15; 265     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 266     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;   //复用推挽输出267     GPIO_Init(GPIOB,&GPIO_InitStructure);  268     /*269     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5|GPIO_Pin_7; 270     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 271     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;   //推挽输出272     GPIO_Init(GPIOA,&GPIO_InitStructure);     273     274     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; 275     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 276     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;   //上拉输入277     GPIO_Init(GPIOA,&GPIO_InitStructure);     */278     279     //Configure PF10 pin: TP_CS pin 280     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; 281     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 282     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;     //推挽输出283     GPIO_Init(GPIOB,&GPIO_InitStructure); 284     285     //Configure PA8 pin: TP_BUSY pin286     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; 287     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 288     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;     //上拉输入289     GPIO_Init(GPIOE,&GPIO_InitStructure); 290     291     /* Configure PE.06 as input floating For TP_IRQ*/292     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;293     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;294     GPIO_Init(GPIOE,&GPIO_InitStructure);295     296     // SPI1 Config  297     SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; 298     SPI_InitStructure.SPI_Mode = SPI_Mode_Master; 299     SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; 300     SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; 301     SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; 302     SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;   //SPI_NSS_Hard303     SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_64; 304     SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; 305     SPI_InitStructure.SPI_CRCPolynomial = 7; 306     SPI_Init(SPI2,&SPI_InitStructure); 307     308     // SPI1 enable  309     SPI_Cmd(SPI2,ENABLE);  310 }311 312 313 unsigned char SPI_WriteByte(unsigned char data) 314 { 315     unsigned char Data = 0; 316     317     //Wait until the transmit buffer is empty 318     while(SPI_I2S_GetFlagStatus(SPI2,SPI_I2S_FLAG_TXE)==RESET); 319     // Send the byte  320     SPI_I2S_SendData(SPI2,data); 321     322     //Wait until a data is received 323     while(SPI_I2S_GetFlagStatus(SPI2,SPI_I2S_FLAG_RXNE)==RESET); 324     // Get the received data 325     Data = SPI_I2S_ReceiveData(SPI2); 326     327     // Return the shifted data 328     return Data; 329 }  330 void SpiDelay(unsigned int DelayCnt)331 {332  unsigned int i;333  for(i=0;i<DelayCnt;i++);334 }335 336 u16 TPReadX(void)337 { 338     u16 x=0;339     TP_CS();340     SpiDelay(10);341     SPI_WriteByte(0x90);342     SpiDelay(10);343     x=SPI_WriteByte(0x00);344     x<<=8;345     x+=SPI_WriteByte(0x00);346     SpiDelay(10);347     TP_DCS(); 348     x = x>>3;349     return (x);350 }351 352 u16 TPReadY(void)353 {354     u16 y=0;355     TP_CS();356     SpiDelay(10);357     SPI_WriteByte(0xD0);358     SpiDelay(10);359     y=SPI_WriteByte(0x00);360     y<<=8;361     y+=SPI_WriteByte(0x00);362     SpiDelay(10);363     TP_DCS();364     y = y>>3; 365     return (y);366 }



向工程中添加两个stm32f10x_fsmc.c,stm32f10x_spi.c这两个文件。


好了,大部分的准备工作都好了, 再在让新建一个任务来运行Dome中的MainTask();在任务3中调用GUI_TOUCH_Exec();


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



设定优先级 和分配空间。任务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      


到此就可以进行编译了。

几分钟的等待,下载~~~


每次编译的时间实在是太长了。这样咱们把源代码生成库,再进行编译。如下图:

图11

再编译生成

到Obj文件夹下到Project.lib 找到,改下名子GUI3_98.lib

把工程中的uCGUI/lib里的所有文件删除,用GUI3_98.lib替换。

再切换回来

图13

图12

再编译, 是不是非常快了。


注意:在对LCD配置变更时,需要重新制作.lib库。


整个工程存于网盘中。

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


好了,就这些了,后期还会慢慢更新最新版。希望以上对新学习uCGUI的朋友有所帮助。

下面传几个Dome的照片。

视频http://www.tudou.com/programs/view/Ut-yCR2jTs0/

分享 转发