开发板上的LCD集成了触摸屏,型号为[color=rgba(0, 0, 0, 0.85)]FT6x06的电容触摸屏。连接到开发板上的I2C1
中断引脚连接到了PF1上:
【移植步骤】
1、在stm32cubemx中使能i2c1,但是不生成代码:
然后重新生成代码
2、把bsp下的ft6x06添加到工程中,加入头文件的路径。
3、bsp下面的stm32l562e_discovery_ts.c加入工程中。
4、同时创建ftfx06_conf.h配置文件:
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef FT6X06_CONF_H
#define FT6X06_CONF_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
/* Macros --------------------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
#define FT6X06_AUTO_CALIBRATION_ENABLED 0U
#define FT6X06_MAX_X_LENGTH 240U
#define FT6X06_MAX_Y_LENGTH 240U
#ifdef __cplusplus
}
#endif
#endif /* FT6X06_CONF_H */
5、在main.c中添加触摸初始化如下:
TS_Init_t TsInit;
/* Initialize the TouchScreen */
TsInit.Width = 240;
TsInit.Height = 240;
TsInit.Orientation = TS_ORIENTATION_PORTRAIT;
TsInit.Accuracy = 10;
if (BSP_TS_Init(0, &TsInit) != BSP_ERROR_NONE)
{
Error_Handler();
}
/* Configure TS interrupt */
if (BSP_TS_EnableIT(0) != BSP_ERROR_NONE)
{
Error_Handler();
}
6、添加测试代码如下:
/* USER CODE BEGIN 3 */
if (BSP_TS_Get_MultiTouchState(0, &TsMultipleState) != BSP_ERROR_NONE)
{
Error_Handler();
}
if(TsMultipleState.TouchDetected >= 1)
{
/* Get X and Y position of the touch post calibrated */
x = TsMultipleState.TouchX[0];
y = TsMultipleState.TouchY[0];
printf("touch:x:%d, y%d\r\n",x,y);
}
}
/* USER CODE END 3 */
在这段代码中,首先判断是否有触摸中断产生,如果有通过串口输出触摸的坐标。
【测试效果】
通过串口查看,触摸屏后,串口打印数据如下:
|