uCGUI 5.22 在stm32 上的移植

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


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

uCGUI 5.22 在stm32 上的移植_第1张图片



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


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

 ..\ Lib\STemWin522_CM3.Lib

..\inc\

..\config\

..\OS\GUI_X.c


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

uCGUI 5.22 在stm32 上的移植_第2张图片

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

uCGUI 5.22 在stm32 上的移植_第3张图片

好了,重点来了。由于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也也一起移植了。


你可能感兴趣的:(uCGUI)