uCGUI 5.22 在stm32 上的移植

来源:互联网 发布:qq农场矿山数据 编辑:程序博客网 时间:2024/06/08 06:46

时间匆匆呀,遥想以前 uCGUI 3.90 用得开心的时候,不知不觉 uCGUI 5.22都出来了,由于笔者对GUI的喜爱,加之 emWin(uCGUI) ,对于嵌入式开发相对简单,所以用得特别顺手,现在更新的emWin 风格更加接近win 7,相对 3.90的版本,其风格更接近 win xp,我还是更喜欢win 7风格,好了,闲话就不多扯了,进入正题。


最近的uCGUI 5.22 已经集成了很多现有LCD的驱动,用这些现有的LCD就可以通过修改相应文件很快地移植,这些现有的驱动可以通过 用户手册 995页查看:




我使用的是ili9320 液晶屏,所以可以直接利用现成的。下面开始移植


首先新建工程,把从ST 官方下载的 源码包解压,需要三个文件夹的文件,

 ..\ Lib\STemWin522_CM3.Lib

..\inc\

..\config\

..\OS\GUI_X.c


好了,将这四个文件加入工程,其他的可以根据自己情况添加,如demo。


注意:LCDConf.c是我修改的文件名,也是最重要的一个文件,它是衔接 GUI 和底层驱动的文件,其源文件名 为LCDConf_FlexColor_Template.c 可以再 config文件夹下找到,找到之后可以选择从命名,也可以不做改动。


好了,重点来了。由于uCGUI 5.22对我的LCD的支持,我可以利用刚才的文件直接修改即可,如果你的LCD 不被支持,那你就要自己利用模板写,也是在Config 文件夹下,知识我 把它们都删除了。


在LCDConf.c文件中提供了5个接口函数,需要用户添加:

static void LcdWriteReg(U16 Data);

static void LcdWriteData(U16 Data);

static void LcdWriteDataMultiple(U16 * pData, int NumItems);

static void LcdReadDataMultiple(U16 * pData, int NumItems);

void LCD_X_Config(void);


前4个函数是对 LCD寄存器以及读、写的操作,在ILI9320的驱动中,定义了 寄存器地址和数据地址,这里也需要,所以复制到这个文件中:


typedef struct
{
  vu16 REG;
  vu16 RAM;
} LCD_TypeDef;


#define LCD_BASE    ((u32)(0x60000000 | 0x0C000000))
#define LCD         ((LCD_TypeDef *) LCD_BASE)

LCD类型定义之后,就可以写底层函数了,其方法和ili9320的驱动类似。最后LCD_X_Config()函数只需要添加 LCD的初始化函数即可:下面是我的文件的源代码:


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


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

typedef struct
{
  vu16 REG;
  vu16 RAM;
} LCD_TypeDef;


/* LCD is connected to the FSMC_Bank1_NOR/SRAM4 and NE4 is used as ship select signal */
#define LCD_BASE    ((u32)(0x60000000 | 0x0C000000))
#define LCD         ((LCD_TypeDef *) LCD_BASE)


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


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


/*********************************************************************
*
*       Local functions
*
**********************************************************************
*/
/********************************************************************
*
*       LcdWriteReg
*
* Function description:
*   Sets display register
*/
static void LcdWriteReg(U16 Data) {
  // ... TBD by user
LCD->REG=Data;
}


/********************************************************************
*
*       LcdWriteData
*
* Function description:
*   Writes a value to a display register
*/
static void LcdWriteData(U16 Data) {
  // ... TBD by user
LCD->RAM=Data;
}


/********************************************************************
*
*       LcdWriteDataMultiple
*
* Function description:
*   Writes multiple values to a display register.
*/
static void LcdWriteDataMultiple(U16 * pData, int NumItems) {
  while (NumItems--) {
    // ... TBD by user
LCD->RAM=*pData++;
  }
}


/********************************************************************
*
*       LcdReadDataMultiple
*
* Function description:
*   Reads multiple values from a display register.
*/
static void LcdReadDataMultiple(U16 * pData, int NumItems) {
*pData = LCD->RAM;
  while (NumItems--) {
    // ... TBD by user
*pData++=LCD->RAM;
  }
}


/*********************************************************************
*
*       Public functions
*
**********************************************************************
*/
/*********************************************************************
*
*       LCD_X_Config
*
* Function description:
*   Called during the initialization process in order to set up the
*   display driver configuration.
*
*/
void LCD_X_Config(void) {
  GUI_DEVICE * pDevice;
  CONFIG_FLEXCOLOR Config = {0};
  GUI_PORT_API PortAPI = {0};
  //
  // Set display driver and color conversion
  //
  pDevice = GUI_DEVICE_CreateAndLink(GUIDRV_FLEXCOLOR, GUICC_565, 0, 0);
  //
  // Display driver configuration, required for Lin-driver
  //
  LCD_SetSizeEx (0, XSIZE_PHYS , YSIZE_PHYS);
  LCD_SetVSizeEx(0, VXSIZE_PHYS, VYSIZE_PHYS);
  //
  // Orientation
  //
  Config.Orientation = GUI_SWAP_XY | GUI_MIRROR_Y;
  GUIDRV_FlexColor_Config(pDevice, &Config);
  //
  // Set controller and operation mode
  //
  PortAPI.pfWrite16_A0  = LcdWriteReg;
  PortAPI.pfWrite16_A1  = LcdWriteData;
  PortAPI.pfWriteM16_A1 = LcdWriteDataMultiple;
  PortAPI.pfReadM16_A1  = LcdReadDataMultiple;
  GUIDRV_FlexColor_SetFunc(pDevice, &PortAPI, GUIDRV_FLEXCOLOR_F66708, GUIDRV_FLEXCOLOR_M16C0B16);
}


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



**********************************************************************/


void GUI_BSP_Init(void)
{
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC, ENABLE);
GUI_Init();
}


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


这样就可以了,注意我最后还有一个 GUI_BSP_Init()函数,这来多添加了一个时钟使能函数,具体原因我也不清楚,如果不使能CRC时钟,则不能运行,如果有知道的朋友可以告诉我,一起交流。


好了,移植就这么结束了,这是没有操作系统的 GUI ,有时间把 uCOS-III也也一起移植了。


1 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 手指夹伤出血了怎么办 手指夹破流血了怎么办 喂了宝宝熊胆粉怎么办 不小心擦伤了皮怎么办 吃了减肥药拉肚子怎么办 遇到他心通的人怎么办 被茅山术害了怎么办 鱼缸鱼身上烂了怎么办 鳄鱼龟皮肤烂了怎么办 墨水渗透进皮肤里了怎么办 中药渗透到皮肤里怎么办 甘露醇渗透到皮肤下怎么办 水银弄到眼睛里怎么办 水银粘到皮肤上怎么办 榴莲和虾同吃了怎么办 吃榴莲和虾中毒怎么办 榴莲和虾一起吃怎么办 狗被别人下毒了怎么办 大掌门2没存元宝怎么办 大掌门2转换阵容怎么办 率土之滨s2绝版怎么办 异界气息的装备怎么办 vivo电板没电了怎么办 门套拼接有缝隙怎么办 公司如果一直没有上税收入怎么办 赛车输了俩百万怎么办 交pk金员工不交怎么办 员工不想交pk金怎么办 心悦光环领错角色怎么办 心悦光环领错了怎么办 扑克牌1到13洗后怎么办 南通长牌没钱了怎么办 镇魔曲手游阵营人数已满怎么办 镇魔曲忘记在哪个区怎么办 登录镇魔曲卡在实名验证怎么办 电脑玩联盟花屏怎么办 优盘文件或目录损坏怎么办 苹果下吃鸡设备不兼容怎么办 龙之谷账号忘了怎么办 不花钱的排风除湿怎么办 苹果平板id密码忘了怎么办