a

Dependents:   SeeedStudioTFTv2

Fork of SPI_TFT_ILI9341 by Components

Embed: (wiki syntax)

« Back to documentation index

SPI_TFT_ILI9341 Class Reference

Display control class, based on GraphicsDisplay and TextDisplay. More...

#include <SPI_TFT_ILI9341.h>

Inherits GraphicsDisplay.

Public Member Functions

 SPI_TFT_ILI9341 (PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset, PinName dc, const char *name="TFT")
 Create a SPI_TFT object connected to SPI and three pins.
virtual int width ()
 Get the width of the screen in pixel.
virtual int height ()
 Get the height of the screen in pixel.
virtual void pixel (int x, int y, int colour)
 Draw a pixel at x,y with color.
void circle (int x, int y, int r, int colour)
 Draw a circle.
void fillcircle (int x, int y, int r, int colour)
 Draw a filled circle.
void line (int x0, int y0, int x1, int y1, int colour)
 Draw a 1 pixel line.
void rect (int x0, int y0, int x1, int y1, int colour)
 Draw a rect.
void fillrect (int x0, int y0, int x1, int y1, int colour)
 Draw a filled rect.
virtual void locate (int x, int y)
 Setup cursor position.
virtual void cls (void)
 Fill the screen with _backgroun color.
virtual int columns (void)
 Calculate the max number of char in a line.
virtual int rows (void)
 Calculate the max number of columns.
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 (unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned char *bitmap)
 Paint a bitmap on the TFT.
int BMP_16 (unsigned int x, unsigned int y, FILE *fd)
 Paint a 16 bit BMP from local filesytem on the TFT (slow)
void set_font (unsigned char *f)
 Select the font to use.
void set_orientation (unsigned int o)
 Set the orientation of the screen x,y: 0,0 is always top left.
virtual bool claim (FILE *stream)
 Redirect output from a stream (stoud, sterr) to display.

Protected Member Functions

void WindowMax (void)
 Set draw window region to whole screen.
void hline (int x0, int x1, int y, int colour)
 Draw a horizontal line.
void vline (int y0, int y1, int x, int colour)
 Draw a vertical line.
virtual void window (unsigned int x, unsigned int y, unsigned int w, unsigned int h)
 Set draw window region.
void tft_reset ()
 Init the HX8347D controller.
void wr_dat (unsigned char value)
 Write data to the LCD controller.
void wr_cmd (unsigned char value)
 Write a command the LCD controller.

Protected Attributes

unsigned char spi_port
 Start data sequence to the LCD controller.

Detailed Description

Display control class, based on GraphicsDisplay and TextDisplay.

Example:

 #include "stdio.h"
 #include "mbed.h"
 #include "SPI_TFT_ILI9341.h"
 #include "string"
 #include "Arial12x12.h"
 #include "Arial24x23.h"
 


 // the TFT is connected to SPI pin 5-7 and IO's 8-10
 SPI_TFT_ILI9341 TFT(p5, p6, p7, p8, p9, p10,"TFT"); // mosi, miso, sclk, cs, reset, dc
 // If your display need a signal for switch the backlight use a aditional IO pin in your program 

 int main() {
     TFT.claim(stdout);      // send stdout to the TFT display 
     //TFT.claim(stderr);      // send stderr to the TFT display

     TFT.background(Black);    // set background to black
     TFT.foreground(White);    // set chars to white
     TFT.cls();                // clear the screen
     TFT.set_font((unsigned char*) Arial12x12);  // select the font
     
     TFT.set_orientation(0);
     printf("  Hello Mbed 0");
     TFT.set_font((unsigned char*) Arial24x23);  // select font 2
     TFT.locate(48,115);
     TFT.printf("Bigger Font");
 }

Definition at line 81 of file SPI_TFT_ILI9341.h.


Constructor & Destructor Documentation

SPI_TFT_ILI9341 ( PinName  mosi,
PinName  miso,
PinName  sclk,
PinName  cs,
PinName  reset,
PinName  dc,
const char *  name = "TFT" 
)

Create a SPI_TFT object connected to SPI and three pins.

Parameters:
mosipin connected to SDO of display
misopin connected to SDI of display
sclkpin connected to RS of display
cspin connected to CS of display
resetpin connected to RESET of display
dcpin connected to WR of display the IM pins have to be set to 1110 (3-0)

Definition at line 27 of file SPI_TFT_ILI9341.cpp.


Member Function Documentation

int _putc ( int  value ) [virtual]

Put a char on the screen.

Parameters:
valuechar to print
Returns:
printed char

Reimplemented from TextDisplay.

Definition at line 566 of file SPI_TFT_ILI9341.cpp.

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

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 649 of file SPI_TFT_ILI9341.cpp.

int BMP_16 ( unsigned int  x,
unsigned int  y,
FILE *  fd 
)

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

Parameters:
x,y: upper left corner
*Name_BMPname of the BMP file
Returns:
1 if bmp file was found and painted
-1 if bmp file was found not found
-2 if bmp file is not 16bit
-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

Definition at line 694 of file SPI_TFT_ILI9341.cpp.

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

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 582 of file SPI_TFT_ILI9341.cpp.

void circle ( int  x,
int  y,
int  r,
int  colour 
)

Draw a circle.

Parameters:
x0,y0center
rradius
color16 bit color

Definition at line 341 of file SPI_TFT_ILI9341.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

Definition at line 65 of file TextDisplay.cpp.

void cls ( void   ) [virtual]

Fill the screen with _backgroun color.

Reimplemented from TextDisplay.

Definition at line 318 of file SPI_TFT_ILI9341.cpp.

int columns ( void   ) [virtual]

Calculate the max number of char in a line.

Returns:
max columns, depends on actual font size

Implements TextDisplay.

Definition at line 552 of file SPI_TFT_ILI9341.cpp.

void fillcircle ( int  x,
int  y,
int  r,
int  colour 
)

Draw a filled circle.

Parameters:
x0,y0center
rradius
color16 bit color

use circle with different radius, can miss some pixel

Definition at line 360 of file SPI_TFT_ILI9341.cpp.

void fillrect ( int  x0,
int  y0,
int  x1,
int  y1,
int  colour 
)

Draw a filled rect.

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

Definition at line 518 of file SPI_TFT_ILI9341.cpp.

int height (  ) [virtual]

Get the height of the screen in pixel.

Returns:
height of screen in pixel

Definition at line 43 of file SPI_TFT_ILI9341.cpp.

void hline ( int  x0,
int  x1,
int  y,
int  colour 
) [protected]

Draw a horizontal line.

Parameters:
x0horizontal start
x1horizontal stop
yvertical position
color16 bit color

Definition at line 376 of file SPI_TFT_ILI9341.cpp.

void line ( int  x0,
int  y0,
int  x1,
int  y1,
int  colour 
)

Draw a 1 pixel line.

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

Definition at line 426 of file SPI_TFT_ILI9341.cpp.

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

Setup cursor position.

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

Reimplemented from TextDisplay.

Definition at line 544 of file SPI_TFT_ILI9341.cpp.

void pixel ( int  x,
int  y,
int  colour 
) [virtual]

Draw a pixel at x,y with color.

Parameters:
xhorizontal position
yvertical position
color16 bit pixel color

Definition at line 270 of file SPI_TFT_ILI9341.cpp.

void rect ( int  x0,
int  y0,
int  x1,
int  y1,
int  colour 
)

Draw a rect.

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

Definition at line 498 of file SPI_TFT_ILI9341.cpp.

int rows ( void   ) [virtual]

Calculate the max number of columns.

Returns:
max column, depends on actual font size

Implements TextDisplay.

Definition at line 559 of file SPI_TFT_ILI9341.cpp.

void set_font ( unsigned char *  f )

Select the font to use.

Parameters:
fpointer to font array

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
  • the vertial size in pixel
  • the horizontal size in pixel
  • the number of byte per vertical line you also have to change the array to char[]

Definition at line 642 of file SPI_TFT_ILI9341.cpp.

void set_orientation ( unsigned int  o )

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

Parameters:
odirection to use the screen (0-3)

Definition at line 50 of file SPI_TFT_ILI9341.cpp.

void tft_reset (  ) [protected]

Init the HX8347D controller.

Definition at line 108 of file SPI_TFT_ILI9341.cpp.

void vline ( int  y0,
int  y1,
int  x,
int  colour 
) [protected]

Draw a vertical line.

Parameters:
xhorizontal position
y0vertical start
y1vertical stop
color16 bit color

Definition at line 401 of file SPI_TFT_ILI9341.cpp.

int width (  ) [virtual]

Get the width of the screen in pixel.

Parameters:
@returnswidth of screen in pixel

Definition at line 36 of file SPI_TFT_ILI9341.cpp.

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

Set draw window region.

Parameters:
xhorizontal position
yvertical position
wwindow width in pixel
hwindow height in pixels

Definition at line 293 of file SPI_TFT_ILI9341.cpp.

void WindowMax ( void   ) [protected]

Set draw window region to whole screen.

Definition at line 311 of file SPI_TFT_ILI9341.cpp.

void wr_cmd ( unsigned char  value ) [protected]

Write a command the LCD controller.

Parameters:
cmd,:command to be written

Definition at line 75 of file SPI_TFT_ILI9341.cpp.

void wr_dat ( unsigned char  value ) [protected]

Write data to the LCD controller.

Parameters:
datdata written to LCD controller

Definition at line 85 of file SPI_TFT_ILI9341.cpp.


Field Documentation

unsigned char spi_port [protected]

Start data sequence to the LCD controller.

Stop of data writing to the LCD controller write data to the LCD controller

Parameters:
datato be written * Read data from the LCD controller
Returns:
data from LCD controller Write a value to the to a LCD register
Parameters:
regregister to be written
valdata to be written Read a LCD register
regregister to be read
Returns:
value of the register

Definition at line 363 of file SPI_TFT_ILI9341.h.