打印
[STM32F1]

uCOSIII uCGUI STM32 平台移植 (转)

[复制链接]
7278|51
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
lzmm|  楼主 | 2013-11-30 22:02 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
一、环境:
         软件:
  • 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


沙发
lzmm|  楼主 | 2013-11-30 22:02 | 只看该作者
下面上两个版本空的工程:
    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

使用特权

评论回复
板凳
lzmm|  楼主 | 2013-11-30 22:02 | 只看该作者
内容介绍:


使用特权

评论回复
地板
lzmm|  楼主 | 2013-11-30 22:03 | 只看该作者
三、开始准备移植文件:
新建文件夹uCGUI


使用特权

评论回复
5
lzmm|  楼主 | 2013-11-30 22:03 | 只看该作者
到此文件的准备就完成了,开始向程序中添加。

四、添加到工程
我还是直接上图,添加哪些文件。


使用特权

评论回复
6
lzmm|  楼主 | 2013-11-30 22:03 | 只看该作者


使用特权

评论回复
7
lzmm|  楼主 | 2013-11-30 22:03 | 只看该作者


使用特权

评论回复
8
lzmm|  楼主 | 2013-11-30 22:04 | 只看该作者


使用特权

评论回复
9
lzmm|  楼主 | 2013-11-30 22:04 | 只看该作者
直接添加所有Dome中的文件。


使用特权

评论回复
10
lzmm|  楼主 | 2013-11-30 22:04 | 只看该作者
添加所有GUI子文件。太多了,还是用CTRL+A吧,不然手都要点麻!

图9

使用特权

评论回复
11
lzmm|  楼主 | 2013-11-30 22:04 | 只看该作者
重要的一步,让添加的文件可直接索引到。

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



五、移植修改文件

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函数。

使用特权

评论回复
12
lzmm|  楼主 | 2013-11-30 22:04 | 只看该作者
/*********************************************************************
*
*       Exported functions
*
**********************************************************************
*/

/*********************************************************************
*
*       LCD_L0_SetPixelIndex
*
* Purpose:
*   Sets the index of the given pixel. The upper layers
*   calling this routine make sure that the coordinates are in range, so
*   that no check on the parameters needs to be performed.
*/
void LCD_L0_SetPixelIndex(int x, int y, int PixelIndex) {
  int xPhys = 0;
  int yPhys = 0;
  GUI_USE_PARA(x);
  GUI_USE_PARA(y);
  GUI_USE_PARA(PixelIndex);
  /* Convert logical into physical coordinates (Dep. on LCDConf.h) */
  #if LCD_SWAP_XY | LCD_MIRROR_X| LCD_MIRROR_Y
    xPhys = LOG2PHYS_X(x, y);
    yPhys = LOG2PHYS_Y(x, y);
  #else
    xPhys = x;
    yPhys = y;
  #endif
  /* Write into hardware ... Adapt to your system */
  {
    ili9320_SetPoint(xPhys, yPhys, PixelIndex);/* ... */
  }
}

/*********************************************************************
*
*       LCD_L0_GetPixelIndex
*
* Purpose:
*   Returns the index of the given pixel. The upper layers
*   calling this routine make sure that the coordinates are in range, so
*   that no check on the parameters needs to be performed.
*/
unsigned int LCD_L0_GetPixelIndex(int x, int y) {
  int xPhys = 0;
  int yPhys = 0;
  LCD_PIXELINDEX PixelIndex;

  GUI_USE_PARA(x);
  GUI_USE_PARA(y);
  /* Convert logical into physical coordinates (Dep. on LCDConf.h) */
  #if LCD_SWAP_XY | LCD_MIRROR_X| LCD_MIRROR_Y
    xPhys = LOG2PHYS_X(x, y);
    yPhys = LOG2PHYS_Y(x, y);
  #else
    xPhys = x;
    yPhys = y;
  #endif
  /* Read from hardware ... Adapt to your system */
  {
    PixelIndex = ili9320_GetPoint(xPhys, yPhys);/* ... */
  }
  return PixelIndex;
}

使用特权

评论回复
13
lzmm|  楼主 | 2013-11-30 22:05 | 只看该作者
在uCGUI\Config找到三个配置文件。
LCDConf.h
在pdf的第20章有详细介绍
图10

使用特权

评论回复
14
lzmm|  楼主 | 2013-11-30 22:05 | 只看该作者
先设定这几个必需的。
初始化宏定义
驱动如果是自己写的需要以下宏定义
#define LCD_CONTROLLER      -1
#define LCD_INIT_CONTROLLER()  ili9320_Initializtion();

GUIConf.h
可以用默认配置

GUITouchConf.h
先用默认值,等运行Dome后,有个校准,获得校准值,再进行修改。
参图:



使用特权

评论回复
15
lzmm|  楼主 | 2013-11-30 22:05 | 只看该作者
UI_X_Touch.c文件修改

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

使用特权

评论回复
16
lzmm|  楼主 | 2013-11-30 22:05 | 只看该作者
UI_X_Touch.c
  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

使用特权

评论回复
17
lzmm|  楼主 | 2013-11-30 22:05 | 只看该作者
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_LCD
111     return(Y);
112 #else
113     Y = 4095-Y;
114     return((Y>100)?(Y-100): 0);
115 #endif
116 }
117
118

使用特权

评论回复
18
lzmm|  楼主 | 2013-11-30 22:05 | 只看该作者
GUI_X_uCOS.c文件如下替换

使用特权

评论回复
19
zhangjin_comeon| | 2013-11-30 22:06 | 只看该作者
谢谢分享

使用特权

评论回复
20
lzmm|  楼主 | 2013-11-30 22:06 | 只看该作者
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.h
100 *********************************************************************************************************
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;

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

386

主题

8575

帖子

11

粉丝