How to develop my gui for simulator and embedded at the same time?

Description

I would like to know how to develop my GUI simulator and embedded at the same time and at the same directories without the need to copy and paste the GUI code with each new change.

What MCU/Processor/Board and compiler are you using?

MCU: STM32F429ZIT6
Board: STM32F429 Discovery
Compilers: arm-none-eabi-gcc 8.3.1 and gcc (x86) 9.3.0
Simulator: Port for Eclipse (Linux)
SO: Ubuntu 16.04
Environment: VS Code

What LVGL version are you using?

7.0

What do you want to achieve?

Develop my GUI in just one directory and build for the simulator or the embedded just by passing arguments like make SIMULATOR and make EMBEDDED.
This approach allows me to change the same code and affect both projects, with no need to copy and paste every time new changes are applied.
Is there any way to do this?

Another way I think it can work is to use symbolic links.
I thought about using symbolic links from my GUI files from my embedded project to my simulator project, but I haven’t tried it yet.

What have you tried so far?

Code to reproduce

/*You code here*/

Screenshot and/or video

Structuring your code so it doesn’t rely on platform-specific APIs (like reads from peripherals) and using symbolic links are probably the best method.

Thanks for your answer.
Yes, isolating code is good practice and I’ve done that.
But, I would like to know, is there another alternative?
Maybe include the simulator code in my embedded code?

There isn’t really anything built-in for this; it’s something you would have to design as part of your project. The general practice is to keep the GUI code separate.

Ok. Thank you.

Just to update and help someone else:
Symbolic links approach worked!

I just create a folder on pc_simulator_sdl_eclipse named gui.
In my embedded project there’s also a folder named gui with some source and header files, gui_app.c, gui_app.h, gui_widgets.c and gui_widgets.h.
To create symbolic links just type on terminal:

ln -s ."path-to-embedded-project/gui/gui_app.*" "path-to-simulator-project/gui/"
ln -s ."path-to-embedded-project/gui/gui_widgets.*" "path-to-simulator-project/gui/"

In my gui_app.c, I added some conditional preprocessor, #ifdef EMBEDDED, when code is hardware interface dependent.
In my embedded Makefile I added -DEMBEDDED.
So, when I build simulator, no code hardware interface dependent will be compiled, and I can change just once my GUI code.

Sorry about my english. I hope this can help other people.

1 Like