Tutorial: Integrate an emWin Application with the redBlocks Simulator (Step 3)

There are only the following things that need to be done in order to integrate the emWin example application in the redBlocks SiL environment:

  1. Define the hardware platform.
  2. Start the emWin main routine.
  3. Configure the emWin library (if necessary)

The hardware platform is defined in the file "emWin_Demo/project/sim/SimulationPlatform.c". We simply replace the content of the redBlocks C example that defines an LED and a push button with the following content:

#include <libredBlocks_sim.h>
#include <Platform.h>

#include <GUI.h>

#define ID_DISPLAY 0
#define ID_TOUCH 0

static void onTouch()
{
  u16 x;
  u16 y;
  const bool pressed = rb_sim_TouchInput_getState( ID_TOUCH, &x, &y );

  GUI_PID_STATE state;
  state.Layer = 0;
  state.x = x;
  state.y = y;
  state.Pressed = pressed;
  GUI_TOUCH_StoreStateEx( &state );
}

void Platform_initSimulation( void )
{
  rb_sim_Display_add( ID_DISPLAY, 800, 480, 24, true );
  rb_sim_TouchInput_add( ID_TOUCH, onTouch );
  rb_sim_TouchInput_enableCallback( ID_TOUCH );
}

This code does the following:

  • "Platform_initSimulation" defines the display interface (with index 0, 800 x 480 pixels and a color depth of 24) and the touch panel (also with index 0) and associates the callback function "onTouch" with touch events.
  • "onTouch" is called upon each touch event and propagates the touch event data (i.e. coordinates and state) to the respective emWin function "GUI_TOUCH_StoreStateEx"

The we need to remove the application logic of the redBlocks C example application (which handles push button events and the LED) in "emWin_Demo/src/Application.c" and replace it with a simple call to the emWin application's main routine:

#include <Application.h>

extern void MainTask(void);

void Application_run()
{
  MainTask();
}

 

The last thing to do is to change the following defines in "emWin_Demo/src/WashingMachine/LCDConf.c":

#define USE_SOFTLAYER 1
#define COLOR_CONVERSION GUICC_M888
#define DISPLAY_DRIVER GUIDRV_TEMPLATE

As already mentioned before, the softlayer support needs to be activated, if the emWin application uses multiple layers. In order to correspond with the 24 bit color depth we configured within the redBlocks Simulator, we need to define "GUICC_M888" and we need to change the display driver that is used (the emWin Washing Machine example is originally configured for a special WIN32 graphic driver simulation, while the redBlocks Simulator does a clean simulation of the target driver).

Now everything is prepared to start the simulation as described in the last step of this tutorial.