2021-05-11 02:47 AM
Hey!
I took the working project that is generated by TouchGFX Designer as a reference and made a new project on the DISCOVERY-F469 board.
I made UI with two screens. Screen1 has a button to jump to screen 2 and an animated image.
After flashing the board I can see my Screen1 with correctly running animation. The problem is that UI button isn't working.
While debugging I checked the following:
What can be wrong?
Thanks!
Solved! Go to Solution.
2021-05-14 06:33 AM
Hi @VLau ,
Could you try this ? Works on my side, I based it on your code, the main difference was that I added the ft6x06_ReadID() calls, and instead of doing everything in init() and sampleTouch() I added extra steps to make sure the program had time to extract and use the right information (if that makes sense :grinning_face_with_sweat:).
In STM32TouchController.cpp:
/**
******************************************************************************
* File Name : STM32TouchController.cpp
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* USER CODE BEGIN STM32TouchController */
#include <STM32TouchController.hpp>
// #include <ft6x06.h>
#include "../Components/ft6x06/ft6x06.h"
#define TS_I2C_ADDRESS ((uint16_t)0x54) //0x54 or 0x70
#define TS_I2C_ADDRESS_A02 ((uint16_t)0x70)
#define TS_SWAP_NONE ((uint8_t) 0x01)
#define TS_SWAP_X ((uint8_t) 0x02)
#define TS_SWAP_Y ((uint8_t) 0x04)
#define TS_SWAP_XY ((uint8_t) 0x08)
#define SIZE_X 800
#define SIZE_Y 480
static uint8_t ts_orientation;
static uint8_t I2C_Address = 0;
bool ts_initialized = false;
bool isTouchDetected = false;
uint16_t tmp = 0, tempoX = 0, tempoY = 0;
bool STM32TouchController::TS_init()
{
ft6x06_Init(0);
ft6x06_ReadID(TS_I2C_ADDRESS_A02);
ft6x06_ReadID(TS_I2C_ADDRESS);
I2C_Address = TS_I2C_ADDRESS_A02;
ft6x06_Reset(I2C_Address);
ft6x06_TS_Start(I2C_Address);
return true;
}
void STM32TouchController::init()
{
/**
* Initialize touch controller and driver
*
*/
if (SIZE_X < SIZE_Y)
{
ts_orientation = TS_SWAP_NONE;
}
else
{
ts_orientation = TS_SWAP_XY | TS_SWAP_Y;
}
if (TS_init())
{
ts_initialized = true;
}
}
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 the TouchGFX framework.
* By default sampleTouch is called every tick, this can be adjusted by HAL::setTouchSampleRate(int8_t);
*
*/
if (ts_initialized)
{
// TS_StateTypeDef TS_State;
isTouchDetected = TS_getCoordinates();
if (isTouchDetected)
{
x = tempoX;
y = tempoY;
return true;
}
}
return false;
}
bool STM32TouchController::TS_getCoordinates()
{
if (ft6x06_TS_DetectTouch(I2C_Address))
{
ft6x06_TS_GetXY(I2C_Address, &tempoX, &tempoY);
if (ts_orientation & TS_SWAP_XY)
{
tmp = tempoX;
tempoX = tempoY;
tempoY = tmp;
}
if (ts_orientation & TS_SWAP_X)
{
tempoX = FT_6206_MAX_WIDTH - 1 - tempoX;
}
if (ts_orientation & TS_SWAP_Y)
{
tempoY = FT_6206_MAX_HEIGHT - 1 - tempoY;
}
return true;
}
return false;
}
/* USER CODE END STM32TouchController */
and in STM32TouchController.hpp just add the two functions TS_init() and TS_getCoordinates() I added
class STM32TouchController : public touchgfx::TouchController
{
public:
STM32TouchController() {}
/**
* @fn virtual void STM32TouchController::init() = 0;
*
* @brief Initializes touch controller.
*
* Initializes touch controller.
*/
virtual void init();
/**
* @fn virtual bool STM32TouchController::sampleTouch(int32_t& x, int32_t& y) = 0;
*
* @brief Checks whether the touch screen is being touched, and if so, what coordinates.
*
* Checks whether the touch screen is being touched, and if so, what coordinates.
*
* @param [out] x The x position of the touch
* @param [out] y The y position of the touch
*
* @return True if a touch has been detected, otherwise false.
*/
virtual bool sampleTouch(int32_t& x, int32_t& y);
bool TS_init();
bool TS_getCoordinates();
private:
};
Hope this helps (and also works on your side),
/Romain
2021-05-11 03:06 AM
Hi,
Do you see the images of the button change when you press it ? Do other animations work (like an animated image) ? Just to make sure the tick is working. What is the animationEndedCallbackHandler you are talking about in Screen1ViewBase (it usually is in widget classes with animations) ? Are you sure it is linked to your button in your case ?
/Romain
2021-05-11 04:08 AM
Thanks for quick response!
Button image is not changing with press, while animation "runs" as expected.
"AnimationEndedCallbackHandler" I took from "Animated Image Example" from TGFX Designer UI templates. There an interaction added: Animation is done -> execute C++ code -> animation.startAnimation(!animation.isReverse(), false, true);
Another interaction on my Screen 1 is: Button Clicked -> Change Screen -> Screen 2.
In TGFX Designer generated project UI buttons work as expected, In CubeMX generated project not.
In case here's CubeMX TouchGFX config: Single Buffer, Address allocated framebuffer, 800x480, no OS. Display-related and TGFX-related code were more or less copied from working project. However since animation is working I think that part is probably fine.
2021-05-12 01:55 AM
I'm a bit confused by what you said concerning the "Designer generated project works, but not the STM32CubeMX generated project". Do you mean the application template available in TouchGFX Designer compared to your custom project started from STM32CubeMX?
I first had my doubts about running without an OS but if the other animations work then it is not a tick issue. Could you share how you configured STM32TouchController.cpp and TouchGFXConfiguration.cpp ? Is it exactly like in the application template ?
/Romain
2021-05-12 02:47 AM
Thanks for your attention to my problem!
Do you mean the application template available in TouchGFX Designer compared to your custom project started from STM32CubeMX?
Yes, exactly.
Is it exactly like in the application template ?
No, a bit different, but generally I took it from template. However with debugger I see correct detected xy values in sampleTouch function.
/* USER CODE BEGIN STM32TouchController */
#include <STM32TouchController.hpp>
#include <ft6x06.h>
#define TS_I2C_ADDRESS ((uint16_t)0x54)
#define TS_SWAP_NONE ((uint8_t) 0x01)
#define TS_SWAP_X ((uint8_t) 0x02)
#define TS_SWAP_Y ((uint8_t) 0x04)
#define TS_SWAP_XY ((uint8_t) 0x08)
#define SIZE_X 800
#define SIZE_Y 480
void STM32TouchController::init()
{
/**
* Initialize touch controller and driver
*
*/
ft6x06_Init(TS_I2C_ADDRESS);
//TERM_printString("TS_id %d\r\n", ft6x06_ReadID(TS_I2C_ADDRESS));
ft6x06_Reset(TS_I2C_ADDRESS);
ft6x06_TS_Start(TS_I2C_ADDRESS);
}
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 the TouchGFX framework.
* By default sampleTouch is called every tick, this can be adjusted by HAL::setTouchSampleRate(int8_t);
*
*/
if (ft6x06_TS_DetectTouch(TS_I2C_ADDRESS))
{
uint16_t tmp, x = 0, y = 0;
uint8_t ts_orientation = TS_SWAP_NONE;
ft6x06_TS_GetXY(TS_I2C_ADDRESS, &x, &y);
if (SIZE_X < SIZE_Y) ts_orientation = TS_SWAP_NONE;
else ts_orientation = TS_SWAP_XY | TS_SWAP_Y;
if (ts_orientation & TS_SWAP_XY)
{
tmp = x;
x = y;
y = tmp;
}
if (ts_orientation & TS_SWAP_X)
{
x = FT_6206_MAX_WIDTH - 1 - x;
}
if (ts_orientation & TS_SWAP_Y)
{
y = FT_6206_MAX_HEIGHT - 1 - y;
}
//TERM_printString("xy %d ", x);
//TERM_printString("%d\r\n", y);
return true;
}
return false;
}
/* USER CODE END STM32TouchController */
I first had my doubts about running without an OS...
I just tried to turn on RTOS - as before, the animation goes on, button touches are not detected. Code isn't stuck, I have TouchGFX_Task and StartDefaultTask - both running.
...TouchGFXConfiguration.cpp...
Generated file, nothing changed here:
extern "C" void touchgfx_init();
extern "C" void touchgfx_taskEntry();
static STM32TouchController tc;
static NoDMA dma;
static LCD16bpp display;
static ApplicationFontProvider fontProvider;
static Texts texts;
static TouchGFXHAL hal(dma, display, tc, 800, 480);
void touchgfx_init()
{
Bitmap::registerBitmapDatabase(BitmapDatabase::getInstance(), BitmapDatabase::getInstanceSize());
TypedText::registerTexts(&texts);
Texts::setLanguage(0);
FontManager::setFontProvider(&fontProvider);
FrontendHeap& heap = FrontendHeap::getInstance();
/*
* we need to obtain the reference above to initialize the frontend heap.
*/
(void)heap;
/*
* Initialize TouchGFX
*/
hal.initialize();
}
void touchgfx_taskEntry()
{
/*
* Main event loop. Will wait for VSYNC signal, and then process next frame. Call
* this function from your GUI task.
*
* Note This function never returns
*/
hal.taskEntry();
}
2021-05-14 06:33 AM
Hi @VLau ,
Could you try this ? Works on my side, I based it on your code, the main difference was that I added the ft6x06_ReadID() calls, and instead of doing everything in init() and sampleTouch() I added extra steps to make sure the program had time to extract and use the right information (if that makes sense :grinning_face_with_sweat:).
In STM32TouchController.cpp:
/**
******************************************************************************
* File Name : STM32TouchController.cpp
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* USER CODE BEGIN STM32TouchController */
#include <STM32TouchController.hpp>
// #include <ft6x06.h>
#include "../Components/ft6x06/ft6x06.h"
#define TS_I2C_ADDRESS ((uint16_t)0x54) //0x54 or 0x70
#define TS_I2C_ADDRESS_A02 ((uint16_t)0x70)
#define TS_SWAP_NONE ((uint8_t) 0x01)
#define TS_SWAP_X ((uint8_t) 0x02)
#define TS_SWAP_Y ((uint8_t) 0x04)
#define TS_SWAP_XY ((uint8_t) 0x08)
#define SIZE_X 800
#define SIZE_Y 480
static uint8_t ts_orientation;
static uint8_t I2C_Address = 0;
bool ts_initialized = false;
bool isTouchDetected = false;
uint16_t tmp = 0, tempoX = 0, tempoY = 0;
bool STM32TouchController::TS_init()
{
ft6x06_Init(0);
ft6x06_ReadID(TS_I2C_ADDRESS_A02);
ft6x06_ReadID(TS_I2C_ADDRESS);
I2C_Address = TS_I2C_ADDRESS_A02;
ft6x06_Reset(I2C_Address);
ft6x06_TS_Start(I2C_Address);
return true;
}
void STM32TouchController::init()
{
/**
* Initialize touch controller and driver
*
*/
if (SIZE_X < SIZE_Y)
{
ts_orientation = TS_SWAP_NONE;
}
else
{
ts_orientation = TS_SWAP_XY | TS_SWAP_Y;
}
if (TS_init())
{
ts_initialized = true;
}
}
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 the TouchGFX framework.
* By default sampleTouch is called every tick, this can be adjusted by HAL::setTouchSampleRate(int8_t);
*
*/
if (ts_initialized)
{
// TS_StateTypeDef TS_State;
isTouchDetected = TS_getCoordinates();
if (isTouchDetected)
{
x = tempoX;
y = tempoY;
return true;
}
}
return false;
}
bool STM32TouchController::TS_getCoordinates()
{
if (ft6x06_TS_DetectTouch(I2C_Address))
{
ft6x06_TS_GetXY(I2C_Address, &tempoX, &tempoY);
if (ts_orientation & TS_SWAP_XY)
{
tmp = tempoX;
tempoX = tempoY;
tempoY = tmp;
}
if (ts_orientation & TS_SWAP_X)
{
tempoX = FT_6206_MAX_WIDTH - 1 - tempoX;
}
if (ts_orientation & TS_SWAP_Y)
{
tempoY = FT_6206_MAX_HEIGHT - 1 - tempoY;
}
return true;
}
return false;
}
/* USER CODE END STM32TouchController */
and in STM32TouchController.hpp just add the two functions TS_init() and TS_getCoordinates() I added
class STM32TouchController : public touchgfx::TouchController
{
public:
STM32TouchController() {}
/**
* @fn virtual void STM32TouchController::init() = 0;
*
* @brief Initializes touch controller.
*
* Initializes touch controller.
*/
virtual void init();
/**
* @fn virtual bool STM32TouchController::sampleTouch(int32_t& x, int32_t& y) = 0;
*
* @brief Checks whether the touch screen is being touched, and if so, what coordinates.
*
* Checks whether the touch screen is being touched, and if so, what coordinates.
*
* @param [out] x The x position of the touch
* @param [out] y The y position of the touch
*
* @return True if a touch has been detected, otherwise false.
*/
virtual bool sampleTouch(int32_t& x, int32_t& y);
bool TS_init();
bool TS_getCoordinates();
private:
};
Hope this helps (and also works on your side),
/Romain
2021-05-17 05:01 AM
Thanks!
Problem was on my side, I by mistake declared "uint16_t x, y" inside "sampleTouch(int32_t& x, int32_t& y)". Sorry for bothering with that.
2021-05-17 06:09 AM
No worries :thumbs_up: Good to hear you made it work.
/Romain