Software Overview of a Graphics Project
Typical Graphics Application
The code on the screen represents a typical PIC® MCU graphics application. Understanding the program flow is essential to developing graphics applications.
The next few screens contain an explanation for each of these lines of code. After reviewing the program overview you will be able to explore the individual graphics topics and begin developing applications. To navigate to another screen select from the grey buttons in the header above.
User's Application Code
These functions represent the non-graphics portion of the application program.
SYSTEM_InitializeBoard(); represents the user written function which performs the one-time start up initialization needed for the application to run.
APP_Tasks(); represents the function (or functions) which run infinitely to execute the non-graphics portion of the user application.
Initializing the Graphics Library
Graphics Library Initialization
Before any graphics items can be output to the display DRVgfx_Initialize must be run to initialize the hardware drivers
GFX_Primitive_Initialize sets up the library to outputs Graphics Primitive elements.
Setting up the Callback Functions
Setting up the Callback Function
Microchip Graphics Applications utilize two callback functions: GFX_GOL_MessageCallback and GFX_GOL_DrawCallback. The user is responsible for writing the functions to perform these tasks and then setting these user-written functions as the call back routines.
This example shows the user-written APP_ObjectMessageCallback being set as the message callback function and APP_ObjectDrawCallback being set as the drawing callback function.
Creating Screens to Display
APP_CreateScreens() represents a user written function that creates screens to display. A screen, or display list, is a list of interactive Graphics Objects linked together and kept in the MCU's heap memory. The application generates the display list at run time by making a series of object creating function calls.
In order to successfully create a screen you will need to understand the object creating functions, the object state bits, and style schemes.
Drawing Graphics Objects
Drawing Graphic Objects
GFX_GOL_ObjectListDraw() parses the linked list of objects and updates the frame buffer based on the state bits of the objects in the list.
When GFX_GOL_ObjectListDraw completes parsing the list a 'true' condition is returned
It may take more than one call to GFX_GOL_ObjectListDraw to complete processing the current linked list
The "Safe" Zone
The "Safe" Zone
Altering the state-bits of the display list while the list is being processed by GFX_GOL_ObjectListDraw can result in anomalies in the image being displayed.
To avoid problems with the display the only safe place to update the list of objects is after the drawing function returns a true condition
Getting Touch Input
Getting User Input
TouchGetMsg is a function supplied by Microchip to detect if (and where) there is a touch, release, or movement on a resistive-touch graphics display. This function populates the structure called msg with information on the touch event.
GFX_GOL_ObjectMessage() analyzes msg to detemine if the touch event impacts an existing graphics object.
If an object has been touched, the callback function GFX_GOL_MessageCallback is executed to process the event.
Message Callback Function
- Written by user and called by: GFX_GOL_ObjectMessage
- Performs MCU actions based on input to an object. These actions may include starting a motor, turning on an LED, or any MCU controlled task
- Changes the appearance of an object (or objects) in the display list and updates their status bit so they will be redrawn to the frame buffer by: GFX_GOL_ObjectListDraw.
- Returns CPU control to: GFX_GOL_ObjectMessage
Draw Callback Function
- Written by user and called by: GFX_GOL_ObjectListDraw
- Executes on each iteration of the main loop regardless of whether or not a touch event has occurred
- Can be used in conjunction with the message callback function to determine how long a touch event has occurred. Timing a touch event facilitates taking a action based on how long a touch event has occurred (e.g. dimmer switches or volume control)
- Returns control to:GFX_GOL_ObjectListDraw
Microchip MASTERs Conference 2016
Register now - Deadline: July 29
JW Marriott Desert Ridge Resort-Phoenix, AZ