Retro Invaders a space invaders clone by Chris Favreau. Written for the RetroMbuino development board from outrageouscircuits.com for the game programming contest.

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

LCD_ST7735 Class Reference

LCD_ST7735 Class Reference

LCD_ST7735 is a simple driver for the ST7735 LCD controller. More...

#include <LCD_ST7735.h>

Inherited by display.

Public Types

enum  Orientation { Rotate0, Rotate90, Rotate180, Rotate270 }
 

Orientation of the display.

More...
enum  PanelColorFilter { RGB = 0, BGR = 8 }
 

Type of color filter of the panel.

More...

Public Member Functions

 LCD_ST7735 (PinName backlightPin, PinName resetPin, PinName dsPin, PinName mosiPin, PinName misoPin, PinName clkPin, PinName csPin, PanelColorFilter colorFilter=BGR)
 Creates an instance of the LCD_ST7735 driver.
void setOrientation (Orientation orientation, bool flip)
 Set the orientation of the display.
int getWidth ()
 Get the width of the display given the current orientation.
int getHeight ()
 Get the height of the display given the current orientation.
void setBacklight (bool state)
 Control the display's backlight.
void clearScreen (uint16_t color=0x0000)
 Clear the screen.
void setPixel (int x, int y, uint16_t color)
 Set a pixel on the display to the specified color.
void drawLine (int x1, int y1, int x2, int y2, uint16_t color)
 Draw a line on the display.
void drawRect (int x1, int y1, int x2, int y2, uint16_t color)
 Draw a rectangle on the display.
void drawCircle (int x, int y, int r, uint16_t color)
 Draw a circle on the display.
void drawEllipse (int x, int y, int rx, int ry, uint16_t color)
 Draw an ellipse on the display.
void fillRect (int x1, int y1, int x2, int y2, uint16_t fillColor)
 Draw a filled rectangle on the display.
void fillRect (int x1, int y1, int x2, int y2, uint16_t borderColor, uint16_t fillColor)
 Draw a filled rectangle on the display.
void fillCircle (int x, int y, int r, uint16_t borderColor, uint16_t fillColor)
 Draw a filled circle on the display.
void fillEllipse (int x, int y, int rx, int ry, uint16_t borderColor, uint16_t fillColor)
 Draw a filled ellipse on the display.
void drawBitmap (int x, int y, const uint16_t *pbmp)
 Draw a bitmap on the screen.
void drawBitmap (int x, int y, const uint16_t *pbmp, int srcX, int srcY, int srcWidth, int srcHeight)
 Extracts a portion of a bitmap and draws it on the screen.
void setForegroundColor (uint16_t color)
 Set the foreground color used to render text.
void setBackgroundColor (uint16_t color)
 Set the background color used to render text.
void drawString (const uint8_t *pFont, int x, int y, const char *pString)
 Draw a string to the screen using the currently active foreground and background colors.
void measureString (const uint8_t *pFont, const char *pString, uint8_t &width, uint8_t &height)
 Measure the width and height of the string when rendered with the specified font.
void selectDevice ()
 Select the device on the SPI bus.

Detailed Description

LCD_ST7735 is a simple driver for the ST7735 LCD controller.

It provides basic drawing primitives sa well as text and font capabilities. The driver is currently hardcoded to support 65K colors using a 565 RGB pixel format.

Definition at line 16 of file LCD_ST7735.h.


Member Enumeration Documentation

Orientation of the display.

Enumerator:
Rotate0 

No rotation of the display image.

Rotate90 

Rotate the display image 90 degrees.

Rotate180 

Rotate the display image 180 degrees.

Rotate270 

Rotate the display image 270 degrees.

Definition at line 20 of file LCD_ST7735.h.

Type of color filter of the panel.

Enumerator:
RGB 

RGB color filter panel.

BGR 

BGR color filter panel.

Definition at line 33 of file LCD_ST7735.h.


Constructor & Destructor Documentation

LCD_ST7735 ( PinName  backlightPin,
PinName  resetPin,
PinName  dsPin,
PinName  mosiPin,
PinName  misoPin,
PinName  clkPin,
PinName  csPin,
PanelColorFilter  colorFilter = BGR 
)

Creates an instance of the LCD_ST7735 driver.

Parameters:
backlightPinpin used to control the backlight
resetPinpin used to reset the display controller
dsPinpin used to put the display controller into data mode
mosiPinSPI channel MOSI pin
misoPinSPI channel MISO pin
clkPinSPI channel clock pin
csPinSPI chip select pin

Definition at line 4 of file LCD_ST7735.cpp.


Member Function Documentation

void clearScreen ( uint16_t  color = 0x0000 )

Clear the screen.

Parameters:
colorThe color used to clear the screen. Defaults to black if not passed.

Definition at line 82 of file LCD_ST7735.cpp.

void drawBitmap ( int  x,
int  y,
const uint16_t *  pbmp,
int  srcX,
int  srcY,
int  srcWidth,
int  srcHeight 
)

Extracts a portion of a bitmap and draws it on the screen.

Parameters:
xThe X coordinate location to draw the bitmap.
yThe Y coordinate location to draw the bitmap.
pbmpPointer to the bitmap.
srcXX offset into the source bitmap of the portion to extract
srcYY offset into the source bitmap of the portion to extract
srcWidthWidth of the bitmap portion to draw
srcHeightHeight of the bitmap portion to draw
Note:
The bitmap is an single dimensional uint8_t (unsigned short) array. The first to elements of the array indicate the width and height of the bitmap repectively. The rest of the entries int the array make up the pixel data for the array.

Definition at line 357 of file LCD_ST7735.cpp.

void drawBitmap ( int  x,
int  y,
const uint16_t *  pbmp 
)

Draw a bitmap on the screen.

Parameters:
xThe X coordinate location to draw the bitmap.
yThe Y coordinate location to draw the bitmap.
pbmpPointer to the bitmap.
Note:
The bitmap is an single dimensional uint8_t (unsigned short) array. The first to elements of the array indicate the width and height of the bitmap repectively. The rest of the entries int the array make up the pixel data for the array.

Definition at line 342 of file LCD_ST7735.cpp.

void drawCircle ( int  x,
int  y,
int  r,
uint16_t  color 
)

Draw a circle on the display.

Parameters:
xThe X coordinate of the center of the circle
yThe Y coordinate of the center of the circle
rThe radius of the circle
colorThe color used to draw the circle

Definition at line 157 of file LCD_ST7735.cpp.

void drawEllipse ( int  x,
int  y,
int  rx,
int  ry,
uint16_t  color 
)

Draw an ellipse on the display.

Parameters:
xThe X coordinate of the center of the ellipse
yThe Y coordinate of the center of the ellipse
rxThe X radius of the ellipse
ryThe X radius of the ellipse
colorThe color used to draw the ellipse

Definition at line 186 of file LCD_ST7735.cpp.

void drawLine ( int  x1,
int  y1,
int  x2,
int  y2,
uint16_t  color 
)

Draw a line on the display.

Parameters:
x1The X coordinate of the starting point on the line
y1The Y coordinate of the starting point on the line
x2The X coordinate of the end point on the line
y2The Y coordinate of the end point on the line
colorThe color used to draw the pixel

Definition at line 102 of file LCD_ST7735.cpp.

void drawRect ( int  x1,
int  y1,
int  x2,
int  y2,
uint16_t  color 
)

Draw a rectangle on the display.

Parameters:
x1The X coordinate of the upper left corner
y1The Y coordinate of the upper left corner
x2The X coordinate of the lower right corner
y2The Y coordinate of the lower right corner
colorThe color used to draw the rectangle

Definition at line 146 of file LCD_ST7735.cpp.

void drawString ( const uint8_t *  pFont,
int  x,
int  y,
const char *  pString 
)

Draw a string to the screen using the currently active foreground and background colors.

Parameters:
pFontPointer to the font used to render the string to the display
xThe X coordinate location to draw the string.
yThe Y coordinate location to draw the string.
pStringASCIIZ string to draw to the display.

Definition at line 388 of file LCD_ST7735.cpp.

void fillCircle ( int  x,
int  y,
int  r,
uint16_t  borderColor,
uint16_t  fillColor 
)

Draw a filled circle on the display.

Parameters:
xThe X coordinate of the center of the circle
yThe Y coordinate of the center of the circle
borderColorThe color used to draw the circumference of the circle
fillColorThe color used to fill the circle

Definition at line 262 of file LCD_ST7735.cpp.

void fillEllipse ( int  x,
int  y,
int  rx,
int  ry,
uint16_t  borderColor,
uint16_t  fillColor 
)

Draw a filled ellipse on the display.

Parameters:
xThe X coordinate of the center of the ellipse
yThe Y coordinate of the center of the ellipse
rxThe X radius of the ellipse
ryThe X radius of the ellipse
borderColorThe color used to draw the circumference of the circle
fillColorThe color used to fill the circle

Definition at line 298 of file LCD_ST7735.cpp.

void fillRect ( int  x1,
int  y1,
int  x2,
int  y2,
uint16_t  fillColor 
)

Draw a filled rectangle on the display.

Parameters:
x1The X coordinate of the upper left corner
y1The Y coordinate of the upper left corner
x2The X coordinate of the lower right corner
y2The Y coordinate of the lower right corner
fillColorThe color used to fill the rectangle

Definition at line 222 of file LCD_ST7735.cpp.

void fillRect ( int  x1,
int  y1,
int  x2,
int  y2,
uint16_t  borderColor,
uint16_t  fillColor 
)

Draw a filled rectangle on the display.

Parameters:
x1The X coordinate of the upper left corner
y1The Y coordinate of the upper left corner
x2The X coordinate of the lower right corner
y2The Y coordinate of the lower right corner
borderColorThe color used to draw the rectangle frame
fillColorThe color used to fill the rectangle

Definition at line 239 of file LCD_ST7735.cpp.

int getHeight (  )

Get the height of the display given the current orientation.

Definition at line 72 of file LCD_ST7735.cpp.

int getWidth (  )

Get the width of the display given the current orientation.

Definition at line 67 of file LCD_ST7735.cpp.

void measureString ( const uint8_t *  pFont,
const char *  pString,
uint8_t &  width,
uint8_t &  height 
)

Measure the width and height of the string when rendered with the specified font.

Parameters:
pFontPointer to the font used to measure the string
pStringASCIIZ string to measure.
widthReference to the variable that will contain the width
heightReference to the variable that will contain the height

Definition at line 411 of file LCD_ST7735.cpp.

void selectDevice (  )

Select the device on the SPI bus.

selectDevice needs to be called before accessing the screen if there are multiple devices on the SPI bus.

Definition at line 424 of file LCD_ST7735.cpp.

void setBackgroundColor ( uint16_t  color )

Set the background color used to render text.

Parameters:
colorColor used when drawing background portions of the text
Note:
The color can be changed multiple times to render text with various background colors on the display

Definition at line 382 of file LCD_ST7735.cpp.

void setBacklight ( bool  state )

Control the display's backlight.

Parameters:
statetrue to turn the backlight on, false to turn it off

Definition at line 77 of file LCD_ST7735.cpp.

void setForegroundColor ( uint16_t  color )

Set the foreground color used to render text.

Parameters:
colorColor used when drawing text to the display
Note:
The color can be changed multiple times to render text in various colors on the display

Definition at line 376 of file LCD_ST7735.cpp.

void setOrientation ( Orientation  orientation,
bool  flip 
)

Set the orientation of the display.

Parameters:
orientationOrientation of the display.
flipFlips the display direction

Definition at line 31 of file LCD_ST7735.cpp.

void setPixel ( int  x,
int  y,
uint16_t  color 
)

Set a pixel on the display to the specified color.

Parameters:
xThe X coordinate of the pixel (0..127)
yThe Y coordinate of the pixel (0..159)
colorColor to set the pixel to.

Definition at line 95 of file LCD_ST7735.cpp.