-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTFT_PARALLEL_ESP8266.CPP
376 lines (335 loc) · 11.3 KB
/
TFT_PARALLEL_ESP8266.CPP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
#include "TFT_PARALLEL_ESP8266.h"
uint32_t xset_mask[256]; // For macros
/*****************************************************************************
** TFT_PARALLEL_ESP8266 CONSTRUCTOR
/*****************************************************************************/
TFT_PARALLEL_ESP8266::TFT_PARALLEL_ESP8266(void) : Adafruit_GFX(TFTWIDTH, TFTHEIGHT)
{
CONSTRUCTOR_INIT_TFT_DATA_BUS;
_width=320; _height=480;
delay(1000);
PIN16_LOW();
//setResolution(TFT_WIDTH,TFT_HEIGHT);
pinMode(TFT_D0,OUTPUT);
pinMode(TFT_D1,OUTPUT);
pinMode(TFT_D2,OUTPUT);
pinMode(TFT_D3,OUTPUT);
pinMode(TFT_D4,OUTPUT);
pinMode(TFT_D5,OUTPUT);
pinMode(TFT_D6,OUTPUT);
pinMode(TFT_D7,OUTPUT);
pinMode(TFT_RS, OUTPUT);
pinMode(TFT_WR, OUTPUT);
pinMode(TFT_CS,OUTPUT);
}
/*****************************************************************************
** WRITEBUS8
******************************************************************************/
/*
void inline writebus(uint8_t d) {
digitalWrite(TFT_SPI_U4,LOW);
////////////////////
//Gestion du 74HC595
////////////////////
GPOC=(((uint32_t)1<<TFT_SPI_CS));
SPI.write(d);
GPOS=((uint32_t)1<<TFT_SPI_CS);
////////////////////////
//Gestion de l'&fficheur
////////////////////////
CS_ACTIVE; //SS du bus 8080
GPOC =(1<<TFT_WR); //Flanc descendant sur WR du bus 8080
GPOS= (1<<TFT_WR); //Flanc montant sur WR du bus 8080
CS_IDLE; //Dévalide bus 8080
}
*/
void writebus(uint8_t d)
{
tft_Write_8(d);
}
/*****************************************************************************
** WRITEBUS16
** Après les 16 décalages, le poids fort est dans U5 et le poids faible dans U4
** Il faut écrire 16 bits sur le bus 8 bit poids fort en tête puis poids faible.
*****************************************************************************/
void inline writeBus16(uint16_t data) {
tft_Write_16(data);
}
/*****************************************************************************
** WRITEDATA16
******************************************************************************/
void TFT_PARALLEL_ESP8266::writedata16(uint16_t c)
{
//CD_DATA;
DC_D;
//writebus(c>>8);
//writebus(c&0xFF);
//writeBus16(c);
tft_Write_16(c);
}
/*****************************************************************************
** WRITEDATA16
******************************************************************************/
void TFT_PARALLEL_ESP8266::writedata16(uint16_t color, uint32_t num)
{
CD_DATA;
for (uint32_t n=0;n<num;n++) {
//writebus(color>>8);
//writebus(color&0xFF);
//writeBus16(color);
tft_Write_16(color);
}
}
/*****************************************************************************
** WRITECOMMAND
******************************************************************************/
void TFT_PARALLEL_ESP8266::writecommand(uint8_t c)
{
//CD_COMMAND;
DC_C;
//digitalWrite(TFT_RS,LOW);
//writebus(c);
tft_Write_8(c);
}
/*****************************************************************************
** WRITEDATA
******************************************************************************/
void TFT_PARALLEL_ESP8266::TFT_PARALLEL_ESP8266:: writedata(uint8_t c)
{
//CD_DATA;
DC_D;
//digitalWrite(TFT_RS,HIGH);
tft_Write_8(c);
}
/*******************************************************************************************************
** BEGIN
********************************************************************************************************/
void TFT_PARALLEL_ESP8266::begin(void)
{
#if defined (ILI9488)
#include "TFT_Drivers/ILI9488_Init.h"
#elif defined (HX8357D)
#include "TFT_Drivers/HX8357D_Init.h"
#elif defined (R61581)
#include "TFT_Drivers/R61581_Init.h"
#elif defined (RM68140)
#include "TFT_Drivers/RM68140_Init.h"
#endif
delay(1000);
}
/*****************************************************************************
** SET ROTATION
******************************************************************************/
void TFT_PARALLEL_ESP8266::setRotation(uint8_t m)
{
#if defined (ILI9488)
#include "TFT_Drivers/ILI9488_Rotation.h"
#elif defined (HX8357D)
#include "TFT_Drivers/HX8357D_Rotation.h"
#elif defined (R61581)
#include "TFT_Drivers/R61581_Rotation.h"
#elif defined (RM68140)
#include "TFT_Drivers/RM68140_Rotation.h"
#endif
}
/*****************************************************************************
** SETADDRWINDOW
******************************************************************************/
void TFT_PARALLEL_ESP8266::setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1)
{
writecommand(TFT_CASET); // Column addr set
//writedata16(x0);
//writedata16(x1);
DC_D;
tft_Write_32C(x0,x1);
writecommand(TFT_PASET); // Row addr set
//writedata16(y0);
//writedata16(y1);
DC_D;
tft_Write_32C(y0,y1);
writecommand(TFT_RAMWR); // write to RAM
}
/*****************************************************************************
** PUSHCOLOR
******************************************************************************/
void TFT_PARALLEL_ESP8266::pushColor(uint16_t color)
{
writedata16(color);
}
/*****************************************************************************
** DRAWPIXEL
******************************************************************************/
void TFT_PARALLEL_ESP8266::drawPixel(int16_t x, int16_t y, uint16_t color)
{
if ((x < 0) || (x >= _width) || (y < 0) || (y >= _height)) return;
setAddrWindow(x, y, x + 1, y + 1);
//pushColor(color);
writedata16(color);
}
/************************************************************************************
** DRAW FAST VLINE
*************************************************************************************/
void TFT_PARALLEL_ESP8266::drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color)
{
// Rudimentary clipping
if ((x >= _width) || (y >= _height || h < 1)) return;
if ((y + h - 1) >= _height) { h = _height - y; }
if (h < 2 ) { drawPixel(x, y, color); return; }
setAddrWindow(x, y, x, y + h - 1);
writedata16(color, h);
}
/****************************************************************************************
** DRAW FAST HLINE
*****************************************************************************************/
void TFT_PARALLEL_ESP8266::drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color)
{
// Rudimentary clipping
if ((x >= _width) || (y >= _height || w < 1)) return;
if ((x + w - 1) >= _width) { w = _width - x; }
if (w < 2 ) { drawPixel(x, y, color); return; }
setAddrWindow(x, y, x + w - 1, y);
writedata16(color, w);
}
/*****************************************************************************************
** FILL SCREEN
******************************************************************************************/
void TFT_PARALLEL_ESP8266::fillScreen(uint16_t color) {
setAddrWindow(0, 0, _width - 1, _height - 1);
writedata16(color, (_width * _height)/2);
//yield();
writedata16(color, (_width * _height)/2);
}
/*****************************************************************************
** FILLRECT
******************************************************************************/
void TFT_PARALLEL_ESP8266::fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
{
// rudimentary clipping (drawChar w/big text requires this)
//uint16_t n =76800;
if ((x >= _width) || (y >= _height || h < 1 || w < 1)) return;
if ((x + w - 1) >= _width) { w = _width - x; }
if ((y + h - 1) >= _height) { h = _height - y; }
if (w == 1 && h == 1) {
drawPixel(x, y, color);
return;
}
setAddrWindow(x, y, x + w - 1, y + h - 1);
writedata16(color, (w*h)/2); /*yield()*/;writedata16(color, (w*h)/2);
}
/**************************************************************************************************
* Draw lines faster by calculating straight sections and drawing them with fastVline and fastHline.
***************************************************************************************************/
void TFT_PARALLEL_ESP8266::drawLine(int16_t x0, int16_t y0,int16_t x1, int16_t y1, uint16_t color)
{
if ((y0 < 0 && y1 <0) || (y0 > _height && y1 > _height)) return;
if ((x0 < 0 && x1 <0) || (x0 > _width && x1 > _width)) return;
if (x0 < 0) x0 = 0;
if (x1 < 0) x1 = 0;
if (y0 < 0) y0 = 0;
if (y1 < 0) y1 = 0;
if (y0 == y1) {
if (x1 > x0) {
drawFastHLine(x0, y0, x1 - x0 + 1, color);
}
else if (x1 < x0) {
drawFastHLine(x1, y0, x0 - x1 + 1, color);
}
else {
drawPixel(x0, y0, color);
}
return;
}
else if (x0 == x1) {
if (y1 > y0) {
drawFastVLine(x0, y0, y1 - y0 + 1, color);
}
else {
drawFastVLine(x0, y1, y0 - y1 + 1, color);
}
return;
}
bool steep = abs(y1 - y0) > abs(x1 - x0);
if (steep) {
swap(x0, y0);
swap(x1, y1);
}
if (x0 > x1) {
swap(x0, x1);
swap(y0, y1);
}
int16_t dx, dy;
dx = x1 - x0;
dy = abs(y1 - y0);
int16_t err = dx / 2;
int16_t ystep;
if (y0 < y1) {
ystep = 1;
}
else {
ystep = -1;
}
int16_t xbegin = x0;
if (steep) {
for (; x0 <= x1; x0++) {
err -= dy;
if (err < 0) {
int16_t len = x0 - xbegin;
if (len) {
drawFastVLine (y0, xbegin, len + 1, color);
//writeVLine_cont_noCS_noFill(y0, xbegin, len + 1);
}
else {
drawPixel(y0, x0, color);
//writePixel_cont_noCS(y0, x0, color);
}
xbegin = x0 + 1;
y0 += ystep;
err += dx;
}
}
if (x0 > xbegin + 1) {
//writeVLine_cont_noCS_noFill(y0, xbegin, x0 - xbegin);
drawFastVLine(y0, xbegin, x0 - xbegin, color);
}
}
else {
for (; x0 <= x1; x0++) {
err -= dy;
if (err < 0) {
int16_t len = x0 - xbegin;
if (len) {
drawFastHLine(xbegin, y0, len + 1, color);
//writeHLine_cont_noCS_noFill(xbegin, y0, len + 1);
}
else {
drawPixel(x0, y0, color);
//writePixel_cont_noCS(x0, y0, color);
}
xbegin = x0 + 1;
y0 += ystep;
err += dx;
}
}
if (x0 > xbegin + 1) {
//writeHLine_cont_noCS_noFill(xbegin, y0, x0 - xbegin);
drawFastHLine(xbegin, y0, x0 - xbegin, color);
}
}
}
/*****************************************************************************/
// Pass 8-bit (each) R,G,B, get back 16-bit packed color
/*****************************************************************************/
uint16_t TFT_PARALLEL_ESP8266::color565(uint8_t r, uint8_t g, uint8_t b)
{
return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);
}
/*****************************************************************************
/** INVERT DISPLAY
******************************************************************************/
void TFT_PARALLEL_ESP8266::invertDisplay(boolean i)
{
writecommand(i ? TFT_INVON : TFT_INVOFF);
}
void TFT_PARALLEL_ESP8266::enable(bool enable) {
writecommand(enable ? 0x29 : 0x28);
}