cancel
Showing results for 
Search instead for 
Did you mean: 

Touchgfx Touch Panel Routine

Hello Dear Engineers,

I am looking for a standard touch handling routine using Touchgfx. The touch panel I am using is resistive which is handled by XPT2046 (TSC2046). The touch controller IC is controlled by SPI.

The main problem I have been encountered is that the touch screen response on the run time test is really sharp and fast, it shouldn't be as usual devices like iPhone or Android devices have some sort of delay. Furthermore, when a button or selectable item is touched, it shouldn't lose focus until the press is released. The routine I have used so far is as follows.

bool STM32TouchController::sampleTouch(int32_t &x, int32_t &y) {
	static int32_t prev_x = 0, prev_y = 0;
	if (XPT2046_TouchPressed()) {
		XPT2046_TouchGetCoordinates((uint16_t*) &x, (uint16_t*) &y);
		if ((abs(prev_x - x)>20) &(abs(prev_y- y)>20)) {
			if ((x != 0) & (y != 0)) {
				prev_x = x;
				prev_y = y;
				return true;
			}
		}
	}
	/**
	 * 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);
	 *
	 */
	return false;
}

I have also yet another question. Is there any standard page by Touchgfx for calibrating touch screen?

Any help would be appreciated.

8 REPLIES 8
Romain DIELEMAN
ST Employee

Hi,

There are no standard page made by TouchGFX on calibrating touch screens. We usually just hard code the coordinates in our examples.

Concerning your Touch Screen routine, is that a bad thing that the response is so fast :grinning_face_with_sweat: ? Are you looking to slow it down/create that delay on purpose ? I guess what you could do is to create custom buttons where you wait a few ticks before doing the "click animation" (so changing the image to the Clicked Button image) and before launching whatever action linked to that button.

/Romain

Dear @Romain DIELEMAN​ 

Well, "what I see" is that the Touchgfx doesn't hold the button as pressed, as the first input is entered, it gets the coordinates and does the job.

"What I want" to see is that until the button is pressed, the button or the widget still holds the focus and does the job when it is released. I didn't see such an option over Touchgfx to have different states for widgets as pressed, hold, released, etc.

As for the calibration, HOW could you be sure that the first touchscreen is the same as the other touchscreens in case of need for replacement?

Uusta.1
Associate III

I'm using same XPT2046 Touch Screen Controller with you ( controlled by SPI and resistive touch screen), but I failed, could you help me? what else do I need to do? I added xpt2046 library to my file. I configured SPI_HandleTypeDef to mine. and I added code as you see below? what else do I need to detect touches.

bool STM32TouchController::sampleTouch(int32_t& x, int32_t& y)
{
	if (XPT2046_TouchPressed()) {
			XPT2046_TouchGetCoordinates((uint16_t*) &x, (uint16_t*) &y);
			return true;
		}
    return false;
}

First, check the XPT2046 without Touchgfx in the bare metal case and then verify if the interrupt pin of xpt2046 is working. Then after check the XPT2046 connection to touchgfx and the pointer case definitions.

Uusta.1
Associate III

On my project void STM32TouchController::init() function is empty. How is yours? Could you share it with me ?

On my project void STM32TouchController::init() function is empty. How is yours? Could you share it with me ?

This chip doesn't require any special sort of initialization. Just check in a bare project if you can get data through SPI, then try to implement the touch routine. While you can not get data from your touchscreen chip in a pure project, you are not allowed to go furthermore.