GLIB is a graphics library that can be used to draw pixels, common shapes, text or bitmaps to a display connected to an MCU. GLIB treats the display as a matrix of pixels which is a model of the physical display. This matrix is exposed to GLIB via an API called DMD (Dot Matrix Display). To draw something on a physical display, the user application needs to provide GLIB with a single implementation of the DMD interface. Sample DMD implementations are provided for the displays that are connected to the Silicon Labs Starter Kits and the Silicon Labs Development Kits.
References
Detailed description is available in the Software documentation of your device. See the same for the Giant Gecko here for your reference.
For an extensive feature showcase, please see MCU example “SLSTKxxxxx_glib” for your MCU development kit in Simplicity Studio.
Initialization
First, glib needs several libraries to be included to work, such as display.h for display specific settings, dmd.h for the Dot Matrix Display library and glib.h for the graphics library itself. The graphics library uses a context for each display. This context must be defined before using glib with
static GLIB_Context_t glibContext;
All the previously listed libraries must be initialized to enable drawing on the screen, by calling the followings:
EMSTATUS status;
/* Initialize the display module. */
status = DISPLAY_Init();
if (DISPLAY_EMSTATUS_OK != status) {
while (1) ;
}
/* Initialize the DMD module for the DISPLAY device driver. */
status = DMD_init(0);
if (DMD_OK != status) {
while (1) ;
}
/* Initialize the glib context */
status = GLIB_contextInit(&glibContext);
if (GLIB_OK != status) {
while (1) ;
}
Drawing on the screen
Drawing usually consist of three steps. First, if we do not want to overlap the previously displayed content and/or are not partially rewriting the display, we should clear it first by calling GLIB_clear(&glibContext). The next step is to set the display content in the context by drawing something on the screen with GLIB_drawXXXX() where XXXX can stand for String, Bitmap, Circle, etc. After the content is set, the last step is to update the display using the DMD driver using DMD_updateDisplay().
In the above example a welcome text is written on the screen. First, we set the back- and foreground colors in the glibContext to white and back respectively. Then, as mentioned before, a screen clear is performed. Before calling the GLIB_drawString() function, the font is set to normal in the context and the string is put together into one character array. The GLIB_drawString() is called with the context, string and its length, along with the X and Y coordinate of the text and with the opaque setting last. The example displays the following on a Giant Gecko STK board:
Updating parts of the screen
When not all the information is outdated on the screen, partial update can be used. In this case do not clear the screen, as then all screen content will be lost. GLIB_clearRegion should be used instead, after setting the clipping region with the GLIB_setClippingRegion() function. This function needs a rectangle as an input, this will be the area the GLIB_clearRegion will clear out. After the clear is complete, you can draw in this territory by providing the appropriate X and Y coordinates to the draw function.
if (refresh) {
GLIB_setClippingRegion(&glibContext, &upperArea);
GLIB_clearRegion(&glibContext);
msgYOffset = 2;
} else {
GLIB_setClippingRegion(&glibContext, &lowerArea);
GLIB_clearRegion(&glibContext);
msgYOffset = 7;
}
/* Update only the current message region using msgYOffset */
GLIB_resetClippingRegion(&glibContext); //reset the clipping region to default
GLIB_applyClippingRegion(&glibContext); //application is not included in the resetting
sprintf(text, "Message from %d,\nRSSI: %d dBm", message->source, message->rssi);
GLIB_drawString(&glibContext, text, strlen(text), X_BORDER,
Y_BORDER + (glibContext.font.fontHeight + glibContext.font.lineSpacing) * msgYOffset, 0);
//print to the upper or lower area using msgYOffset
/* Update display */
DMD_updateDisplay();
refresh = !refresh;
The above example shows a way to display incoming messages alternately in the upper and the lower part of the screen. A previously defined upper and lower area clipping region is cleared and the upper or lower message is displayed using the predefined screen borders and the available font height and line spacing in the glib context.
Proprietary Knowledge Base
Displaying on the LCD screen using glib
Introduction
GLIB is a graphics library that can be used to draw pixels, common shapes, text or bitmaps to a display connected to an MCU. GLIB treats the display as a matrix of pixels which is a model of the physical display. This matrix is exposed to GLIB via an API called DMD (Dot Matrix Display). To draw something on a physical display, the user application needs to provide GLIB with a single implementation of the DMD interface. Sample DMD implementations are provided for the displays that are connected to the Silicon Labs Starter Kits and the Silicon Labs Development Kits.
References
Detailed description is available in the Software documentation of your device. See the same for the Giant Gecko here for your reference.
For an extensive feature showcase, please see MCU example “SLSTKxxxxx_glib” for your MCU development kit in Simplicity Studio.
Initialization
First, glib needs several libraries to be included to work, such as
display.h
for display specific settings,dmd.h
for the Dot Matrix Display library andglib.h
for the graphics library itself. The graphics library uses a context for each display. This context must be defined before using glib withAll the previously listed libraries must be initialized to enable drawing on the screen, by calling the followings:
Drawing on the screen
Drawing usually consist of three steps. First, if we do not want to overlap the previously displayed content and/or are not partially rewriting the display, we should clear it first by calling
GLIB_clear(&glibContext)
. The next step is to set the display content in the context by drawing something on the screen withGLIB_drawXXXX()
where XXXX can stand for String, Bitmap, Circle, etc. After the content is set, the last step is to update the display using the DMD driver usingDMD_updateDisplay()
.In the above example a welcome text is written on the screen. First, we set the back- and foreground colors in the
glibContext
to white and back respectively. Then, as mentioned before, a screen clear is performed. Before calling theGLIB_drawString()
function, the font is set to normal in the context and the string is put together into one character array. TheGLIB_drawString()
is called with the context, string and its length, along with the X and Y coordinate of the text and with the opaque setting last. The example displays the following on a Giant Gecko STK board:Updating parts of the screen
When not all the information is outdated on the screen, partial update can be used. In this case do not clear the screen, as then all screen content will be lost.
GLIB_clearRegion
should be used instead, after setting the clipping region with theGLIB_setClippingRegion()
function. This function needs a rectangle as an input, this will be the area theGLIB_clearRegion
will clear out. After the clear is complete, you can draw in this territory by providing the appropriate X and Y coordinates to the draw function.The above example shows a way to display incoming messages alternately in the upper and the lower part of the screen. A previously defined upper and lower area clipping region is cleared and the upper or lower message is displayed using the predefined screen borders and the available font height and line spacing in the glib context.