ART-PI移植Touchgfx(2022最新方法)
   
    
    
    
     一、移植环境
    
   
    
     开发板
    
    :ART-PI
    
    
     屏幕
    
    :正点原子7寸屏幕(1024✖600)
    
    
     移植平台
    
    :RttStudio最新版本
    
    
     移植时间
    
    :2022-2-16
    
    
     TouchgfxDesigner版本
    
    :4.18.1(最新版)
   
    移植最重要的是
    
     屏幕
    
    ,ART-PI和正点原子的屏幕,FPC连接器的引脚是相同的,所以可以直接用FPC连接线连接到正点原子的屏幕上,这点在
    
     ART-PI
    
    的原理图上可以看出
    
    
    
    如果你使用的是正点原子的
    
     其他屏幕
    
    ,只需要修改程序里面的屏幕参数即可
    
    如果你使用的是
    
     野火
    
    的屏幕,需要
    
     转接板
    
    ,我自己制作的抓接板如下:
    
    
    
    
     转接板PCB工程文件,AD版本
    
    
    链接:https://pan.baidu.com/s/1XxEHGmm0mW8ZO8_a6tnHHg
    
    提取码:a9h3
   
    
    
    
     二、移植结果
    
   
    
   
    
    
    
     三、移植过程
    
   
    1、新建项目
    
    
    
    
    
    
    
    
    
    
    
    
    
    
     ctrl+s
    
    保存一下,
    
     RttStudio
    
    会自动加载这些软件包
    
    
    
    
   
正点原子7寸屏幕 1024*600
/* atk 7 inch screen, 1024 * 600 */
#define LCD_WIDTH           1024
#define LCD_HEIGHT          600
#define LCD_BITS_PER_PIXEL  24
#define LCD_BUF_SIZE        (LCD_WIDTH * LCD_HEIGHT * LCD_BITS_PER_PIXEL / 8)
#define LCD_PIXEL_FORMAT    RTGRAPHIC_PIXEL_FORMAT_RGB888
#define LCD_HSYNC_WIDTH     20
#define LCD_VSYNC_HEIGHT    3
#define LCD_HBP             140
#define LCD_VBP             20
#define LCD_HFP             160
#define LCD_VFP             12
正点原子7寸屏幕 800*480
/* atk 7 inch screen, 800 * 480 */
#define LCD_WIDTH           800
#define LCD_HEIGHT          480
#define LCD_BITS_PER_PIXEL  24
#define LCD_BUF_SIZE        (LCD_WIDTH * LCD_HEIGHT * LCD_BITS_PER_PIXEL / 8)
#define LCD_PIXEL_FORMAT    RTGRAPHIC_PIXEL_FORMAT_RGB888
#define LCD_HSYNC_WIDTH     40
#define LCD_VSYNC_HEIGHT    20
#define LCD_HBP             46
#define LCD_VBP             23
#define LCD_HFP             210
#define LCD_VFP             22
    
    
    进入
    
     art-pi-touchgfx\libraries\touchgfx_lib\TouchGFX
    
    文件夹
    
    
    
    
   
    这里修改的是TouchgfxDesigner里面的
    
     画布尺寸
    
    ,这个尺寸
    
     不会影响硬件效果
    
    ,但会影响你的
    
     UI设计
    
   
    
    
    如果你没有下载TouchgfxDesigner就先去下载,
    
     网盘如下
    
    ,有
    
     4.15 4.17 4.18.0 4.18.1
    
    版本
    
    链接:https://pan.baidu.com/s/1jMuiywgusGXJaxQ4GbR-eQ
    
    提取码:o6t7
    
    也可以去ST官网下载,百度搜索
    
     Touchgfx
    
    即可
    
    这里用
    
     4.15版本
    
    打开也可以,4.15一下的好像不行,不过4.15一下的也挺老了,应该没什么人用,使用最新版本的即可
    
    用
    
     TouchgfxDesigner4.18.1
    
    打开之后,放置一个BOX控件,修改BOX尺寸和屏幕尺寸一样大,并把BOX放到最底层
    
    
    
    
     然后编译生成代码,等待几分钟编译完成
    
    
    
   
    
     编译完成:
    
    
    
    
    如果出现
    
     找不到指定文件
    
    ,就关闭设计软件,重新打开再编译
   
    
    
    然后在RttStudio更新软件包
   
    这步很重要,要不然
    
     直接编译会生成很多错误
    
    ,是因为你目前添加的
    
     Touchgfx
    
    软件包
    
     是老版本的
    
    
    
    
    
     修改C++的一些配置
    
    
    
    
    
     选中如下,应用并关闭
    
    
    
    
    
     编译工程
    
    
    
    
    
     没有错误和警告,烧录程序
    
    
    
    
    
     如果出现
    
    
    No rule to make target ‘…/libraries/touchgfx_lib/TouchGFX/generated/images/src/__designer/image_Blue_Backgrounds_Main_bg_480x272px.cpp’, needed by ‘libraries/touchgfx_lib/TouchGFX/
    
    
     不用管,再次编译即可消除
    
   
    
    
    
     烧录结果
    
    
    
    
    
     这个时候只是在屏幕上面显示,点击是没有反应的,还需要添加触摸控制程序
    
    
    需要知道自己的屏幕控制芯片是什么,我的正点原子的7寸屏幕是FT5426,在软件包中心搜索对应的驱动程序即可,常用的屏幕触摸芯片,软件包中心都有,如果没有就自己找到屏幕驱动程序,自己手动添加到程序中去
    
    
    
    添加完成之后,
    
     保存
    
    (ctrl+s),RttStudio会
    
     自动更新
    
    软件包
    
    在程序里面可以看到,
    
     ft5426的驱动
    
    ,如下图
    
    
    
    
   
#ifdef PKG_USING_FT5426
#include "ft5426.h"
int rt_hw_ft5426_port(void)
{
    struct rt_touch_config config;
    config.dev_name = "i2c1";
    rt_hw_ft5426_init("ft5426", &config);
    return 0;
}
INIT_ENV_EXPORT(rt_hw_ft5426_port);
#endif
    
   
#ifdef PKG_USING_FT5426
#ifdef __cplusplus
extern "C"{
#endif
#include "ft5426.h"
#include "touch.h"
#ifdef __cplusplus
}
#endif
static rt_device_t  dev = RT_NULL;
static struct       rt_touch_data *read_data = NULL;
static struct       rt_touch_info info;
int ft5426_init(void)
{
    void *id;
//    //same init include sample_touchgfx.c
//    struct rt_touch_config cfg;
//    cfg.dev_name = "i2c1";
//    rt_hw_ft5426_init("ft5426", &cfg);
    dev = rt_device_find("ft5426");
    if (dev == RT_NULL)
    {
        rt_kprintf("can't find device ft5426\n");
        return -1;
    }
    if (rt_device_open(dev, RT_DEVICE_FLAG_RDONLY) != RT_EOK)
    {
        rt_kprintf("open device failed!");
        return -1;
    }
    read_data = (struct rt_touch_data *)rt_malloc(sizeof(struct rt_touch_data) * info.point_num);
    id = rt_malloc(sizeof(rt_uint8_t) * 8);
    rt_device_control(dev, RT_TOUCH_CTRL_GET_ID, id);
    rt_uint8_t * read_id = (rt_uint8_t *)id;
    rt_kprintf("id = %c %c %c %c \n", read_id[0], read_id[1], read_id[2], read_id[3]);
    rt_device_control(dev, RT_TOUCH_CTRL_GET_INFO, &info);
    rt_kprintf("range_x = %d \n", info.range_x);
    rt_kprintf("range_y = %d \n", info.range_y);
    rt_kprintf("point_num = %d \n", info.point_num);
    rt_free(id);
    return 0;
}
#endif
    
     继续添加
    
    
    
   
#ifdef PKG_USING_FT5426
    ft5426_init();
#endif
    
     最后添加:
    
    
    
   
#ifdef PKG_USING_FT5426
    rt_device_read(dev, 0, read_data, info.point_num);
    if (read_data[0].event == RT_TOUCH_EVENT_DOWN || read_data[0].event == RT_TOUCH_EVENT_MOVE)
    {
        y = read_data[0].x_coordinate;
        x = read_data[0].y_coordinate;
        rt_kprintf("down x: %03d y: %03d\n", x, y);
        return true;
    }
    else
#endif
    
     
      FT5426触摸程序添加完成
     
     ,再次编译、烧录
    
    
    开发板上触摸正常,这里不再展示
    
    
     最终工程文件
    
    ,分享给大家
    
    链接:https://pan.baidu.com/s/1wvbiWPxqwKixeUSsPVDBZg
    
    提取码:0uz0
   
    
    
    
     四、结语
    
   
    本教程详细的展示了ART-PI开发板移植Touchgfx的
    
     全过程
    
    ,并给出了常见问题的
    
     解决方案
    
    ,此移植方案是基于
    
     ART-PI的官方SDK
    
    ,所以移植过程
    
     很简单
    
    ,主要是屏幕驱动、触摸驱动官方
    
     已经写好
    
    ,还有一种移植方案是用
    
     软件包中心
    
    的
    
     Touchgfx软件包
    
    ,这时候需要
    
     自己修改
    
    相应的屏幕驱动,网上已经有详细的教程,这里不再细说,最后希望此教程对大家有所帮助!!!