首先感谢大佬手把手操作,我们做下来,不出意外的话编译没有错误,我们也需要根据大佬的文章进行操作,但是有一个问题就是ART-Pi中Touchgfx默认的是GT9147触摸屏,如果使用其它的触摸屏就需要在
中适配,由于时间原因长话短说,完成大佬的操作后,可以看到显示屏上显示demo但是并不能进行触摸操作,我们需要在
这个文件中适配修改,比方说我使用的GT1151,先把GT1151的示例在工程中注释掉,然后根据GT1151的示例进行修改。
直接上代码:使用其它的触摸屏应该也是一样的方法。
/**
******************************************************************************
* 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>
#include "gt1151.h"
#include <touch.h>
#include <rtdevice.h>
#define DBG_TAG "gt1151_sample"
#define DBG_LVL DBG_LOG
#include <rtdbg.h>
#ifdef PKG_USING_GT1151
int gt1151_init(void)
{
rt_thread_mdelay(1000);
rt_device_t touch_dev = rt_device_find("gt1151");
RT_ASSERT(touch_dev != RT_NULL);
rt_device_open(touch_dev, RT_DEVICE_FLAG_RDONLY);
/* 璇� ID */
rt_uint8_t read_id[4];
rt_device_control(touch_dev, RT_TOUCH_CTRL_GET_ID, read_id);
LOG_I("id = %d %d %d %d \n", read_id[0] - '0', read_id[1] - '0', read_id[2] - '0', read_id[3] - '0');
/* 鑾峰彇璁惧淇℃伅 */
struct rt_touch_info info;
rt_device_control(touch_dev, RT_TOUCH_CTRL_GET_INFO, &info);
LOG_I("type :%d", info.type); /* 绫诲瀷锛氱數瀹瑰瀷/鐢甸樆鍨�*/
LOG_I("vendor :%d", info.vendor); /* 鍘傚晢 */
LOG_I("point_num :%d", info.point_num); /* 鏀寔鐨勮Е鐐逛釜鏁� */
LOG_I("range_x :%d", info.range_x); /* X 杞村垎杈ㄧ巼 */
LOG_I("range_y :%d\n", info.range_y); /* Y 杞村垎杈ㄧ巼*/
/* 璁剧疆宸ヤ綔妯″紡涓轰腑鏂ā寮� */
rt_device_control(touch_dev, RT_TOUCH_CTRL_SET_MODE, (void *)RT_DEVICE_FLAG_INT_RX);
/* 璁剧疆宸ヤ綔妯″紡涓鸿疆璇㈡ā寮� */
rt_device_control(touch_dev, RT_TOUCH_CTRL_SET_MODE, (void *)RT_DEVICE_FLAG_RDONLY);
/* 浜ゆ崲 X銆乊 杞村潗鏍� */
// rt_device_control(touch_dev, RT_TOUCH_CTRL_SET_X_TO_Y, RT_NULL);
struct rt_touch_data data;
rt_memset(&data, 0, sizeof(data));
return 0;
}
#endif
void STM32TouchController::init()
{
/**
* Initialize touch controller and driver
*
*/
#ifdef PKG_USING_GT1151
gt1151_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);
*
*/
rt_thread_mdelay(20);
#ifdef PKG_USING_GT1151
struct rt_touch_data data;
rt_device_t touch_dev = rt_device_find("gt1151");
rt_device_read(touch_dev, 0, &data, 1);
if ((data.x_coordinate > 0&&data.x_coordinate<=800) || (data.y_coordinate > 0&&data.y_coordinate <=480))
{
if (data.event == RT_TOUCH_EVENT_DOWN || data.event == RT_TOUCH_EVENT_MOVE)
{
x =data.x_coordinate;
y =data.y_coordinate;
LOG_I("\t x: %d, y: %d", x, y);
rt_memset(&data, 0, sizeof(data));
}
return true;
}
else
#endif
{
return false;
}
}
/* USER CODE END STM32TouchController */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/