cancel
Showing results for 
Search instead for 
Did you mean: 

Hardware button with TouchGFX for screen transition

Josh_W020
Associate II

Hi,

I have been trying to implement the functionality to change the currently active screen on TouchGFX using a hardware button with no luck so far.

I'm using an STM32H743zit6.

Here are the resources I've looked at but haven't managed to get working:

https://www.youtube.com/watch?v=ufvJ5bcesL8

https://www.youtube.com/watch?v=QgEDSjvGAlk

https://support.touchgfx.com/docs/development/scenarios/example-gpio

https://support.touchgfx.com/docs/development/board-bring-up/how-to/10-physical-buttons

https://support.touchgfx.com/docs/development/ui-development/touchgfx-engine-features/screen-transitions

https://community.st.com/t5/stm32-mcus-touchgfx-and-gui/hardware-button/td-p/640357

 

Any help would be greatly appreciated,

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Josh_W020
Associate II

HI,

Thought I'd update this incase anyone else is having the same issue.
In my project I am using an internal framebuffer. In order to set this up I followed this guide made by STM: https://support.touchgfx.com/docs/development/board-bring-up/how-to/03-display-internal
In the guide it specifically states to add the line:

 HAL_LTDC_ProgramLineEvent(&hltdc,0);

to the stm32h7xx_it.c file. However, adding this line will prevent tick from updating? So my tick function was only called once on startup and this if statement never checked: 

if (HAL_GPIO_ReadPin(GPIOD, GPIO_PIN_2) == GPIO_PIN_RESET)
	{
		static_cast<FrontendApplication*>(Application::getInstance())->handleKeyEvent('A');
	}

 Removing that line from stm32h7xx_it.c fixed the issue and now tick updates as expected. Just out of curiosity if anyone can explain a bit of the reasoning behind this that would be great.

Thank you for the help,
Josh.

View solution in original post

15 REPLIES 15

@Josh_W020 wrote:

Here are the resources I've looked at


What we really need to see is what you've done.

https://community.st.com/t5/community-guidelines/how-to-write-your-question-to-maximize-your-chances-to-find-a/ta-p/575228

 


@Josh_W020 wrote:

I have been trying to implement the functionality to change the currently active screen on TouchGFX using a hardware button .


Which part are you stuck on:

  • change the currently active screen?
  • detecting a hardware button?
SofLit
ST Employee

Hello,

I think you need to use application().gotoScreen2CoverTransitionxxx() API from the button callback.

See for example this thread.

 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
PS: This is NOT an online support (https://ols.st.com) but a collaborative space. So please be polite in your reply. Otherwise, it will be reported as inappropriate and you will be permanently blacklisted from my help/support.
MM..1
Chief III

Ohh boy zero info... Try this

MM1_0-1736362775916.png

run simultor and press A key on keyboard Work transition ?

Interaction1 in my example is add on main screen (FYI your screen marked to start) and transition go to Screen1...

When this works ok you can step to physical button code ...

 

Hi thanks for the reply,

I have tried setting the hardware button up in this way and the screen changes as expected in the simulator.

I also know the hardware button is working as I have another button used for saving images to a USB that works correctly.

However, if you have any suggestions on how to call the change screen functions through code even without pressing a button that would be great too (for example calling it after a short delay in the main while loop).

Josh

The transition is done using the call of application().gotoScreenXXXTransitionYYY() 

See the link I share previously.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
PS: This is NOT an online support (https://ols.st.com) but a collaborative space. So please be polite in your reply. Otherwise, it will be reported as inappropriate and you will be permanently blacklisted from my help/support.

Hi,

I already have a different hardware button implemented for a separate function so I believe this is working correctly.

Sorry if I haven't provided enough info, I'll drop some code in below that i have tried so far.

Button setup in TouchGFX:

Screenshot 2025-01-09 093106.png

This is the cpp file as created in the youtube video provided by STM.

#include <newButtonController.hpp>
#include <main.h>
#include <touchgfx/hal/HAL.hpp>

extern "C" uint8_t User_ButtonState;

void newButtonController::init()
{
	previousState = 0xFF;
}

bool newButtonController::sample(uint8_t& key)
{
	if(HAL_GPIO_ReadPin(GPIOD, GPIO_PIN_2) == GPIO_PIN_RESET && previousState == 0x00)
	{
		previousState = 0xFF;
		key = 1; // here key determines which key will be trigger in TouchGFX
		return true;
	}
	previousState = 0x00;
	return false;
}

And this the header file:

#ifndef NEWBUTTONCONTROLLER_HPP_
#define NEWBUTTONCONTROLLER_HPP_

#include <platform/driver/button/ButtonController.hpp>

class newButtonController : public touchgfx::ButtonController
{
	virtual void init();
	virtual bool sample(uint8_t& key);

private:
	uint8_t previousState;
};



#endif /* NEWBUTTONCONTROLLER_HPP_ */

Finally the modified TouchGFXHAL.cpp file:

#include <TouchGFXHAL.hpp>

/* USER CODE BEGIN TouchGFXHAL.cpp */

#include "main.h"
#include <newButtonController.hpp>
newButtonController bc;

using namespace touchgfx;
extern "C" uint8_t framebuffer[800 * 480];

void TouchGFXHAL::initialize()
{
    // Calling parent implementation of initialize().
    //
    // To overwrite the generated implementation, omit the call to the parent function
    // and implement the needed functionality here.
    // Please note, HAL::initialize() must be called to initialize the framework.
	/*

	*/
    TouchGFXGeneratedHAL::initialize();

    // Set the framebuffer start address
       HAL::getInstance()->setFrameBufferStartAddresses(
           framebuffer,    // Framebuffer for the first layer (internal memory)
           nullptr,        // Framebuffer for the second layer (if unused, set to nullptr)
           nullptr         // Framebuffer for the third layer (if unused, set to nullptr)
       );

       setButtonController(&bc);
}

And here is how the button is configured in the ioc file:

Screenshot 2025-01-09 093623.png

Thanks again,

Josh

Hi, thanks for the response.

I have checked my StartUpScreenViewBAse.cpp file and it appears to have generated correctly.

void StartUpScreenViewBase::handleKeyEvent(uint8_t key)
{
    if(1 == key)
    {
        //Interaction1
        //When hardware button 1 clicked change screen to FFTScreen
        //Go to FFTScreen with no screen transition
        application().gotoFFTScreenScreenNoTransition();
    
    }
}

Is it that I need to call "application().gotoFFTScreenScreenNoTransition();" from another place in my code?

GaetanGodart
ST Employee

Hello @Josh_W020 ,

 

From what I understood, you are sure that the button itself works and you are sure that you are able to do a screen transition.
So the issue must be between connecting these 2 actions.

We provide examples of boards and UI using hardware buttons with the GFX01M2 display extension.
One of the GUI using hardware button is the "Aircon remote demo":

GaetanGodart_0-1736424458944.png

Instead of adding a hardware button to TouchGFX Designer (which is possible), we mapped it to a keyboard key.
This way, we can execute an interaction from pressing a key on the keyboard (when simulating for instance) and we are also able to map our physical button to execute the interaction.

Here you can see that the interaction is executed when pressing the key '8' :

GaetanGodart_1-1736424597788.png

And here you can see how we mapped the hardware button to a key in MB1642ButtonController.cpp :

GaetanGodart_2-1736424667818.png

 

I hope this example is helpful to you!

 

Regards,

Gaetan Godart
Software engineer at ST (TouchGFX)

I manage it in model tick, TGFX examples with key is long way ...

Try in model.cpp

void Model::tick() {
	if (HAL_GPIO your button test == SET) {
         //wait for release add here
		static_cast<FrontendApplication*>(Application::getInstance())->handleKeyEvent(
				'A'); // here use key from my window example 
...

good is add inteligent key handler release this is only example. Positive is this send event A key to actual screen , and this can handle different reactions on different screens.  All is setup in designer.

And your second Q transition with delay you can setup in designer. Not require any code in main or while.

Learn use Interactions, here for example exist action wait for ...