cancel
Showing results for 
Search instead for 
Did you mean: 

Touchgfx Simple Touchscreen library FT5316 Hangs and freezes

Caan
Associate III
#include "cmsis_os.h"
#include <stdio.h>
#include <stdlib.h>
#include "main.h"
#include <stdbool.h>

extern I2C_HandleTypeDef hi2c4;
uint8_t DATA, DEVICE_STATUS = 0x00, XH, XL, YH, YL;
uint16_t X_AXIS, Y_AXIS;

#define DEVICE_ADDRESS (0x38 << 1)  // Shifted for STM32 HAL

uint16_t x_axis = 0, y_axis = 0;
uint8_t STATUS = 0;

void STM32TouchController::init()
{
    // Initialization if needed (e.g., configure GPIO, I2C, etc.)
}

bool STM32TouchController::sampleTouch(int32_t& x, int32_t& y)
{
    static uint16_t prev_x = 0xFFFF, prev_y = 0xFFFF;

    STATUS = HAL_GPIO_ReadPin(GPIOG, GPIO_PIN_2);  // Touch INT pin low = active

    if (STATUS == GPIO_PIN_RESET)
    {
        // Read X high & low
        HAL_I2C_Mem_Read(&hi2c4, DEVICE_ADDRESS, 0x03, I2C_MEMADD_SIZE_8BIT, &XH, 1, 100);
        HAL_I2C_Mem_Read(&hi2c4, DEVICE_ADDRESS, 0x04, I2C_MEMADD_SIZE_8BIT, &XL, 1, 100);

        // Read Y high & low
        HAL_I2C_Mem_Read(&hi2c4, DEVICE_ADDRESS, 0x05, I2C_MEMADD_SIZE_8BIT, &YH, 1, 100);
        HAL_I2C_Mem_Read(&hi2c4, DEVICE_ADDRESS, 0x06, I2C_MEMADD_SIZE_8BIT, &YL, 1, 100);

        // Combine bytes to get coordinates
        uint16_t current_x = ((XH & 0x0F) << 8) | XL;
        uint16_t current_y = ((YH & 0x0F) << 8) | YL;

        // Store coordinates
        X_AXIS = current_x;
        Y_AXIS = current_y;

        // Return only if the value changed
        if (current_x != prev_x || current_y != prev_y)
        {
            prev_x = current_x;
            prev_y = current_y;

            x = current_x;
            y = current_y;
            return true;
            osDelay(1000);
        }
    }

    return false; // No touch or same value as before
}

This Library runs fine but after few seconds of usage the debugger throughs the following

static void prvTaskExitError( void )
{
volatile uint32_t ulDummy = 0;

	/* A function that implements a task must not exit or attempt to return to
	its caller as there is nothing to return to.  If a task wants to exit it
	should instead call vTaskDelete( NULL ).

	Artificially force an assert() to be triggered if configASSERT() is
	defined, then stop here so application writers can catch the error. */
	configASSERT( uxCriticalNesting == ~0UL );
	portDISABLE_INTERRUPTS();
	while( ulDummy == 0 )
	{
		/* This file calls prvTaskExitError() after the scheduler has been
		started to remove a compiler warning about the function being defined
		but never called.  ulDummy is used purely to quieten other warnings
		about code appearing after this function is called - making ulDummy
		volatile makes the compiler think the function could return and
		therefore not output an 'unreachable code' warning for code that appears
		after it. */
	}
}

And if I keep my finger pressed on the GUI button, it tends to click repeatedly very quickly, and the GUI freezes after a few seconds.

0 REPLIES 0