forked from ArduinoHannover/HackBoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ILI9341_due.h
executable file
·2258 lines (1970 loc) · 66 KB
/
ILI9341_due.h
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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
v1.01.005
ILI9341_due.h - Arduino Due library for interfacing with ILI9341-based TFTs
Code: https://github.com/marekburiak/ILI9341_due
Documentation: http://marekburiak.github.io/ILI9341_due/
Copyright (c) 2015 Marek Buriak
2.4 TFT Pin-out
T_IRQ T_DO T_DIN T_CS T_CLK MISO LED CLK MOSI DC RESET CS GND VCC
This library is based on ILI9341_t3 library from Paul Stoffregen
(https://github.com/PaulStoffregen/ILI9341_t3), Adafruit_ILI9341
and Adafruit_GFX libraries from Limor Fried/Ladyada
(https://github.com/adafruit/Adafruit_ILI9341).
This file is part of the Arduino ILI9341_due library.
Sources for this library can be found at https://github.com/marekburiak/ILI9341_Due.
ILI9341_due is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 of the License, or
(at your option) any later version.
ILI9341_due 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with ILI9341_due. If not, see <http://www.gnu.org/licenses/>.
*/
/***************************************************
This is our library for the Adafruit ILI9341 Breakout and Shield
----> http://www.adafruit.com/products/1651
Check out the links above for our tutorials and wiring diagrams
These displays use SPI to communicate, 4 or 5 pins are required to
interface (RST is optional)
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
MIT license, all text above must be included in any redistribution
****************************************************/
#ifndef _ILI9341_dueH_
#define _ILI9341_dueH_
#include <ILI9341_due_config.h>
//#include "../Streaming/Streaming.h"
#include "Arduino.h"
#ifdef ARDUINO_ARCH_AVR
#include <avr/pgmspace.h>
#endif
#ifdef ARDUINO_ARCH_AVR
#define SPI_MODE_NORMAL 1
#define SPI_MODE_EXTENDED 0
#define SPI_MODE_DMA 0
#else
#ifndef ILI9341_SPI_MODE_NORMAL
#define SPI_MODE_NORMAL 0
#else
#define SPI_MODE_NORMAL 1
#endif
#ifndef ILI9341_SPI_MODE_EXTENDED
#define SPI_MODE_EXTENDED 0
#else
#define SPI_MODE_EXTENDED 1
#endif
#ifndef ILI9341_SPI_MODE_DMA
#define SPI_MODE_DMA 0
#else
#define SPI_MODE_DMA 1
#endif
#endif
#if SPI_MODE_NORMAL | SPI_MODE_EXTENDED | defined(ILI_USE_SPI_TRANSACTION)
#include <SPI.h>
#endif
#if SPI_MODE_DMA
#include <stdint.h>
#endif
#define ILI9341_TFTWIDTH 240
#define ILI9341_TFTHEIGHT 320
#define ILI9341_NOP 0x00
#define ILI9341_SWRESET 0x01
#define ILI9341_RDDID 0x04
#define ILI9341_RDDST 0x09
#define ILI9341_SLPIN 0x10
#define ILI9341_SLPOUT 0x11
#define ILI9341_PTLON 0x12
#define ILI9341_NORON 0x13
#define ILI9341_RDMODE 0x0A
#define ILI9341_RDMADCTL 0x0B
#define ILI9341_RDPIXFMT 0x0C
#define ILI9341_RDIMGFMT 0x0D
#define ILI9341_RDDSPSGNMODE 0x0E
#define ILI9341_RDSELFDIAG 0x0F
#define ILI9341_INVOFF 0x20
#define ILI9341_INVON 0x21
#define ILI9341_GAMMASET 0x26
#define ILI9341_DISPOFF 0x28
#define ILI9341_DISPON 0x29
#define ILI9341_CASET 0x2A
#define ILI9341_PASET 0x2B
#define ILI9341_RAMWR 0x2C
#define ILI9341_RAMRD 0x2E
#define ILI9341_PTLAR 0x30
#define ILI9341_MADCTL 0x36
#define ILI9341_IDMOFF 0x38
#define ILI9341_IDMON 0x39
#define ILI9341_PIXFMT 0x3A
#define ILI9341_FRMCTR1 0xB1
#define ILI9341_FRMCTR2 0xB2
#define ILI9341_FRMCTR3 0xB3
#define ILI9341_INVCTR 0xB4
#define ILI9341_DFUNCTR 0xB6
#define ILI9341_PWCTR1 0xC0
#define ILI9341_PWCTR2 0xC1
#define ILI9341_PWCTR3 0xC2
#define ILI9341_PWCTR4 0xC3
#define ILI9341_PWCTR5 0xC4
#define ILI9341_VMCTR1 0xC5
#define ILI9341_VMCTR2 0xC7
#define ILI9341_RDID1 0xDA
#define ILI9341_RDID2 0xDB
#define ILI9341_RDID3 0xDC
#define ILI9341_RDID4 0xDD
#define ILI9341_GMCTRP1 0xE0
#define ILI9341_GMCTRN1 0xE1
/*
#define ILI9341_PWCTR6 0xFC
*/
// Color definitions
#define ILI9341_ALICEBLUE 0xF7DF
#define ILI9341_ANTIQUEWHITE 0xFF5A
#define ILI9341_AQUA 0x07FF
#define ILI9341_AQUAMARINE 0x7FFA
#define ILI9341_AZURE 0xF7FF
#define ILI9341_BEIGE 0xF7BB
#define ILI9341_BISQUE 0xFF38
#define ILI9341_BLACK 0x0000
#define ILI9341_BLANCHEDALMOND 0xFF59
#define ILI9341_BLUE 0x001F
#define ILI9341_BLUEVIOLET 0x895C
#define ILI9341_BROWN 0xA145
#define ILI9341_BURLYWOOD 0xDDD0
#define ILI9341_CADETBLUE 0x5CF4
#define ILI9341_CHARTREUSE 0x7FE0
#define ILI9341_CHOCOLATE 0xD343
#define ILI9341_CORAL 0xFBEA
#define ILI9341_CORNFLOWERBLUE 0x64BD
#define ILI9341_CORNSILK 0xFFDB
#define ILI9341_CRIMSON 0xD8A7
#define ILI9341_CYAN 0x07FF
#define ILI9341_DARKBLUE 0x0011
#define ILI9341_DARKCYAN 0x0451
#define ILI9341_DARKGOLDENROD 0xBC21
#define ILI9341_DARKGRAY 0xAD55
#define ILI9341_DARKGREEN 0x0320
#define ILI9341_DARKKHAKI 0xBDAD
#define ILI9341_DARKMAGENTA 0x8811
#define ILI9341_DARKOLIVEGREEN 0x5345
#define ILI9341_DARKORANGE 0xFC60
#define ILI9341_DARKORCHID 0x9999
#define ILI9341_DARKRED 0x8800
#define ILI9341_DARKSALMON 0xECAF
#define ILI9341_DARKSEAGREEN 0x8DF1
#define ILI9341_DARKSLATEBLUE 0x49F1
#define ILI9341_DARKSLATEGRAY 0x2A69
#define ILI9341_DARKTURQUOISE 0x067A
#define ILI9341_DARKVIOLET 0x901A
#define ILI9341_DEEPPINK 0xF8B2
#define ILI9341_DEEPSKYBLUE 0x05FF
#define ILI9341_DIMGRAY 0x6B4D
#define ILI9341_DODGERBLUE 0x1C9F
#define ILI9341_FIREBRICK 0xB104
#define ILI9341_FLORALWHITE 0xFFDE
#define ILI9341_FORESTGREEN 0x2444
#define ILI9341_FUCHSIA 0xF81F
#define ILI9341_GAINSBORO 0xDEFB
#define ILI9341_GHOSTWHITE 0xFFDF
#define ILI9341_GOLD 0xFEA0
#define ILI9341_GOLDENROD 0xDD24
#define ILI9341_GRAY 0x8410
#define ILI9341_GREEN 0x0400
#define ILI9341_GREENYELLOW 0xAFE5
#define ILI9341_HONEYDEW 0xF7FE
#define ILI9341_HOTPINK 0xFB56
#define ILI9341_INDIANRED 0xCAEB
#define ILI9341_INDIGO 0x4810
#define ILI9341_IVORY 0xFFFE
#define ILI9341_KHAKI 0xF731
#define ILI9341_LAVENDER 0xE73F
#define ILI9341_LAVENDERBLUSH 0xFF9E
#define ILI9341_LAWNGREEN 0x7FE0
#define ILI9341_LEMONCHIFFON 0xFFD9
#define ILI9341_LIGHTBLUE 0xAEDC
#define ILI9341_LIGHTCORAL 0xF410
#define ILI9341_LIGHTCYAN 0xE7FF
#define ILI9341_LIGHTGOLDENRODYELLOW 0xFFDA
#define ILI9341_LIGHTGREEN 0x9772
#define ILI9341_LIGHTGREY 0xD69A
#define ILI9341_LIGHTPINK 0xFDB8
#define ILI9341_LIGHTSALMON 0xFD0F
#define ILI9341_LIGHTSEAGREEN 0x2595
#define ILI9341_LIGHTSKYBLUE 0x867F
#define ILI9341_LIGHTSLATEGRAY 0x7453
#define ILI9341_LIGHTSTEELBLUE 0xB63B
#define ILI9341_LIGHTYELLOW 0xFFFC
#define ILI9341_LIME 0x07E0
#define ILI9341_LIMEGREEN 0x3666
#define ILI9341_LINEN 0xFF9C
#define ILI9341_MAGENTA 0xF81F
#define ILI9341_MAROON 0x8000
#define ILI9341_MEDIUMAQUAMARINE 0x6675
#define ILI9341_MEDIUMBLUE 0x0019
#define ILI9341_MEDIUMORCHID 0xBABA
#define ILI9341_MEDIUMPURPLE 0x939B
#define ILI9341_MEDIUMSEAGREEN 0x3D8E
#define ILI9341_MEDIUMSLATEBLUE 0x7B5D
#define ILI9341_MEDIUMSPRINGGREEN 0x07D3
#define ILI9341_MEDIUMTURQUOISE 0x4E99
#define ILI9341_MEDIUMVIOLETRED 0xC0B0
#define ILI9341_MIDNIGHTBLUE 0x18CE
#define ILI9341_MINTCREAM 0xF7FF
#define ILI9341_MISTYROSE 0xFF3C
#define ILI9341_MOCCASIN 0xFF36
#define ILI9341_NAVAJOWHITE 0xFEF5
#define ILI9341_NAVY 0x0010
#define ILI9341_OLDLACE 0xFFBC
#define ILI9341_OLIVE 0x8400
#define ILI9341_OLIVEDRAB 0x6C64
#define ILI9341_ORANGE 0xFD20
#define ILI9341_ORANGERED 0xFA20
#define ILI9341_ORCHID 0xDB9A
#define ILI9341_PALEGOLDENROD 0xEF55
#define ILI9341_PALEGREEN 0x9FD3
#define ILI9341_PALETURQUOISE 0xAF7D
#define ILI9341_PALEVIOLETRED 0xDB92
#define ILI9341_PAPAYAWHIP 0xFF7A
#define ILI9341_PEACHPUFF 0xFED7
#define ILI9341_PERU 0xCC27
#define ILI9341_PINK 0xFE19
#define ILI9341_PLUM 0xDD1B
#define ILI9341_POWDERBLUE 0xB71C
#define ILI9341_PURPLE 0x8010
#define ILI9341_RED 0xF800
#define ILI9341_ROSYBROWN 0xBC71
#define ILI9341_ROYALBLUE 0x435C
#define ILI9341_SADDLEBROWN 0x8A22
#define ILI9341_SALMON 0xFC0E
#define ILI9341_SANDYBROWN 0xF52C
#define ILI9341_SEAGREEN 0x2C4A
#define ILI9341_SEASHELL 0xFFBD
#define ILI9341_SIENNA 0xA285
#define ILI9341_SILVER 0xC618
#define ILI9341_SKYBLUE 0x867D
#define ILI9341_SLATEBLUE 0x6AD9
#define ILI9341_SLATEGRAY 0x7412
#define ILI9341_SNOW 0xFFDF
#define ILI9341_SPRINGGREEN 0x07EF
#define ILI9341_STEELBLUE 0x4416
#define ILI9341_TAN 0xD5B1
#define ILI9341_TEAL 0x0410
#define ILI9341_THISTLE 0xDDFB
#define ILI9341_TOMATO 0xFB08
#define ILI9341_TURQUOISE 0x471A
#define ILI9341_VIOLET 0xEC1D
#define ILI9341_WHEAT 0xF6F6
#define ILI9341_WHITE 0xFFFF
#define ILI9341_WHITESMOKE 0xF7BE
#define ILI9341_YELLOW 0xFFE0
#define ILI9341_YELLOWGREEN 0x9E66
// Font Indices
#define GTEXT_FONT_LENGTH 0
#define GTEXT_FONT_FIXED_WIDTH 2
#define GTEXT_FONT_HEIGHT 3
#define GTEXT_FONT_FIRST_CHAR 4
#define GTEXT_FONT_CHAR_COUNT 5
#define GTEXT_FONT_WIDTH_TABLE 6
typedef enum {
gTextFontModeSolid = 0,
gTextFontModeTransparent = 1
} gTextFontMode;
// the following returns true if the given font is fixed width
// zero length is flag indicating fixed width font (array does not contain width data entries)
#define isFixedWidthFont(font) (pgm_read_byte(font+GTEXT_FONT_LENGTH) == 0 && pgm_read_byte(font+GTEXT_FONT_LENGTH+1) == 0))
typedef enum {
gTextAlignTopLeft,
gTextAlignTopCenter,
gTextAlignTopRight,
gTextAlignMiddleLeft,
gTextAlignMiddleCenter,
gTextAlignMiddleRight,
gTextAlignBottomLeft,
gTextAlignBottomCenter,
gTextAlignBottomRight
} gTextAlign;
typedef enum {
gTextPivotDefault,
gTextPivotTopLeft,
gTextPivotTopCenter,
gTextPivotTopRight,
gTextPivotMiddleLeft,
gTextPivotMiddleCenter,
gTextPivotMiddleRight,
gTextPivotBottomLeft,
gTextPivotBottomCenter,
gTextPivotBottomRight
} gTextPivot;
typedef enum {
gTextEraseToEOL = 0x01, /**< Erase From cursor to end of Line */
gTextEraseFromBOL = 0x02, /**< Erase From Begining of Line to Cursor*/
gTextEraseFullLine = 0x03 /**< Erase Entire line */
} gTextEraseLine;
typedef struct
{
uint16_t x;
uint16_t y;
uint16_t w;
uint16_t h;
} gTextArea;
typedef const uint8_t* gTextFont;
typedef enum {
iliRotation0 = 0,
iliRotation90 = 1,
iliRotation180 = 2,
iliRotation270 = 3
} iliRotation;
typedef enum {
// Normal Mode On (full display)
// In this mode, the display is able to show maximum 262,144 colors.
pwrLevelNormal = 1,
// Idle Mode On
// In this mode, the full display area is used but with 8 colors.
pwrLevelIdle = 2,
// In this mode, the DC : DC converter, Internal oscillator and panel driver circuit are stopped. Only the MCU
// interface and memory works with VDDI power supply. Contents of the memory are safe.
pwrLevelSleep = 3
} pwrLevel;
#ifndef swap
#define swap(a, b) { typeof(a) t = a; a = b; b = t; }
#endif
#ifdef ARDUINO_SAM_DUE
#define SCANLINE_PIXEL_COUNT 320
#elif defined ARDUINO_ARCH_AVR
#define SCANLINE_PIXEL_COUNT 16
#endif
#if SPI_MODE_DMA | SPI_MODE_EXTENDED
#define SCANLINE_BUFFER_SIZE SCANLINE_PIXEL_COUNT << 1
#elif SPI_MODE_NORMAL
#define SCANLINE_BUFFER_SIZE SCANLINE_PIXEL_COUNT
#endif
class ILI9341_due
: public Print
{
protected:
int16_t _width, _height; // Display w/h as modified by current rotation
iliRotation _rotation;
float _arcAngleMax;
int16_t _angleOffset;
void fillArcOffsetted(uint16_t cx, uint16_t cy, uint16_t radius, uint16_t thickness, float startAngle, float endAngle, uint16_t color);
void drawFastVLine_cont_noFill(int16_t x, int16_t y, int16_t h, uint16_t color);
void drawFastVLine_noTrans(int16_t x, int16_t y, uint16_t h, uint16_t color);
void drawFastHLine_noTrans(int16_t x, int16_t y, uint16_t w, uint16_t color);
void drawLine_noTrans(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color);
void printHex8(uint8_t *data, uint8_t length);
void printHex16(uint16_t *data, uint8_t length);
void printHex32(uint32_t *data, uint8_t length);
uint8_t _rst;
uint8_t _hiByte, _loByte;
bool _isIdle, _isInSleep;
uint16_t _color;
uint16_t _scanline16[SCANLINE_PIXEL_COUNT];
//#if SPI_MODE_DMA | SPI_MODE_EXTENDED
// uint8_t _scanline[SCANLINE_BUFFER_SIZE];
//
//#elif SPI_MODE_NORMAL
// uint16_t _scanline[SCANLINE_BUFFER_SIZE];
//#endif
//uint16_t _scanlineCounter = 0;
#if SPI_MODE_DMA | SPI_MODE_EXTENDED
//uint16_t _scanline[SCANLINE_BUFFER_SIZE]; // DMA16
#endif
uint8_t _spiClkDivider;
#ifdef ILI_USE_SPI_TRANSACTION
SPISettings _spiSettings;
uint8_t _transactionId;
bool _isInTransaction;
#endif
//Pio *_dcport;
#ifdef ARDUINO_SAM_DUE
volatile RwReg *_dcport;
uint32_t _cs, _dc, _dcpinmask;
#else
volatile uint8_t *_dcport, *_csport;
volatile uint8_t _dcport2;
uint8_t _cs, _dc, _cspinmask, _dcpinmask, _backupSPCR;
#endif
#if SPI_MODE_NORMAL | SPI_MODE_DMA
#ifdef ARDUINO_SAM_DUE
//Pio *_csport;
volatile RwReg *_csport;
uint32_t _cspinmask;
#endif
#endif
gTextFontMode _fontMode;
uint16_t _fontColor;
uint16_t _fontBgColor;
gTextFont _font;
gTextArea _area;
int16_t _x;
int16_t _xStart;
int16_t _y;
int16_t _yStart;
uint8_t _letterSpacing;
uint8_t _lineSpacing;
bool _isFirstChar;
//bool _needScroll;
//bool _wrap;
#ifdef TEXT_SCALING_ENABLED
uint8_t _textScale;
#else
#define _textScale 1
#endif
void fillRect_noTrans(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t color);
void drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, uint16_t color);
void fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, int16_t delta, uint16_t color);
void pushColors_noTrans_noCS(const uint16_t *colors, uint16_t offset, uint32_t len);
void specialChar(uint8_t c);
void drawSolidChar(char c, uint16_t index, uint16_t charWidth, uint16_t charHeight);
void drawTransparentChar(char c, uint16_t index, uint16_t charWidth, uint16_t charHeight);
void applyPivot(const char *str, gTextPivot pivot, gTextAlign align);
void applyPivot(const String &str, gTextPivot pivot, gTextAlign align);
void applyPivot(const __FlashStringHelper *str, gTextPivot pivot, gTextAlign align);
void applyAlignOffset(gTextAlign align, int16_t offsetX, int16_t offsetY);
void applyAlignPivotOffset(const char *str, gTextAlign align, gTextPivot pivot, int16_t offsetX, int16_t offsetY);
void applyAlignPivotOffset(const String &str, gTextAlign align, gTextPivot pivot, int16_t offsetX, int16_t offsetY);
void applyAlignPivotOffset(const __FlashStringHelper *str, gTextAlign align, gTextPivot pivot, int16_t offsetX, int16_t offsetY);
void clearPixelsOnLeft(uint16_t pixelsToClearOnLeft);
void clearPixelsOnRight(uint16_t pixelsToClearOnRight);
bool pinIsChipSelect(uint8_t cs);
public:
ILI9341_due(uint8_t cs, uint8_t dc, uint8_t rst = 255);
bool begin(void);
void getDisplayStatus();
void fillScreen(uint16_t color);
void fillRect(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t color);
void pushColor(uint16_t color);
void pushColors(const uint16_t *colors, uint16_t offset, uint32_t len);
void pushColors(uint16_t *colors, uint16_t offset, uint32_t len);
/*void pushColors565(uint8_t *colors, uint16_t offset, uint32_t len);
void pushColors565(const uint16_t *colors, uint16_t offset, uint32_t len);*/
void drawPixel(int16_t x, int16_t y, uint16_t color);
void drawFastVLine(int16_t x, int16_t y, uint16_t h, uint16_t color);
void drawFastHLine(int16_t x, int16_t y, uint16_t w, uint16_t color);
void drawRect(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t color);
void setRotation(iliRotation r);
void invertDisplay(boolean i);
void display(boolean d);
void sleep(boolean s);
void idle(boolean i);
void setPowerLevel(pwrLevel p);
void setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1);
void setAddrWindowRect(uint16_t x, uint16_t y, uint16_t w, uint16_t h);
void setSPIClockDivider(uint8_t divider);
void setAngleOffset(int16_t angleOffset);
void setArcParams(float arcAngleMax);
uint16_t readPixel(int16_t x, int16_t y);
void drawCircle(int16_t x, int16_t y, int16_t r, uint16_t color);
void fillCircle(int16_t x, int16_t y, int16_t r, uint16_t color);
void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color);
void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color);
void drawRoundRect(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t radius, uint16_t color);
void fillRoundRect(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t radius, uint16_t color);
void drawBitmap(const uint8_t *bitmap, int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t color);
void drawBitmap(const uint8_t *bitmap, int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t color, uint16_t bgcolor);
void drawImage(const uint16_t *colors, uint16_t x, uint16_t y, uint16_t w, uint16_t h);
uint8_t getRotation(void);
void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color);
void drawLineByAngle(int16_t x, int16_t y, int16_t angle, uint16_t length, uint16_t color);
void drawLineByAngle(int16_t x, int16_t y, int16_t angle, uint16_t start, uint16_t length, uint16_t color);
void screenshotToConsole();
void setTextArea(gTextArea area);
void setTextArea(int16_t x, int16_t y, int16_t w, int16_t h); //, textMode mode=DEFAULT_SCROLLDIR);
void setTextArea(int16_t x, int16_t y, int16_t columns, int16_t rows, gTextFont font); //, textMode mode=DEFAULT_SCROLLDIR);
gTextArea getTextArea()
{
return _area;
}
void clearTextArea();
void clearTextArea(gTextArea area);
void clearTextArea(uint16_t color);
void clearTextArea(gTextArea area, uint16_t color);
// Font Functions
void setFont(gTextFont font);
gTextFont getFont() {
return _font;
}
void setTextColor(uint16_t color);
void setTextColor(uint8_t R, uint8_t G, uint8_t B);
void setTextColor(uint16_t color, uint16_t backgroundColor);
void setTextColor(uint8_t R, uint8_t G, uint8_t B, uint8_t bgR, uint8_t bgG, uint8_t bgB);
uint16_t getTextColor()
{
return _fontColor;
}
uint16_t getTextBackgroundColor()
{
return _fontBgColor;
}
void setTextLetterSpacing(uint8_t letterSpacing);
uint8_t getTextLetterSpacing() {
return _letterSpacing;
};
void setTextLineSpacing(uint8_t lineSpacing);
uint8_t getTextLineSpacing() {
return _lineSpacing;
};
//void setTextWrap(bool wrap);
void setFontMode(gTextFontMode fontMode);
gTextFontMode getFontMode()
{
return _fontMode;
}
void setTextScale(uint8_t textScale);
uint8_t getTextScale() {
return _textScale;
}
//void puts(const char *str);
//void puts(const String &str);
//void puts(const __FlashStringHelper* str);
void printAt(const char *str, int16_t x, int16_t y);
void printAt(const String &str, int16_t x, int16_t y);
void printAt(const __FlashStringHelper* str, int16_t x, int16_t y);
void printAt(const char *str, int16_t x, int16_t y, gTextEraseLine eraseLine);
void printAt(const String &str, int16_t x, int16_t y, gTextEraseLine eraseLine);
void printAt(const __FlashStringHelper *str, int16_t x, int16_t y, gTextEraseLine eraseLine);
void printAt(const char *str, int16_t x, int16_t y, uint16_t pixelsClearedOnLeft, uint16_t pixelsClearedOnRight);
void printAt(const String &str, int16_t x, int16_t y, uint16_t pixelsClearedOnLeft, uint16_t pixelsClearedOnRight);
void printAt(const __FlashStringHelper *str, int16_t x, int16_t y, uint16_t pixelsClearedOnLeft, uint16_t pixelsClearedOnRight);
void printAtPivoted(const char *str, int16_t x, int16_t y, gTextPivot pivot);
void printAtPivoted(const String &str, int16_t x, int16_t y, gTextPivot pivot);
void printAtPivoted(const __FlashStringHelper *str, int16_t x, int16_t y, gTextPivot pivot);
void printAligned(const char *str, gTextAlign align);
void printAligned(const String &str, gTextAlign align);
void printAligned(const __FlashStringHelper *str, gTextAlign align);
void printAligned(const char *str, gTextAlign align, gTextEraseLine eraseLine);
void printAligned(const String &str, gTextAlign align, gTextEraseLine eraseLine);
void printAligned(const __FlashStringHelper *str, gTextAlign align, gTextEraseLine eraseLine);
void printAligned(const char *str, gTextAlign align, uint16_t pixelsClearedOnLeft, uint16_t pixelsClearedOnRight);
void printAligned(const String &str, gTextAlign align, uint16_t pixelsClearedOnLeft, uint16_t pixelsClearedOnRight);
void printAligned(const __FlashStringHelper *str, gTextAlign align, uint16_t pixelsClearedOnLeft, uint16_t pixelsClearedOnRight);
void printAlignedOffseted(const char *str, gTextAlign align, int16_t offsetX, int16_t offsetY);
void printAlignedOffseted(const String &str, gTextAlign align, int16_t offsetX, int16_t offsetY);
void printAlignedOffseted(const __FlashStringHelper *str, gTextAlign align, int16_t offsetX, int16_t offsetY);
void printAlignedOffseted(const char *str, gTextAlign align, int16_t offsetX, int16_t offsetY, gTextEraseLine eraseLine);
void printAlignedOffseted(const String &str, gTextAlign align, int16_t offsetX, int16_t offsetY, gTextEraseLine eraseLine);
void printAlignedOffseted(const __FlashStringHelper *str, gTextAlign align, int16_t offsetX, int16_t offsetY, gTextEraseLine eraseLine);
void printAlignedOffseted(const char *str, gTextAlign align, int16_t offsetX, int16_t offsetY, uint16_t pixelsClearedOnLeft, uint16_t pixelsClearedOnRight);
void printAlignedOffseted(const String &str, gTextAlign align, int16_t offsetX, int16_t offsetY, uint16_t pixelsClearedOnLeft, uint16_t pixelsClearedOnRight);
void printAlignedOffseted(const __FlashStringHelper *str, gTextAlign align, int16_t offsetX, int16_t offsetY, uint16_t pixelsClearedOnLeft, uint16_t pixelsClearedOnRight);
void printAlignedPivoted(const char *str, gTextAlign align, gTextPivot pivot);
void printAlignedPivoted(const String &str, gTextAlign align, gTextPivot pivot);
void printAlignedPivoted(const __FlashStringHelper *str, gTextAlign align, gTextPivot pivot);
void printAlignedPivoted(const char *str, gTextAlign align, gTextPivot pivot, gTextEraseLine eraseLine);
void printAlignedPivoted(const String &str, gTextAlign align, gTextPivot pivot, gTextEraseLine eraseLine);
void printAlignedPivoted(const __FlashStringHelper *str, gTextAlign align, gTextPivot pivot, gTextEraseLine eraseLine);
void printAlignedPivoted(const char *str, gTextAlign align, gTextPivot pivot, uint16_t pixelsClearedOnLeft, uint16_t pixelsClearedOnRight);
void printAlignedPivoted(const String &str, gTextAlign align, gTextPivot pivot, uint16_t pixelsClearedOnLeft, uint16_t pixelsClearedOnRight);
void printAlignedPivoted(const __FlashStringHelper *str, gTextAlign align, gTextPivot pivot, uint16_t pixelsClearedOnLeft, uint16_t pixelsClearedOnRight);
void printAlignedPivotedOffseted(const char *str, gTextAlign align, gTextPivot pivot, int16_t offsetX, int16_t offsetY);
void printAlignedPivotedOffseted(const String &str, gTextAlign align, gTextPivot pivot, int16_t offsetX, int16_t offsetY);
void printAlignedPivotedOffseted(const __FlashStringHelper *str, gTextAlign align, gTextPivot pivot, int16_t offsetX, int16_t offsetY);
void printAlignedPivotedOffseted(const char *str, gTextAlign align, gTextPivot pivot, int16_t offsetX, int16_t offsetY, gTextEraseLine eraseLine);
void printAlignedPivotedOffseted(const String &str, gTextAlign align, gTextPivot pivot, int16_t offsetX, int16_t offsetY, gTextEraseLine eraseLine);
void printAlignedPivotedOffseted(const __FlashStringHelper *str, gTextAlign align, gTextPivot pivot, int16_t offsetX, int16_t offsetY, gTextEraseLine eraseLine);
void printAlignedPivotedOffseted(const char *str, gTextAlign align, gTextPivot pivot, int16_t offsetX, int16_t offsetY, uint16_t pixelsClearedOnLeft, uint16_t pixelsClearedOnRight);
void printAlignedPivotedOffseted(const String &str, gTextAlign align, gTextPivot pivot, int16_t offsetX, int16_t offsetY, uint16_t pixelsClearedOnLeft, uint16_t pixelsClearedOnRight);
void printAlignedPivotedOffseted(const __FlashStringHelper *str, gTextAlign align, gTextPivot pivot, int16_t offsetX, int16_t offsetY, uint16_t pixelsClearedOnLeft, uint16_t pixelsClearedOnRight);
void cursorTo(uint8_t column, uint8_t row); // 0 based coordinates for character columns and rows
void cursorTo(int8_t column); // move cursor on the current row
void cursorToXY(int16_t x, int16_t y); // coordinates relative to active text area
__attribute__((always_inline))
uint8_t getFontHeight() {
return pgm_read_byte(_font + GTEXT_FONT_HEIGHT);
};
__attribute__((always_inline))
static uint8_t getFontHeight(gTextFont font) {
return pgm_read_byte(font + GTEXT_FONT_HEIGHT);
};
uint8_t readcommand8(uint8_t c) {
writecommand_cont(0xD9); // woo sekret command?
writedata8_last(0x10);
writecommand_cont(c);
return readdata8_last();
}
// Pass 8-bit (each) R,G,B, get back 16-bit packed color
static uint16_t color565(uint8_t r, uint8_t g, uint8_t b) {
return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);
}
int16_t width() {
return _width;
}
int16_t height() {
return _height;
}
virtual size_t write(uint8_t);
virtual size_t print(const __FlashStringHelper *);
virtual size_t print(const String &);
virtual size_t print(const char[]);
virtual size_t print(char);
virtual size_t print(unsigned char, int = DEC);
virtual size_t print(int, int = DEC);
virtual size_t print(unsigned int, int = DEC);
virtual size_t print(long, int = DEC);
virtual size_t print(unsigned long, int = DEC);
virtual size_t print(double, int = 2);
virtual size_t print(const Printable&);
virtual size_t println(const __FlashStringHelper *);
virtual size_t println(const String &s);
virtual size_t println(const char[]);
virtual size_t println(char);
virtual size_t println(unsigned char, int = DEC);
virtual size_t println(int, int = DEC);
virtual size_t println(unsigned int, int = DEC);
virtual size_t println(long, int = DEC);
virtual size_t println(unsigned long, int = DEC);
virtual size_t println(double, int = 2);
virtual size_t println(const Printable&);
virtual size_t println(void);
uint16_t getCharWidth(uint8_t c);
uint16_t getStringWidth(const char* str);
uint16_t getStringWidth(const __FlashStringHelper *str);
uint16_t getStringWidth(const String &str);
void eraseTextLine(uint16_t color, gTextEraseLine type = gTextEraseToEOL); //ansi like line erase function
void eraseTextLine(uint16_t color, uint8_t row); // erase the entire text line in the given row and move cursor to left position
int16_t getCursorX() {
return _x;
}
int16_t getCursorY() {
return _y;
}
static uint16_t getCharWidth(uint8_t c, gTextFont font, uint8_t textScale)
{
int16_t width = 0;
if (isFixedWidthFont(font){
width = (pgm_read_byte(font + GTEXT_FONT_FIXED_WIDTH)) * textScale;
}
else{
// variable width font
uint8_t firstChar = pgm_read_byte(font + GTEXT_FONT_FIRST_CHAR);
uint8_t charCount = pgm_read_byte(font + GTEXT_FONT_CHAR_COUNT);
// read width data
if (c >= firstChar && c < (firstChar + charCount)) {
c -= firstChar;
width = (pgm_read_byte(font + GTEXT_FONT_WIDTH_TABLE + c)) * textScale;
}
}
return width;
};
static uint16_t getStringWidth(const char* str, gTextFont font, uint8_t letterSpacing, uint8_t textScale)
{
uint16_t width = 0;
while (*str != 0) {
width += getCharWidth(*str++, font, textScale) + letterSpacing * textScale;
}
if (width > 0)
width -= letterSpacing * textScale;
return width;
};
inline __attribute__((always_inline))
void fillArc(uint16_t x, uint16_t y, uint16_t radius, uint16_t thickness, float start, float end, uint16_t color)
{
beginTransaction();
if (start == 0 && end == _arcAngleMax)
fillArcOffsetted(x, y, radius, thickness, 0, _arcAngleMax, color);
else
fillArcOffsetted(x, y, radius, thickness, start + (_angleOffset / (float)360)*_arcAngleMax, end + (_angleOffset / (float)360)*_arcAngleMax, color);
endTransaction();
}
//int32_t cos_lookup(int32_t angle)
//{
// float radians = (float)angle/_arcAngleMax * 2 * PI;
// //Serial << "COS_LOOKUP angle:" << (float)angle << " radians:" << radians << " cos:" << cos(radians) << " return: " << cos(radians) * (double)65535 << endl;
// return (cos(radians) * _arcAngleMax);
//}
//int32_t sin_lookup(int32_t angle)
//{
// float radians = (float)angle/_arcAngleMax * 2 * PI;
// //Serial << "SIN_LOOKUP angle:" << (float)angle << " radians:" << radians << " sin:" << sin(radians) << " return: " << sin(radians) * (double)65535 << endl;
// return (sin(radians) * _arcAngleMax);
//}
float cosDegrees(float angle)
{
//float radians = angle / (float)360 * 2 * PI;
//Serial << "COS_LOOKUP angle:" << (float)angle << " radians:" << radians << " cos:" << cos(radians) << " return: " << cos(radians) * (double)65535 << endl;
return cos(angle * DEG_TO_RAD);
}
float sinDegrees(float angle)
{
//float radians = angle / (float)360 * 2 * PI;
//Serial << "SIN_LOOKUP angle:" << (float)angle << " radians:" << radians << " sin:" << sin(radians) << " return: " << sin(radians) * (double)65535 << endl;
return sin(angle * DEG_TO_RAD);
}
protected:
__attribute__((always_inline))
uint16_t scaledFontHeight() {
return (uint16_t)(pgm_read_byte(_font + GTEXT_FONT_HEIGHT)) * (uint16_t)_textScale;
};
__attribute__((always_inline))
void beginTransaction() {
#ifdef ILI_USE_SPI_TRANSACTION
#if defined ARDUINO_ARCH_AVR
SPI.beginTransaction(_spiSettings);
#elif defined (ARDUINO_SAM_DUE)
#if SPI_MODE_NORMAL
SPI.beginTransaction(_spiSettings);
#elif SPI_MODE_EXTENDED
SPI.beginTransaction(_cs, _spiSettings);
#elif SPI_MODE_DMA
SPI.beginTransaction(_spiSettings);
dmaInit(_spiClkDivider);
#endif
#endif
#endif
}
__attribute__((always_inline))
void endTransaction() {
#ifdef ILI_USE_SPI_TRANSACTION
#if defined ARDUINO_ARCH_AVR
SPI.endTransaction();
#elif defined (ARDUINO_SAM_DUE)
SPI.endTransaction();
#endif
#endif
}
__attribute__((always_inline))
void spiwrite(uint8_t c) {
#if defined ARDUINO_ARCH_AVR
SPDR = c;
asm volatile("nop");
while (!(SPSR & _BV(SPIF))); // wait
#elif defined (ARDUINO_SAM_DUE)
#if SPI_MODE_NORMAL
SPI.transfer(c);
#endif
#endif
}
__attribute__((always_inline))
void spiwrite16(uint16_t d) {
#if defined ARDUINO_ARCH_AVR
SPDR = highByte(d);
while (!(SPSR & _BV(SPIF)));
SPDR = lowByte(d);
while (!(SPSR & _BV(SPIF)));
#elif defined (ARDUINO_SAM_DUE)
#if SPI_MODE_NORMAL
SPI.transfer(highByte(d));
SPI.transfer(lowByte(d));
#endif
#endif
}
// writes 1 byte
// CS and DC have to be set prior to calling this method
__attribute__((always_inline))
void write8_cont(uint8_t c){
#if SPI_MODE_NORMAL
spiwrite(c);
#elif SPI_MODE_EXTENDED
SPI.transfer(_cs, c, SPI_CONTINUE);
#elif SPI_MODE_DMA
dmaSend(c);
#endif
}
// writes 1 byte and disables CS
// CS and DC have to be set prior to calling this method
inline __attribute__((always_inline))
void write8_last(uint8_t c) {
#if SPI_MODE_NORMAL
spiwrite(c);
disableCS();
#elif SPI_MODE_EXTENDED
SPI.transfer(_cs, c, SPI_LAST);
#elif SPI_MODE_DMA
dmaSend(c);
disableCS();
#endif
}
// Writes 2 bytes
// CS, DC have to be set prior to calling this method
__attribute__((always_inline))
void write16_cont(uint16_t d) {
#if SPI_MODE_NORMAL
spiwrite16(d);
#elif SPI_MODE_EXTENDED
SPI.transfer(_cs, highByte(d), SPI_CONTINUE);
SPI.transfer(_cs, lowByte(d), SPI_CONTINUE);
#elif SPI_MODE_DMA
dmaSend(highByte(d));
dmaSend(lowByte(d));
#endif
}
__attribute__((always_inline))
void write16_last(uint16_t d) {
#if SPI_MODE_NORMAL
spiwrite16(d);
disableCS();
#elif SPI_MODE_EXTENDED
SPI.transfer(_cs, highByte(d), SPI_CONTINUE);
SPI.transfer(_cs, lowByte(d), SPI_LAST);
#elif SPI_MODE_DMA
dmaSend(highByte(d));
dmaSend(lowByte(d));
disableCS();
#endif
}
// Writes commands to set the GRAM area where data/pixels will be written
void setAddr_cont(uint16_t x, uint16_t y, uint16_t w, uint16_t h)
__attribute__((always_inline)) {
writecommand_cont(ILI9341_CASET); // Column addr set
setDCForData();
write16_cont(x); // XSTART
write16_cont(x+w-1); // XEND
writecommand_cont(ILI9341_PASET); // Row addr set
setDCForData();
write16_cont(y); // YSTART
write16_cont(y+h-1); // YEND
}
//__attribute__((always_inline))
//void setAddrAndRW_cont(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1)
// {
// writecommand_cont(ILI9341_CASET); // Column addr set
// writedata16_cont(x0); // XSTART
// writedata16_cont(x1); // XEND
// writecommand_cont(ILI9341_PASET); // Row addr set
// writedata16_cont(y0); // YSTART
// writedata16_cont(y1); // YEND
// writecommand_cont(ILI9341_RAMWR); // write to RAM
//}
// Enables CS, writes commands to set the GRAM area where data/pixels will be written
//__attribute__((always_inline))
// void setAddr_cont(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1)
//{
// enableCS();
// setDCForCommand();
// write8_cont(ILI9341_CASET); // Column addr set
// setDCForData();
// write16_cont(x0); // XSTART
// write16_cont(x1); // XEND
// setDCForCommand();
// write8_cont(ILI9341_PASET); // Row addr set
// setDCForData();
// write16_cont(y0); // XSTART
// write16_cont(y1); // XEND
//}
// Enables CS, writes commands to set the GRAM area where data/pixels will be written
// Also sends RAM WRITE command which should be followed by writing data/pixels
#ifdef ARDUINO_SAM_DUE
inline __attribute__((always_inline))
#endif
void setAddrAndRW_cont(uint16_t x, uint16_t y, uint16_t w, uint16_t h)
{
setDCForCommand();
write8_cont(ILI9341_CASET); // Column addr set
setDCForData();
write16_cont(x); // XSTART
write16_cont(x+w-1); // XEND
setDCForCommand();
write8_cont(ILI9341_PASET); // Row addr set
setDCForData();