How to use VGDD (old)

From VirtualFabWiki
Jump to: navigation, search

This guide will explain how to modify an existing MPLAB project to adopt VGDD.


  • A working Hardware
  • A working Microchip's Graphics Object Layer Demo software. For this HOWTO to be effective, you should be able to compile and run Microchip's GOL Demo on your specific hardware
  • A VGDD project consisting of one ore more screens each with the desired number of GOL and/or GPL objects (Buttons and so on)

In this example we will use HelloWorld as the VGDD project name.

VGDD uses the same screenState logic used in GOL Demo, so this is the ideal starting point. But every working software that uses GOL can be easily adapted.

Strip all the unneeded code in MainDemo.c

From the working GOL Demo you can strip all code referring to the existing demo screens (the Microchip's ones). In particular the sections that can be safely removed are:

  1. The CreateXXX() functions
  2. The MsgXXX() functions
  3. The #defines for the objects used in the demo
  4. All the scheme definitions: lines from StartScreen() to the main loop start while(1)
  5. All code between the end of GOLDrawCallback and the Timer4 ISR

Including VGDD generated code

1. Include Screens headers

Just after the #include "Main.h", insert the following line:

#include "VGDD_HelloWorld_Screens.h"

2. Modify GOLMsgCallback

Strip all code from it and replace the existing GOLMsgCallback return line with the following:

return(VGDD_HelloWorld_MsgCallback(objMsg, pObj, pMsg));

The resulting code block should appear as follows:

WORD GOLMsgCallback(WORD objMsg, OBJ_HEADER *pObj, GOL_MSG *pMsg)
return(VGDD_HelloWorld_MsgCallback(objMsg, pObj, pMsg));

3. Modify GOLDrawCallback

Strip all code from it and replace the existing GOLDrawCallback return line with the following:


The resulting code block should appear as follows:

WORD GOLDrawCallback(void)

4. Include Screen States and move enum to MainDemo.h

Locate where in your program the SCREEN_STATES enum is defined. In the GOL Demo there is a section in main.c named "DEMO STATES".

Here you can strip all the defined states and insert the following line:

#include "VGDD_HelloWorld_ScreenStates.h"

The resulting block should appear as follows:

typedef enum
#include "VGDD_HelloWorld_ScreenStates.h"

Now move the resulting enum block from MainDemo.c to MainDemo.h since it is needed from the other modules

Code modifications

1. Set initial screenState

In MainDemo.c locate the screenState variable declaration (it is just after the SCREEN_STATES enum) and set its initial value to


where SCREEN1 is the uppercase name of the first screen to be displayed. Look in VGDD_HelloWorld_ScreenStates.h for possible values.

2. Add screenState definition to MainDemo.h

Add the following line to MainDemo.h:

extern SCREEN_STATES   screenState;

3. Populate VGDD_HelloWorld_EventsHelper.h

This .h file is needed by VGDD_HelloWorld_Screens.c module and must contain all variable declarations used in it which are unknown to VGDD.

The most handy procedure is simply #include the main.h in here and then put those definitions in main.h

So in the VGDD_HelloWorld_EventsHelper.h add the following line:

#include "MainDemo.h"

Remove unneeded source files from project

Remove all unneeded modules from the project. in particular modules that can safely be romvoed are:

  1. rtcc.c
  2. SideButtons.c
  3. Monofont.c
  4. CustomControlDemo.c

Compile and enjoy!

Now everything should be working and the HelloWorld demo should be displayed on your hardware.

GUI editing chain

The GUI editing chain is as follow:

  1. Go back to VGDD
  2. Add/remove/modify screens and events
  3. Generate code in VGDD
  4. Go back to MPLAB and build
  5. Watch results
  6. Go to step 1

Minimal main.c example

Here follows a minimal (and thus not working as is!) example of the main loop as VGDD expects to be:

#include "MainDemo.h"
#include "VGDD_HelloWorld_Screens.h"
SCREEN_STATES   screenState = CREATE_VGDDSCREEN1;	// current state of main demo state machine
int main(void) {
   GOL_MSG msg;        // GOL message structure to interact with GOL
   HardwareInit();	// Initialize Hardware (PIC, TFT, TouchScreen, Buzzer, I/O Ports, etc.)
   GOLInit();		// Initialize graphics library and crete default style scheme for GOL
   while(1) {
       if(GOLDraw()) { 	// Draw GOL objects
           // Drawing is done here, process messages
           TouchGetMsg(&msg);          // Get message from touch screen
           GOLMsg(&msg);               // Process message

WORD GOLMsgCallback(WORD objMsg, OBJ_HEADER *pObj, GOL_MSG *pMsg) {
    return(VGDD_HelloWorld_MsgCallback(objMsg, pObj, pMsg));

WORD GOLDrawCallback(void) {

That's it! :-)