Added methods and features
Fork of SPI_TFT_ILI9341 by
SPI_TFT_ILI9341 Class Reference
Display control class, based on GraphicsDisplay and TextDisplay. More...
#include <SPI_TFT_ILI9341.h>
Inherits GraphicsDisplay.
Public Types | |
enum | Origin { Origin_LeftTop = 0, Origin_RightTop, Origin_RightBot, Origin_LeftBot } |
Display origin. More... | |
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 | ~SPI_TFT_ILI9341 () |
Destructor for SPI_TFT object. | |
virtual int | width () |
Get the width of the screen in pixels. | |
virtual int | height () |
Get the height of the screen in pixels. | |
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 | oval (int x, int y, int b, int color, float aspect=1.0) |
draw an oval | |
void | filloval (int x, int y, int b, int color, float aspect=1.0) |
draw a filled oval | |
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 | |
void | roundrect (int x0, int y0, int x1, int y1, int color) |
draw a rounded rect | |
void | fillroundrect (int x0, int y0, int x1, int y1, int color) |
draw a filled rounded rect | |
virtual void | locate (int x, int y) |
setup cursor position | |
virtual void | cls () |
Fill the screen with _background color. | |
virtual void | newcls () |
Fill the screen with _background color. | |
virtual int | columns (void) |
calculate the max number of char in a line | |
virtual int | rows (void) |
calculate the max number of rows | |
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, const char *Name_BMP) |
paint a 16 bit BMP from filesytem on the TFT (slow) | |
void | set_font (unsigned char *f) |
select the font to use | |
void | set_origin (Origin origin) |
Set the orientation of the screen x,y: 0,0 is always top left. | |
void | set_transparancy (bool state) |
Set background transparancy for characters, meaning that background pixels remain unchanged. | |
void | tft_on (bool on) |
Enable the ILI9341 display. | |
int | Read_ID (void) |
read out the manufacturer ID of the LCD can used for checking the connection to the display | |
virtual bool | claim (FILE *stream) |
redirect output from a stream (stoud, sterr) to display | |
Protected Member Functions | |
void | hline (int x0, int x1, int y, int colour) |
draw a horizontal line | |
void | vline (int x, int y0, int y1, 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 | window_max (void) |
Set draw window region to whole screen. | |
void | tft_reset () |
Init the ILI9341 controller. | |
void | _hwreset () |
HW Reset to ILI9341 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. | |
char | rd_byte (unsigned char cmd) |
Read byte from the LCD controller. | |
int | rd_32 (unsigned char cmd) |
Read int from the LCD controller. | |
Protected Attributes | |
SPI | _spi |
Write a value to the to a LCD register. |
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 169 of file SPI_TFT_ILI9341.h.
Member Enumeration Documentation
enum Origin |
Display origin.
- Enumerator:
Origin_LeftTop Left Top of panel is origin.
Origin_RightTop Right Top of panel is origin.
Origin_RightBot Right Bottom of panel is origin.
Origin_LeftBot Left Bottom panel is origin.
Definition at line 173 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:
-
mosi pin connected to SDO of display miso pin connected to SDI of display sclk pin connected to RS of display cs pin connected to CS of display reset pin connected to RESET of display (may be NC) dc pin connected to WR of display The IM pins have to be set to 1110 (3-0). Note: the M24SR board uses 0110 which also works.
Definition at line 26 of file SPI_TFT_ILI9341.cpp.
~SPI_TFT_ILI9341 | ( | ) | [virtual] |
Destructor for SPI_TFT object.
Destruct a SPI_TFT LCD object.
- Parameters:
-
none
- Returns:
- none
Definition at line 58 of file SPI_TFT_ILI9341.cpp.
Member Function Documentation
void _hwreset | ( | ) | [protected] |
int _putc | ( | int | value ) | [virtual] |
put a char on the screen
- Parameters:
-
value char to print
- Returns:
- printed char
Definition at line 949 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 w width of bitmap h height of bitmap *bitmap pointer 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 1164 of file SPI_TFT_ILI9341.cpp.
int BMP_16 | ( | unsigned int | x, |
unsigned int | y, | ||
const char * | Name_BMP | ||
) |
paint a 16 bit BMP from filesytem on the TFT (slow)
- Parameters:
-
x,y : position of upper left corner *Name_BMP name 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 1216 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:
-
x x-position of char (top left) y y-position c char to print
Definition at line 965 of file SPI_TFT_ILI9341.cpp.
void circle | ( | int | x, |
int | y, | ||
int | r, | ||
int | colour | ||
) |
draw a circle
- Parameters:
-
x0,y0 center r radius color 16 bit color *
Definition at line 529 of file SPI_TFT_ILI9341.cpp.
bool claim | ( | FILE * | stream ) | [virtual, inherited] |
redirect output from a stream (stoud, sterr) to display
- Parameters:
-
stream stream that shall be redirected to the TextDisplay
Definition at line 65 of file TextDisplay.cpp.
void cls | ( | ) | [virtual] |
Fill the screen with _background color.
- Parameters:
-
none
- Returns:
- none
Definition at line 459 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
Definition at line 935 of file SPI_TFT_ILI9341.cpp.
void fillcircle | ( | int | x, |
int | y, | ||
int | r, | ||
int | colour | ||
) |
draw a filled circle
- Parameters:
-
x0,y0 center r radius color 16 bit color *
Definition at line 548 of file SPI_TFT_ILI9341.cpp.
void filloval | ( | int | x, |
int | y, | ||
int | b, | ||
int | color, | ||
float | aspect = 1.0 |
||
) |
draw a filled oval
- Parameters:
-
x,y center b radius aspect hor/ver ratio ( hor. oval < 1.0; circle = 1.0; vert. oval > 1.0 ) color 16 bit color *
Definition at line 621 of file SPI_TFT_ILI9341.cpp.
void fillrect | ( | int | x0, |
int | y0, | ||
int | x1, | ||
int | y1, | ||
int | colour | ||
) |
draw a filled rect
- Parameters:
-
x0,y0 top left corner x1,y1 down right corner color 16 bit color
Definition at line 832 of file SPI_TFT_ILI9341.cpp.
void fillroundrect | ( | int | x0, |
int | y0, | ||
int | x1, | ||
int | y1, | ||
int | color | ||
) |
draw a filled rounded rect
- Parameters:
-
x0,y0 top left corner x1,y1 down right corner color 16 bit color
Definition at line 894 of file SPI_TFT_ILI9341.cpp.
int height | ( | ) | [virtual] |
Get the height of the screen in pixels.
- Returns:
- height of screen in pixels
Definition at line 74 of file SPI_TFT_ILI9341.cpp.
void hline | ( | int | x0, |
int | x1, | ||
int | y, | ||
int | colour | ||
) | [protected] |
draw a horizontal line
- Parameters:
-
x0 horizontal start x1 horizontal stop y vertical position color 16 bit color
- Returns:
- None
Definition at line 676 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,y0 start point x1,y1 stop point color 16 bit color
Definition at line 741 of file SPI_TFT_ILI9341.cpp.
void locate | ( | int | x, |
int | y | ||
) | [virtual] |
setup cursor position
- Parameters:
-
x x-position (top left) y y-position
Definition at line 927 of file SPI_TFT_ILI9341.cpp.
void newcls | ( | void | ) | [virtual] |
Fill the screen with _background color.
- Parameters:
-
none
- Returns:
- none
Definition at line 466 of file SPI_TFT_ILI9341.cpp.
void oval | ( | int | x, |
int | y, | ||
int | b, | ||
int | color, | ||
float | aspect = 1.0 |
||
) |
draw an oval
- Parameters:
-
x,y center b radius aspect hor/ver ratio ( hor. oval < 1.0; circle = 1.0; vert. oval > 1.0 ) color 16 bit color *
Definition at line 564 of file SPI_TFT_ILI9341.cpp.
void pixel | ( | int | x, |
int | y, | ||
int | colour | ||
) | [virtual] |
Draw a pixel at x,y with color.
- Parameters:
-
x horizontal position y vertical position color 16 bit pixel color
Definition at line 393 of file SPI_TFT_ILI9341.cpp.
int rd_32 | ( | unsigned char | cmd ) | [protected] |
Read int from the LCD controller.
- Parameters:
-
cmd command to controller
- Returns:
- data from LCD controller
Definition at line 181 of file SPI_TFT_ILI9341.cpp.
char rd_byte | ( | unsigned char | cmd ) | [protected] |
Read byte from the LCD controller.
- Parameters:
-
cmd command to controller
- Returns:
- data from LCD controller
Definition at line 168 of file SPI_TFT_ILI9341.cpp.
int Read_ID | ( | void | ) |
read out the manufacturer ID of the LCD can used for checking the connection to the display
- Returns:
- ID
Definition at line 209 of file SPI_TFT_ILI9341.cpp.
void rect | ( | int | x0, |
int | y0, | ||
int | x1, | ||
int | y1, | ||
int | colour | ||
) |
draw a rect
- Parameters:
-
x0,y0 top left corner x1,y1 down right corner color 16 bit color *
Definition at line 813 of file SPI_TFT_ILI9341.cpp.
void roundrect | ( | int | x0, |
int | y0, | ||
int | x1, | ||
int | y1, | ||
int | color | ||
) |
draw a rounded rect
- Parameters:
-
x0,y0 top left corner x1,y1 down right corner color 16 bit color *
Definition at line 872 of file SPI_TFT_ILI9341.cpp.
int rows | ( | void | ) | [virtual] |
calculate the max number of rows
- Returns:
- max row depends on actual font size
Definition at line 942 of file SPI_TFT_ILI9341.cpp.
void set_font | ( | unsigned char * | f ) |
select the font to use
- Parameters:
-
f pointer 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 1157 of file SPI_TFT_ILI9341.cpp.
void set_origin | ( | Origin | origin ) |
Set the orientation of the screen x,y: 0,0 is always top left.
- Parameters:
-
o direction to use the screen (0-3) Set the origin of the screen x,y: 0,0 is always top left origin top left corner of the screen
- Returns:
- None
Definition at line 107 of file SPI_TFT_ILI9341.cpp.
void set_transparancy | ( | bool | state ) |
Set background transparancy for characters, meaning that background pixels remain unchanged.
- Parameters:
-
state transparancy on/off
- Returns:
- None
Definition at line 131 of file SPI_TFT_ILI9341.cpp.
void tft_on | ( | bool | on ) |
Enable the ILI9341 display.
- Parameters:
-
on,: display On/Off
- Returns:
- None
Definition at line 382 of file SPI_TFT_ILI9341.cpp.
void tft_reset | ( | ) | [protected] |
void vline | ( | int | x, |
int | y0, | ||
int | y1, | ||
int | colour | ||
) | [protected] |
draw a vertical line
- Parameters:
-
x horizontal position y0 vertical start y1 vertical stop color 16 bit color
- Returns:
- None
Definition at line 709 of file SPI_TFT_ILI9341.cpp.
int width | ( | ) | [virtual] |
Get the width of the screen in pixels.
- Returns:
- width of screen in pixels
Definition at line 64 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:
-
x horizontal position y vertical position w window width in pixel h window height in pixels
- Returns:
- None
Definition at line 429 of file SPI_TFT_ILI9341.cpp.
void window_max | ( | void | ) | [protected] |
Set draw window region to whole screen.
- Returns:
- None
Definition at line 448 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
- Returns:
- None
Definition at line 147 of file SPI_TFT_ILI9341.cpp.
void wr_dat | ( | unsigned char | value ) | [protected] |
Write data to the LCD controller.
- Parameters:
-
dat data written to LCD controller
- Returns:
- None
Definition at line 157 of file SPI_TFT_ILI9341.cpp.
Field Documentation
SPI _spi [protected] |
Write a value to the to a LCD register.
- Parameters:
-
reg register to be written val data to be written
- Returns:
- None Read a LCD register
- Parameters:
-
reg register to be read
- Returns:
- value of the register
Definition at line 571 of file SPI_TFT_ILI9341.h.
Generated on Wed Jul 13 2022 09:36:56 by 1.7.2