This is a port of Henning Kralsen's UTFT library for Arduino/chipKIT to mbed, refactored to make full use of C++ inheritance and access control, in order to reduce work when implementing new drivers and at the same time make the code more readable and easier to maintain. As of now supported are SSD1289 (16-bit interface), HX8340-B (serial interface) and ST7735 (serial interface). Drivers for other controllers will be added as time and resources to acquire the displays to test the code permit.

Dependents:   test SDCard capstone_display capstone_display_2 ... more

Embed: (wiki syntax)

« Back to documentation index

LCD Class Reference

Base class for LCD implementations. More...

#include <lcd_base.h>

Inherited by HX8340S_LCD, ILI9328_LCD, SSD1289_LCD, and ST7735_LCD.

Public Member Functions

virtual void Initialize (orientation_t orientation, colordepth_t colors)=0
 Initialize display.
virtual void Sleep (void)
 Puts the display to sleep.
virtual void WakeUp (void)
 Wakes up the display from sleep mode.
virtual void SetForeground (unsigned int color=COLOR_WHITE)
 Set the foreground color for painting.
virtual void SetBackground (unsigned int color=COLOR_BLACK)
 Set the background color for painting.
virtual void SetFont (const font_t *font)
 Sets the font to be used for painting of text on the screen.
unsigned short GetWidth (void)
 Gets the display width.
unsigned short GetHeight (void)
 Gets the display height.
uint8_t GetFontWidth (void)
 Gets the font width.
uint8_t GetFontHeight (void)
 Gets the font height.
virtual void FillScreen (int color=-1)
 Fills the whole screen with a single color.
virtual void SetBacklightLevel (float level)
 Sets the backlight intensity in percent as a float value in the range [0.0,1.0].
virtual void ClearScreen (void)
 Clears the screen.
virtual void DrawPixel (unsigned short x, unsigned short y, int color=-2)
 Draws a pixel at the specified location.
virtual void DrawLine (unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color=-2)
 Draws a line.
virtual void DrawRect (unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color=-2)
 Paints a rectangle.
virtual void DrawRoundRect (unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color=-2)
 Paints a rectangle and fills it with the paint color.
virtual void FillRect (unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color=-2)
 Paints a rectangle with rounded corners.
virtual void FillRoundRect (unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color=-2)
 Paints a rectangle with rounded corners and fills it with the paint color.
virtual void DrawCircle (unsigned short x, unsigned short y, unsigned short radius, int color=-2)
 Paints a circle.
virtual void FillCircle (unsigned short x, unsigned short y, unsigned short radius, int color=-2)
 Paints a circle and fills it with the paint color.
virtual void Print (const char *str, unsigned short x, unsigned short y, int fgColor=-2, int bgColor=-1, unsigned short deg=0)
 Print a text on the screen.
virtual void DrawBitmap (unsigned short x, unsigned short y, const bitmap_t *img, unsigned char scale=1)
 Draw an image on the screen.
virtual void DrawBitmap (unsigned short x, unsigned short y, const bitmap_t *img, unsigned short deg, unsigned short rox, unsigned short roy)
 Draw an image on the screen.

Protected Member Functions

 LCD (unsigned short width, unsigned short height, PinName CS, PinName RS, PinName RESET, PinName BL, backlight_t blType, float defaultBacklight)
 Creates an instance of the class.
virtual void Activate (void)
 Activates the display for command/data transfer.
virtual void Deactivate (void)
 Deactivates the display after data has been transmitted.
virtual void WriteCmd (unsigned short cmd)=0
 Sends a command to the display.
virtual void WriteData (unsigned short data)=0
 Sends pixel data to the display.
virtual void WriteCmdData (unsigned short cmd, unsigned short data)
 Sends both command and data to the display controller.
virtual void SetXY (unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2)=0
 Assigns a chunk of the display memory to receive data.
virtual void ClearXY (void)
 Resets the memory address for the next display write operation to the screen origins (0,0).
virtual void SetPixelColor (unsigned int color, colordepth_t mode=RGB24)=0
 Sets the color of the pixel at the address pointer of the controller.
virtual void DrawHLine (unsigned short x, unsigned short y, unsigned short len, int color=-2)
 Draws a horizontal line.
virtual void DrawVLine (unsigned short x, unsigned short y, unsigned short len, int color=-2)
 Draws a vertical line.
virtual void PrintChar (char c, unsigned short x, unsigned short y, int fgColor=-2, int bgColor=-1)
 Prints a character at the given position and using the given color.
virtual void RotateChar (char c, unsigned short x, unsigned short y, int pos, int fgColor=-2, int bgColor=-1, unsigned short deg=0)
 Prints a character at the given position and using the given color and with the given rotation.

Detailed Description

Base class for LCD implementations.

All separate LCD controller implementations have to subclass this one.

Version:
0.1
Author:
Todor Todorov

Definition at line 197 of file lcd_base.h.


Constructor & Destructor Documentation

LCD ( unsigned short  width,
unsigned short  height,
PinName  CS,
PinName  RS,
PinName  RESET,
PinName  BL,
backlight_t  blType,
float  defaultBacklight 
) [protected]

Creates an instance of the class.

Parameters:
widthWidth of the display in pixels.
heightHeight of the display in pixels.
CSPin connected to the CS input of the display.
RSPin connected to the RS input of the display.
RESETPin connected to the RESET input of the display.
BLPin connected to the circuit controlling the LCD's backlight.
blTypeThe type of backlight to be used.
defaultBacklightThe standard backlight intensity (if using PWM control), expressed in percent as float value from 0.0 to 1.0

Definition at line 25 of file lcd_base.cpp.


Member Function Documentation

void Activate ( void   ) [protected, virtual]

Activates the display for command/data transfer.

Usually achieved by pulling the CS pin of the display low.

Definition at line 507 of file lcd_base.cpp.

void ClearScreen ( void   ) [virtual]

Clears the screen.

This is the same as calling FillScreen() or FillScreen( -1 ) to use the background color.

Definition at line 151 of file lcd_base.cpp.

void ClearXY ( void   ) [protected, virtual]

Resets the memory address for the next display write operation to the screen origins (0,0).

Definition at line 526 of file lcd_base.cpp.

void Deactivate ( void   ) [protected, virtual]

Deactivates the display after data has been transmitted.

Usually achieved by pulling the CS pin of the display high.

Definition at line 513 of file lcd_base.cpp.

void DrawBitmap ( unsigned short  x,
unsigned short  y,
const bitmap_t img,
unsigned char  scale = 1 
) [virtual]

Draw an image on the screen.

The pixels of the picture must be in the RGB-565 format. The data can be provided as an array in a source or a header file. To convert an image file to the appropriate format, a special utility must be utilized. One such tool is provided by Henning Karlsen, the author of the UTFT display liberary and can be downloaded for free from his web site: http://henningkarlsen.com/electronics/library.php?id=52

Parameters:
xHorizontal offset of the first pixel of the image.
yVertical offset of the first pixel of the image.
imgImage data pointer.
scaleA value of 1 will produce an image with its original size, while a different value will scale the image.

Definition at line 400 of file lcd_base.cpp.

void DrawBitmap ( unsigned short  x,
unsigned short  y,
const bitmap_t img,
unsigned short  deg,
unsigned short  rox,
unsigned short  roy 
) [virtual]

Draw an image on the screen.

The pixels of the picture must be in the RGB-565 format. The data can be provided as an array in a source or a header file. To convert an image file to the appropriate format, a special utility must be utilized. One such tool is provided by Henning Karlsen, the author of the UTFT display liberary and can be downloaded for free from his web site: http://henningkarlsen.com/electronics/library.php?id=52

Parameters:
xHorizontal offset of the first pixel of the image.
yVertical offset of the first pixel of the image.
imgImage data pointer.
degAngle to rotate the image before painting on screen, in degrees.
rox
roy

Definition at line 462 of file lcd_base.cpp.

void DrawCircle ( unsigned short  x,
unsigned short  y,
unsigned short  radius,
int  color = -2 
) [virtual]

Paints a circle.

Parameters:
xThe offset of the circle's center from the left edge of the screen.
yThe offset of the circle's center from the top edge of the screen.
radiusThe circle's radius.
colorThe color to use for painting. -1 indicated background, -2 foreground, or custom color.

Definition at line 318 of file lcd_base.cpp.

void DrawHLine ( unsigned short  x,
unsigned short  y,
unsigned short  len,
int  color = -2 
) [protected, virtual]

Draws a horizontal line.

This is a utility function to draw horizontal-only lines for reduced code complexity and faster execution.

Parameters:
xX coordinate of the starting point of the line.
yY coordinate of the starting point of the line.
lenLength of the line.
colorThe color to use to draw the line. By default the global foreground color is used ( -2 ), -1 switches to the default background color, or any custom color can be used.

Definition at line 531 of file lcd_base.cpp.

void DrawLine ( unsigned short  x1,
unsigned short  y1,
unsigned short  x2,
unsigned short  y2,
int  color = -2 
) [virtual]

Draws a line.

Parameters:
x1Horizontal offset of the beginning point of the line.
y1Vertical offset of the beginning point of the line.
x2Horizontal offset of the end point of the line.
y2Verical offset of the end point of the line.
colorThe color to use for painting, or -1 for background, or -2 for foreground.

Definition at line 165 of file lcd_base.cpp.

void DrawPixel ( unsigned short  x,
unsigned short  y,
int  color = -2 
) [virtual]

Draws a pixel at the specified location.

By default the function will use the preset foreground color, but the background or a custom color could be used as well.

Parameters:
xThe horizontal offset of the pixel from the upper left corner of the screen.
yThe vertical offset of the pixel from the upper left corner of the screen.
colorThe color to be used. Use a custom color, or -1 for background and -2 for foreground color.

Definition at line 156 of file lcd_base.cpp.

void DrawRect ( unsigned short  x1,
unsigned short  y1,
unsigned short  x2,
unsigned short  y2,
int  color = -2 
) [virtual]

Paints a rectangle.

Parameters:
x1The horizontal offset of the beginning point of one of the rectangle's diagonals.
y1The vertical offset of the beginning point of one of the rectangle's diagonals.
x2The horizontal offset of the end point of the same of the rectangle's diagonals.
y2The vertical offset of the end point of the same of the rectangle's diagonals.
colorThe color to use for painting. -1 indicated background, -2 foreground, or custom color.

Definition at line 247 of file lcd_base.cpp.

void DrawRoundRect ( unsigned short  x1,
unsigned short  y1,
unsigned short  x2,
unsigned short  y2,
int  color = -2 
) [virtual]

Paints a rectangle and fills it with the paint color.

Parameters:
x1The horizontal offset of the beginning point of one of the rectangle's diagonals.
y1The vertical offset of the beginning point of one of the rectangle's diagonals.
x2The horizontal offset of the end point of the same of the rectangle's diagonals.
y2The vertical offset of the end point of the same of the rectangle's diagonals.
colorThe color to use for painting. -1 indicated background, -2 foreground, or custom color.

Definition at line 258 of file lcd_base.cpp.

void DrawVLine ( unsigned short  x,
unsigned short  y,
unsigned short  len,
int  color = -2 
) [protected, virtual]

Draws a vertical line.

This is a utility function to draw vertical-only lines for reduced code complexity and faster execution.

Parameters:
xX coordinate of the starting point of the line.
yY coordinate of the starting point of the line.
lenHeight of the line.
colorThe color to use to draw the line. By default the global foreground color is used ( -2 ), -1 switches to the default background color, or any custom color can be used.

Definition at line 542 of file lcd_base.cpp.

void FillCircle ( unsigned short  x,
unsigned short  y,
unsigned short  radius,
int  color = -2 
) [virtual]

Paints a circle and fills it with the paint color.

Parameters:
xThe offset of the circle's center from the left edge of the screen.
yThe offset of the circle's center from the top edge of the screen.
radiusThe circle's radius.
colorThe color to use for painting. -1 indicated background, -2 foreground, or custom color.

Definition at line 368 of file lcd_base.cpp.

void FillRect ( unsigned short  x1,
unsigned short  y1,
unsigned short  x2,
unsigned short  y2,
int  color = -2 
) [virtual]

Paints a rectangle with rounded corners.

Parameters:
x1The horizontal offset of the beginning point of one of the rectangle's diagonals.
y1The vertical offset of the beginning point of one of the rectangle's diagonals.
x2The horizontal offset of the end point of the same of the rectangle's diagonals.
y2The vertical offset of the end point of the same of the rectangle's diagonals.
colorThe color to use for painting. -1 indicated background, -2 foreground, or custom color.

Definition at line 276 of file lcd_base.cpp.

void FillRoundRect ( unsigned short  x1,
unsigned short  y1,
unsigned short  x2,
unsigned short  y2,
int  color = -2 
) [virtual]

Paints a rectangle with rounded corners and fills it with the paint color.

Parameters:
x1The horizontal offset of the beginning point of one of the rectangle's diagonals.
y1The vertical offset of the beginning point of one of the rectangle's diagonals.
x2The horizontal offset of the end point of the same of the rectangle's diagonals.
y2The vertical offset of the end point of the same of the rectangle's diagonals.
colorThe color to use for painting. -1 indicated background, -2 foreground, or custom color.

Definition at line 288 of file lcd_base.cpp.

void FillScreen ( int  color = -1 ) [virtual]

Fills the whole screen with a single color.

Parameters:
colorThe color to be used. The value must be in RGB-565 format.
Remarks:
The special values -1 and -2 signify the preset background and foreground colors, respectively. The backround color is the default.

Definition at line 140 of file lcd_base.cpp.

uint8_t GetFontHeight ( void   )

Gets the font height.

Returns:
The current font height.

Definition at line 114 of file lcd_base.cpp.

uint8_t GetFontWidth ( void   )

Gets the font width.

Returns:
The current font width.

Definition at line 107 of file lcd_base.cpp.

unsigned short GetHeight ( void   )

Gets the display height.

Returns:
Display height in pixels.

Definition at line 100 of file lcd_base.cpp.

unsigned short GetWidth ( void   )

Gets the display width.

Returns:
Display width in pixels.

Definition at line 93 of file lcd_base.cpp.

virtual void Initialize ( orientation_t  orientation,
colordepth_t  colors 
) [pure virtual]

Initialize display.

Wakes up the display from sleep, initializes power parameters. This function must be called first, befor any painting on the display is done, otherwise the positioning of graphical elements will not work properly and any paynt operation will not be visible or produce garbage.

This function is controller-specific and needs to be implemented separately for each available display.

Parameters:
oritentationThe display orientation, landscape is default.
colorsThe correct color depth to use for the pixel data.

Implemented in HX8340S_LCD, ILI9328_LCD, SSD1289_LCD, and ST7735_LCD.

void Print ( const char *  str,
unsigned short  x,
unsigned short  y,
int  fgColor = -2,
int  bgColor = -1,
unsigned short  deg = 0 
) [virtual]

Print a text on the screen.

Parameters:
strThe text.
xThe horizontal offset form the left edge of the screen. The special values LEFT, CENTER, or RIGHT can be used instead of pixel offset to indicate the text's horizontal alignment.
yThe vertical offset of the text from the top of the screen.
fgColorThe foreground to use for painting the text; -1 indicates background color, -2 the foreground setting, or custom color.
bgColorThe color to use for painting the empty pixels; -1 indicates the background color, -2 the foreground setting, or custom color.
degIf different than 0, the text will be rotated at an angle this many degrees around its starting point. Default is not to ratate.

Definition at line 382 of file lcd_base.cpp.

void PrintChar ( char  c,
unsigned short  x,
unsigned short  y,
int  fgColor = -2,
int  bgColor = -1 
) [protected, virtual]

Prints a character at the given position and using the given color.

Parameters:
cThe character.
xX coordinate of the character position.
yY coordinate of the character position.
fgColorForeground color for drawing. By default the global foreground color is used ( -2 ), -1 switches to the default background color, or any custom color can be used.
bgColorBackground color for drawing. By default the global background color is used ( -1 ), -2 switches to the default foreground color, or any custom color can be used.

Definition at line 553 of file lcd_base.cpp.

void RotateChar ( char  c,
unsigned short  x,
unsigned short  y,
int  pos,
int  fgColor = -2,
int  bgColor = -1,
unsigned short  deg = 0 
) [protected, virtual]

Prints a character at the given position and using the given color and with the given rotation.

Parameters:
cThe character.
xX coordinate of the character position.
yY coordinate of the character position.
posPosition of the character in the string from which it originates (used to rotate a whole string).
fgColorForeground color for drawing. By default the global foreground color is used ( -2 ), -1 switches to the default background color, or any custom color can be used.
bgColorBackground color for drawing. By default the global background color is used ( -1 ), -2 switches to the default foreground color, or any custom color can be used.
degThe angle at which to rotate.

Definition at line 581 of file lcd_base.cpp.

void SetBackground ( unsigned int  color = COLOR_BLACK ) [virtual]

Set the background color for painting.

This is the default color to be used for "empty" pixels while painting. If a particular function allows for a different value to be specified when the function is called, the new value will be used only for this single call and will not change this setting.

Parameters:
colorThe background color (24-bit color depth).
See also:
RGB(r,g,b)

Definition at line 82 of file lcd_base.cpp.

void SetBacklightLevel ( float  level ) [virtual]

Sets the backlight intensity in percent as a float value in the range [0.0,1.0].

Parameters:
levelThe backligh intensity in percent, where 0.0 is off and 1.0 is full brightness.

Definition at line 120 of file lcd_base.cpp.

void SetFont ( const font_t *  font ) [virtual]

Sets the font to be used for painting of text on the screen.

Parameters:
fontA pointer to the font data.
See also:
Comments in file fonts.h

Definition at line 87 of file lcd_base.cpp.

void SetForeground ( unsigned int  color = COLOR_WHITE ) [virtual]

Set the foreground color for painting.

This is the default foreground color to be used in painting operations. If a specific output function allows for a different color to be specified in place, the new setting will be used for that single operation only and will not change this value.

Parameters:
colorThe color to be used (24-bit color depth).
See also:
RGB(r,g,b)

Definition at line 76 of file lcd_base.cpp.

virtual void SetPixelColor ( unsigned int  color,
colordepth_t  mode = RGB24 
) [protected, pure virtual]

Sets the color of the pixel at the address pointer of the controller.

This function is to be provided by each implementation separately in order to account for different color depths used by the controller.

Parameters:
colorThe color of the pixel.
modeThe depth (palette) of the color.

Implemented in HX8340S_LCD, ILI9328_LCD, SSD1289_LCD, and ST7735_LCD.

virtual void SetXY ( unsigned short  x1,
unsigned short  y1,
unsigned short  x2,
unsigned short  y2 
) [protected, pure virtual]

Assigns a chunk of the display memory to receive data.

When data is sent to the display after this function completes, the opertion will start from the begining of the assigned address (pixel position) and the pointer will be automatically incremented so that the next data write operation will continue with the next pixel from the memory block. If more data is written than available pixels, at the end of the block the pointer will jump back to its beginning and commence again, until the next address change command is sent to the display.

Parameters:
x1The X coordinate of the pixel at the beginning of the block.
y1The Y coordinate of the pixel at the beginning of the block.
x2The X coordinate of the pixel at the end of the block.
y2The Y coordinate of the pixel at the end of the block.
Remarks:
Addressing commands are controller-specific and this function needs to be implemented separately for each available controller.

Implemented in HX8340S_LCD, ILI9328_LCD, SSD1289_LCD, and ST7735_LCD.

void Sleep ( void   ) [virtual]

Puts the display to sleep.

When the display is in sleep mode, its power consumption is minimized. Before new pixel data can be written to the display memory, the controller needs to be brought out of sleep mode.

See also:
WakeUp( void );
Remarks:
The result of this operation might not be exactly as expected. Putting the display to sleep will cause the controller to switch to the standard color of the LCD, so depending on whether the display is normally white, or normally dark, the screen might or might not go dark. Additional power saving can be achieved, if the backlight of the used display is not hardwired on the PCB and can be controlled via the BL pin.
This function is controller-specific and needs to be implemented separately for each available display.

Reimplemented in HX8340S_LCD, ILI9328_LCD, SSD1289_LCD, and ST7735_LCD.

Definition at line 59 of file lcd_base.cpp.

void WakeUp ( void   ) [virtual]

Wakes up the display from sleep mode.

This function needs to be called before any other, when the display has been put into sleep mode by a previois call to Sleep( void ).

Remarks:
This function is controller-specific and needs to be implemented separately for each available display.

Reimplemented in HX8340S_LCD, ILI9328_LCD, SSD1289_LCD, and ST7735_LCD.

Definition at line 67 of file lcd_base.cpp.

virtual void WriteCmd ( unsigned short  cmd ) [protected, pure virtual]

Sends a command to the display.

Parameters:
cmdThe display command.
Remarks:
Commands are controller-specific and this function needs to be implemented separately for each available controller.

Implemented in HX8340S_LCD, ILI9328_LCD, SSD1289_LCD, and ST7735_LCD.

void WriteCmdData ( unsigned short  cmd,
unsigned short  data 
) [protected, virtual]

Sends both command and data to the display controller.

This is a helper utility function which combines the 2 functions above into one single convenience step.

Parameters:
cmdThe display command.
dataThe display pixel data.

Definition at line 519 of file lcd_base.cpp.

virtual void WriteData ( unsigned short  data ) [protected, pure virtual]

Sends pixel data to the display.

Parameters:
dataThe display data.
Remarks:
Sendin data is controller-specific and this function needs to be implemented separately for each available controller.

Implemented in HX8340S_LCD, ILI9328_LCD, SSD1289_LCD, and ST7735_LCD.