Skip to main content
MuratUnal
Associate II
November 13, 2019
Question

calling screen interactions via using function pointers

  • November 13, 2019
  • 1 reply
  • 1351 views

Hello,

I am developing a software with STM32L4R9AI-Disco. I am trying to make

some menu screens. All screens have scroll wheels. the project has no touch. it

has physical buttons. I need screen transitions between all screen

combinations.

* I have interactions for screen transitions. When I call the interactions,

everything works well.

* I want to call the interactions via using function pointers. You can

see the source codes and explanations below.

* I need to know last selected items of scroll wheels for every closing

screen. Because when I return back the screen again, I need to setup scroll wheel

last position. I defined a struct type from my C code and a buffer to hold

variables from that struct types.

//my declarations from C code

typedef struct{
 
 void *intFuncPtr; //function pointers for screen transition fuctions
 
 uint32_t parameter; // scrollweels last positions
 
}screenTransitionType;
 
 
 
#define MAX_SCREEN_TRANSITION 20
 
screenTransitionType screenTransitionBuffer[MAX_SCREEN_TRANSITION]; //transition buffer
 
extern bool putScreenTransitionBuffer(screenTransitionType st); //put new struct to buffer
 
extern bool pullScreenTransitionBuffer(screenTransitionType *st); // pull last struct from buffer and destroy it //from buffer
 
extern bool checkLastScreenTransitionBuffer(screenTransitionType *st); // check and get last struct from buffer //without destroy it from buffer

//one of my screen calls screen transition (it is inside the screen_modeMenuView.cpp)

void screen_modeMenuView::btn_enter_clicked()
 
{
 
 screenTransitionType st; //define a screenTransitionType variable 
 
 int itemIndex=scrollWheel_modeMenu.getSelectedItem(); 
 
 
 
 switch((modeMenuItem::modeMenuItemType)itemIndex){
 
 
 
 case modeMenuItem::MODE_MENU_ITEM_SETTINGS:
 
 void(FrontendApplicationBase::*ptr)()= &FrontendApplicationBase::gotoscreen_modeMenuScreenCoverTransitionNorth; //function pointer for 
 
	//return screen
 
 st.intFuncPtr = (void *&)(ptr); //save func pointer
 
 st.parameter=(uint32_t)modeMenuItem::MODE_MENU_ITEM_SETTINGS; //save scrollwheel slected item
 
 if(putScreenTransitionBuffer(st)){ //save them in buffer
 
 static_cast<FrontendApplication*>(Application::getInstance())
 
->gotoscreen_mainSettingsMenuScreenCoverTransitionSouth(); //change screen
 
 }
 
 break;
 
 }
 
 
 
}

//the other screen (screen_mainSettingsMenuView.cpp)

void screen_mainSettingsMenuView::btn_home_clicked()
 
{
 screenTransitionType st;
 
 void (FrontendApplicationBase::* ptr)(); //function pointer for screen transition function type
 if(checkLastScreenTransitionBuffer(&st)){ //get last screen parameters that already put on the buffer
 
ptr = (void (FrontendApplicationBase::* &)())(st.intFuncPtr); //get the transition function address from struct and store it to ptr
(static_cast<FrontendApplication*>(Application::getInstance())->*ptr)(); //call the transition function
 
 }

When i call the transition function via function pointer ptr and check it in debugger, my code goes to correct transition function:

void FrontendApplicationBase::gotoscreen_modeMenuScreenCoverTransitionNorth()
{
 transitionCallback = touchgfx::Callback<FrontendApplicationBase>(this, &FrontendApplication::gotoscreen_modeMenuScreenCoverTransitionNorthImpl);
 pendingScreenTransitionCallback = &transitionCallback;
}

but when my code run

transitionCallback = touchgfx::Callback<FrontendApplicationBase>(this, &FrontendApplication::gotoscreen_modeMenuScreenCoverTransitionNorthImpl);

this line in transition function, it goes to HardFauldHandler.

My question is how can i call transition function via function pointers? I guess my way is OK, and i can call transition function via pointer but i couldn’t understand why my code goes to HardFaultHandler.

if any idea, I will be happy.

Best Regards,

Murat

This topic has been closed for replies.

1 reply

Martin KJELDSEN
Principal III
November 13, 2019

Hi,

Check this example i prepared some time ago that pushes function pointers onto a stack, allowing a "go back to last view" functionality. Maybe this can give you some inspiration.

http://sw-center-st-com.s3-eu-west-1.amazonaws.com/touchgfx/TouchGFX/Community/gotoStack_example.zip

/Martin

MuratUnal
MuratUnalAuthor
Associate II
November 15, 2019

Hello Martin,

Thanks for your example. I regulated your code for my project and it is working very well.

I want to ask one more question.

I want to change screen transition speed but i couldn't find a way. Could you give me any advice, please?