目录
ART-PI创建Touchgfx工程实现触摸
一、创建ART-PI工程
1.在RT-Thread Studio里下载相关芯片包
2.创建ATR-PI工程
3.点击完成自动创建工程。
二、创建Touchgfx工程
1.使能相关软件,添加触摸芯片
2.配置IIC
配置如图:
3.使能Touchgfx相关库4. 保存相关操作,软件会自动添加进工程,如下:
5.先打开DAM2D与CRC宏定义:
6.打开项目属性更改C/C++构建设置
7.编译运行,此时会有以下fatal error: touch.h: No such file or directory gt9147.c /touchgfx-test/packages/gt9147-v1.1.0/src 第 22 行 C/C++ 问题这样的报错,这是因为我们没有使能touch设备,打开RT-Thread Settings,使能touch设备,保存退出。
再次对工程进行编译,可以发现无报错,无警告。
8.将程序下载进板子,现象如下(无法使用触摸功能,大概是因为出现了死机):
三、添加触摸功能
1.打开\packages\touchgfx2rtt-latest\TouchGFX\target\STM32TouchController.cpp文件修改程序(可直接复制替换):
/**
******************************************************************************
* File Name : STM32TouchController.cpp
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* USER CODE BEGIN STM32TouchController */
#include <STM32TouchController.hpp>
#include <rtthread.h>
#ifdef PKG_USING_GT9147
#include "gt9147.h"
static rt_device_t dev = RT_NULL;
static struct rt_touch_data *read_data = NULL;
static struct rt_touch_info info;
int gt9147_init(void)
{
void *id;
dev = rt_device_find("gt");
if (dev == RT_NULL)
{
rt_kprintf("can't find device gt\n");
return -1;
}
if (rt_device_open(dev, RT_DEVICE_FLAG_INT_RX) != 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
void STM32TouchController::init()
{
/**
* Initialize touch controller and driver
*
*/
#ifdef PKG_USING_GT9147
gt9147_init();
#endif
}
bool STM32TouchController::sampleTouch(int32_t& x, int32_t& y)
{
/**
* By default sampleTouch returns false,
* return true if a touch has been detected, otherwise false.
*
* Coordinates are passed to the caller by reference by x and y.
*
* This function is called by the TouchGFX framework.
* By default sampleTouch is called every tick, this can be adjusted by HAL::setTouchSampleRate(int8_t);
*
*/
#ifdef PKG_USING_GT9147
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)
{
x = /*800 -*/ read_data[0].x_coordinate;
y = /*480 -*/ read_data[0].y_coordinate;
return true;
}
else
#endif
{
return false;
}
}
/* USER CODE END STM32TouchController */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
编译下载现象如下(触摸功能可以正常使用):
2.添加使用不同Touchgfx官方dome(建议使用touchgfx的版本为4.15.0,虽然使用较新版的touchfgx会自动更新相关软件包,但是在编译过程中会缺少文件,用4.15.0版本的touchgfxkeyi1减少移植过程中出现的问题)
使用官方提供的例程:
3.选择你需要的dome(占用空间不要太大,否则导入后编译不通过)添加
根据自己的需要更改,生成相关代码:
4.打开art-pi工程,更新一下软件包,然后编译下载(效果如图)(出现以下情况原因是其尺寸并未重新调整):
四、总结
在之前使用较新版本的touchgfx移植过程中报了很多错,搜索很多博客大佬的解决方法都没有相关的解决办法,后面换用与触摸芯片例程中touchgfx相同的版本后解决相关问题,触摸芯片添加后不能触摸请观看该博客的解决办法:
(15条消息) RT-Thread学习笔记之一:如何在ART-PI上运行TouchGFX+正点原子RGB屏并解决gt9147软件包死机的问题_Ye0522.的博客-CSDN博客RT-Thread学习笔记之一:如何在ART-PI上运行TouchGFX+正点原子RGB屏并解决gt9147软件包死机的问题_Ye0522.的博客-CSDN博客(15条消息) RT-Thread学习笔记之一:如何在ART-PI上运行TouchGFX+正点原子RGB屏并解决gt9147软件包死机的问题_Ye0522.的博客-CSDN博客(15条消息) RT-Thread学习笔记之一:如何在ART-PI上运行TouchGFX+正点原子RGB屏并解决gt9147软件包死机的问题_Ye0522.的博客-CSDN博客
以上就是我分享的内容,本文仅仅简单介绍如何在ART-PI上运行TouchGFX,记录了创建touchgfx工程添加触摸芯片gt9147软件包后死机的解决办法以及移植dome过程中需要注意的相关内容。