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.
Diff: Picaso_4DGL-32PTU.h
- Revision:
- 2:81eaaa491a02
- Parent:
- 1:e2337e2653e1
- Child:
- 3:dcfbceb81fef
--- a/Picaso_4DGL-32PTU.h Thu Sep 08 13:40:36 2016 +0000
+++ b/Picaso_4DGL-32PTU.h Fri Sep 09 06:17:05 2016 +0000
@@ -1,7 +1,19 @@
//
-// TFT_4DGL is a class to drive 4D Systems TFT touch screens with Picaso processor
+// Picaso_4DGL-32PTU is a class to drive 4D Systems TFT touch screens with PICASO processor
+// Tested with NUCLEO L152RE development board
+// Copyright (C) <2016> Rihards Balass <rihards.balass@gmail.com>
//
-// Copyright (C) <2016> Rihards Balass
+// Picaso_4DGL-32PTU is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Picaso_4DGL-32PTU is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You can see GNU General Public License at <http://www.gnu.org/licenses/>.
//
#include "mbed.h"
@@ -11,81 +23,48 @@
#endif
// functions
-#define CHECK_BIT(var,pos) ((var) & (1<<(pos)))
+#define CHECK_BIT(var,pos) ((var) & (1<<(pos))) // to check if required bit is set
// Common WAIT value in millisecond
#define TEMPO 1
// Main Functions values
-#define CLS_MSB 0xFF
-#define CLS_LSB 0xCD
-#define BAUDRATE_MSB 0x00
-#define BAUDRATE_LSB 0x26
+#define CLS 0xFFCD
+#define BAUDRATE 0x0026
+#define ORIENTATION 0xFF9E
// text functions values
-#define TEXT_BG_COLOR_MSB 0xFF
-#define TEXT_BG_COLOR_LSB 0xE6
-#define SET_FONT_MSB 0xFF
-#define SET_FONT_LSB 0xE5
-#define PUT_CHAR_MSB 0xFF
-#define PUT_CHAR_LSB 0xFE
-#define PUT_STRING_MSB 0x00
-#define PUT_STRING_LSB 0x18
-#define MOVE_CURSOR_MSB 0xFF
-#define MOVE_CURSOR_LSB 0xE9
-#define TEXT_FG_COLOR_MSB 0xFF
-#define TEXT_FG_COLOR_LSB 0xE7
-#define TEXT_WIDTH_MSB 0xFF
-#define TEXT_WIDTH_LSB 0xE4
-#define TEXT_HEIGHT_MSB 0xFF
-#define TEXT_HEIGHT_LSB 0xE3
-#define TEXT_X_GAP_MSB 0xFF
-#define TEXT_X_GAP_LSB 0xE2
-#define TEXT_Y_GAP_MSB 0xFF
-#define TEXT_Y_GAP_LSB 0xE1
-#define TEXT_BOLD_MSB 0xFF
-#define TEXT_BOLD_LSB 0xDE
-#define TEXT_INVERSE_MSB 0xFF
-#define TEXT_INVERSE_LSB 0xDC
-#define TEXT_ITALIC_MSB 0xFF
-#define TEXT_ITALIC_LSB 0xDD
-#define TEXT_OPACITY_MSB 0xFF
-#define TEXT_OPACITY_LSB 0xDF
-#define TEXT_UNDERLINE_MSB 0xFF
-#define TEXT_UNDERLINE_LSB 0xDB
-#define TEXT_ATTRIBUTES_MSB 0xFF
-#define TEXT_ATTRIBUTES_LSB 0xDA
+#define TEXT_BG_COLOR 0xFFE6
+#define SET_FONT 0xFFE5
+#define PUT_CHAR 0xFFFE
+#define PUT_STRING 0x0018
+#define MOVE_CURSOR 0xFFE9
+#define TEXT_FG_COLOR 0xFFE7
+#define TEXT_WIDTH 0xFFE4
+#define TEXT_HEIGHT 0xFFE3
+#define TEXT_X_GAP 0xFFE2
+#define TEXT_Y_GAP 0xFFE1
+#define TEXT_BOLD 0xFFDE
+#define TEXT_INVERSE 0xFFDC
+#define TEXT_ITALIC 0xFFDD
+#define TEXT_OPACITY 0xFFDF
+#define TEXT_UNDERLINE 0xFFDB
+#define TEXT_ATTRIBUTES 0xFFDA
// graphics functions values
-#define CHANGE_COLOR_MSB 0xFF
-#define CHANGE_COLOR_LSB 0xB4
-#define DRAW_CIRCLE_MSB 0xFF
-#define DRAW_CIRCLE_LSB 0xC3
+#define CHANGE_COLOR 0xFFB4
+#define DRAW_CIRCLE 0xFFC3
+#define DRAW_F_CIRCLE 0xFFC2
// Screen answers
#define ACK 0x06
#define NACK 0x15
-// Screen states
-#define OFF '\x00'
-#define ON '\x01'
-
-// Graphics modes
-#define SOLID '\x00'
-#define WIREFRAME '\x01'
-
-// Text modes
-#define TRANSPARENT '\x00'
-#define OPAQUE '\x01'
-
// Predefined Fonts
-#define FONT1_MSB 0x00
-#define FONT1_LSB 0x00
-#define FONT2_MSB 0x00
-#define FONT2_LSB 0x01
-#define FONT3_MSB 0x00
-#define FONT3_LSB 0x02
+#define FONT1 0x0000
+#define FONT2 0x0001
+#define FONT3 0x0002
// Line and column values depending on orientation and font F1LL = font1 landscape line
#define F1LL 29
@@ -103,132 +82,71 @@
#define F3PL 26
#define F3PC 29
-// Touch Values
-#define WAIT '\x00'
-#define PRESS '\x01'
-#define RELEASE '\x02'
-#define MOVE '\x03'
-#define STATUS '\x04'
-#define GETPOSITION '\x05'
-
// Data speed
-#define BAUD_300_MSB 0x00
-#define BAUD_300_LSB 0x01
-#define BAUD_600_MSB 0x00
-#define BAUD_600_LSB 0x02
-#define BAUD_1200_MSB 0x00
-#define BAUD_1200_LSB 0x03
-#define BAUD_2400_MSB 0x00
-#define BAUD_2400_LSB 0x04
-#define BAUD_4800_MSB 0x00
-#define BAUD_4800_LSB 0x05
-#define BAUD_9600_MSB 0x00
-#define BAUD_9600_LSB 0x06
-#define BAUD_14400_MSB 0x00
-#define BAUD_14400_LSB 0x07
-#define BAUD_19200_MSB 0x00
-#define BAUD_19200_LSB 0x08
-#define BAUD_38400_MSB 0x00
-#define BAUD_38400_LSB 0x0A
-#define BAUD_56000_MSB 0x00
-#define BAUD_56000_LSB 0x0B
-#define BAUD_57600_MSB 0x00
-#define BAUD_57600_LSB 0x0C
-#define BAUD_115200_MSB 0x00
-#define BAUD_115200_LSB 0x0D
-#define BAUD_128000_MSB 0x0E
-#define BAUD_128000_LSB 0x0E
-#define BAUD_256000_MSB 0x0F
-#define BAUD_256000_LSB 0x0F
-#define BAUD_300000_MSB 0x10
-#define BAUD_300000_LSB 0x10
-#define BAUD_375000_MSB 0x11
-#define BAUD_375000_LSB 0x11
-#define BAUD_500000_MSB 0x12
-#define BAUD_500000_LSB 0x12
-#define BAUD_600000_MSB 0x13
-#define BAUD_600000_LSB 0x13
+#define BAUD_300 0x0001
+#define BAUD_600 0x0002
+#define BAUD_1200 0x0003
+#define BAUD_2400 0x0004
+#define BAUD_4800 0x0005
+#define BAUD_9600 0x0006
+#define BAUD_14400 0x0007
+#define BAUD_19200 0x0008
+#define BAUD_31250 0x0009
+#define BAUD_38400 0x000A
+#define BAUD_56000 0x000B
+#define BAUD_57600 0x000C
+#define BAUD_115200 0x000D
+#define BAUD_128000 0x000E
+#define BAUD_256000 0x000F
+#define BAUD_300000 0x0010
+#define BAUD_375000 0x0011
+#define BAUD_500000 0x0012
+#define BAUD_600000 0x0013
// Defined Colors
-#define BLACK_MSB 0x00
-#define BLACK_LSB 0x00
-#define NAVY_MSB 0x00
-#define NAVY_LSB 0x0F
-#define DGREEN_MSB 0x03
-#define DGREEN_LSB 0xE0
-#define DCYAN_MSB 0x03
-#define DCYAN_LSB 0xEF
-#define PURPLE_MSB 0x78
-#define PURPLE_LSB 0x0F
-#define OLIVE_MSB 0x7B
-#define OLIVE_LSB 0xE0
-#define GREY_MSB 0x84
-#define GREY_LSB 0x10
-#define BLUE_MSB 0x00
-#define BLUE_LSB 0x1F
-#define GREEN_MSB 0x07
-#define GREEN_LSB 0xE0
-#define RED_MSB 0xF8
-#define RED_LSB 0x00
-#define YELLOW_MSB 0xFF
-#define YELLOW_LSB 0xE0
-#define WHITE_MSB 0xFF
-#define WHITE_LSB 0xFF
-#define ORANGE_MSB 0xFD
-#define ORANGE_LSB 0x20
-#define G_YELLOW_MSB 0xAF
-#define G_YELLOW_LSB 0xE5
-#define PINK_MSB 0xF8
-#define PINK_LSB 0x1F
-#define VIOLET_MSB 0x90
-#define VIOLET_LSB 0x1A
-#define AQUA_MSB 0x07
-#define AQUA_LSB 0xFF
-#define CREAM_MSB 0xFF
-#define CREAM_LSB 0xDE
-
-// Mode data
-#define BACKLIGHT '\x00'
-#define DISPLAY '\x01'
-#define CONTRAST '\x02'
-#define POWER '\x03'
-#define ORIENTATION_MSB '\xFF'
-#define ORIENTATION_LSB '\x9E'
-#define TOUCH_CTRL '\x05'
-#define IMAGE_FORMAT '\x06'
-#define PROTECT_FAT '\x08'
-
-// change this to your specific screen (newer versions) if needed
-// Startup orientation is PORTRAIT so SIZE_X must be lesser than SIZE_Y
-//#define SIZE_X 240
-//#define SIZE_Y 320
-
-//#define IS_LANDSCAPE 0
-//#define IS_PORTRAIT 1
+#define Black 0x0000
+#define Navy 0x000F
+#define DGreen 0x03E0
+#define DCyan 0x03EF
+#define Purple 0x780F
+#define Olive 0x7BE0
+#define Grey 0x8410
+#define Blue 0x001F
+#define Green 0x07E0
+#define Red 0xF800
+#define Yellow 0xFFE0
+#define White 0xFFFF
+#define Orange 0xFD20
+#define GYellow 0xAFE5
+#define Pink 0xF81F
+#define Violet 0x901A
+#define Aqua 0x07FF
+#define Cream 0xFFDE
// Screen orientation
-#define LANDSCAPE_MSB 0x00
-#define LANDSCAPE_LSB 0x00
-#define LANDSCAPE_R_MSB 0x00
-#define LANDSCAPE_R_LSB 0x01
-#define PORTRAIT_MSB 0x00
-#define PORTRAIT_LSB 0x02
-#define PORTRAIT_R_MSB 0x00
-#define PORTRAIT_R_LSB 0x03
+#define LANDSCAPE 0x0000
+#define LANDSCAPE_R 0x0001
+#define PORTRAIT 0x0002
+#define PORTRAIT_R 0x0003
// Parameters
-//#define ENABLE '\x00'
-//#define DISABLE '\x01'
-//#define RESET '\x02'
+#define ENABLE 1
+#define DISABLE 0
+
+#define landscape 1
+#define landscapeRew 2
+#define portrait 3
+#define portraitRew 4
-//#define NEW '\x00'
-//#define OLD '\x01'
+#define bold 16
+#define italic 32
+#define inverse 64
+#define underline 128
-//#define DOWN '\x00'
-//#define UP '\x01'
+#define font1 1
+#define font2 2
+#define font3 3
-//#define PROTECT '\x00'
-//#define UNPROTECT '\x02'
//**************************************************************************
class TFT_4DGL {
@@ -252,89 +170,38 @@
// Graphics Commands
void cls(); // clear screen
- void changeColor(char, char, char, char); // change one color to another
- void drawCircle(short, short, short, char, char);
- //void circle(int, int, int, int);
- //void triangle(int, int, int, int, int, int, int);
- //void line(int, int, int, int, int);
- //void rectangle(int, int, int, int, int);
- //void ellipse(int, int, int, int, int);
- //void pixel(int, int, int);
- //int read_pixel(int, int);
- //void screen_copy(int, int, int, int, int, int);
- //void pen_size(char);
- //void SD_Card_Wav(char[]);
- //void Set_Volume(char);
- //void uSD_FAT_Image(char[], int, int, long);
- //void uSD_Image(int, int, long);
- //void uSD_Video(int, int, long);
-
+ void changeColor(short, short); // change one color to another
+ void drawCircle(short, short, short, short); // draw a circle (x, y, radius, color)
+
// Texts Commands
void setFont(char); // set desired font from embedded fonts
char moveCursor(short, short); // move cursot to a specific location
char validateMoveCursor(short, short); // check if requested values are not out of range, based on font and orientation
- void textBgColor(char, char); // set background color of next text messages
+ void textBgColor(short); // set background color of next text messages
void putc(char); // send a single character to LCD
void puts(char *); // send a string to LCD
- void textFgColor(char, char); // set text color
- int textWidth(short);
- int textHeight(short);
- int textXGap(short);
- int textYGap(short);
- void textBold(short);
- void textInverse(short);
- void textItalic(short);
- void textOpacity(short);
- void textUnderline(short);
- void textAttributes(short);
-
-
- //void text_mode(char);
- //void textChar(char);
- //void graphic_char(char, int, int, int, char, char);
- //void textString(char *); // +
- //void graphic_string(char *, int, int, char, int, char, char);
- //void text_button(char *, char, int, int, int, char, int, char, char);
-
- //void locate(char, char);
-
-// Touch Command
- //void touch_mode(char);
- //void get_touch(int *, int *);
- //void wait_touch(int);
- //void set_touch(int, int, int, int);
- //int touch_status(void);
- //void Pause_Until_Touch(int *, int *);
-
-// Screen Data
- //int type;
- //int revision;
- //int firmware;
- //int reserved1;
- //int reserved2;
+ void textFgColor(short); // set text color
+ int textWidth(short); // set width of a text
+ int textHeight(short); // set text height
+ int textXGap(short); // set gap between characters in pixels (X axis)
+ int textYGap(short); // set gap between characters in pixels (Y axis)
+ void textBold(short); // set text to bold
+ void textInverse(short); // invert text BG and FG colors
+ void textItalic(short); // set text to italic
+ void textOpacity(short); // set text opacity
+ void textUnderline(short); // set text to underline
+ void textAttributes(short); // set 4 attributes (bold, italic, inverse, underline)
// Text data
- char currentFont;
- char currentOrientation;
+ char currentFont; // stores current used font
+ char currentOrientation; // stores current orientation
- //char current_col;
- //char current_row;
- //int current_color;
- //char max_col;
- //char max_row;
-
protected :
- Serial _cmd;
- DigitalOut _rst;
+ Serial _cmd; // serial variable, to comunicate with screen
+ DigitalOut _rst; // screen reset pin
void freeBUFFER (void);
void writeBYTE (char);
- void writeCOMMAND(char *, int);
- //int readVERSION (char *, int);
- //void getTOUCH (char *, int, int *,int *);
- //int getSTATUS (char *, int);
- //void version (void);
+ void writeCOMMAND(char *, int); // send command to screen
};
-
-typedef unsigned char BYTE;
\ No newline at end of file