TouchGFX automatically generates GUI C++ code for STM32 based applications that use a display and touch screen. Here is a demonstration on how to attach a C function callbackto a TouchGFX entity (a button).
When a button is clicked, a C function in a custom C file has to be called. Here is how.
Create a Default TouchGFX Page and Button
Create a new project (we call this one MyApplication_1) and select a Discovery or similar STM32 display-capable kit.
A blank TouchGFX screen is created by default (note that the default name is Screen1, this will be relevant later).
Drag and drop a button, in this case, a toggle button named ToggleButton1.
Create a Default Screen with Toggle Button
Add a Custom Click Event to Toggle Button
Select the ToggleButton1 object
On the Interactions tab, add Interaction1 with the following properties
Add a Virtual Function Callback to Button Click Event
When ToggleButton1 is clicked, the virtual function called btn1_pressed_vfn is called by the TouchGFX core.
Create Target Callback C Code
When ToggleButton1 is clicked, the goal is to execute a C function placed in a custom C file. The C file is placed in the application code folder (Code/Src).
Create a source file gfx_callbacks.c in MyApplication_1\Core\Src with the following function. This function will be called when ToggleButton1 is clicked.