Detailed Description

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. The main goal of this library is easy of use and small code and memory footprint. In this way GLIB can be used on even the smallest Cortex-M0 devices.

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). So in order 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 Silion Labs Starter Kits and the Silicon Labs Development Kits.

Initialization

There are two things that must be initialized before GLIB can be used to draw pixels on the display. First the user needs to initialize the DMD implementation for the actual hardware display which is used. This initialization is display hardware specific.

Every GLIB drawing function will require a GLIB_Context_t as one of the functions arguments. The GBLI context contains important configuration values that all the drawing functions use. It contains the foreground and background color, and it also contains information on what font to use when rendering text on the display.

Color

GLIB represent color in a pixel as three 8 bit color values representing red, green and blue, giving the user support for a 24 bit color depth. The GLIB_rgbColor() function can be used to convert from distinct red, green and blue values to an 32-bit integer representing the color of single pixel. Similarly the GLIB_colorTranslate24bpp() function can be used to convert from the 32-bit integer representation into the 3 separate red, green and blue components. The 32-bit integer representation of a pixel color is used when configuring the foreground and background color.

GLIB also contains some common predefined colors for use in places where a 32-bit integer is used to represent the color. These predefined colors include White, Black, Brown, Orange, and many more. See the glib_color.h file for the full list of colors.

Some displays are monochrome, meaning that they only support 2 colors. When using GLIB to draw shapes on these displays the applications should use only the 2 colors White and Black.

Draw Shapes

GLIB contains functions for drawing common shapes to a display. Here is a list containing all the drawing functions.

To change the font the user calls GLIB_setFont() with a pointer to a GLIB_Font_t structure which describes the whole font. The GLIB_Font_t structure contains a pointer to the bitmap for each character and it describes attributes of the font like the width and height of each character and it also contains the bitmap of each character.

Draw Bitmap

To draw an image or custom bitmaps on the display the GLIB_drawBitmap() function can be used. Note that the format of the bitmap depends on the DMD implementation of the display. The color displays typically use a bitmap format where each pixel is represented by 3 consecutive bytes representing the red, green and blue color components. While a monochrome display typically use a bitmap format where 1 byte represents 8 pixels where a 0 bit is white and a 1 bit is black.

Example

This examples shows how to initialize a GLIB context and draw something on a display.

Makes the module ready for new bmp file. Reads in header from file, and checks if the provided bmp file is valid and supported. It reads in palette if BMP file is 8bpp. Uses function pointer set in BMP_init().

Size of palette in bytes. If BMP is 8-bit, this potentially has to be 256 * 4 bytes. If the user knows that he only loads BMPs with N bytes, he can pass in paletteSize = N. Otherwise this value should be 256 * 4 = 1024 bytes to ensure that the palette is big enough for all 8-bits BMPs.

fp

Function pointer that is used to read in bytes from BMP file. The function has to return an EMSTATUS and have the following parameter list (uint32_t buffer[], uint32_t bufLength, uint32_t bytesToRead). The function should fill (buffer) with (bytesToRead) bytes from the beginning. If it succeds it has to return BMP_OK, otherwise it should return BMP_ERROR_IO. When the function returns it should be ready to read from where it left off.

Makes the module ready for new bmp file. Reads in header from file, and checks if the provided bmp file is valid and supported. It reads in palette if BMP file is 8bpp. Uses function pointer set in BMP_init().

For RGB displays with 8-bits per color, each pixel is represented by 24-bits, with one byte for each of the red, green and blue components. The data has to be organized like this: picData = { R, G, B, R, G, B, R, G, B ... }

The pixels are ordered by increasing x coordinate, after the last pixel of a row, the next pixel will be the first pixel on the next row.

Draws a partial circle using the Midpoint Circle Algorithm. Algorithm is optimized to use only integer arithmetic, so no floating point arithmetic is needed. The bitMask passed in decides which octant that should be drawn. The octants is numbered 1 to 8 in counterclockwise order.

This function draws a line between all points outlining the polygon. The first and last point doesn't have to be the same. The function automatically draws a line from the start point to the end point.

Parameters

pContext

Pointer to a GLIB_Context_t which the line is drawn. The lines are drawn using the foreground color.

numPoints

Number of points in the polygon ( Has to be greater than 1 )

polyPoints

Pointer to array of polygon points. The points are laid out like this: polyPoints = {x1,y1,x2,y2 ... } Polypoints has to contain at least (numPoints * 2) entries

Returns

Returns GLIB_OK on if at least one element was drawn, or else error code