GRaphics: LCD and Contexts
In this section, you will learn about:
The specifications of the LCD screen
What a graphics context is
What the background and foreground are
Before we dive into using the TI Graphics Library, let's take a look at the specifications of the LCD screen. Here is a snippet from the BoosterPack User Guide:
There are lot of words, but the important takeaways are these:
The LCD screen is 128x128 pixels (so the smallest x and y values are 0 and the largest are 127)
While not shown in the snippet, it is important to note that (0,0) is the top-left corner of the LCD, whereas (127, 127) is the bottom-right corner. In other words, increases in the x direction correspond to moving toward the right, and increases in the y direction correspond to moving down.
The LCD's manufacturer is Crystalfontz
This is important because DriverLib functions that work on the LCD itself are often prefixed with "Crystalfontz". These functions will be covered in the Initialization page
The LCD screen is driven by a TFT LCD module, which communicates to the MSP432 through SPI
Because the devices communicate through SPI, the display can have some latency. This is especially apparent when trying to clear the display using Graphics_clearDisplay
Graphics can be rather complicated to operate efficiently. As such, an important tool is used when operating with graphics functions: contexts. A graphics context is simply a group of settings used by the graphics driver. Whenever you call a graphics function, you will almost always pass a graphics context as a parameter to the function. For the sake of simplicity, it is strongly recommended to only use one context. The snippet below is taken from the file located at <ti/grlib/grlib.h> and shows what settings are contained within the Graphics_Context struct:
For now, let's focus on the foreground and background (we will talk about fonts in a later page). The foreground is the color used to draw new graphics objects on the LCD screen, whereas the background is the color that fills the screen when the screen has been cleared. The foreground and background are similar to using Microsoft Paint. In the screenshot below, black (Color 1) serves as the background color and white (Color 2) is the foreground color.
It's worth noting that the foreground color works especially like Microsoft Paint. Changing the foreground color has no impact on graphics that were already drawn on the screen. Notice how Color 2 (which was white in the previous example) has been changed to red, but the image is still the same.
While the old graphics are still in white, the new ones are now in red!
The analogy somewhat falls apart with changing the background color, though. In this example, Color 1 is now blue, but the graphics have not changed. This is also what happens with the LCD -- changing the background color has no immediate effect.
In Microsoft Paint, you can (mostly) change the background by using the fill tool without erasing what you had previously.
This is not the case with the LCD. The background will only update to the new color after the screen has been cleared. Thus, the only way to see the new background color is to call Graphics_clearDisplay().