cancel
Showing results for 
Search instead for 
Did you mean: 

Send variable from screen1View.cpp to Model.cpp

OBorz.1
Associate II

Hello,

I would like to send the value of a parameter from screen1View.cpp to Model.cpp.

Is there any way to do this?

I work with TouchGFX 4.14 and STM32429-Eval

Thanks!

22 REPLIES 22

For this too dont need queue, simply in model tick check gpio , but all checks need be non blocking

Hello OBorz.1,

The easiest solution to what you just described is to create a buttonController class and give it to TouchGFX.

There is an example available in the Designer. If you refer to the G0 Application Template you should understand how it is implemented.

The created buttonController class is located in <your project>/Core/Src/MB1642BButtonController.cpp and <your project>/Core/Inc/MB1642BButtonController.hpp.

Then in the file <your project>/TouchGFX/target/TouchGFXHAL.cpp you will find

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

When it is set, you can simply use Designer or write user code to associate a hardware button pressed event to an action.

See also this link : https://support.touchgfx.com/docs/development/touchgfx-hal-development/touchgfx-architecture#report-touch-and-physical-button-events

/Alexandre

OBorz.1
Associate II

Hello Alexandre,

thank you very much for the answer.

Where can I find the G0 application template?

Do you know if it works with a button connected to the processor via I²C?

Realy this work in 4.14?

Hello Alexandre,

thank you very much for the answer.

Where can I find the G0 application template?

Do you know if it works with a button connected to the processor via I²C?

As i write all checking in gui thread need be minimal blocking type , then you cant while wait to transfer i2c ...

For this type is better use other thread and set shared memory variable when key is received

i2C ...

keyCode = xx; (OR USE QUEUE)

Then in model tick or buttoncontroller class do if(keyCode ...

OBorz.1
Associate II

I tried to include the hardware button as described in the TouchGFX document: "External events as trigger" (https://support.touchgfx.com/docs/4.14/development/board-bring-up/example-gpio).

It fails already at the definition of the PIN! The GPIO pin cannot be declared as "input" in "GPIO_MODE". Currently it is set to "GPIO_MODE_IT_RISING_FALLING".

I think this is the reason why my program terminates after a few clicks on the button.

Is there an example somewhere?

MM..1
Chief II
OBorz.1
Associate II

I already did that with the keyboard a few months ago and it worked.

I have tried this now.

First:

Initialize interrput of the joystick on the board in main.c.

__________________________________________________________________________________________________________________

 uint8_t i2c_buffer[3];

 //uint8_t joystik_state = 0xFF;

 memset(i2c_buffer,0x00,sizeof(i2c_buffer));

 volatile HAL_StatusTypeDef result = HAL_OK;

 /* In System Control soft reset */

 i2c_buffer[0] = 0x10;

 result = HAL_I2C_Mem_Write(&hi2c1, 0x84, 0x03, I2C_MEMADD_SIZE_8BIT, i2c_buffer, 1, 1000);

 /* Read the Chip-ID and version number */

 result = HAL_I2C_Mem_Read(&hi2c1, 0x84, 0x00, I2C_MEMADD_SIZE_8BIT, i2c_buffer,3, 1000);

 /* Set joystick PINs of Input*/

 result = HAL_I2C_Mem_Read(&hi2c1, 0x84, 0x15, I2C_MEMADD_SIZE_8BIT, i2c_buffer, 1, 1000);

 i2c_buffer[0] = i2c_buffer[0] & 0x13;

 result = HAL_I2C_Mem_Write(&hi2c1, 0x84, 0x15, I2C_MEMADD_SIZE_8BIT, i2c_buffer, 1, 1000);

 /* In system Control register activate interrupt */

 i2c_buffer[0] = 0x04;

 result = HAL_I2C_Mem_Write(&hi2c1, 0x84, 0x03, I2C_MEMADD_SIZE_8BIT, i2c_buffer, 1, 1000);

 /* activate interrupt Joystick PINs */

 i2c_buffer[0] = 0x7C;

 result = HAL_I2C_Mem_Write(&hi2c1, 0x84, 0x09, I2C_MEMADD_SIZE_8BIT, i2c_buffer, 1, 1000);

 /* delete interrupt in state register*/

 i2c_buffer[0] = 0x00;

 result = HAL_I2C_Mem_Read(&hi2c1, 0x84, 0x0B, I2C_MEMADD_SIZE_8BIT, i2c_buffer, 1, 1000);

 _________________________________________________________________________________________________________________

Second:

Implemented the following code in Model.cpp

__________________________________________________________________________________________________________________

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)

{

 // Prevent unused argument(s) compilation warning

 UNUSED(GPIO_Pin);

 uint8_t joystik_NEW_state = 0xFF;

      I2C_HandleTypeDef hi2c1;

 //aks Value from PIN

 if(GPIO_PIN_8)

 {

       uint8_t joystik_state = 0xFF;

       HAL_StatusTypeDef result = HAL_OK;

       result = HAL_I2C_Mem_Read(&hi2c1, 0x84, 0x0B, I2C_MEMADD_SIZE_8BIT, &joystik_state, 1, 1000);

       

       uint8_t dummy = 0x00;

       result = HAL_I2C_Mem_Read(&hi2c1, 0x84, 0x0B, I2C_MEMADD_SIZE_8BIT, &dummy, 1, 1000);

 }

}

 __________________________________________________________________________________________________________________

I have set a breakpoint at the beginning of the function. When I press the joystick button once, the program also stops at this point. If I press it a second time, the breakpoint is not reached anymore.

I have run the code to query the interrupts also in the main.c and there it runs through often, but sometime after 10....20...30 times pressing the program hangs in the task.c.

Hmm your coding style is out of range...

You cant cretae new  I2C_HandleTypeDef hi2c1; in irq and without init.

C calback placed in C++ file isnt good idea too.

USW.