Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
touch_tft Class Reference
touchscreen control class, based on SPI_TFT More...
#include <touch_tft.h>
Inherits SPI_TFT.
Public Member Functions | |
| touch_tft (PinName xp, PinName xm, PinName yp, PinName ym, PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset, const char *name="TFT") | |
| create a TFT with touch object connected to the pins: | |
| void | calibrate (void) |
| calibrate the touch display | |
| point | get_touch (void) |
| read x and y analog samples | |
| point | to_pixel (point a_point) |
| calculate coord on screen | |
| bool | is_touched (point a) |
| test if screen is touched | |
| 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 | |
| void | locate (int x, int y) |
| setup cursor position | |
| virtual void | cls (void) |
| Fill the screen with _backgroun color. | |
| int | columns (void) |
| calculate the max number of char in a line | |
| int | rows (void) |
| calculate the max number of columns | |
| 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 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 | |
| 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 (int value) |
| Write data to the LCD controller. | |
| void | wr_cmd (int value) |
| Write a command the LCD controller. | |
| void | wr_dat_start () |
| Start data sequence to the LCD controller. | |
| void | wr_dat_stop () |
| Stop of data writing to the LCD controller. | |
| void | wr_dat_only (unsigned short dat) |
| write data to the LCD controller | |
| unsigned short | rd_dat (void) |
| Read data from the LCD controller. | |
| void | wr_reg (unsigned char reg, unsigned short val) |
| Write a value to the to a LCD register. | |
| unsigned short | rd_reg (unsigned char reg) |
| Read a LCD register. | |
Detailed Description
touchscreen control class, based on SPI_TFT
Example:
#include "mbed.h" #include "SPI_TFT.h" #include "Arial12x12.h" #include "Arial28x28.h" #include "touch_tft.h" // the TFT is connected to SPI pin 5-7 // the touch is connected to 19,20,16,17 touch_tft tt(p19,p20,p16,p17,p5, p6, p7, p8, p15,"TFT"); // x+,x-,y+,y-,mosi, miso, sclk, cs, reset int main() { point p; tt.claim(stdout); // send stdout to the TFT display tt.background(Black); // set background to black tt.foreground(White); // set chars to white tt.cls(); // clear the screen tt.set_font((unsigned char*) Arial12x12); // select the font tt.set_orientation(1); tt.calibrate(); // calibrate the touch while (1) { p = tt.get_touch(); // read analog pos. if (tt.is_touched(p)) { // test if touched p = tt.to_pixel(p); // convert to pixel pos tt.fillcircle(p.x,p.y,3,Blue); // print a blue dot on the screen } }
Definition at line 61 of file touch_tft.h.
Constructor & Destructor Documentation
| touch_tft | ( | PinName | xp, |
| PinName | xm, | ||
| PinName | yp, | ||
| PinName | ym, | ||
| PinName | mosi, | ||
| PinName | miso, | ||
| PinName | sclk, | ||
| PinName | cs, | ||
| PinName | reset, | ||
| const char * | name = "TFT" |
||
| ) |
create a TFT with touch object connected to the pins:
- Parameters:
-
pin xp resistiv touch x+ pin xm resistiv touch x- pin yp resistiv touch y+ pin ym resistiv touch y- mosi,miso,sclk SPI connection to TFT cs pin connected to CS of display reset pin connected to RESET of display based on my SPI_TFT lib
Definition at line 21 of file touch_tft.cpp.
Member Function Documentation
| int _putc | ( | int | value ) | [inherited] |
put a char on the screen
- Parameters:
-
value char to print
- Returns:
- printed char
Definition at line 570 of file SPI_TFT.cpp.
| void Bitmap | ( | unsigned int | x, |
| unsigned int | y, | ||
| unsigned int | w, | ||
| unsigned int | h, | ||
| unsigned char * | bitmap | ||
| ) | [inherited] |
paint a bitmap on the TFT
- Parameters:
-
x,y : upper left corner w width of bitmap h high 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 643 of file SPI_TFT.cpp.
| int BMP_16 | ( | unsigned int | x, |
| unsigned int | y, | ||
| const char * | Name_BMP | ||
| ) | [inherited] |
paint a 16 bit BMP from local filesytem on the TFT (slow)
- Parameters:
-
x,y : upper left corner *Name_BMP name 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 671 of file SPI_TFT.cpp.
| void calibrate | ( | void | ) |
calibrate the touch display
User is asked to touch on two points on the screen
Definition at line 110 of file touch_tft.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:
-
x x-position of char (top left) y y-position c char to print
Definition at line 586 of file SPI_TFT.cpp.
| void circle | ( | int | x, |
| int | y, | ||
| int | r, | ||
| int | colour | ||
| ) | [inherited] |
draw a circle
- Parameters:
-
x0,y0 center r radius color 16 bit color *
Definition at line 288 of file SPI_TFT.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 | ( | void | ) | [virtual, inherited] |
Fill the screen with _backgroun color.
Definition at line 275 of file SPI_TFT.cpp.
| int columns | ( | void | ) | [inherited] |
calculate the max number of char in a line
- Returns:
- max columns depends on actual font size
Definition at line 558 of file SPI_TFT.cpp.
| void fillcircle | ( | int | x, |
| int | y, | ||
| int | r, | ||
| int | colour | ||
| ) | [inherited] |
draw a filled circle
- Parameters:
-
x0,y0 center r radius color 16 bit color *
use circle with different radius, can miss some pixel
Definition at line 395 of file SPI_TFT.cpp.
| void fillrect | ( | int | x0, |
| int | y0, | ||
| int | x1, | ||
| int | y1, | ||
| int | colour | ||
| ) | [inherited] |
draw a filled rect
- Parameters:
-
x0,y0 top left corner x1,y1 down right corner color 16 bit color
Definition at line 531 of file SPI_TFT.cpp.
| point get_touch | ( | void | ) |
| int height | ( | ) | [virtual, inherited] |
Get the height of the screen in pixel.
- Returns:
- height of screen in pixel
Definition at line 40 of file SPI_TFT.cpp.
| void hline | ( | int | x0, |
| int | x1, | ||
| int | y, | ||
| int | colour | ||
| ) | [protected, inherited] |
draw a horizontal line
- Parameters:
-
x0 horizontal start x1 horizontal stop y vertical position color 16 bit color
Definition at line 403 of file SPI_TFT.cpp.
| bool is_touched | ( | point | a ) |
test if screen is touched
- Parameters:
-
point analog x,y
- Returns:
- true is touched
Definition at line 225 of file touch_tft.cpp.
| void line | ( | int | x0, |
| int | y0, | ||
| int | x1, | ||
| int | y1, | ||
| int | colour | ||
| ) | [inherited] |
draw a 1 pixel line
- Parameters:
-
x0,y0 start point x1,y1 stop point color 16 bit color
Definition at line 439 of file SPI_TFT.cpp.
| void locate | ( | int | x, |
| int | y | ||
| ) | [inherited] |
setup cursor position
- Parameters:
-
x x-position (top left) y y-position
Definition at line 551 of file SPI_TFT.cpp.
| void pixel | ( | int | x, |
| int | y, | ||
| int | colour | ||
| ) | [virtual, inherited] |
Draw a pixel at x,y with color.
- Parameters:
-
x horizontal position y vertical position color 16 bit pixel color
Definition at line 241 of file SPI_TFT.cpp.
| unsigned short rd_dat | ( | void | ) | [protected, inherited] |
Read data from the LCD controller.
- Returns:
- data from LCD controller
Definition at line 110 of file SPI_TFT.cpp.
| unsigned short rd_reg | ( | unsigned char | reg ) | [protected, inherited] |
Read a LCD register.
- Parameters:
-
reg register to be read
- Returns:
- value of the register
Definition at line 133 of file SPI_TFT.cpp.
| void rect | ( | int | x0, |
| int | y0, | ||
| int | x1, | ||
| int | y1, | ||
| int | colour | ||
| ) | [inherited] |
draw a rect
- Parameters:
-
x0,y0 top left corner x1,y1 down right corner color 16 bit color *
Definition at line 512 of file SPI_TFT.cpp.
| int rows | ( | void | ) | [inherited] |
calculate the max number of columns
- Returns:
- max column depends on actual font size
Definition at line 564 of file SPI_TFT.cpp.
| void set_font | ( | unsigned char * | f ) | [inherited] |
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 637 of file SPI_TFT.cpp.
| void set_orientation | ( | unsigned int | o ) | [inherited] |
Set the orientation of the screen x,y: 0,0 is always top left.
- Parameters:
-
o direction to use the screen (0-3) 90� Steps
Definition at line 47 of file SPI_TFT.cpp.
| void tft_reset | ( | ) | [protected, inherited] |
Init the HX8347D controller.
Definition at line 141 of file SPI_TFT.cpp.
| point to_pixel | ( | point | a_point ) |
calculate coord on screen
- Parameters:
-
a_point point(analog x, analog y)
- Returns:
- point(pixel x, pixel y)
Definition at line 215 of file touch_tft.cpp.
| void vline | ( | int | y0, |
| int | y1, | ||
| int | x, | ||
| int | colour | ||
| ) | [protected, inherited] |
draw a vertical line
- Parameters:
-
x horizontal position y0 vertical start y1 vertical stop color 16 bit color
Definition at line 421 of file SPI_TFT.cpp.
| int width | ( | ) | [virtual, inherited] |
Get the width of the screen in pixel.
- Parameters:
-
@returns width of screen in pixel
Definition at line 34 of file SPI_TFT.cpp.
| void window | ( | unsigned int | x, |
| unsigned int | y, | ||
| unsigned int | w, | ||
| unsigned int | h | ||
| ) | [protected, inherited] |
Set draw window region.
- Parameters:
-
x horizontal position y vertical position w window width in pixel h window height in pixels
Definition at line 257 of file SPI_TFT.cpp.
| void WindowMax | ( | void | ) | [protected, inherited] |
Set draw window region to whole screen.
Definition at line 270 of file SPI_TFT.cpp.
| void wr_cmd | ( | int | value ) | [protected, inherited] |
Write a command the LCD controller.
- Parameters:
-
cmd,: command to be written
Definition at line 68 of file SPI_TFT.cpp.
| void wr_dat | ( | int | value ) | [protected, inherited] |
Write data to the LCD controller.
- Parameters:
-
dat data written to LCD controller
Definition at line 77 of file SPI_TFT.cpp.
| void wr_dat_only | ( | unsigned short | dat ) | [protected, inherited] |
write data to the LCD controller
- Parameters:
-
data to be written *
Definition at line 101 of file SPI_TFT.cpp.
| void wr_dat_start | ( | void | ) | [protected, inherited] |
Start data sequence to the LCD controller.
Definition at line 88 of file SPI_TFT.cpp.
| void wr_dat_stop | ( | void | ) | [protected, inherited] |
Stop of data writing to the LCD controller.
Definition at line 95 of file SPI_TFT.cpp.
| void wr_reg | ( | unsigned char | reg, |
| unsigned short | val | ||
| ) | [protected, inherited] |
Write a value to the to a LCD register.
- Parameters:
-
reg register to be written val data to be written
Definition at line 125 of file SPI_TFT.cpp.
Generated on Tue Jul 19 2022 21:47:14 by
1.7.2