BayEOS-Arduino  1.8.0_0.0.4
UTFT.h
1 /*
2  UTFT.h - Multi-Platform library support for Color TFT LCD Boards
3  Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved
4 
5  This library is the continuation of my ITDB02_Graph, ITDB02_Graph16
6  and RGB_GLCD libraries for Arduino and chipKit. As the number of
7  supported display modules and controllers started to increase I felt
8  it was time to make a single, universal library as it will be much
9  easier to maintain in the future.
10 
11  Basic functionality of this library was origianlly based on the
12  demo-code provided by ITead studio (for the ITDB02 modules) and
13  NKC Electronics (for the RGB GLCD module/shield).
14 
15  This library supports a number of 8bit, 16bit and serial graphic
16  displays, and will work with both Arduino, chipKit boards and select
17  TI LaunchPads. For a full list of tested display modules and controllers,
18  see the document UTFT_Supported_display_modules_&_controllers.pdf.
19 
20  When using 8bit and 16bit display modules there are some
21  requirements you must adhere to. These requirements can be found
22  in the document UTFT_Requirements.pdf.
23  There are no special requirements when using serial displays.
24 
25  You can find the latest version of the library at
26  http://www.RinkyDinkElectronics.com/
27 
28  This library is free software; you can redistribute it and/or
29  modify it under the terms of the CC BY-NC-SA 3.0 license.
30  Please see the included documents for further information.
31 
32  Commercial use of this library requires you to buy a license that
33  will allow commercial use. This includes using the library,
34  modified or not, as a tool to sell products.
35 
36  The license applies to all part of the library including the
37  examples and tools supplied with the library.
38 */
39 
40 #ifndef UTFT_h
41 #define UTFT_h
42 
43 #define UTFT_VERSION 281
44 
45 #define LEFT 0
46 #define RIGHT 9999
47 #define CENTER 9998
48 
49 #define PORTRAIT 0
50 #define LANDSCAPE 1
51 
52 #define HX8347A 0
53 #define ILI9327 1
54 #define SSD1289 2
55 #define ILI9325C 3
56 #define ILI9325D_8 4
57 #define ILI9325D_16 5
58 #define HX8340B_8 6
59 #define HX8340B_S 7
60 #define HX8352A 8
61 #define ST7735 9
62 #define PCF8833 10
63 #define S1D19122 11
64 #define SSD1963_480 12
65 #define SSD1963_800 13
66 #define S6D1121_8 14
67 #define S6D1121_16 15
68 #define SSD1289LATCHED 16
69 //#define NOT_IN_USE 17
70 //#define NOT_IN_USE 18
71 #define SSD1289_8 19
72 #define SSD1963_800ALT 20
73 #define ILI9481 21
74 #define ILI9325D_16ALT 22
75 #define S6D0164 23
76 #define ST7735S 24
77 #define ILI9341_S5P 25
78 #define ILI9341_S4P 26
79 #define R61581 27
80 #define ILI9486 28
81 #define CPLD 29
82 #define HX8353C 30
83 #define ST7735_ALT 31
84 
85 #define ITDB32 0 // HX8347-A (16bit)
86 #define ITDB32WC 1 // ILI9327 (16bit)
87 #define TFT01_32W 1 // ILI9327 (16bit)
88 #define ITDB32S 2 // SSD1289 (16bit)
89 #define TFT01_32 2 // SSD1289 (16bit)
90 #define CTE32 2 // SSD1289 (16bit)
91 #define ITDB24 3 // ILI9325C (8bit)
92 #define ITDB24D 4 // ILI9325D (8bit)
93 #define ITDB24DWOT 4 // ILI9325D (8bit)
94 #define ITDB28 4 // ILI9325D (8bit)
95 #define TFT01_24_8 4 // ILI9325D (8bit)
96 #define DMTFT24104 4 // ILI9325D (8bit)
97 #define DMTFT28103 4 // ILI9325D (8bit)
98 #define TFT01_24_16 5 // ILI9325D (16bit)
99 #define ITDB22 6 // HX8340-B (8bit)
100 #define ITDB22SP 7 // HX8340-B (Serial 4Pin)
101 #define ITDB32WD 8 // HX8352-A (16bit)
102 #define TFT01_32WD 8 // HX8352-A (16bit)
103 #define CTE32W 8 // HX8352-A (16bit)
104 #define ITDB18SP 9 // ST7735 (Serial 5Pin)
105 #define LPH9135 10 // PCF8833 (Serial 5Pin)
106 #define ITDB25H 11 // S1D19122 (16bit)
107 #define ITDB43 12 // SSD1963 (16bit) 480x272
108 #define TFT01_43 12 // SSD1963 (16bit) 480x272
109 #define ITDB50 13 // SSD1963 (16bit) 800x480
110 #define TFT01_50 13 // SSD1963 (16bit) 800x480
111 #define CTE50 13 // SSD1963 (16bit) 800x480
112 #define EHOUSE50 13 // SSD1963 (16bit) 800x480
113 #define ITDB24E_8 14 // S6D1121 (8bit)
114 #define TFT01_24R2 14 // S6D1121 (8bit)
115 #define ITDB24E_16 15 // S6D1121 (16bit)
116 #define INFINIT32 16 // SSD1289 (Latched 16bit) -- Legacy, will be removed later
117 #define ELEE32_REVA 16 // SSD1289 (Latched 16bit)
118 //#define NOT_IN_USE 17
119 //#define NOT_IN_USE 18
120 #define ELEE32_REVB 19 // SSD1289 (8bit)
121 #define TFT01_70 20 // SSD1963 (16bit) 800x480 Alternative Init
122 #define CTE70 20 // SSD1963 (16bit) 800x480 Alternative Init
123 #define EHOUSE70 20 // SSD1963 (16bit) 800x480 Alternative Init
124 #define CTE32HR 21 // ILI9481 (16bit)
125 #define CTE28 22 // ILI9325D (16bit) Alternative Init
126 #define TFT01_28 22 // ILI9325D (16bit) Alternative Init
127 #define CTE22 23 // S6D0164 (8bit)
128 #define TFT01_22 23 // S6D0164 (8bit)
129 #define DMTFT22102 23 // S6D0164 (8bit)
130 #define TFT01_18SP 24 // ST7735S (Serial 5Pin)
131 #define TFT01_22SP 25 // ILI9341 (Serial 5Pin)
132 #define TFT01_24SP 25 // ILI9341 (Serial 5Pin)
133 #define TFT22SHLD 25 // ILI9341 (Serial 5Pin)
134 #define DMTFT28105 25 // ILI9341 (Serial 5Pin)
135 #define MI0283QT9 26 // ILI9341 (Serial 4Pin)
136 #define CTE35IPS 27 // R61581 (16bit)
137 #define CTE40 28 // ILI9486 (16bit)
138 #define EHOUSE50CPLD 29 // CPLD (16bit)
139 #define CTE50CPLD 29 // CPLD (16bit)
140 #define CTE70CPLD 29 // CPLD (16bit)
141 #define DMTFT18101 30 // HX8353C (Serial 5Pin)
142 #define TFT18SHLD 31 // ST7735 (Serial 5Pin) Alternative Init
143 
144 #define SERIAL_4PIN 4
145 #define SERIAL_5PIN 5
146 #define LATCHED_16 17
147 
148 #define NOTINUSE 255
149 
150 //*********************************
151 // COLORS
152 //*********************************
153 // VGA color palette
154 #define VGA_BLACK 0x0000
155 #define VGA_WHITE 0xFFFF
156 #define VGA_RED 0xF800
157 #define VGA_GREEN 0x0400
158 #define VGA_BLUE 0x001F
159 #define VGA_SILVER 0xC618
160 #define VGA_GRAY 0x8410
161 #define VGA_MAROON 0x8000
162 #define VGA_YELLOW 0xFFE0
163 #define VGA_OLIVE 0x8400
164 #define VGA_LIME 0x07E0
165 #define VGA_AQUA 0x07FF
166 #define VGA_TEAL 0x0410
167 #define VGA_NAVY 0x0010
168 #define VGA_FUCHSIA 0xF81F
169 #define VGA_PURPLE 0x8010
170 #define VGA_TRANSPARENT 0xFFFFFFFF
171 
172 #if defined(__AVR__)
173  #include "Arduino.h"
174  #include "hardware/avr/HW_AVR_defines.h"
175 #elif defined(__PIC32MX__)
176  #include "WProgram.h"
177  #include "hardware/pic32/HW_PIC32_defines.h"
178 #elif defined(__arm__)
179  #include "Arduino.h" // This will include energia.h where appropriate
180  #include "hardware/arm/HW_ARM_defines.h"
181 #endif
182 
184 {
185  uint8_t* font;
186  uint8_t x_size;
187  uint8_t y_size;
188  uint8_t offset;
189  uint8_t numchars;
190 };
191 
192 class UTFT
193 {
194  public:
195  UTFT();
196  UTFT(byte model, int RS, int WR, int CS, int RST, int SER=0);
197  void InitLCD(byte orientation=LANDSCAPE);
198  void clrScr();
199  void drawPixel(int x, int y);
200  void drawLine(int x1, int y1, int x2, int y2);
201  void fillScr(byte r, byte g, byte b);
202  void fillScr(word color);
203  void drawRect(int x1, int y1, int x2, int y2);
204  void drawRoundRect(int x1, int y1, int x2, int y2);
205  void fillRect(int x1, int y1, int x2, int y2);
206  void fillRoundRect(int x1, int y1, int x2, int y2);
207  void drawCircle(int x, int y, int radius);
208  void fillCircle(int x, int y, int radius);
209  void setColor(byte r, byte g, byte b);
210  void setColor(word color);
211  word getColor();
212  void setBackColor(byte r, byte g, byte b);
213  void setBackColor(uint32_t color);
214  word getBackColor();
215  void print(char *st, int x, int y, int deg=0);
216  void print(String st, int x, int y, int deg=0);
217  void printNumI(long num, int x, int y, int length=0, char filler=' ');
218  void printNumF(double num, byte dec, int x, int y, char divider='.', int length=0, char filler=' ');
219  void setFont(uint8_t* font);
220  uint8_t* getFont();
221  uint8_t getFontXsize();
222  uint8_t getFontYsize();
223  void drawBitmap(int x, int y, int sx, int sy, bitmapdatatype data, int scale=1);
224  void drawBitmap(int x, int y, int sx, int sy, bitmapdatatype data, int deg, int rox, int roy);
225  void lcdOff();
226  void lcdOn();
227  void setContrast(char c);
228  int getDisplayXSize();
229  int getDisplayYSize();
230  void setBrightness(byte br);
231  void setDisplayPage(byte page);
232  void setWritePage(byte page);
233 
234 /*
235  The functions and variables below should not normally be used.
236  They have been left publicly available for use in add-on libraries
237  that might need access to the lower level functions of UTFT.
238 
239  Please note that these functions and variables are not documented
240  and I do not provide support on how to use them.
241 */
242  byte fch, fcl, bch, bcl;
243  byte orient;
244  long disp_x_size, disp_y_size;
245  byte display_model, display_transfer_mode, display_serial_mode;
246  regtype *P_RS, *P_WR, *P_CS, *P_RST, *P_SDA, *P_SCL, *P_ALE;
247  regsize B_RS, B_WR, B_CS, B_RST, B_SDA, B_SCL, B_ALE;
248  byte __p1, __p2, __p3, __p4, __p5;
249  _current_font cfont;
250  boolean _transparent;
251 
252  void LCD_Writ_Bus(char VH,char VL, byte mode);
253  void LCD_Write_COM(char VL);
254  void LCD_Write_DATA(char VH,char VL);
255  void LCD_Write_DATA(char VL);
256  void LCD_Write_COM_DATA(char com1,int dat1);
257  void _hw_special_init();
258  void setPixel(word color);
259  void drawHLine(int x, int y, int l);
260  void drawVLine(int x, int y, int l);
261  void printChar(byte c, int x, int y);
262  void setXY(word x1, word y1, word x2, word y2);
263  void clrXY();
264  void rotateChar(byte c, int x, int y, int pos, int deg);
265  void _set_direction_registers(byte mode);
266  void _fast_fill_16(int ch, int cl, long pix);
267  void _fast_fill_8(int ch, long pix);
268  void _convert_float(char *buf, double num, int width, byte prec);
269 
270 #if defined(ENERGIA)
271  volatile uint32_t* portOutputRegister(int value);
272 #endif
273 };
274 
275 #endif
Definition: UTFT.h:192