在之前的博客中移植了STemwin5.32版本的,最近更换了
GD芯片
所以STemwin没法用了,只有移植emwin或者是ucGUI所有芯片都可以用了!
之前都是分散修改GUIxxx.c文件或者GUIxxx.h文件,现在打包成一个接口文件和一个库文件,不用再折腾了,累。。。
移植前提条件
涉及文件
- emwPort.c–修改驱动
- emwPort.h–修改配置
- ucGUI3.9.a
- 一堆ucGUI的头文件,无需改
移植过程
修改绘制驱动文件
ucGUI底层将调用以下绘制函数,必须对画点函数进行填充
/**
* @file: emwPort.c
*
* @date: 2020/5/8
*
* @author: aron566
*
* @brief:emwin 移植接口
*
* @version:v1.0
*/
#ifdef __cplusplus ///<use C compiler
extern "C" {
#endif
/** Includes -----------------------------------------------------------------*/
/* Private includes ----------------------------------------------------------*/
#include "emwPort.h"
#include "GUI.h"
/** Private typedef ----------------------------------------------------------*/
/** Private macros -----------------------------------------------------------*/
/** Private constants --------------------------------------------------------*/
/** Public variables ---------------------------------------------------------*/
/** Private variables --------------------------------------------------------*/
/** Private function prototypes ----------------------------------------------*/
/** Private user code --------------------------------------------------------*/
/** Public application code --------------------------------------------------*/
/*******************************************************************************
*
* Public code
*
********************************************************************************
*/
/******************************************************************
* @brief 读取个某点的颜色值
* @param[in] x,y:坐标
* @return 此点的颜色
******************************************************************/
uint32_t EMPORT_LCD_ReadPoint(int x, int y)
{
return *(uint16_t*)((uint32_t)ltdc_layer1[0] + 2 * (EMPORT_LCD_X_PIXEL * y + x));
}
/******************************************************************
* @brief 画点
* @param[in] x,y:坐标 color:颜色
* @return None
******************************************************************/
void EMPORT_LCD_DrawPoint(int x ,int y ,uint32_t color)
{
uint16_t *TargetAddr = (uint16_t*)((uint32_t)ltdc_layer1[0] + 2 * (EMPORT_LCD_X_PIXEL * y + x));
*TargetAddr = (uint16_t)color;
}
/******************************************************************
* @brief 在指定区域内填充单个颜色
* @param[in] (sx,sy),(ex,ey):填充矩形对角坐标,区域大小为:(ex-sx+1)*(ey-sy+1)
* @param[in] color:要填充的颜色
* @return None
******************************************************************/
void EMPORT_LCD_Fill(int sx ,int sy ,int ex ,int ey ,uint32_t color)
{
/*NEW Code*/
// LCD_DrawFullRect(sx ,sy, ex+1, ey+1);
for (; sy <= ey; sy++)
{
EMPORT_LCD_DrawHLine(sx ,sy ,ex ,color);
}
}
/**
******************************************************************
* @brief 绘制横线
* @param[in] X起点
* @param[in] Y起点
* @param[in] X长度
* @param[in] 颜色
* @retval None
* @author aron566
* @version v1.0
* @date 2020/5/9
******************************************************************
*/
void EMPORT_LCD_DrawHLine(int x0 ,int y, int x1 ,uint32_t color)
{
for (; x0 <= x1; x0++) {
EMPORT_LCD_DrawPoint(x0, y, color);
}
}
/**
******************************************************************
* @brief 绘制竖线
* @param[in] X起点
* @param[in] Y起点
* @param[in] Y长度
* @param[in] 颜色
* @retval None
* @author aron566
* @version v1.0
* @date 2020/5/9
******************************************************************
*/
void EMPORT_LCD_DrawVLine(int x ,int y0 ,int y1 ,uint32_t color)
{
for (; y0 <= y1; y0++) {
EMPORT_LCD_DrawPoint(x, y0, color);
}
}
/**
******************************************************************
* @brief GUI触摸接口 ,获取X坐标
* @param None
* @retval X坐标
* @author aron566
* @version v1.0
* @date 2020/5/8
******************************************************************
*/
int EMPORT_Touch_GetPhyX(void)
{
return 0;
}
/**
******************************************************************
* @brief GUI触摸接口 ,获取Y坐标
* @param None
* @retval Y坐标
* @author aron566
* @version v1.0
* @date 2020/5/8
******************************************************************
*/
int EMPORT_Touch_GetPhyY(void)
{
return 0;
}
/**
******************************************************************
* @brief GUI时基 放入1ms中断
* @param None
* @retval None
* @author aron566
* @version v1.0
* @date 2020/5/8
******************************************************************
*/
void EMPORT_GUI_Inc_Ticks_Port(void)
{
extern volatile GUI_TIMER_TIME OS_TimeMS;
OS_TimeMS++;
}
#ifdef __cplusplus ///<end extern c
}
#endif
/******************************** End of file *********************************/
修改配置文件
emwPort.h
/**
* @file: emwPort.h
*
* @date: 2020/5/8
*
* @author: aron566
*
* @brief:emwin 移植接口
*
* @version:v1.0
*/
#ifndef __EMWPORT_H
#define __EMWPORT_H
#ifdef __cplusplus ///<use C compiler
extern "C" {
#endif
/** Includes -----------------------------------------------------------------*/
#include <stdint.h> /**< nedd definition of uint8_t */
#include <stddef.h> /**< need definition of NULL */
//#include <stdbool.h>/**< need definition of BOOL */
#include <stdio.h> /**< if need printf */
#include <stdlib.h>
#include <string.h>
/** Private includes ---------------------------------------------------------*/
#include "cmsis_os.h"
#include "ipa.h"
/** Private defines ----------------------------------------------------------*/
/**
* @name EMWIN移植配置
* @{
*/
#define EMPORT_FRAME_BUFF_ADDR ((void*)(LCD_FRAME_BUFFER+BUFFER_OFFSET))
#define EMPORT_BUFF_SIZE (1024*20U)
#define EMPORT_BLOCKSIZE (0x80)
#define EMPORT_USE_OS (0) /**< 启用OS */
#define EMPORT_XSIZE_PHYS (480) /**< 配合显示方向的X像素*/
#define EMPORT_YSIZE_PHYS (320) /**< 配合显示方向的Y像素*/
#define EMPORT_LCD_X_PIXEL (320) /**< 实际X像素 */
#define EMPORT_LCD_Y_PIXEL (480) /**< 实际Y像素 */
#define EMPORT_LCD_BITSPERPIXEL (16) /**< 像素位大小 */
#define EMPORT_LCD_FIXEDPALETTE (565) /**< 颜色格式 */
#define EMPORT_LCD_SWAP_RB (1) /**< 红蓝交换 */
#define EMPORT_LCD_CONTROLLER (566) /**< 控制器名称 */
#define EMPORT_NUM_LAYERS (1) /**< 最大层级 */
#define EMPORT_SUPPORT_TOUCH (0) /**< 支持触摸 */
#define EMPORT_SUPPORT_UNICODE (1) /**< 支持UNICODE*/
#define EMPORT_SUPPORT_MOUSE (0) /**< 支持鼠标 */
#define EMPORT_WINSUPPORT (1)
#define EMPORT_SUPPORT_MEMDEV (1)
#define EMPORT_SUPPORT_AA (1) /**< 支持反锯齿 */
#define EMPORT_SUPPORT_DEVICES (1)
#define EMPORT_SUPPORT_NOTIFY_VIS_CHANGED (1)
#define EMPORT_DEFAULT_FONT (&GUI_FontD24x32) /**< 默认字体大小*/
#define EMPORT_COLOR_CONVERSION GUICC_M565//GUICC_565//GUICC_888
#define EMPORT_DISPLAY_DRIVER GUIDRV_WIN32//GUIDRV_TEMPLATE
/**
* @name EMWIN调整显示方向
* @{
*/
/* 1 1 0 横竖屏切换 */
#define EMPORT_LCD_SWAP_XY (1)
#define EMPORT_LCD_MIRROR_X (1)
#define EMPORT_LCD_MIRROR_Y (0)
/** @}*/
#define EMPORT_TOUCH_SWAP_XY (1)
#define EMPORT_TOUCH_MIRROR_X (0)
#define EMPORT_TOUCH_MIRROR_Y (1)
#define EMPORT_CALIBRATION (4000)
#define EMPORT_TOUCH_AD_LEFT (300)
#define EMPORT_TOUCH_AD_RIGHT (3700)
#define EMPORT_TOUCH_AD_TOP (300)
#define EMPORT_TOUCH_AD_BOTTOM (3700)
/** @}*/
/** Exported typedefines -----------------------------------------------------*/
/** Exported constants -------------------------------------------------------*/
/** Exported macros-----------------------------------------------------------*/
/** Exported variables -------------------------------------------------------*/
/** Exported functions prototypes --------------------------------------------*/
uint32_t EMPORT_LCD_ReadPoint(int x ,int y);
void EMPORT_LCD_DrawPoint(int x ,int y ,uint32_t color);
void EMPORT_LCD_Fill(int sx ,int sy ,int ex ,int ey ,uint32_t color);
void EMPORT_LCD_DrawHLine(int x0 ,int y, int x1 ,uint32_t color);
void EMPORT_LCD_DrawVLine(int x ,int y0 ,int y1 ,uint32_t color);
void EMPORT_GUI_Inc_Ticks_Port(void);
int EMPORT_Touch_GetPhyX(void);
int EMPORT_Touch_GetPhyY(void);
#ifdef __cplusplus ///<end extern c
}
#endif
#endif
/******************************** End of file *********************************/
打包进工程
三个文件夹:
INCLUDE ucGUI的一堆头文件
LIB 库文件
PORT ucGUI移植接口
加入工程,图为IAR工程,两个文件即可,接口文件,库文件,其他的头文件路径包含即可