BayEOSArduino Library
UTFT.h
1 /*
2  UTFT.h - Arduino/chipKit library support for Color TFT LCD Boards
3  Copyright (C)2010-2013 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 and chipKit boards. For a
17  full list of tested display modules and controllers, see the
18  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 always find the latest version of the library at
26  http://electronics.henningkarlsen.com/
27 
28  If you make any modifications or improvements to the code, I would
29  appreciate that you share the code with me so that I might include
30  it in the next release. I can be contacted through
31  http://electronics.henningkarlsen.com/contact.php.
32 
33  This library is free software; you can redistribute it and/or
34  modify it under the terms of the CC BY-NC-SA 3.0 license.
35  Please see the included documents for further information.
36 */
37 
38 #ifndef UTFT_h
39 #define UTFT_h
40 
41 #define UTFT_VERSION 241
42 
43 #define LEFT 0
44 #define RIGHT 9999
45 #define CENTER 9998
46 
47 #define PORTRAIT 0
48 #define LANDSCAPE 1
49 
50 #define HX8347A 0
51 #define ILI9327 1
52 #define SSD1289 2
53 #define ILI9325C 3
54 #define ILI9325D_8 4
55 #define ILI9325D_16 5
56 #define HX8340B_8 6
57 #define HX8340B_S 7
58 #define HX8352A 8
59 #define ST7735 9
60 #define PCF8833 10
61 #define S1D19122 11
62 #define SSD1963_480 12
63 #define SSD1963_800 13
64 #define S6D1121_8 14
65 #define S6D1121_16 15
66 #define SSD1289LATCHED 16
67 #define ILI9320_8 17
68 #define ILI9320_16 18
69 #define SSD1289_8 19
70 #define SSD1963_800ALT 20
71 #define ILI9481 21
72 
73 #define ITDB32 0 // HX8347-A (16bit)
74 #define ITDB32WC 1 // ILI9327 (16bit)
75 #define TFT01_32W 1 // ILI9327 (16bit)
76 #define ITDB32S 2 // SSD1289 (16bit)
77 #define TFT01_32 2 // SSD1289 (16bit)
78 #define CTE32 2 // SSD1289 (16bit)
79 #define GEEE32 2 // SSD1289 (16bit)
80 #define ITDB24 3 // ILI9325C (8bit)
81 #define ITDB24D 4 // ILI9325D (8bit)
82 #define ITDB24DWOT 4 // ILI9325D (8bit)
83 #define ITDB28 4 // ILI9325D (8bit)
84 #define TFT01_24_8 4 // ILI9325D (8bit)
85 #define TFT01_24_16 5 // ILI9325D (16bit)
86 #define ITDB22 6 // HX8340-B (8bit)
87 #define GEEE22 6 // HX8340-B (8bit)
88 #define ITDB22SP 7 // HX8340-B (Serial)
89 #define ITDB32WD 8 // HX8352-A (16bit)
90 #define TFT01_32WD 8 // HX8352-A (16bit)
91 #define ITDB18SP 9 // ST7735 (Serial)
92 #define LPH9135 10 // PCF8833 (Serial)
93 #define ITDB25H 11 // S1D19122 (16bit)
94 #define ITDB43 12 // SSD1963 (16bit) 480x272
95 #define ITDB50 13 // SSD1963 (16bit) 800x480
96 #define TFT01_50 13 // SSD1963 (16bit) 800x480
97 #define CTE50 13 // SSD1963 (16bit) 800x480
98 #define ITDB24E_8 14 // S6D1121 (8bit)
99 #define ITDB24E_16 15 // S6D1121 (16bit)
100 #define INFINIT32 16 // SSD1289 (Latched 16bit) -- Legacy, will be removed later
101 #define ELEE32_REVA 16 // SSD1289 (Latched 16bit)
102 #define GEEE24 17 // ILI9320 (8bit)
103 #define GEEE28 18 // ILI9320 (16bit)
104 #define ELEE32_REVB 19 // SSD1289 (8bit)
105 #define TFT01_70 20 // SSD1963 (16bit) 800x480 Alternative Init
106 #define CTE70 20 // SSD1963 (16bit) 800x480 Alternative Init
107 #define CTE32HR 21 // ILI9481 (16bit)
108 
109 #define SERIAL_4PIN 4
110 #define SERIAL_5PIN 5
111 #define LATCHED_16 17
112 
113 //*********************************
114 // COLORS
115 //*********************************
116 // VGA color palette
117 #define VGA_BLACK 0x0000
118 #define VGA_WHITE 0xFFFF
119 #define VGA_RED 0xF800
120 #define VGA_GREEN 0x0400
121 #define VGA_BLUE 0x001F
122 #define VGA_SILVER 0xC618
123 #define VGA_GRAY 0x8410
124 #define VGA_MAROON 0x8000
125 #define VGA_YELLOW 0xFFE0
126 #define VGA_OLIVE 0x8400
127 #define VGA_LIME 0x07E0
128 #define VGA_AQUA 0x07FF
129 #define VGA_TEAL 0x0410
130 #define VGA_NAVY 0x0010
131 #define VGA_FUCHSIA 0xF81F
132 #define VGA_PURPLE 0x8010
133 #define VGA_TRANSPARENT 0xFFFFFFFF
134 
135 #if defined(__AVR__)
136  #include "Arduino.h"
137  #include "hardware/avr/HW_AVR_defines.h"
138 #elif defined(__PIC32MX__)
139  #include "WProgram.h"
140  #include "hardware/pic32/HW_PIC32_defines.h"
141 #elif defined(__arm__)
142  #include "Arduino.h"
143  #include "hardware/arm/HW_ARM_defines.h"
144 #endif
145 
147 {
148  uint8_t* font;
149  uint8_t x_size;
150  uint8_t y_size;
151  uint8_t offset;
152  uint8_t numchars;
153 };
154 
155 class UTFT
156 {
157  public:
158  UTFT();
159  UTFT(byte model, int RS, int WR,int CS, int RST, int SER=0);
160  void InitLCD(byte orientation=LANDSCAPE);
161  void clrScr();
162  void drawPixel(int x, int y);
163  void drawLine(int x1, int y1, int x2, int y2);
164  void fillScr(byte r, byte g, byte b);
165  void fillScr(word color);
166  void drawRect(int x1, int y1, int x2, int y2);
167  void drawRoundRect(int x1, int y1, int x2, int y2);
168  void fillRect(int x1, int y1, int x2, int y2);
169  void fillRoundRect(int x1, int y1, int x2, int y2);
170  void drawCircle(int x, int y, int radius);
171  void fillCircle(int x, int y, int radius);
172  void setColor(byte r, byte g, byte b);
173  void setColor(word color);
174  word getColor();
175  void setBackColor(byte r, byte g, byte b);
176  void setBackColor(uint32_t color);
177  word getBackColor();
178  void print(char *st, int x, int y, int deg=0);
179  void print(String st, int x, int y, int deg=0);
180  void printNumI(long num, int x, int y, int length=0, char filler=' ');
181  void printNumF(double num, byte dec, int x, int y, char divider='.', int length=0, char filler=' ');
182  void setFont(uint8_t* font);
183  uint8_t* getFont();
184  uint8_t getFontXsize();
185  uint8_t getFontYsize();
186  void drawBitmap(int x, int y, int sx, int sy, bitmapdatatype data, int scale=1);
187  void drawBitmap(int x, int y, int sx, int sy, bitmapdatatype data, int deg, int rox, int roy);
188  void lcdOff();
189  void lcdOn();
190  void setContrast(char c);
191  int getDisplayXSize();
192  int getDisplayYSize();
193 
194 /*
195  The functions and variables below should not normally be used.
196  They have been left publicly available for use in add-on libraries
197  that might need access to the lower level functions of UTFT.
198 
199  Please note that these functions and variables are not documented
200  and I do not provide support on how to use them.
201 */
202  byte fch, fcl, bch, bcl;
203  byte orient;
204  long disp_x_size, disp_y_size;
205  byte display_model, display_transfer_mode, display_serial_mode;
206  regtype *P_RS, *P_WR, *P_CS, *P_RST, *P_SDA, *P_SCL, *P_ALE;
207  regsize B_RS, B_WR, B_CS, B_RST, B_SDA, B_SCL, B_ALE;
208  _current_font cfont;
209  boolean _transparent;
210 
211  void LCD_Writ_Bus(char VH,char VL, byte mode);
212  void LCD_Write_COM(char VL);
213  void LCD_Write_DATA(char VH,char VL);
214  void LCD_Write_DATA(char VL);
215  void LCD_Write_COM_DATA(char com1,int dat1);
216  void _hw_special_init();
217  void setPixel(word color);
218  void drawHLine(int x, int y, int l);
219  void drawVLine(int x, int y, int l);
220  void printChar(byte c, int x, int y);
221  void setXY(word x1, word y1, word x2, word y2);
222  void clrXY();
223  void rotateChar(byte c, int x, int y, int pos, int deg);
224  void _set_direction_registers(byte mode);
225  void _fast_fill_16(int ch, int cl, long pix);
226  void _fast_fill_8(int ch, long pix);
227  void _convert_float(char *buf, double num, int width, byte prec);
228 };
229 
230 #endif
Definition: UTFT.h:156
Definition: UTFT.h:147