基于NIOS II的液晶显示设计——ucGUI移植

自己写图形库不怎么完善,而且功能有限,在NIOS II上移植ucGUI,做界面设计就简单了!

当然首先要下载ucGUI源代码,改变TFT LCD设定的参数和读写TFT LCD函数即可。

首先我们要把GUI和Config两个文件夹放到NIOS II工程目录中,改变其只读属性,因为我们要修改文件。

在NIOS II工程名上点击右键选择Refresh就可以看到GUI和Config了,还是在工程上点击右键选择Properties,

添加ucGUI头文件路径,如下图:

基于NIOS II的液晶显示设计——ucGUI移植_第1张图片

修改config文件里面的GUIConf.h如下:

#ifndef GUICONF_H
#define GUICONF_H

#define GUI_OS                    (0)  /* Compile with multitasking support */
#define GUI_SUPPORT_TOUCH         (0)  /* Support a touch screen (req. win-manager) */
#define GUI_SUPPORT_MOUSE         (0)  /* Support a mouse */
#define GUI_SUPPORT_UNICODE       (0)  /* Support mixed ASCII/UNICODE strings */

#define GUI_DEFAULT_FONT          &GUI_Font8x16
#define GUI_ALLOC_SIZE            12500  /* Size of dynamic memory ... For WM and memory devices*/

/*********************************************************************
*
*         Configuration of available packages
*/

#define GUI_WINSUPPORT            0  /* Window manager package available */
#define GUI_SUPPORT_MEMDEV        0  /* Memory devices available */
#define GUI_SUPPORT_AA            0  /* Anti aliasing available */

#endif  /* Avoid multiple inclusion */

修改LCDConf.h如下:

#ifndef LCDCONF_H
#define LCDCONF_H
/*********************************************************************
*
*                   General configuration of LCD
*
**********************************************************************
*/
#include"io.h"
#include"system.h"
#define SRAM_BASE       LCD_BASE + 320*2
#define LCD_XSIZE      (320)  /* X-resolution of LCD, Logical coor. */

#define LCD_YSIZE      (240)  /* Y-resolution of LCD, Logical coor. */

#define LCD_BITSPERPIXEL (16) /* 每个象素点需要的Bit数 */

#define LCD_CONTROLLER 3200   /* 控制器名称 */

#define LCD_ENDIAN_BIG      1 /* 选择little endian */

#define LCD_FIXEDPALETTE  565 /* 选择RGB565色彩模式 */

#define LCD_SWAP_RB         1 /* gui默认为GRB565,定义这个开关可以使之转换为RGB565,即交换R和B */

#define LCD_LIN_SWAP        16

//#define LCD_MIRRO_X         1

#define LCD_ALLOW_NON_OPTIMIZED_MODE 1


#define LCD_READ_MEM(Off)           IORD_32DIRECT((U32)SRAM_BASE,(U32)(4*Off))
#define LCD_WRITE_MEM(Off,data)     IOWR_32DIRECT((U32)SRAM_BASE,(U32)(4*Off),data)

//#define LCD_READ_MEM(Off)        *((U32 *)LCD_BASE + (U32)Off)  
//#define LCD_WRITE_MEM(Off,data)  *((U32 *)LCD_BASE + (U32)Off) = Data;

/* 使用驱动LCDLin32.c需要定义的函数,用于读写显示缓冲区,由于把显示缓冲区的地址指针放到LCDLin32.c中去了,所以这两个函数也直接放到LCDLin32.c中去,在这里就可以不要了 */

#define LCD_INIT_CONTROLLER()  LCD_Controller_Init() /* LCD 控制器初始化函数,由gui_init()调用,我在这里替换为自己的控制器初始化函数LCD_Controller_Init(),该函数在后文中叙述 */
#endif

修改LCDDriver/LCDLin32.c的LCD_Controller_Init()函数如下:

void LCD_Controller_Init(void)
{

   int i;
   for(i=0;i<320*240/2;i++)  IOWR_32DIRECT(LCD_BASE,4*i,0);
}

这样直接编译会报错,需要在NIOS II工程目录里面添加一个GUI_X.c的文件,代码如下:

#include "GUI.h"
#include "GUI_X.h"

/*********************************************************************
*
*       Global data
*/
volatile int OS_TimeMS;

/*********************************************************************
*
*      Timing:
*                 GUI_X_GetTime()
*                 GUI_X_Delay(int)

  Some timing dependent routines require a GetTime
  and delay function. Default time unit (tick), normally is
  1 ms.
*/

int GUI_X_GetTime(void)
{
//  return OS_TimeMS;
    return 0;
}

void GUI_X_Delay(int ms)
{
    //int tEnd = OS_TimeMS + ms;
    //while ((tEnd - OS_TimeMS) > 0);
}

/*********************************************************************
*
*       GUI_X_Init()
*
* Note:
*     GUI_X_Init() is called from GUI_Init is a possibility to init
*     some hardware which needs to be up and running before the GUI.
*     If not required, leave this routine blank.
*/

void GUI_X_Init(void) {}


/*********************************************************************
*
*       GUI_X_ExecIdle
*
* Note:
*  Called if WM is in idle state
*/

void GUI_X_ExecIdle(void) {}

/*********************************************************************
*
*      Logging: OS dependent

Note:
  Logging is used in higher debug levels only. The typical target
  build does not use logging and does therefor not require any of
  the logging routines below. For a release build without logging
  the routines below may be eliminated to save some space.
  (If the linker is not function aware and eliminates unreferenced
  functions automatically)

*/

void GUI_X_Log     (const char *s) { GUI_USE_PARA(s); }
void GUI_X_Warn    (const char *s) { GUI_USE_PARA(s); }
void GUI_X_ErrorOut(const char *s) { GUI_USE_PARA(s); }

你可能感兴趣的:(ios)