STM32CUBEMX配置
打开一个IIC接口配置如下
TouchGFX设置
找到按钮 添加一个按钮
仿真效果
点击屏幕之后会变状态
代码分析
在 STM32TouchController.cpp 中添加代码
extern "C"
{
#include "bsp_ft6336.h"
}
extern "C" FT6336_TouchPointType tp;
extern volatile uint32_t ft6336_on_touch_count;
在原代码中添加触摸采集部分
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);
*
*/
uint16_t xDiff = 0,yDiff = 0;
static uint16_t pI_Touch_X = 0, pI_Touch_Y = 0;
//触摸中断产生
if (ft6336_on_touch_count) // irq done
{
uint8_t id1 = FT6336_read_touch1_id(); // id1 = 0 or 1
tp.tp[id1].status = (tp.tp[id1].status == release) ? touch : stream;
tp.tp[id1].x = FT6336_read_touch1_x();
tp.tp[id1].y = FT6336_read_touch1_y();
tp.tp[~id1 & 0x01].status = release;
//更新数据至TouchGFX
if (tp.tp[0].status == 1) //最多支持两个触点
{
xDiff = tp.tp[0].x > pI_Touch_X ? (tp.tp[0].x - pI_Touch_X): (pI_Touch_X - tp.tp[0].x);
yDiff = tp.tp[0].y > pI_Touch_Y ? (tp.tp[0].y - pI_Touch_Y): (pI_Touch_Y - tp.tp[0].y);
//判断阈值
if ((xDiff + yDiff) > 5)
{
pI_Touch_X = tp.tp[0].x;
pI_Touch_Y = tp.tp[0].y;
}
//更新触摸,横屏触摸坐标变换
x = 320 - pI_Touch_Y;
y = pI_Touch_X;
}
ft6336_on_touch_count = 0;
//
return true;
}
return false;
}