0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

TouchGFXを使おう7~ハードウェアボタン編~

Posted at

TouchGFXを使おう6~Lチカ編2~の続きです。

TouchGFXでハードウェアボタンを使ってみましょう。

画面の製作

新規プロジェクトを作成します。
今回は、2枚のスクリーンをハードウェアボタンと画面のボタンで行き来するプログラムにします。

インタラクションの設定

2枚のスクリーンを作成し1枚目のスクリーンのインタラクションを以下に設定します。

Interaction1
Trigger Hardware button is clicked
Choose button key 1
Action Change screen
Choose screen Screen2

image.png

ピン設定

コード生成を行い、STM32CubeIDEでプロジェクトをインポートしiocファイルを開きます。
今回、PC13がスイッチにつながっていますので、PC13に割り込みの設定を行います。
image.png

割り込み設定

PC13 を選択し、GPIO_EXIT13 を設定します。
image.png
NVIC から EXIT line[15:10]interrupts のチェックを入れます。
image.png
それでは、Generation しましょう、
image.png
Warningが出ますが Yes で進みます。
image.png
TouchGFXでも変更されたことが表示されますのでYesをクリックします。
image.png

プログラムファイルを追加する

Application/User/CoreフォルダMyButtonController.cpp を追加します。
ファイル⇒ソース・ファイル⇒ソース・フォルダー、ソース・ファイル名 を入力します。
ソース・フォルダ:Application/User/Core
ソース・ファイル名:MyButtonController.cpp
とします。
image.png
image.png
MyButtonController.cpp が追加されました。
image.png

/*
 * MyButtonController.cpp
 *
 *  Created on: Feb 1, 2025
 *      Author: user
 */

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

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

bool MyButtonController::sample(uint8_t& key)
{

    if (HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13) == GPIO_PIN_RESET)
    {
    	if (previousState == 0xFF)
    	{
    		previousState = 0x00;
   // 		User_ButtonState = 0x00;
	        key = 1;
	        return true;
    	}
    	return false;
    }

    previousState = 0xFF;
    return false;
}

ヘッダーファイルを追加する

次にヘッダーファイル MyButtonController.hpp を作ります。
image.png

/*
 * MyButtonController.hpp
 *
 *  Created on: Feb 1, 2025
 *      Author: user
 */

#ifndef APPLICATION_USER_CORE_MYBUTTONCONTROLLER_HPP_
#define APPLICATION_USER_CORE_MYBUTTONCONTROLLER_HPP_

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

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


private:
    uint8_t previousState;
};
#endif /* APPLICATION_USER_CORE_MYBUTTONCONTROLLER_HPP_ */

ヘッダーファイルを移動する

MyButtonController.hpp をエクスプローラで
\MyApplication_button\Core\Inc に移動します。
image.png

TouchGFXHAL.cppの修正

最後に \TouchGFX\target\TouchGFXHAL.cpp を修正します。
以下3行を追加します。

#include <MyButtonController.hpp>
MyButtonController bc;
setButtonController(&bc);

image.png
以上でボタンを押すとScreen1からScreen2に移動するプログラムになりました。

TouchGFXを使おう8~ADC編~に続きます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?