Main Page | Modules | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

otGraphics Class Reference
[Graphics - TFT display library for ILI9341,ILI9486,ILI9488 and ST7735 controllerGraphics - TFT display library for ILI9341,ILI9486,ILI9488 and ST7735 controller]

Class to handle TFT display module on SPI interface.

#include <otGraphics.h>


Public Types

typedef otGraphics::rotation_t rotation_t
typedef otGraphics::controller_t controller_t
typedef otGraphics::tab_t tab_t
enum  rotation_t {
  IR_0, IR_90, IR_180, IR_270,
  IR_BMP_0, IR_BMP_90, IR_BMP_180, IR_BMP_270
}
enum  controller_t { ILI9341, ILI9486, ILI9488, ST7735 }
enum  tab_t { GREEN_TAB, RED_TAB, BLACK_TAB, NONE_TAB }

Public Member Functions

 otGraphics ()
void init (controller_t crt=ILI9341, U8 spiClk=20, tab_t tab=NONE_TAB)
void backlight (bool ena)
void invert (bool ena)
void clear (U16 col=RGB565_BLACK)
void setRotation (rotation_t r)
void setWindow (U16 x0, U16 y0, U16 x1, U16 y1)
void pushColor (U16 color)
void pushColor (U16 color, U32 n)
void pushColor (U16 *data, U32 len)
void setPixel (U16 x, U16 y, U16 color)
void fillRect (U16 x, U16 y, U16 w, U16 h, U16 color)
void drawLine (U16 x0, U16 y0, U16 x1, U16 y1, U16 color)
void drawCircle (U16 x0, U16 y0, U16 r, U16 color)
void fillCircle (U16 x0, U16 y0, U16 r, U16 color)
void drawRect (U16 x, U16 y, U16 w, U16 h, U16 color)
void drawRoundRect (U16 x, U16 y, U16 w, U16 h, U16 r, U16 color)
void fillRoundRect (U16 x, U16 y, U16 w, U16 h, U16 r, U16 color)
void drawTriangle (U16 x0, U16 y0, U16 x1, U16 y1, U16 x2, U16 y2, U16 color)
void fillTriangle (U16 x0, U16 y0, U16 x1, U16 y1, U16 x2, U16 y2, U16 color)
void drawBitmap (U16 x, U16 y, const U8 *bitmap, U16 w, U16 h, U16 color)
void drawBitmapBackground (U16 x, U16 y, const U8 *bitmap, U16 w, U16 h, U16 color, U16 bg)
void drawXBitmap (U16 x, U16 y, const U8 *bitmap, U16 w, U16 h, U16 color)
void drawGrayscaleBitmap (U16 x, U16 y, const U8 *bitmap, U16 w, U16 h)
void drawGrayscaleBitmapMask (U16 x, U16 y, const U8 *bitmap, const U8 *mask, U16 w, U16 h)
void draw565Bitmap (U16 x, U16 y, const U16 *bitmap, U16 w, U16 h, U16 mask=0xFFFF)
void drawRGB (U16 x, U16 y, const U8 *bitmap, U16 w, U16 h)
void drawRgbBitmapMask (U16 x, U16 y, const U16 *bitmap, const U8 *mask, U16 w, U16 h)
void drawChar (U16 x, U16 y, U8 c, U16 color, U16 bg, U8 size)
U32 write (U8 c)
U32 writeString (const char *str, U16 color=DEFAULT_COLOR)
U32 writeString (const char *str, S32 len)
U32 writeString (U16 y, const char *str, U16 color=DEFAULT_COLOR)
void setCursor (U16 x, U16 y)
void cursor (U16 &x, U16 &y)
void setTextSize (U8 s)
U8 textSize ()
void setTextColor (U16 c)
void setTextColor (U16 c, U16 b)
void setTextWrap (bool w)
U8 rotation ()
void setCp437 (bool x)
void setFont (const GFXfont *f)
void size (U16 &w, U16 &h)
void charBounds (char c, U16 &x, U16 &y, U16 &minx, U16 &miny, U16 &maxx, U16 &maxy)
void textBounds (const char *str, U16 x, U16 y, U16 &x1, U16 &y1, U16 &w, U16 &h)
void drawEllipse (U16 x0, U16 y0, U16 rx, U16 ry, U16 color)
void fillEllipse (U16 x0, U16 y0, U16 rx, U16 ry, U16 color)
U16 to565 (U8 r, U8 g, U8 b)
void setScroll (U16 offset)
void showImagePal (U16 x, U16 y, U16 w, U16 h, const U8 *pixels, const U16 *palette)
void showImagePalZx2 (U16 x, U16 y, U16 w, U16 h, const U8 *pixels, const U16 *palette)
void showImagePalZx4 (U16 x, U16 y, U16 w, U16 h, const U8 *pixels, const U16 *palette)
void showImagePal4bit (U16 x, U16 y, U16 w, U16 h, const U8 *pixels, const U16 *palette)
void showImagePal2bit (U16 x, U16 y, U16 w, U16 h, const U8 *pixels, const U16 *palette)
void showImagePal1bit (U16 x, U16 y, U16 w, U16 h, const U8 *pixels, const U16 *palette)
void fillRectHGradient (S16 x, S16 y, U16 w, U16 h, U16 color1, U16 color2)
void fillRectVGradient (S16 x, S16 y, U16 w, U16 h, U16 color1, U16 color2)


Member Typedef Documentation

typedef otGraphics::controller_t otGraphics.controller_t
 

typedef otGraphics::rotation_t otGraphics.rotation_t
 

typedef otGraphics::tab_t otGraphics.tab_t
 


Member Enumeration Documentation

enum otGraphics::controller_t
 

Enumeration values:
ILI9341  240x320 pixels
ILI9486  320x480 pixel on 4" display
ILI9488  320x480 pixel on 3.5" display
ST7735  128x160 pixel on 1.8" display

enum otGraphics::rotation_t
 

Enumeration values:
IR_0  Don't apply any rotation.
IR_90  Apply 90 degree rotation.
IR_180  Apply 180 degree rotation.
IR_270  Apply 270 degree rotation.
IR_BMP_0  Don't apply any rotation to bitmap.
IR_BMP_90  Apply 90 degree any rotation to bitmap.
IR_BMP_180  Apply 180 degree any rotation to bitmap.
IR_BMP_270  Apply 270 degree any rotation to bitmap.

enum otGraphics::tab_t
 

Enumeration values:
GREEN_TAB 
RED_TAB 
BLACK_TAB 
NONE_TAB 


Constructor & Destructor Documentation

otGraphics.otGraphics  ) 
 

Create the object.


Member Function Documentation

void otGraphics.backlight bool  ena  ) 
 

Turn on/off LCD backlight

Parameters:
ena If true turn on LCD backlight

void otGraphics.charBounds char  c,
U16 x,
U16 y,
U16 minx,
U16 miny,
U16 maxx,
U16 maxy
 

Return the size of a character in pixels to the minimum and maximum values.

Parameters:
c Character to be tested
x Horizontal position at the start and at the end
y Vertical position at the start and at the end
minx Return the minimum horizontal dimension
miny Return the minimum vertical dimension
maxx Return the maximum horizontal dimension
maxy Return the maximum vertical dimension

void otGraphics.clear U16  col = RGB565_BLACK  ) 
 

Clear LCD with specified color

Parameters:
col Used color for clear

void otGraphics.cursor U16 x,
U16 y
 

Return the cursor coordinates

Parameters:
x Return horizontal position
y Return vertical position

void otGraphics.draw565Bitmap U16  x,
U16  y,
const U16 bitmap,
U16  w,
U16  h,
U16  mask = 0xFFFF
 

Draw an RGB image bitmap with 565 encode

Parameters:
x Top left horizontal coordinate
y Top left vertical coordinate
bitmap Bitmap pointer
w Bitmap width
h Bitmap Height
mask Mask 565 bit

void otGraphics.drawBitmap U16  x,
U16  y,
const U8 bitmap,
U16  w,
U16  h,
U16  color
 

Draw a resident 1-bit image at the specified (x,y) position, using the specified foreground color (unset bits are transparent).

Parameters:
x Top left horizontal coordinate
y Top left vertical coordinate
bitmap Bitmap pointer
w Bitmap width
h Bitmap height
color Used foreground color

void otGraphics.drawBitmapBackground U16  x,
U16  y,
const U8 bitmap,
U16  w,
U16  h,
U16  color,
U16  bg
 

Draw a resident 1-bit image at the specified (x,y) position, using the specified foreground (for set bits) and background (unset bits) colors.

Parameters:
x Top left horizontal coordinate
y Top left vertical coordinate
bitmap Bitmap pointer
w Bitmap width
h Bitmap height
color Used foreground color
bg Used background color

void otGraphics.drawChar U16  x,
U16  y,
U8  c,
U16  color,
U16  bg,
U8  size
 

Draw a character

Parameters:
x Top left horizontal coordinate
y Top left vertical coordinate
c Character
color Foreground color
bg Background color
size Character size

void otGraphics.drawCircle U16  x0,
U16  y0,
U16  r,
U16  color
 

Draw a circle.

Parameters:
x0 Horizontal coordinate of the circle center
y0 Vertical coordinate of the circle center
r Circle ray
color Used color

void otGraphics.drawEllipse U16  x0,
U16  y0,
U16  rx,
U16  ry,
U16  color
 

Draw an ellipse

Parameters:
x0 Horizontal coordinate of the ellipse center
y0 Vertical coordinate of the ellipse center
rx Horizontal ray
ry Vertical ray
color Ellipse color

void otGraphics.drawGrayscaleBitmap U16  x,
U16  y,
const U8 bitmap,
U16  w,
U16  h
 

Draw a RAM-resident 8-bit image (grayscale) at the specified (x,y) pos. Specifically for 8-bit display devices such as IS31FL3731; no color reduction/expansion is performed.

Parameters:
x Top left horizontal coordinate
y Top left vertical coordinate
bitmap Bitmap pointer
w Bitmap width
h Bitmap height

void otGraphics.drawGrayscaleBitmapMask U16  x,
U16  y,
const U8 bitmap,
const U8 mask,
U16  w,
U16  h
 

Draw a resident 8-bit image (grayscale) with a 1-bit mask (set bits = opaque, unset bits = clear) at the specified (x,y) pos. BOTH buffers (grayscale and mask) must be resident, no mix-and- match. Specifically for 8-bit display devices such as IS31FL3731; no color reduction/expansion is performed.

Parameters:
x Top left horizontal coordinate
y Top left vertical coordinate
bitmap Bitmap pointer
mask Mask pointer
w Bitmap width
h Bitmap height

void otGraphics.drawLine U16  x0,
U16  y0,
U16  x1,
U16  y1,
U16  color
 

Draw a line.

Parameters:
x0 Start horizontal coordinate
y0 Start vertical coordinate
x1 End horizontal coordinate
y1 End vertical coordinate
color Used color

void otGraphics.drawRect U16  x,
U16  y,
U16  w,
U16  h,
U16  color
 

Draw a rectangle

Parameters:
x Top left horizontal coordinate
y Top left vertical coordinate
w Rectangle width
h Rectangle Height
color Used color

void otGraphics.drawRGB U16  x,
U16  y,
const U8 bitmap,
U16  w,
U16  h
 

Draw an RGB image bitmap with 24bit encode

Parameters:
x Top left horizontal coordinate
y Top left vertical coordinate
bitmap Bitmap pointer
w Bitmap width
h Bitmap height

void otGraphics.drawRgbBitmapMask U16  x,
U16  y,
const U16 bitmap,
const U8 mask,
U16  w,
U16  h
 

Draw an RGB image bitmap with 24bit encode with mask

Parameters:
x Top left horizontal coordinate
y Top left vertical coordinate
bitmap Bitmap pointer
mask Mask pointer
w Bitmap width
h Bitmap height

void otGraphics.drawRoundRect U16  x,
U16  y,
U16  w,
U16  h,
U16  r,
U16  color
 

Draw a rectangle with rounded angles

Parameters:
x Top left horizontal coordinate
y Top left vertical coordinate
w Rectangle width
h Rectangle Height
r Ray
color Used color

void otGraphics.drawTriangle U16  x0,
U16  y0,
U16  x1,
U16  y1,
U16  x2,
U16  y2,
U16  color
 

Draw a triangle.

Parameters:
x0 Horizontal start of base
y0 Vertical start of base
x1 Horizontal end of base
y1 Vertical end of base
x2 Horizontal coordinate of top vertex
y2 vertical coordinate of top vertex
color Used color

void otGraphics.drawXBitmap U16  x,
U16  y,
const U8 bitmap,
U16  w,
U16  h,
U16  color
 

Draw resident XBitMap Files (*.xbm), exported from GIMP, Usage: Export from GIMP to *.xbm, rename *.xbm to *.c and open in editor. C Array can be directly used with this function.

Parameters:
x Top left horizontal coordinate
y Top left vertical coordinate
bitmap Bitmap pointer
w Bitmap width
h Bitmap height
color Used foreground color

void otGraphics.fillCircle U16  x0,
U16  y0,
U16  r,
U16  color
 

Draw a filled circle.

Parameters:
x0 Horizontal coordinate of the circle center
y0 Vertical coordinate of the circle center
r Circle ray
color Used color

void otGraphics.fillEllipse U16  x0,
U16  y0,
U16  rx,
U16  ry,
U16  color
 

Draw an filled ellipse

Parameters:
x0 Horizontal coordinate of the ellipse center
y0 Vertical coordinate of the ellipse center
rx Horizontal ray
ry Vertical ray
color Ellipse color

void otGraphics.fillRect U16  x,
U16  y,
U16  w,
U16  h,
U16  color
 

Draw a filled rectangle

Parameters:
x Top left horizontal coordinate
y Top left vertical coordinate
w Rectangle width
h Rectangle Height
color Used color

void otGraphics.fillRectHGradient S16  x,
S16  y,
U16  w,
U16  h,
U16  color1,
U16  color2
 

Create an horizontal color gradient area

Parameters:
x Horizontal start position
y Vertical start position
w Width of the area
h Height of the area
color1 Start color
color2 End color

void otGraphics.fillRectVGradient S16  x,
S16  y,
U16  w,
U16  h,
U16  color1,
U16  color2
 

Create a vertical color gradient area

Parameters:
x Horizontal start position
y Vertical start position
w Width of the area
h Height of the area
color1 Start color
color2 End color

void otGraphics.fillRoundRect U16  x,
U16  y,
U16  w,
U16  h,
U16  r,
U16  color
 

Draw a filled rectangle with rounded angles

Parameters:
x Top left horizontal coordinate
y Top left vertical coordinate
w Rectangle width
h Rectangle Height
r Ray
color Used color

void otGraphics.fillTriangle U16  x0,
U16  y0,
U16  x1,
U16  y1,
U16  x2,
U16  y2,
U16  color
 

Draw a filled triangle.

Parameters:
x0 Horizontal start of base
y0 Vertical start of base
x1 Horizontal end of base
y1 Vertical end of base
x2 Horizontal coordinate of top vertex
y2 vertical coordinate of top vertex
color Used color

void otGraphics.init controller_t  crt = ILI9341,
U8  spiClk = 20,
tab_t  tab = NONE_TAB
 

Init the hardware

Parameters:
crt Used controller
spiClk SPI clock frequency as MHz
tab Selector for ST7735 (older controller version)

void otGraphics.invert bool  ena  ) 
 

Invert LCD display.

Parameters:
ena If true invert LCD display

void otGraphics.pushColor U16 data,
U32  len
 

Write a specified color on display

Parameters:
data Pointers to color array with 565 encode
len Number of colors to be write

void otGraphics.pushColor U16  color,
U32  n
 

Write a specified color n time on display

Parameters:
color Used color with 565 encode
n Times to write

void otGraphics.pushColor U16  color  ) 
 

Write a specified color on display

Parameters:
color Used color with 565 encode

U8 otGraphics.rotation  ) 
 

Return used display rotation

Returns:
Angle of rotation see rotation_t

void otGraphics.setCp437 bool  x  ) 
 

Enable (or disable) Code Page 437-compatible charset. There was an error in glcdfont.c for the longest time -- one character (#176, the 'light shade' block) was missing -- this threw off the index of every character that followed it. But a TON of code has been written with the erroneous character indices. By default, the library uses the original 'wrong' behavior and old sketches will still work. Pass 'true' to this function to use correct CP437 character values in your code.

Parameters:
x If true for correction

void otGraphics.setCursor U16  x,
U16  y
 

Specify the cursor coordinates

Parameters:
x Horizontal position
y Vertical position

void otGraphics.setFont const GFXfont f  ) 
 

Set a specified font

Parameters:
f Font pointer

void otGraphics.setPixel U16  x,
U16  y,
U16  color
 

Write a color pixel on display

Parameters:
x Horizontal coordinate
y Vertical coordinate
color Used color

void otGraphics.setRotation rotation_t  r  ) 
 

Change display orientation

Parameters:
r Rotation angle see rotation_t

void otGraphics.setScroll U16  offset  ) 
 

Scroll the display for a specified value

Parameters:
offset Number of pixel

void otGraphics.setTextColor U16  c,
U16  b
 

Specify the foreground and background text color

Parameters:
c Foreground color
b Background color

void otGraphics.setTextColor U16  c  ) 
 

Specify the foreground text color

Parameters:
c Used color

void otGraphics.setTextSize U8  s  ) 
 

Specify the text size

Parameters:
s Text size 1 to n

void otGraphics.setTextWrap bool  w  ) 
 

Enable or disable text wrap

Parameters:
w If true enable text wrap

void otGraphics.setWindow U16  x0,
U16  y0,
U16  x1,
U16  y1
 

Specifiy a window where allow graphics operations.

Parameters:
x0 Top left horizontal coordinate
y0 Top left vertical coordinate
x1 Bot right horizontal coordinate
y1 Bot right vertical coordinate

void otGraphics.showImagePal U16  x,
U16  y,
U16  w,
U16  h,
const U8 pixels,
const U16 palette
 

Show an 8bit image trough a specified palette

Parameters:
x Horizontal start position
y Vertical start position
w Width of the image
h Height of the image
pixels Pointer to the image data
palette Pointer to the 565 palette. 256 value.

void otGraphics.showImagePal1bit U16  x,
U16  y,
U16  w,
U16  h,
const U8 pixels,
const U16 palette
 

Show an 1bit image trough a specified palette

Parameters:
x Horizontal start position
y Vertical start position
w Width of the image
h Height of the image
pixels Pointer to the image data
palette Pointer to the 565 palette. 256 value.

void otGraphics.showImagePal2bit U16  x,
U16  y,
U16  w,
U16  h,
const U8 pixels,
const U16 palette
 

Show an 2bit image trough a specified palette

Parameters:
x Horizontal start position
y Vertical start position
w Width of the image
h Height of the image
pixels Pointer to the image data
palette Pointer to the 565 palette. 256 value.

void otGraphics.showImagePal4bit U16  x,
U16  y,
U16  w,
U16  h,
const U8 pixels,
const U16 palette
 

Show an 4bit image trough a specified palette

Parameters:
x Horizontal start position
y Vertical start position
w Width of the image
h Height of the image
pixels Pointer to the image data
palette Pointer to the 565 palette. 256 value.

void otGraphics.showImagePalZx2 U16  x,
U16  y,
U16  w,
U16  h,
const U8 pixels,
const U16 palette
 

Show an 8bit image trough a specified palette with a zoom of 2x

Parameters:
x Horizontal start position
y Vertical start position
w Width of the image
h Height of the image
pixels Pointer to the image data
palette Pointer to the 565 palette. 256 value.

void otGraphics.showImagePalZx4 U16  x,
U16  y,
U16  w,
U16  h,
const U8 pixels,
const U16 palette
 

Show an 8bit image trough a specified palette with a zoom of 4x

Parameters:
x Horizontal start position
y Vertical start position
w Width of the image
h Height of the image
pixels Pointer to the image data
palette Pointer to the 565 palette. 256 value.

void otGraphics.size U16 w,
U16 h
 

Return the display size

Parameters:
w Return width of display
h Return height of display

void otGraphics.textBounds const char *  str,
U16  x,
U16  y,
U16 x1,
U16 y1,
U16 w,
U16 h
 

Return the size of a string in pixels to the minimum and maximum values.

Parameters:
str String to be tested
x Horizontal position
y Vertical position
x1 Return the horizontal postion
y1 Return the vertical position
w Return the width
h Return the height

U8 otGraphics.textSize  ) 
 

Return current text size

Returns:
Text size

U16 otGraphics.to565 U8  r,
U8  g,
U8  b
 

Pass 8-bit (each) R,G,B, get back 16-bit packed color

Parameters:
r Red value
g Green value
b Blue value
Returns:
Encoded 565 color

U32 otGraphics.write U8  c  ) 
 

Write a character using cursor coordinates

Parameters:
c Character

U32 otGraphics.writeString U16  y,
const char *  str,
U16  color = DEFAULT_COLOR
 

Write a centered string

Parameters:
y Vertical position
str C string
color String color

U32 otGraphics.writeString const char *  str,
S32  len
 

Write a string using cursor coordinates

Parameters:
str C string
len Characters to write

U32 otGraphics.writeString const char *  str,
U16  color = DEFAULT_COLOR
 

Write a string using cursor coordinates

Parameters:
str C string
color String color


The documentation for this class was generated from the following file: footer
otStudio - Library Reference - (C) 2020-25 Officina Turini, All Rights Reserved
Document built with Doxygen 1.4.0