-
Notifications
You must be signed in to change notification settings - Fork 1
/
ILI9225_due.h
2106 lines (1863 loc) · 72.2 KB
/
ILI9225_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
/*
v0.1
ILI9225_Due.h - Arduino Due library for interfacing with (write only) ILI9225-based TFTs
Copyright (c) 2019 by Martin Zwerschke
based on the Library ILI9341_Due
v1.01.008
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 ILI9225_t3 library from Paul Stoffregen
(https://github.com/PaulStoffregen/ILI9225_t3), Adafruit_ILI9225
and Adafruit_GFX libraries from Limor Fried/Ladyada
(https://github.com/adafruit/Adafruit_ILI9225).
and on ILI9225_t3.cpp by Bruce Tsao
(https://github.com/brucetsao/LIB_for_MCU/tree/master/Arduino_Lib/libraries/ILI9225_t3)
This file is part of the Arduino ILI9225_due library.
Sources for this library can be found at https://github.com/martinzw/ILI9225_Due.
ILI9225_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.
ILI9225_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 ILI9225_due. If not, see <http://www.gnu.org/licenses/>.
*/
/***************************************************
This is our library for the Adafruit ILI9225 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 _ILI9225_dueH_
#define _ILI9225_dueH_
#include <ILI9225_due_config.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 ILI9225_SPI_MODE_NORMAL
#define SPI_MODE_NORMAL 0
#else
#define SPI_MODE_NORMAL 1
#endif
#ifndef ILI9225_SPI_MODE_EXTENDED
#define SPI_MODE_EXTENDED 0
#else
#define SPI_MODE_EXTENDED 1
#endif
#ifndef ILI9225_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 ILI9225_TFTWIDTH 176
#define ILI9225_TFTHEIGHT 220
#define ILI9225_DRIVER_OUTPUT_CTRL (0x01u) // Driver Output Control
#define ILI9225_LCD_AC_DRIVING_CTRL (0x02u) // LCD AC Driving Control
#define ILI9225_ENTRY_MODE (0x03u) // Entry Mode
#define ILI9225_DISP_CTRL1 (0x07u) // Display Control 1
#define ILI9225_DISP_CTRL2 (0x08u) // Blank Period Control
#define ILI9225_FRAME_CYCLE_CTRL (0x0Bu) // Frame Cycle Control
#define ILI9225_INTERFACE_CTRL (0x0Cu) // Interface Control
#define ILI9225_OSC_CTRL (0x0Fu) // Osc Control
#define ILI9225_POWER_CTRL1 (0x10u) // Power Control 1
#define ILI9225_POWER_CTRL2 (0x11u) // Power Control 2
#define ILI9225_POWER_CTRL3 (0x12u) // Power Control 3
#define ILI9225_POWER_CTRL4 (0x13u) // Power Control 4
#define ILI9225_POWER_CTRL5 (0x14u) // Power Control 5
#define ILI9225_VCI_RECYCLING (0x15u) // VCI Recycling
#define ILI9225_RAM_ADDR_SET1 (0x20u) // Horizontal GRAM Address Set
#define ILI9225_RAM_ADDR_SET2 (0x21u) // Vertical GRAM Address Set
#define ILI9225_GRAM_DATA_REG (0x22u) // GRAM Data Register
#define ILI9225_GATE_SCAN_CTRL (0x30u) // Gate Scan Control Register
#define ILI9225_VERTICAL_SCROLL_CTRL1 (0x31u) // Vertical Scroll Control 1 Register
#define ILI9225_VERTICAL_SCROLL_CTRL2 (0x32u) // Vertical Scroll Control 2 Register
#define ILI9225_VERTICAL_SCROLL_CTRL3 (0x33u) // Vertical Scroll Control 3 Register
#define ILI9225_PARTIAL_DRIVING_POS1 (0x34u) // Partial Driving Position 1 Register
#define ILI9225_PARTIAL_DRIVING_POS2 (0x35u) // Partial Driving Position 2 Register
#define ILI9225_HORIZONTAL_WINDOW_ADDR1 (0x36u) // Horizontal Address Start Position (Window-HStart)
#define ILI9225_HORIZONTAL_WINDOW_ADDR2 (0x37u) // Horizontal Address End Position (Window-HEnd)
#define ILI9225_VERTICAL_WINDOW_ADDR1 (0x38u) // Vertical Address Start Position (Window-VStart)
#define ILI9225_VERTICAL_WINDOW_ADDR2 (0x39u) // Vertical Address End Position (Window-VEnd)
#define ILI9225_GAMMA_CTRL1 (0x50u) // Gamma Control 1
#define ILI9225_GAMMA_CTRL2 (0x51u) // Gamma Control 2
#define ILI9225_GAMMA_CTRL3 (0x52u) // Gamma Control 3
#define ILI9225_GAMMA_CTRL4 (0x53u) // Gamma Control 4
#define ILI9225_GAMMA_CTRL5 (0x54u) // Gamma Control 5
#define ILI9225_GAMMA_CTRL6 (0x55u) // Gamma Control 6
#define ILI9225_GAMMA_CTRL7 (0x56u) // Gamma Control 7
#define ILI9225_GAMMA_CTRL8 (0x57u) // Gamma Control 8
#define ILI9225_GAMMA_CTRL9 (0x58u) // Gamma Control 9
#define ILI9225_GAMMA_CTRL10 (0x59u) // Gamma Control 10
// Color definitions (RGB565)
#define ILI9225_ALICEBLUE 0xF7DF
#define ILI9225_ANTIQUEWHITE 0xFF5A
#define ILI9225_AQUA 0x07FF
#define ILI9225_AQUAMARINE 0x7FFA
#define ILI9225_AZURE 0xF7FF
#define ILI9225_BEIGE 0xF7BB
#define ILI9225_BISQUE 0xFF38
#define ILI9225_BLACK 0x0000
#define ILI9225_BLANCHEDALMOND 0xFF59
#define ILI9225_BLUE 0x001F
#define ILI9225_BLUEVIOLET 0x895C
#define ILI9225_BROWN 0xA145
#define ILI9225_BURLYWOOD 0xDDD0
#define ILI9225_CADETBLUE 0x5CF4
#define ILI9225_CHARTREUSE 0x7FE0
#define ILI9225_CHOCOLATE 0xD343
#define ILI9225_CORAL 0xFBEA
#define ILI9225_CORNFLOWERBLUE 0x64BD
#define ILI9225_CORNSILK 0xFFDB
#define ILI9225_CRIMSON 0xD8A7
#define ILI9225_CYAN 0x07FF
#define ILI9225_DARKBLUE 0x0011
#define ILI9225_DARKCYAN 0x0451
#define ILI9225_DARKGOLDENROD 0xBC21
#define ILI9225_DARKGRAY 0xAD55
#define ILI9225_DARKGREEN 0x0320
#define ILI9225_DARKKHAKI 0xBDAD
#define ILI9225_DARKMAGENTA 0x8811
#define ILI9225_DARKOLIVEGREEN 0x5345
#define ILI9225_DARKORANGE 0xFC60
#define ILI9225_DARKORCHID 0x9999
#define ILI9225_DARKRED 0x8800
#define ILI9225_DARKSALMON 0xECAF
#define ILI9225_DARKSEAGREEN 0x8DF1
#define ILI9225_DARKSLATEBLUE 0x49F1
#define ILI9225_DARKSLATEGRAY 0x2A69
#define ILI9225_DARKTURQUOISE 0x067A
#define ILI9225_DARKVIOLET 0x901A
#define ILI9225_DEEPPINK 0xF8B2
#define ILI9225_DEEPSKYBLUE 0x05FF
#define ILI9225_DIMGRAY 0x6B4D
#define ILI9225_DODGERBLUE 0x1C9F
#define ILI9225_FIREBRICK 0xB104
#define ILI9225_FLORALWHITE 0xFFDE
#define ILI9225_FORESTGREEN 0x2444
#define ILI9225_FUCHSIA 0xF81F
#define ILI9225_GAINSBORO 0xDEFB
#define ILI9225_GHOSTWHITE 0xFFDF
#define ILI9225_GOLD 0xFEA0
#define ILI9225_GOLDENROD 0xDD24
#define ILI9225_GRAY 0x8410
#define ILI9225_GREEN 0x0400
#define ILI9225_GREENYELLOW 0xAFE5
#define ILI9225_HONEYDEW 0xF7FE
#define ILI9225_HOTPINK 0xFB56
#define ILI9225_INDIANRED 0xCAEB
#define ILI9225_INDIGO 0x4810
#define ILI9225_IVORY 0xFFFE
#define ILI9225_KHAKI 0xF731
#define ILI9225_LAVENDER 0xE73F
#define ILI9225_LAVENDERBLUSH 0xFF9E
#define ILI9225_LAWNGREEN 0x7FE0
#define ILI9225_LEMONCHIFFON 0xFFD9
#define ILI9225_LIGHTBLUE 0xAEDC
#define ILI9225_LIGHTCORAL 0xF410
#define ILI9225_LIGHTCYAN 0xE7FF
#define ILI9225_LIGHTGOLDENRODYELLOW 0xFFDA
#define ILI9225_LIGHTGREEN 0x9772
#define ILI9225_LIGHTGREY 0xD69A
#define ILI9225_LIGHTPINK 0xFDB8
#define ILI9225_LIGHTSALMON 0xFD0F
#define ILI9225_LIGHTSEAGREEN 0x2595
#define ILI9225_LIGHTSKYBLUE 0x867F
#define ILI9225_LIGHTSLATEGRAY 0x7453
#define ILI9225_LIGHTSTEELBLUE 0xB63B
#define ILI9225_LIGHTYELLOW 0xFFFC
#define ILI9225_LIME 0x07E0
#define ILI9225_LIMEGREEN 0x3666
#define ILI9225_LINEN 0xFF9C
#define ILI9225_MAGENTA 0xF81F
#define ILI9225_MAROON 0x8000
#define ILI9225_MEDIUMAQUAMARINE 0x6675
#define ILI9225_MEDIUMBLUE 0x0019
#define ILI9225_MEDIUMORCHID 0xBABA
#define ILI9225_MEDIUMPURPLE 0x939B
#define ILI9225_MEDIUMSEAGREEN 0x3D8E
#define ILI9225_MEDIUMSLATEBLUE 0x7B5D
#define ILI9225_MEDIUMSPRINGGREEN 0x07D3
#define ILI9225_MEDIUMTURQUOISE 0x4E99
#define ILI9225_MEDIUMVIOLETRED 0xC0B0
#define ILI9225_MIDNIGHTBLUE 0x18CE
#define ILI9225_MINTCREAM 0xF7FF
#define ILI9225_MISTYROSE 0xFF3C
#define ILI9225_MOCCASIN 0xFF36
#define ILI9225_NAVAJOWHITE 0xFEF5
#define ILI9225_NAVY 0x0010
#define ILI9225_OLDLACE 0xFFBC
#define ILI9225_OLIVE 0x8400
#define ILI9225_OLIVEDRAB 0x6C64
#define ILI9225_ORANGE 0xFD20
#define ILI9225_ORANGERED 0xFA20
#define ILI9225_ORCHID 0xDB9A
#define ILI9225_PALEGOLDENROD 0xEF55
#define ILI9225_PALEGREEN 0x9FD3
#define ILI9225_PALETURQUOISE 0xAF7D
#define ILI9225_PALEVIOLETRED 0xDB92
#define ILI9225_PAPAYAWHIP 0xFF7A
#define ILI9225_PEACHPUFF 0xFED7
#define ILI9225_PERU 0xCC27
#define ILI9225_PINK 0xFE19
#define ILI9225_PLUM 0xDD1B
#define ILI9225_POWDERBLUE 0xB71C
#define ILI9225_PURPLE 0x8010
#define ILI9225_RED 0xF800
#define ILI9225_ROSYBROWN 0xBC71
#define ILI9225_ROYALBLUE 0x435C
#define ILI9225_SADDLEBROWN 0x8A22
#define ILI9225_SALMON 0xFC0E
#define ILI9225_SANDYBROWN 0xF52C
#define ILI9225_SEAGREEN 0x2C4A
#define ILI9225_SEASHELL 0xFFBD
#define ILI9225_SIENNA 0xA285
#define ILI9225_SILVER 0xC618
#define ILI9225_SKYBLUE 0x867D
#define ILI9225_SLATEBLUE 0x6AD9
#define ILI9225_SLATEGRAY 0x7412
#define ILI9225_SNOW 0xFFDF
#define ILI9225_SPRINGGREEN 0x07EF
#define ILI9225_STEELBLUE 0x4416
#define ILI9225_TAN 0xD5B1
#define ILI9225_TEAL 0x0410
#define ILI9225_THISTLE 0xDDFB
#define ILI9225_TOMATO 0xFB08
#define ILI9225_TURQUOISE 0x471A
#define ILI9225_VIOLET 0xEC1D
#define ILI9225_WHEAT 0xF6F6
#define ILI9225_WHITE 0xFFFF
#define ILI9225_WHITESMOKE 0xF7BE
#define ILI9225_YELLOW 0xFFE0
#define ILI9225_YELLOWGREEN 0x9E66
/* RGB 24-bits color table definition (RGB888). */
#define RGB888_RGB565(color) ((((color) >> 19) & 0x1f) << 11) | ((((color) >> 10) & 0x3f) << 5) | (((color) >> 3) & 0x1f)
#define COLOR_BLACK RGB888_RGB565(0x000000u)
#define COLOR_WHITE RGB888_RGB565(0xFFFFFFu)
#define COLOR_BLUE RGB888_RGB565(0x0000FFu)
#define COLOR_GREEN RGB888_RGB565(0x00FF00u)
#define COLOR_RED RGB888_RGB565(0xFF0000u)
#define COLOR_NAVY RGB888_RGB565(0x000080u)
#define COLOR_DARKBLUE RGB888_RGB565(0x00008Bu)
#define COLOR_DARKGREEN RGB888_RGB565(0x006400u)
#define COLOR_DARKCYAN RGB888_RGB565(0x008B8Bu)
#define COLOR_CYAN RGB888_RGB565(0x00FFFFu)
#define COLOR_TURQUOISE RGB888_RGB565(0x40E0D0u)
#define COLOR_INDIGO RGB888_RGB565(0x4B0082u)
#define COLOR_DARKRED RGB888_RGB565(0x800000u)
#define COLOR_OLIVE RGB888_RGB565(0x808000u)
#define COLOR_GRAY RGB888_RGB565(0x808080u)
#define COLOR_SKYBLUE RGB888_RGB565(0x87CEEBu)
#define COLOR_BLUEVIOLET RGB888_RGB565(0x8A2BE2u)
#define COLOR_LIGHTGREEN RGB888_RGB565(0x90EE90u)
#define COLOR_DARKVIOLET RGB888_RGB565(0x9400D3u)
#define COLOR_YELLOWGREEN RGB888_RGB565(0x9ACD32u)
#define COLOR_BROWN RGB888_RGB565(0xA52A2Au)
#define COLOR_DARKGRAY RGB888_RGB565(0xA9A9A9u)
#define COLOR_SIENNA RGB888_RGB565(0xA0522Du)
#define COLOR_LIGHTBLUE RGB888_RGB565(0xADD8E6u)
#define COLOR_GREENYELLOW RGB888_RGB565(0xADFF2Fu)
#define COLOR_SILVER RGB888_RGB565(0xC0C0C0u)
#define COLOR_LIGHTGREY RGB888_RGB565(0xD3D3D3u)
#define COLOR_LIGHTCYAN RGB888_RGB565(0xE0FFFFu)
#define COLOR_VIOLET RGB888_RGB565(0xEE82EEu)
#define COLOR_AZUR RGB888_RGB565(0xF0FFFFu)
#define COLOR_BEIGE RGB888_RGB565(0xF5F5DCu)
#define COLOR_MAGENTA RGB888_RGB565(0xFF00FFu)
#define COLOR_TOMATO RGB888_RGB565(0xFF6347u)
#define COLOR_GOLD RGB888_RGB565(0xFFD700u)
#define COLOR_ORANGE RGB888_RGB565(0xFFA500u)
#define COLOR_SNOW RGB888_RGB565(0xFFFAFAu)
#define COLOR_YELLOW RGB888_RGB565(0xFFFF00u)
// 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 Beginning 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 swap2(a, b) { typeof(a) t = a; a = b; b = t; }
#endif
#ifdef ARDUINO_SAM_DUE
#define SCANLINE_PIXEL_COUNT 220
#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 ILI9225_due: public Print //derived from Print class to be able to "println"
{
protected:
int16_t _width, _height; // Display w/h as modified by current rotation
iliRotation _rotation;
uint8_t startH, endH, startV, endV, ramAddrOne, ramAddrTwo;
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]; //220 16Bit values as abuffer for the 16*220 pixelbits for one screen row
#if SPI_MODE_DMA | SPI_MODE_EXTENDED
#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 fillRectWithShader_noTrans(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t(*fillShader)(uint16_t rx, uint16_t ry));
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:
ILI9225_due(uint8_t cs, uint8_t dc, uint8_t rst = 255);
bool begin(void);
void getDisplayStatus();
void fillScreen(uint16_t color=COLOR_BLACK);
void fillRect(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t color);
void fillRectWithShader(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t(*fillShader)(uint16_t rx, uint16_t ry));
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, uint8_t i=0);
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();
}
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))
{
beginTransaction();
writeRegister(endH, x+w-1);
writeRegister(startH, x);
writeRegister(endV, y+h-1);
writeRegister(startV, y);
writeRegister(ramAddrOne, x);
writeRegister(ramAddrTwo, y);
}
// Writes Data to a ILI9225-Register
#ifdef ARDUINO_SAM_DUE
inline __attribute__((always_inline))
#endif
void writeRegister(uint16_t reg, uint16_t val)
{
setDCForIndexOrStatus();
write8_cont(reg);
setDCForControlOrGRAM();
write16_cont(val);
}
// 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)
{