Hi @VLau ,
Could you try this ? Works on my side, I based it on your code, the main difference was that I added the ft6x06_ReadID() calls, and instead of doing everything in init() and sampleTouch() I added extra steps to make sure the program had time to extract and use the right information (if that makes sense :grinning_face_with_sweat:).
In 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 <ft6x06.h>
#include "../Components/ft6x06/ft6x06.h"
#define TS_I2C_ADDRESS ((uint16_t)0x54) //0x54 or 0x70
#define TS_I2C_ADDRESS_A02 ((uint16_t)0x70)
#define TS_SWAP_NONE ((uint8_t) 0x01)
#define TS_SWAP_X ((uint8_t) 0x02)
#define TS_SWAP_Y ((uint8_t) 0x04)
#define TS_SWAP_XY ((uint8_t) 0x08)
#define SIZE_X 800
#define SIZE_Y 480
static uint8_t ts_orientation;
static uint8_t I2C_Address = 0;
bool ts_initialized = false;
bool isTouchDetected = false;
uint16_t tmp = 0, tempoX = 0, tempoY = 0;
bool STM32TouchController::TS_init()
{
ft6x06_Init(0);
ft6x06_ReadID(TS_I2C_ADDRESS_A02);
ft6x06_ReadID(TS_I2C_ADDRESS);
I2C_Address = TS_I2C_ADDRESS_A02;
ft6x06_Reset(I2C_Address);
ft6x06_TS_Start(I2C_Address);
return true;
}
void STM32TouchController::init()
{
/**
* Initialize touch controller and driver
*
*/
if (SIZE_X < SIZE_Y)
{
ts_orientation = TS_SWAP_NONE;
}
else
{
ts_orientation = TS_SWAP_XY | TS_SWAP_Y;
}
if (TS_init())
{
ts_initialized = true;
}
}
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);
*
*/
if (ts_initialized)
{
// TS_StateTypeDef TS_State;
isTouchDetected = TS_getCoordinates();
if (isTouchDetected)
{
x = tempoX;
y = tempoY;
return true;
}
}
return false;
}
bool STM32TouchController::TS_getCoordinates()
{
if (ft6x06_TS_DetectTouch(I2C_Address))
{
ft6x06_TS_GetXY(I2C_Address, &tempoX, &tempoY);
if (ts_orientation & TS_SWAP_XY)
{
tmp = tempoX;
tempoX = tempoY;
tempoY = tmp;
}
if (ts_orientation & TS_SWAP_X)
{
tempoX = FT_6206_MAX_WIDTH - 1 - tempoX;
}
if (ts_orientation & TS_SWAP_Y)
{
tempoY = FT_6206_MAX_HEIGHT - 1 - tempoY;
}
return true;
}
return false;
}
/* USER CODE END STM32TouchController */
and in STM32TouchController.hpp just add the two functions TS_init() and TS_getCoordinates() I added
class STM32TouchController : public touchgfx::TouchController
{
public:
STM32TouchController() {}
/**
* @fn virtual void STM32TouchController::init() = 0;
*
* @brief Initializes touch controller.
*
* Initializes touch controller.
*/
virtual void init();
/**
* @fn virtual bool STM32TouchController::sampleTouch(int32_t& x, int32_t& y) = 0;
*
* @brief Checks whether the touch screen is being touched, and if so, what coordinates.
*
* Checks whether the touch screen is being touched, and if so, what coordinates.
*
* @param [out] x The x position of the touch
* @param [out] y The y position of the touch
*
* @return True if a touch has been detected, otherwise false.
*/
virtual bool sampleTouch(int32_t& x, int32_t& y);
bool TS_init();
bool TS_getCoordinates();
private:
};
Hope this helps (and also works on your side),
/Romain