Rihards Balass / 4DGL-mbed-32PTU
Revision:
0:a5ef6bc3c2e8
Child:
1:e2337e2653e1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Picaso_4DGL-32PTU.h	Thu Sep 08 13:35:36 2016 +0000
@@ -0,0 +1,352 @@
+//
+// TFT_4DGL is a class to drive 4D Systems TFT touch screens
+//
+// Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr>
+//
+// TFT_4DGL 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.
+//
+// TFT_4DGL 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 should have received a copy of the GNU General Public License
+// along with TFT_4DGL.  If not, see <http://www.gnu.org/licenses/>.
+
+#include "mbed.h"
+
+#ifndef DEBUGMODE
+#define DEBUGMODE 1
+#endif
+
+// functions
+#define CHECK_BIT(var,pos) ((var) & (1<<(pos)))
+
+// 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
+
+// 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
+
+// graphics functions values
+#define CHANGE_COLOR_MSB    0xFF
+#define CHANGE_COLOR_LSB    0xB4
+#define DRAW_CIRCLE_MSB    0xFF
+#define DRAW_CIRCLE_LSB    0xC3
+
+
+// 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
+
+// Line and column values depending on orientation and font F1LL = font1 landscape line
+#define F1LL    29
+#define F1LC    44
+#define F1PL    39
+#define F1PC    33
+
+#define F2LL    29
+#define F2LC    39
+#define F2PL    39
+#define F2PC    29
+
+#define F3LL    19
+#define F3LC    39
+#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
+
+// 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
+
+// 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
+
+// Parameters
+//#define ENABLE       '\x00'
+//#define DISABLE      '\x01'
+//#define RESET        '\x02'
+
+//#define NEW          '\x00'
+//#define OLD          '\x01'
+
+//#define DOWN         '\x00'
+//#define UP           '\x01'
+
+//#define PROTECT      '\x00'
+//#define UNPROTECT    '\x02'
+
+//**************************************************************************
+class TFT_4DGL {
+
+public :
+
+    Serial pc; // serial variable for debug information
+    TFT_4DGL(PinName tx, PinName rx, PinName rst); // LCD serial construnctor
+    int resp, respLen; // received response from screen
+    char response[];
+    
+// General Commands
+    void getResponse();
+    void responseBuild(int, char);
+    void reset(); // reset screen
+    void baudrate(long); // set baudrate
+    void screenOrientation(char); // set desired orientation of a screen
+    void mainDemo(); // play demo with text based functions
+    void textDemo(); // play demo with text based functions
+    void graphicsDemo(); // play demo with text based functions
+
+// 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);
+
+// 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 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;
+
+// Text data
+    char currentFont;
+    char currentOrientation;
+    
+    //char current_col;
+    //char current_row;
+    //int  current_color;
+    //char max_col;
+    //char max_row;
+
+protected :
+
+    Serial     _cmd;
+    DigitalOut _rst;
+
+    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);
+};
+
+typedef unsigned char BYTE;
\ No newline at end of file