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

SSD1289_LCD Class Reference

SSD1289_LCD Class Reference

Represents a LCD instance. More...

#include <ssd1289.h>

Inherits LCD.

Public Member Functions

 SSD1289_LCD (PinName CS, PinName RESET, PinName RS, PinName WR, BusOut *DATA_PORT, PinName BL=NC, PinName RD=NC, backlight_t blType=Constant, float defaultBackLightLevel=1.0)
 Creates a new instance of the class.
virtual void Initialize (orientation_t orientation=LANDSCAPE, colordepth_t colors=RGB16)
 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

virtual void WriteCmd (unsigned short cmd)
 Sends a command to the display.
virtual void WriteData (unsigned short data)
 Sends pixel data to the display.
virtual void SetXY (unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2)
 Assigns a chunk of the display memory to receive data.
virtual void SetPixelColor (unsigned int color, colordepth_t mode=RGB24)
 Sets the color of the pixel at the address pointer of the controller.
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 WriteCmdData (unsigned short cmd, unsigned short data)
 Sends both command and data to the display controller.
virtual void ClearXY (void)
 Resets the memory address for the next display write operation to the screen origins (0,0).
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

Represents a LCD instance.

This is the utility class, through which the display can be manipulated and graphics objects can be shown to the user. A known display, which works with this library is the ITDB02-3.2S from iTeadStudio - a RGB TFT with 240x320 pixels resolution and 65K colors, using 16-bit interface.

The display needs 20 to 22 pins to work with mbed, so it is possibly not the best of choices out there, but other than that it uses +3.3V for power and logic, as well as the backlight, thus can be interfaced directly to the mbed without the need of shields or level shifters as with Arduino.

How to use:

 // include the library, this will also pull in the header for the provided fonts
 #include "ssd1289.h"
 
 // prepare the data bus for writing commands and pixel data
 BusOut dataBus( p30, p29, p28, p27, p26, p25, p24, p23, p22, p21, p20, p19, p18, p17, p16, p15 ); // 16 pins
 // create the lcd instance
 SSD1289_LCD lcd( p14, p13, p12, p11, &dataBus ); // control pins and data bus

 int main()
 {
     // initialize display - place it in standard portrait mode and set background to black and
     //                      foreground to white color.
     lcd.Initialize();
     // set current font to the smallest 8x12 pixels font.
     lcd.SetFont( Font8x12 );
     // print something on the screen
     lcd.Print( "Hello, World!", CENTER, 25 ); // align text to center horizontally and use starndard colors

     while ( 1 ) { }
 }
Version:
0.1
Author:
Todor Todorov

Definition at line 80 of file ssd1289.h.


Constructor & Destructor Documentation

SSD1289_LCD ( PinName  CS,
PinName  RESET,
PinName  RS,
PinName  WR,
BusOut *  DATA_PORT,
PinName  BL = NC,
PinName  RD = NC,
backlight_t  blType = Constant,
float  defaultBackLightLevel = 1.0 
)

Creates a new instance of the class.

Parameters:
CSPin for the ChipSelect signal.
RESETPin for the RESET line.
RSPin for the RS signal.
WRPin for the WR signal.
DATA_PORTAddress of the data bus for transfer of commands and pixel data.
BLPin for controlling the backlight. By default not used.
RDPin for the RD signal. This line is not needed by the driver, so if you would like to use the pin on the mbed for something else, just pull-up the respective pin on the LCD high, and do not assign a value to this parameter when creating the controller instance.
blTypeThe backlight type, the default is to utilize the pin - if supplied - as a simple on/off switch
defaultBacklightLevelIf using PWM to control backlight, this would be the default brightness in percent after LCD initialization.

Definition at line 25 of file ssd1289.cpp.


Member Function Documentation

void Activate ( void   ) [protected, virtual, inherited]

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, inherited]

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, inherited]

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, inherited]

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 short  deg,
unsigned short  rox,
unsigned short  roy 
) [virtual, inherited]

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 DrawBitmap ( unsigned short  x,
unsigned short  y,
const bitmap_t img,
unsigned char  scale = 1 
) [virtual, inherited]

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 DrawCircle ( unsigned short  x,
unsigned short  y,
unsigned short  radius,
int  color = -2 
) [virtual, inherited]

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, inherited]

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, inherited]

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, inherited]

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, inherited]

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, inherited]

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, inherited]

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, inherited]

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, inherited]

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, inherited]

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, inherited]

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   ) [inherited]

Gets the font height.

Returns:
The current font height.

Definition at line 114 of file lcd_base.cpp.

uint8_t GetFontWidth ( void   ) [inherited]

Gets the font width.

Returns:
The current font width.

Definition at line 107 of file lcd_base.cpp.

unsigned short GetHeight ( void   ) [inherited]

Gets the display height.

Returns:
Display height in pixels.

Definition at line 100 of file lcd_base.cpp.

unsigned short GetWidth ( void   ) [inherited]

Gets the display width.

Returns:
Display width in pixels.

Definition at line 93 of file lcd_base.cpp.

void Initialize ( orientation_t  orientation = LANDSCAPE,
colordepth_t  colors = RGB16 
) [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.

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

Implements LCD.

Definition at line 33 of file ssd1289.cpp.

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

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, inherited]

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, inherited]

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, inherited]

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, inherited]

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, inherited]

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, inherited]

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.

void SetPixelColor ( unsigned int  color,
colordepth_t  mode = RGB24 
) [protected, 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 depth used by the controller.

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

Implements LCD.

Definition at line 244 of file ssd1289.cpp.

void SetXY ( unsigned short  x1,
unsigned short  y1,
unsigned short  x2,
unsigned short  y2 
) [protected, 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.

Implements LCD.

Definition at line 223 of file ssd1289.cpp.

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.

Reimplemented from LCD.

Definition at line 197 of file ssd1289.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 ).

Reimplemented from LCD.

Definition at line 203 of file ssd1289.cpp.

void WriteCmd ( unsigned short  cmd ) [protected, 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.

Implements LCD.

Definition at line 209 of file ssd1289.cpp.

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

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.

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

Sends pixel data to the display.

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

Implements LCD.

Definition at line 216 of file ssd1289.cpp.