uc/gui横屏/竖屏切换(显示方向XY翻转与镜像)基于ILI9341

uc/gui中横竖屏切换分为2步:
1. LCDConf.h中定义LCD_SWAP_XY宏
2. 修改底层驱动

1. LCDConf.h中定义LCD_SWAP_XY宏
在ucgui/Config/LCDConf.h文件中宏定义如下:

#define LCD_XSIZE          (320)   	/* 配置TFT的水平分辨率  */
#define LCD_YSIZE          (240)  	/* 配置TFT的垂直分辨率  */
#define LCD_BITSPERPIXEL   (16)		/* 每个像素的位数  */
#define LCD_CONTROLLER     (9341)	/* TFT控制器的名称 */
#define LCD_FIXEDPALETTE   (565)	/* 调色板格式 */
#define LCD_SWAP_RB        (1)		/* 红蓝反色交换 */
#define LCD_SWAP_XY        (0)
#define LCD_MIRROR_X	   (0)
#define LCD_MIRROR_Y	   (0)
#define LCD_INIT_CONTROLLER()  ILI9341_Init();	/* TFT初始化函数  */
其中
#define LCD_SWAP_XY        (1)
#define LCD_MIRROR_X	   (1)
#define LCD_MIRROR_Y	   (0)

这3个宏搭配起来有8种显示方向,具体含义可以在ucgui手册第20.4节看到。

2. 修改底层驱动
由于ucgui源码中没有9341的驱动,所以需要自己写。 驱动下载链接
首先需要注意,要在LCDConf.h中定义驱动器名称和初始化函数,也就是 LCD_CONTROLLERLCD_INIT_CONTROLLER()两个宏。
然后要定义X,Y坐标转换的宏,这部分可以直接从UC/GUI源码自带的空白驱动("uCGUI源码\UCGUI390a\Start\GUI\LCDDriver\LCDDummy.c")中找到:

/*********************************************************************
*
*       Macros for MIRROR_, SWAP_ and LUT_
*/
#if (!defined (LCD_LUT_COM) && !defined(LCD_LUT_SEG))
  #if   (!LCD_MIRROR_X && !LCD_MIRROR_Y && !LCD_SWAP_XY)
    #define LOG2PHYS_X(x, y) x
    #define LOG2PHYS_Y(x, y) y
  #elif (!LCD_MIRROR_X && !LCD_MIRROR_Y &&  LCD_SWAP_XY)
    #define LOG2PHYS_X(x, y) y
    #define LOG2PHYS_Y(x, y) x
  #elif (!LCD_MIRROR_X &&  LCD_MIRROR_Y && !LCD_SWAP_XY)
    #define LOG2PHYS_X(x, y) x
    #define LOG2PHYS_Y(x, y) LCD_YSIZE - 1 - (y)
  #elif (!LCD_MIRROR_X &&  LCD_MIRROR_Y &&  LCD_SWAP_XY)
    #define LOG2PHYS_X(x, y) y
    #define LOG2PHYS_Y(x, y) LCD_XSIZE - 1 - (x)
  #elif ( LCD_MIRROR_X && !LCD_MIRROR_Y && !LCD_SWAP_XY)
    #define LOG2PHYS_X(x, y) LCD_XSIZE - 1 - (x)
    #define LOG2PHYS_Y(x, y) y
  #elif ( LCD_MIRROR_X && !LCD_MIRROR_Y &&  LCD_SWAP_XY)
    #define LOG2PHYS_X(x, y) LCD_YSIZE - 1 - (y)
    #define LOG2PHYS_Y(x, y) x
  #elif ( LCD_MIRROR_X &&  LCD_MIRROR_Y && !LCD_SWAP_XY)
    #define LOG2PHYS_X(x, y) LCD_XSIZE - 1 - (x)
    #define LOG2PHYS_Y(x, y) LCD_YSIZE - 1 - (y)
  #elif ( LCD_MIRROR_X &&  LCD_MIRROR_Y &&  LCD_SWAP_XY)
    #define LOG2PHYS_X(x, y) LCD_YSIZE - 1 - (y)
    #define LOG2PHYS_Y(x, y) LCD_XSIZE - 1 - (x)
  #endif
#else
  #if   ( defined (LCD_LUT_COM) && !defined(LCD_LUT_SEG))
    #define LOG2PHYS_X(x, y) x
    #define LOG2PHYS_Y(x, y) LCD__aLine2Com0[y]
  #elif (!defined (LCD_LUT_COM) &&  defined(LCD_LUT_SEG))
    #define LOG2PHYS_X(x, y) LCD__aCol2Seg0[x]
    #define LOG2PHYS_Y(x, y) y
  #elif ( defined (LCD_LUT_COM) &&  defined(LCD_LUT_SEG))
    #define LOG2PHYS_X(x, y) LCD__aCol2Seg0[x]
    #define LOG2PHYS_Y(x, y) LCD__aLine2Com0[y]
  #endif
#endif

将其粘贴到9341驱动文件中即可。

然后写底层的2个函数:
//设定指定点颜色
void LCD_L0_SetPixelIndex(int x, int y, int PixelIndex)
{
	#if LCD_SWAP_XY | LCD_MIRROR_X| LCD_MIRROR_Y
		int xPhys = LOG2PHYS_X(x, y);
		int yPhys = LOG2PHYS_Y(x, y);
	#else
		#define xPhys x
		#define yPhys y
	#endif

	IOWR_ALTERA_AVALON_PIO_DATA(TFT9341_NCS_BASE,0);
	ILI9341_SetCursor(xPhys, yPhys, LCD_XSIZE, LCD_YSIZE);
	ILI9341_WrCmd(0x2c);
	ILI9341_WrData_16b(PixelIndex);
	IOWR_ALTERA_AVALON_PIO_DATA(TFT9341_NCS_BASE,1);
}

//获取指定点颜色
unsigned int LCD_L0_GetPixelIndex(int x, int y)
{
	#if LCD_SWAP_XY | LCD_MIRROR_X| LCD_MIRROR_Y
		int xPhys = LOG2PHYS_X(x, y);
		int yPhys = LOG2PHYS_Y(x, y);
	#else
		#define xPhys x
		#define yPhys y
	#endif

	alt_u16 Readdata;

	IOWR_ALTERA_AVALON_PIO_DATA(TFT9341_NCS_BASE,0);
	ILI9341_SetCursor(xPhys, yPhys, LCD_XSIZE, LCD_YSIZE);
	ILI9341_WrCmd(0x2c);
	Readdata = ILI9341_RdData();
	Readdata = ILI9341_RdData();
	IOWR_ALTERA_AVALON_PIO_DATA(TFT9341_NCS_BASE,1);
	return(Readdata);
}
完整下载链接: 驱动下载链接

你可能感兴趣的:(UC/GUI,ILI9341,QSYS,FPGA,FPGA)