Skip to main content
ikassma
Associate III
March 8, 2019
Solved

How to use TouchscreenCalibration.hpp ?

  • March 8, 2019
  • 15 replies
  • 3314 views
#include <bsp/OTM8009TouchController.hpp>
#include <touchgfx/transforms/TouchCalibration.hpp>
extern "C"
{
#include "stm32f769i_discovery.h"
#include "stm32f769i_discovery_ts.h"
}
using namespace touchgfx;
using touchgfx::TouchCalibration;
TouchCalibration tsCalibration;
static touchgfx::Point lcdCalibPoints[3] = /* Display size is 800x480 */
{
 { 20, 20 }, /* 10%, 10% */
 { 780, 20 }, /* 90%, 50% */
 { 780, 460 }, /* 50%, 90% */
};
//calibration ADC 12 bit values
static touchgfx::Point touchCalibPoints[3] =
{
 { 200, 370 }, /* ADC values read when clicking in 80,48 */
 { 3927, 341 }, /* ADC values read when clicking in 720,240 */
 { 3919, 3807 }, /* ADC values read when clicking in 400,432 */
};
 
 
void OTM8009TouchController::init()
{
 BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize());
 tsCalibration.setCalibrationMatrix(lcdCalibPoints, touchCalibPoints);
}
 
bool OTM8009TouchController::sampleTouch(int32_t& x, int32_t& y)
{
 touchgfx::Point tsPos;
 uint8_t status;
 TS_StateTypeDef state;
 
 BSP_TS_GetState(&state);
 if (state.touchDetected)
 {
 tsPos.x = state.touchX[0];
 tsPos.y = state.touchY[0];
 tsCalibration.translatePoint(*&tsPos);
 x = (uint16_t)tsPos.x;
 y = (uint16_t)tsPos.y;
 
 if ((x > 800) || (y > 480))
 {
 return false;
 }
 return true;
 }
 return false;
}

​I wrote the code above and the data I checked with the debugger was correct.

but button is not work...

This topic has been closed for replies.
Best answer by Martin KJELDSEN

Hi @ikassma​,

TouchGFX HAL will call translatePoints() automatically as long as you set the calibration matrix (as you've done in your init() function. Try without translating it yourself in sampleTouch().

If sampleTouch() is returning true (without touch happening) then it must be a driver problem since that will only happen if state.touchDetected is true.

Best regards,

Martin

15 replies

ikassma
ikassmaAuthor
Associate III
March 8, 2019

I used 8"(800x480) TFT LCD and Resistive Touch Screen(driver is MAX11801).

I succeeded in receiving the touch screen ADC value. And I got to the coordinates using TouchScreenCalibration Class provided by TouchGFX. However, using the TouchScreenCalibration Class, sampleTouch () periodically returns a value, but no event has occurred.

I'm looking for an example using TouchScreenCalibation Class from TouchGFX.

Martin KJELDSEN
Martin KJELDSENBest answer
Principal III
March 9, 2019

Hi @ikassma​,

TouchGFX HAL will call translatePoints() automatically as long as you set the calibration matrix (as you've done in your init() function. Try without translating it yourself in sampleTouch().

If sampleTouch() is returning true (without touch happening) then it must be a driver problem since that will only happen if state.touchDetected is true.

Best regards,

Martin

ikassma
ikassmaAuthor
Associate III
March 9, 2019

hi @Martin KJELDSEN​ 

Thanks for your mention it.

i will try your suggest.

DVale
Associate II
August 29, 2019

Hi @Martin KJELDSEN​ ,

I have a very similar issue. I'm running a simple touchGfx application, the STM32F4TouchController::sampleTouch function output looks correct (true the boolean, while x and y change correctly on the basis of the pressed area), but the application doesn't recognize the pressed button as happens in touchgfx simulator.

Here's is the code, for this stage state.TouchDetected is always 1.

bool STM32F4TouchController::sampleTouch(int32_t& x, int32_t& y)

{

 /* USER CODE BEGIN F4TouchController_sampleTouch */

   

  TS_StateTypeDef state;

  BSP_TS_GetState(&state);

  if (state.TouchDetected)

  {

    x = state.X;

    y = state.Y;

    return true;

  }

  return false;

 /* USER CODE END F4TouchController_sampleTouch */   

}

Thanks in advance

Martin KJELDSEN
Principal III
August 29, 2019

It's always 1? Then there's something wrong with the drivers. How did you create this project? Looks like with CubeMX.

Which F4 board is this? Try creating the project using the Application Template from the designer and do some comparisons.

/Martin

DVale
Associate II
August 29, 2019

Yes, I started with F4 evaluation board but I'm using a different display (720x720) and a different controller.

The video output looks good, the interactions that doesn't involve any touch action work good, but it can't detect any touch.

I forced the touchDetected field to 1 to debug this issue, I cannot understand how the touchgfx core can ignore the "touch" when x, y and the boolean returned are correct.

Is there a touch register? Is there any way to debug how the output of the sampleTouch function is used?

Thank you

DVale
Associate II
August 29, 2019

As suggested I opened a new thread "Touchgfx can't detect any touch"

DVale
Associate II
August 29, 2019
Martin KJELDSEN
Principal III
August 29, 2019

Thanks!