cancel
Showing results for 
Search instead for 
Did you mean: 

How to use TouchscreenCalibration.hpp ?

ikassma
Senior
#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...

15 REPLIES 15

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

Thanks! I'll head over there now :)

Hmm, i don't see it. Can you post the link? Maybe it doesn't show up in the TouchGFX feed.

TouchGFX won't ignore it. I'm not sure what's going on because i don't have your project or board.

TouchGFX at its core does not really care about touch. It offers a handle that you can implement and use your own drivers (ST-drivers in this case, since its an eval board). We have to look to the project and version of drivers, etc. The touch registers are read by the driver through a protocol like I2C. You can't inspect it directly.

Can you please try to create your project through the designer? And which F4 board is this?

/Martin

Thanks!