Basically i glued Peter Drescher and Simon Ford libs in a GraphicsDisplay class, then derived TFT or LCD class (which inherits Protocols class), then the most derived ones (Inits), which are per-display and are the only part needed to be adapted to diff hw.

Fork of UniGraphic by GraphicsDisplay

Embed: (wiki syntax)

« Back to documentation index

TFT932x Class Reference

A custom base class for ILI932x color TFT Display (except ILI9327 which is MIPI standard) More...

#include <TFT932x.h>

Inherits GraphicsDisplay.

Inherited by ILI932x.

Public Member Functions

 TFT932x (proto_t displayproto, PortName port, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD, const int lcdsize_x, const int lcdsize_y, const char *name)
 Create TFT Parallel Port interface.
 TFT932x (proto_t displayproto, PinName *buspins, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD, const int lcdsize_x, const int lcdsize_y, const char *name)
 Create TFT Parallel Bus interface.
 TFT932x (proto_t displayproto, int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, const int lcdsize_x, const int lcdsize_y, const char *name)
 Create TFT SPI interface.
virtual void pixel (int x, int y, unsigned short color)
 Draw a pixel in the specified color.
virtual void window (int x, int y, int w, int h)
 Set the window, which controls where items are written to the screen.
virtual unsigned short pixelread (int x, int y)
 Read pixel color at location.
virtual void window4read (int x, int y, int w, int h)
 Set the window from which gram is read from.
virtual void window_pushpixel (unsigned short color)
 Push a single pixel into the window and increment position.
virtual void window_pushpixel (unsigned short color, unsigned int count)
 Push some pixels of the same color into the window and increment position.
virtual void window_pushpixelbuf (unsigned short *color, unsigned int lenght)
 Push array of pixel colors into the window and increment position.
virtual void copy_to_lcd ()
 Framebuffer is not used for TFT.
void invert (unsigned char o)
 display inverted colors
virtual void cls ()
 clear the entire screen The inherited one sets windomax then fill with background color We override it to speedup
virtual void set_orientation (int o)
 Set the orientation of the screen x,y: 0,0 is always top left.
virtual void BusEnable (bool enable)
 Set ChipSelect high or low.
void FastWindow (bool enable)
 Enable fast window (default disabled) used to speedup functions that plots single pixels, like circle, oblique lines or just sparse pixels.
void setscrollarea (int startY=0, int areasize=0)
 Enable scroll scroll is done in hw but only on the native vertical axis TFTs are mainly native protrait view, so horizontal scroll if rotated in landscape view.
void scroll (int lines)
 Scroll up(or left) the scrollarea.
void scrollreset ()
 Disable scroll and display un-scrolled screen.
int sizeX ()
 get display X size in pixels (native, orientation independent)
int sizeY ()
 get display Y size in pixels (native, orientation independent)
virtual void WindowMax (void)
 Set window to max possible size May be overridden in a derived class.
virtual void circle (int x, int y, int r, unsigned short color)
 draw a circle
virtual void fillcircle (int x, int y, int r, unsigned short color)
 draw a filled circle
virtual void line (int x0, int y0, int x1, int y1, unsigned short color)
 draw a 1 pixel line
void hline (int x0, int x1, int y, unsigned short color)
 draw a horizontal line
void vline (int y0, int y1, int x, unsigned short color)
 draw a vertical line
virtual void rect (int x0, int y0, int x1, int y1, unsigned short color)
 draw a rect
virtual void fillrect (int x0, int y0, int x1, int y1, unsigned short color)
 draw a filled rect
virtual void locate (int x, int y)
 setup cursor position for text
virtual int _putc (int value)
 put a char on the screen
virtual void character (int x, int y, int c)
 draw a character on given position out of the active font to the TFT
void Bitmap (int x, int y, int w, int h, unsigned char *bitmap)
 paint a bitmap on the TFT
void Bitmap_BW (Bitmap_s bm, int x, int y)
 paint monochrome bitmap to screen
int BMP_16 (int x, int y, const char *Name_BMP)
 paint a 16 bit BMP from filesytem on the TFT (slow)
void set_font (unsigned char *f, unsigned char firstascii=32, unsigned char lastascii=127, bool proportional=true)
 select the font to use
virtual int columns ()
 Get the number of columns based on the currently active font.
virtual int rows ()
 Get the number of rows based on the currently active font.
int width ()
 get the current oriented screen width in pixels
int height ()
 get the current oriented screen height in pixels
void set_width (int width)
 set the current oriented screen width in pixels
void set_height (int height)
 set the current oriented screen height in pixels
void set_auto_up (bool up)
 setup auto update of screen
bool get_auto_up (void)
 get status of the auto update function
virtual bool claim (FILE *stream)
 redirect output from a stream (stoud, sterr) to display
virtual void foreground (uint16_t colour)
 set the foreground color
virtual void background (uint16_t colour)
 set the background color

Protected Member Functions

virtual void dummyread ()
 ILI932x specific, does a dummy read cycle, number of bits is protocol dependent for PAR protocols: a signle RD bit toggle for SPI8: 8clocks for SPI16: 16 clocks.
virtual void reg_select (unsigned char reg, bool forread=false)
 ILI932x specific, select register for a successive write or read.
virtual void reg_write (unsigned char reg, unsigned short data)
 ILI932x specific, write register with data.
virtual unsigned short reg_read (unsigned char reg)
 ILI932x specific, read register.
virtual void wr_gram (unsigned short data)
 Send 16bit pixeldata to display controller.
virtual void wr_gram (unsigned short data, unsigned int count)
 Send same 16bit pixeldata to display controller multiple times.
virtual void wr_grambuf (unsigned short *data, unsigned int lenght)
 Send array of pixeldata shorts to display controller.
virtual unsigned short rd_gram ()
 Read 16bit pixeldata from display controller (with dummy cycle)
void hw_reset ()
 HW reset sequence (without display init commands)
virtual void auto_gram_read_format ()
 Try to get read gram pixel format, could be 16bit or 18bit, RGB or BGR autoset internal flags so pixelread() will always return correct value.
virtual void identify ()
 Try to identify display ID.

Detailed Description

A custom base class for ILI932x color TFT Display (except ILI9327 which is MIPI standard)

Definition at line 16 of file TFT932x.h.


Constructor & Destructor Documentation

TFT932x ( proto_t  displayproto,
PortName  port,
PinName  CS,
PinName  reset,
PinName  DC,
PinName  WR,
PinName  RD,
const int  lcdsize_x,
const int  lcdsize_y,
const char *  name 
)

Create TFT Parallel Port interface.

Parameters:
nameThe name used by the parent class to access the interface

Definition at line 12 of file TFT932x.cpp.

TFT932x ( proto_t  displayproto,
PinName *  buspins,
PinName  CS,
PinName  reset,
PinName  DC,
PinName  WR,
PinName  RD,
const int  lcdsize_x,
const int  lcdsize_y,
const char *  name 
)

Create TFT Parallel Bus interface.

Parameters:
nameThe name used by the parent class to access the interface

Definition at line 36 of file TFT932x.cpp.

TFT932x ( proto_t  displayproto,
int  Hz,
PinName  mosi,
PinName  miso,
PinName  sclk,
PinName  CS,
PinName  reset,
const int  lcdsize_x,
const int  lcdsize_y,
const char *  name 
)

Create TFT SPI interface.

Note:
ILI9325D has different SPI protocol, not supported here
Parameters:
nameThe name used by the parent class to access the interface

Definition at line 63 of file TFT932x.cpp.


Member Function Documentation

int _putc ( int  value ) [virtual, inherited]

put a char on the screen

Parameters:
valuechar to print
Returns:
printed char

Reimplemented from TextDisplay.

Definition at line 248 of file GraphicsDisplay.cpp.

void auto_gram_read_format (  ) [protected, virtual]

Try to get read gram pixel format, could be 16bit or 18bit, RGB or BGR autoset internal flags so pixelread() will always return correct value.

Definition at line 303 of file TFT932x.cpp.

void background ( uint16_t  colour ) [virtual, inherited]

set the background color

Note:
this method may be overridden in a derived class.
Parameters:
coloris color to use for background drawing.

Definition at line 61 of file TextDisplay.cpp.

void Bitmap ( int  x,
int  y,
int  w,
int  h,
unsigned char *  bitmap 
) [inherited]

paint a bitmap on the TFT

Parameters:
x,y: upper left corner
wwidth of bitmap
hhigh of bitmap
*bitmappointer to the bitmap data

bitmap format: 16 bit R5 G6 B5

use Gimp to create / load , save as BMP, option 16 bit R5 G6 B5 use winhex to load this file and mark data stating at offset 0x46 to end use edit -> copy block -> C Source to export C array paste this array into your program

define the array as static const unsigned char to put it into flash memory cast the pointer to (unsigned char *) : tft.Bitmap(10,40,309,50,(unsigned char *)scala);

Definition at line 334 of file GraphicsDisplay.cpp.

void Bitmap_BW ( Bitmap_s  bm,
int  x,
int  y 
) [inherited]

paint monochrome bitmap to screen

Parameters:
bmBitmap in flash
xx start
yy start

Definition at line 309 of file GraphicsDisplay.cpp.

int BMP_16 ( int  x,
int  y,
const char *  Name_BMP 
) [inherited]

paint a 16 bit BMP from filesytem on the TFT (slow)

Parameters:
x,y: position of upper left corner
*Name_BMPname of the BMP file with drive: "/local/test.bmp"
Returns:
1 if bmp file was found and painted
0 if bmp file was found not found
-1 if file is no bmp
-2 if bmp file is no 16 bit bmp
-3 if bmp file is to big for screen
-4 if buffer malloc go wrong

bitmap format: 16 bit R5 G6 B5

use Gimp to create / load , save as BMP, option 16 bit R5 G6 B5 copy to internal file system or SD card

Definition at line 360 of file GraphicsDisplay.cpp.

void BusEnable ( bool  enable ) [virtual]

Set ChipSelect high or low.

Parameters:
enabletrue/false

Definition at line 140 of file TFT932x.cpp.

void character ( int  x,
int  y,
int  c 
) [virtual, inherited]

draw a character on given position out of the active font to the TFT

Parameters:
xx-position of char (top left)
yy-position
cchar to print

Implements TextDisplay.

Definition at line 262 of file GraphicsDisplay.cpp.

void circle ( int  x,
int  y,
int  r,
unsigned short  color 
) [virtual, inherited]

draw a circle

Parameters:
x0,y0center
rradius
color16 bit color *

Definition at line 58 of file GraphicsDisplay.cpp.

bool claim ( FILE *  stream ) [virtual, inherited]

redirect output from a stream (stoud, sterr) to display

Parameters:
streamstream that shall be redirected to the TextDisplay
Note:
this method may be overridden in a derived class.
Returns:
true if the claim succeeded.

Definition at line 65 of file TextDisplay.cpp.

void cls ( void   ) [virtual]

clear the entire screen The inherited one sets windomax then fill with background color We override it to speedup

Reimplemented from GraphicsDisplay.

Definition at line 297 of file TFT932x.cpp.

int columns (  ) [virtual, inherited]

Get the number of columns based on the currently active font.

Returns:
number of columns.
Note:
this method may be overridden in a derived class.

Implements TextDisplay.

Definition at line 226 of file GraphicsDisplay.cpp.

virtual void copy_to_lcd ( void   ) [virtual]

Framebuffer is not used for TFT.

Implements GraphicsDisplay.

Definition at line 94 of file TFT932x.h.

void dummyread (  ) [protected, virtual]

ILI932x specific, does a dummy read cycle, number of bits is protocol dependent for PAR protocols: a signle RD bit toggle for SPI8: 8clocks for SPI16: 16 clocks.

Definition at line 89 of file TFT932x.cpp.

void FastWindow ( bool  enable )

Enable fast window (default disabled) used to speedup functions that plots single pixels, like circle, oblique lines or just sparse pixels.

Parameters:
enabletrue/false
Note:
most but not all controllers support this, even if datasheet tells they should

Definition at line 190 of file TFT932x.cpp.

void fillcircle ( int  x,
int  y,
int  r,
unsigned short  color 
) [virtual, inherited]

draw a filled circle

Parameters:
x0,y0center
rradius
color16 bit color *

Definition at line 75 of file GraphicsDisplay.cpp.

void fillrect ( int  x0,
int  y0,
int  x1,
int  y1,
unsigned short  color 
) [virtual, inherited]

draw a filled rect

Parameters:
x0,y0top left corner
x1,y1down right corner
color16 bit color

Definition at line 207 of file GraphicsDisplay.cpp.

void foreground ( uint16_t  colour ) [virtual, inherited]

set the foreground color

Note:
this method may be overridden in a derived class.
Parameters:
coloris color to use for foreground drawing.

Definition at line 57 of file TextDisplay.cpp.

bool get_auto_up ( void   ) [inherited]

get status of the auto update function

Returns:
if auto update is on

Definition at line 456 of file GraphicsDisplay.cpp.

int height (  ) [inherited]

get the current oriented screen height in pixels

Returns:
screen height in pixels.

Definition at line 54 of file GraphicsDisplay.cpp.

void hline ( int  x0,
int  x1,
int  y,
unsigned short  color 
) [inherited]

draw a horizontal line

Parameters:
x0horizontal start
x1horizontal stop
yvertical position
color16 bit color

Definition at line 96 of file GraphicsDisplay.cpp.

void hw_reset (  ) [protected]

HW reset sequence (without display init commands)

Definition at line 135 of file TFT932x.cpp.

void identify (  ) [protected, virtual]

Try to identify display ID.

Note:
support ILI9341,94xx, MIPI standard. May be be overridden in Init class for other specific IC

Definition at line 324 of file TFT932x.cpp.

void invert ( unsigned char  o )

display inverted colors

Parameters:
o= 0 normal, 1 invert

Definition at line 184 of file TFT932x.cpp.

void line ( int  x0,
int  y0,
int  x1,
int  y1,
unsigned short  color 
) [virtual, inherited]

draw a 1 pixel line

Parameters:
x0,y0start point
x1,y1stop point
color16 bit color

Definition at line 114 of file GraphicsDisplay.cpp.

void locate ( int  x,
int  y 
) [virtual, inherited]

setup cursor position for text

Parameters:
xx-position (top left)
yy-position

Reimplemented from TextDisplay.

Definition at line 221 of file GraphicsDisplay.cpp.

void pixel ( int  x,
int  y,
unsigned short  color 
) [virtual]

Draw a pixel in the specified color.

Parameters:
xis the horizontal offset to this pixel.
yis the vertical offset to this pixel.
colordefines the color for the pixel.

Implements GraphicsDisplay.

Definition at line 232 of file TFT932x.cpp.

unsigned short pixelread ( int  x,
int  y 
) [virtual]

Read pixel color at location.

Parameters:
xis the horizontal offset to this pixel.
yis the vertical offset to this pixel.
Returns:
16bit color.

Definition at line 254 of file TFT932x.cpp.

unsigned short rd_gram (  ) [protected, virtual]

Read 16bit pixeldata from display controller (with dummy cycle)

Note:
autoconverts 18to16bit based on display identify info
Returns:
16bit color

Definition at line 117 of file TFT932x.cpp.

void rect ( int  x0,
int  y0,
int  x1,
int  y1,
unsigned short  color 
) [virtual, inherited]

draw a rect

Parameters:
x0,y0top left corner
x1,y1down right corner
color16 bit color *

Definition at line 185 of file GraphicsDisplay.cpp.

unsigned short reg_read ( unsigned char  reg ) [protected, virtual]

ILI932x specific, read register.

Parameters:
regregister to be read
Returns:
16bit register value

Definition at line 101 of file TFT932x.cpp.

void reg_select ( unsigned char  reg,
bool  forread = false 
) [protected, virtual]

ILI932x specific, select register for a successive write or read.

Parameters:
regregister to be selected
forreadfalse = a write next (default), true = a read next
Note:
forread only used by SPI protocols

Definition at line 93 of file TFT932x.cpp.

void reg_write ( unsigned char  reg,
unsigned short  data 
) [protected, virtual]

ILI932x specific, write register with data.

Parameters:
regregister to write
data16bit data

Definition at line 97 of file TFT932x.cpp.

int rows (  ) [virtual, inherited]

Get the number of rows based on the currently active font.

Returns:
number of rows.
Note:
this method may be overridden in a derived class.

Implements TextDisplay.

Definition at line 230 of file GraphicsDisplay.cpp.

void scroll ( int  lines )

Scroll up(or left) the scrollarea.

Parameters:
linesnumber of lines to scroll, 1= scrollup 1, areasize-1= scrolldown 1

Definition at line 287 of file TFT932x.cpp.

void scrollreset (  )

Disable scroll and display un-scrolled screen.

Definition at line 291 of file TFT932x.cpp.

void set_auto_up ( bool  up ) [inherited]

setup auto update of screen

Parameters:
up1 = on , 0 = off if switched off the program has to call copy_to_lcd() to update screen from framebuffer

Definition at line 451 of file GraphicsDisplay.cpp.

void set_font ( unsigned char *  f,
unsigned char  firstascii = 32,
unsigned char  lastascii = 127,
bool  proportional = true 
) [inherited]

select the font to use

Parameters:
fpointer to font array
firstasciifirst ascii code present in font array, default 32 (space)
lastasciilast ascii code present in font array, default 127 (DEL)
proportionalenable/disable variable font width (default enabled)

font array can created with GLCD Font Creator from http://www.mikroe.com you have to add 4 parameter at the beginning of the font array to use:

  • the number of byte / char (not used in this revision, set to whatever)
  • the vertial size in pixel
  • the horizontal size in pixel
  • the number of byte per vertical line (not used in this revision, set to whatever) you also have to change the array to cont unsigned char[] and __align(2)

Definition at line 234 of file GraphicsDisplay.cpp.

void set_height ( int  height ) [inherited]

set the current oriented screen height in pixels

Parameters:
heightscreen height in pixels.

Definition at line 46 of file GraphicsDisplay.cpp.

void set_orientation ( int  o ) [virtual]

Set the orientation of the screen x,y: 0,0 is always top left.

Parameters:
odirection to use the screen (0-3) 0 = default 0° portrait view 1 = +90° landscape view 2 = +180° portrait view 3 = -90° landscape view

Definition at line 146 of file TFT932x.cpp.

void set_width ( int  width ) [inherited]

set the current oriented screen width in pixels

Parameters:
widthscreen width in pixels.

Definition at line 42 of file GraphicsDisplay.cpp.

void setscrollarea ( int  startY = 0,
int  areasize = 0 
)

Enable scroll scroll is done in hw but only on the native vertical axis TFTs are mainly native protrait view, so horizontal scroll if rotated in landscape view.

Note:
ILI932x does not allow partial screen scrolling, only full screen is selectable
Parameters:
startYunused, always 0 for ILI932x
areasizeunused, always screensize_Y for ILI932x

Definition at line 281 of file TFT932x.cpp.

int sizeX (  )

get display X size in pixels (native, orientation independent)

Returns:
X size in pixels

Definition at line 329 of file TFT932x.cpp.

int sizeY (  )

get display Y size in pixels (native, orientation independent)

Returns:
Y size in pixels

Definition at line 333 of file TFT932x.cpp.

void vline ( int  y0,
int  y1,
int  x,
unsigned short  color 
) [inherited]

draw a vertical line

Parameters:
xhorizontal position
y0vertical start
y1vertical stop
color16 bit color

Definition at line 105 of file GraphicsDisplay.cpp.

int width (  ) [inherited]

get the current oriented screen width in pixels

Returns:
screen width in pixels.

Definition at line 50 of file GraphicsDisplay.cpp.

void window ( int  x,
int  y,
int  w,
int  h 
) [virtual]

Set the window, which controls where items are written to the screen.

When something hits the window width, it wraps back to the left side and down a row. If the initial write is outside the window, it will be captured into the window when it crosses a boundary.

Parameters:
xis the left edge in pixels.
yis the top edge in pixels.
wis the window width in pixels.
his the window height in pixels.

Implements GraphicsDisplay.

Definition at line 195 of file TFT932x.cpp.

void window4read ( int  x,
int  y,
int  w,
int  h 
) [virtual]

Set the window from which gram is read from.

Autoincrements row/column

Parameters:
xis the left edge in pixels.
yis the top edge in pixels.
wis the window width in pixels.
his the window height in pixels.

Definition at line 213 of file TFT932x.cpp.

void window_pushpixel ( unsigned short  color,
unsigned int  count 
) [virtual]

Push some pixels of the same color into the window and increment position.

You must first call window() then push pixels.

Parameters:
coloris the pixel color.
count,:how many

Implements GraphicsDisplay.

Definition at line 127 of file TFT932x.cpp.

void window_pushpixel ( unsigned short  color ) [virtual]

Push a single pixel into the window and increment position.

You must first call window() then push pixels.

Parameters:
coloris the pixel color.

Implements GraphicsDisplay.

Definition at line 123 of file TFT932x.cpp.

void window_pushpixelbuf ( unsigned short *  color,
unsigned int  lenght 
) [virtual]

Push array of pixel colors into the window and increment position.

You must first call window() then push pixels.

Parameters:
coloris the pixel color.

Implements GraphicsDisplay.

Definition at line 131 of file TFT932x.cpp.

void WindowMax ( void   ) [virtual, inherited]

Set window to max possible size May be overridden in a derived class.

Definition at line 38 of file GraphicsDisplay.cpp.

void wr_gram ( unsigned short  data,
unsigned int  count 
) [protected, virtual]

Send same 16bit pixeldata to display controller multiple times.

Parameters:
data,:halfword to send
count,:how many

Definition at line 109 of file TFT932x.cpp.

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

Send 16bit pixeldata to display controller.

Parameters:
data,:halfword to send

Definition at line 105 of file TFT932x.cpp.

void wr_grambuf ( unsigned short *  data,
unsigned int  lenght 
) [protected, virtual]

Send array of pixeldata shorts to display controller.

Parameters:
data,:unsigned short pixeldata array
lenght,:lenght (in shorts)

Definition at line 113 of file TFT932x.cpp.