Resistive touch screen calibration problem: setCalibrationMatrix translating points incorrectly
Hey,
I'm working on custom board project with display size 800x480px and resistive touch screen. I have issue with using setCalibrationMatrix. Below is code snippet from my STM32TouchController.cpp file. In initalization, calibration matrix i set by calling calib.setCalibrationMatrix(reference_points, adc_points). I determined adc_points using the debugger by clicking on reference_points drawn on the screen. adc_points are raw values from AD converter the same goes for x_val and y_val in sampleTouch routine. After the calibration matrix is set as seen below the values in touchgfx engine are translated incorrectly. To be precise y coordinate is offseted by +160. Here are three examples for touched and translated points:
- pressed reference point drawn on screen in position
x: 40 y: 40 is translated to x: 42 y: 203 (raw adc values: x: 427 y: 804)
- x: 760 y: 40 -----------------> x: 762 y: 202 (raw adc values: x: 3678 y: 844)
- x: 760 y: 440 -----------------> x: 762 y: 603 (raw adc values: x: 3677 y: 3489)
So my question is am I doing something wrong or is something wrong with mathematics in touchgfx engine ?
TouchCalibration calib;
touchgfx::Point reference_points[3] =
{
{ 40, 40 },
{ 760, 40 },
{ 760, 440 }
};
touchgfx::Point adc_points[3]=
{
{ 424, 820},
{ 3675, 861},
{ 3678, 3502},
};
void STM32TouchController::init()
{
/**
* Initialize touch controller and driver
*
*/
calib.setCalibrationMatrix(reference_points, adc_points);
}
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 th
* e TouchGFX framework.
* By default sampleTouch is called every tick, this can be adjusted by HAL::setTouchSampleRate(int8_t);
*
*/
osDelay(debounce_time);
if(touch_detect()){
int32_t x_val = read_ch_x();
int32_t y_val = read_ch_y();
if(touch_detect()){
x=x_val;
y=y_val;
return true;
}else return false;
}
return false;
}