Skip to main content

10. Physical Buttons

Motivation

Physical buttons can function as external events usable as triggers from the TouchGFX Designer during application development, or simply used as events in the application backend.

Note
Skip this step if physical buttons are not relevant for your board bring up.

Goal

The goal of this section is to develop code that can be used in subsequent TouchGFX HAL- and/or application development.

Verification

Here are the verification points for this section:

Verification PointRationale
MCU is configuredMCU GPIOs must be configured to read the state of connected physical buttons.
Connected GPIO can be readOnce code has been developed to read the physical button state from a GPIO this can be used in sub-sequent TouchGFX HAL development.
Reading performs as expectedPolling is a part of application render time. If polling takes too long this should be moved to a different thread or made interrupt based.

Prerequisites

  • Physical buttons must be connected to GPIOs on the MCU

Do

The following images show how the schematics might look for a physical button and how it is connected to the MCU

In CubeMX GPIO Port C Pin 13 (PC13) can be configured as an input and configured as a pull-down in the GPIO section of the System Core category.

The code generated by CubeMX will setup the appropriate GPIO port(s) which can now be read:

main.c
uint8_t key;
if (HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13) != GPIO_PIN_RESET)
{
key = 1;
}

Performance is as expected

Polling the state of physical buttons should be possible within 1 ms if the code is executed in the same thread as the TouchGFX Appliaction. If not fast enough, consider moving the code to a seperate task, at a later stage or making it interrupt based.