cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with interface with physical buttons

EEuge
Senior

Hello!

I try to create intefrace with physical buttons, following this instruction https://touchgfx.zendesk.com/hc/en-us/articles/205074551-Interfacing-with-physical-buttons

  1. I Added  ../Middlewares/ST/touchgfx/framework/include/platform/driver/button to include path
  2. I created file Keysamper.cpp and added to it

#include "KeySampler.hpp"
#include "touchgfx/HAL/Buttons.hpp"
using namespace touchgfx;
void KeySampler::init()
{
  //Initialise gpio for buttons here   
}
bool KeySampler::sample(uint8_t &key)
{
//   unsigned int buttons = ...; //sample GPIO
   //Return true if button 1 was pressed, save 1 to key argument 
   //Return true if button 2 was pressed, save 2 to key argument 
//   ...
   return false;
}

3. I created file Keysampler.hpp and added to it

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

4. I modified file TouchGFXConfiguration.hpp

KeySampler btnCtrl;
 
void touchgfx_init()
{
  Bitmap::registerBitmapDatabase(BitmapDatabase::getInstance(), BitmapDatabase::getInstanceSize());
  TypedText::registerTexts(&texts);
  Texts::setLanguage(0);
 
  FontManager::setFontProvider(&fontProvider);
 
  FrontendHeap& heap = FrontendHeap::getInstance();
  (void)heap; // we need to obtain the reference above to initialize the frontend heap.
 
  hal.initialize();
  hal.enableLCDControllerInterrupt();
  hal.enableInterrupts();
	 hal.setButtonController(&btnCtrl); //Enable button controller
}

6. try to complie, got errors

..\Drivers\KeySampler.hpp(1): error: #276: name followed by "::" must be a class or namespace name

 class KeySampler : public touchgfx::ButtonController

..\Drivers\KeySampler.hpp(1): error: #262: not a class or struct name

 class KeySampler : public touchgfx::ButtonController

..\Drivers\KeySampler.hpp(9): error: #20: identifier "uint8_t" is undefined

   virtual bool sample(uint8_t& key);

../TouchGFX/target/generated/TouchGFXConfiguration.cpp(38): error: #20: identifier "KeySampler" is undefined

 KeySampler btnCtrl;

What's wrong?

9 REPLIES 9
Alexandre RENOUX
Principal

Hello,

What do you use to compile your code ? IAR, TouchGFX Designer or something else ?

I created an empty project with a box as a background and a tiled image using the application template for STM32F746G_DISCO and compiled using IAR and TouchGFX Designer. I do not get the error you encounter.

/Alexandre

I can't understand you.

I asked about interface with physical buttons. You wrote me about empty project with image.

​Did you configure interface with physical buttons?

Phisicysical buttons is GPIO.​

I use keil, and my project comiled good. But I can't compile it with physyical buttons library​

Sorry I did not specified it but I implemented the files you are talking about in your post and which can be also found in the article you linked.

Can you upload your ptoject here? For keil, if you can.​

Alexandre RENOUX
Principal

I think your error comes from your Keysampler.hpp file. You should include the header file for ButtonController, otherwise, it cannot know from which class it should inherit from.

Here is a corrected version :

#ifndef KEYSAMPLER_HPP
#define KEYSAMPLER_HPP
 
#include <platform/driver/button/ButtonController.hpp>
 
class KeySampler : public touchgfx::ButtonController
{
public:
    KeySampler() {
        init();
    }
    virtual ~KeySampler() {}
    virtual void init();
    virtual bool sample(uint8_t& key);
};
 
#endif /* KEYSAMPLER_HPP */

If you still have compiling errors, please feel free to post again and we will see how to resolve it.

Thanks! Compiling is without errors.

Works good!

Only one problem

Then I make changes in CubeMX project, changes in TouchGFXConfiguration.cpp not saving ((

Can you make in future versions of CubeMX possibility to use something like /* USER CODE BEGIN 2 */ /* USER CODE END 2 */ ?

All working very well.

I checked many iteractions, triggered by button click.

But then I add iteraction which changes TextArea after buttonclick - program goes to HardFault immediatly after start.

0690X00000DBvDkQAL.png

0690X00000DBvE4QAL.png

What's wrong?