forked from adafruit/Adafruit_RA8875
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdafruit_RA8875.cpp
More file actions
1291 lines (1116 loc) · 38.4 KB
/
Adafruit_RA8875.cpp
File metadata and controls
1291 lines (1116 loc) · 38.4 KB
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
/**************************************************************************/
/*!
@file Adafruit_RA8875.cpp
@author Limor Friend/Ladyada, K.Townsend/KTOWN for Adafruit Industries
@license BSD license, all text above and below must be included in
any redistribution
This is the library for the Adafruit RA8875 Driver board for TFT displays
---------------> http://www.adafruit.com/products/1590
The RA8875 is a TFT driver for up to 800x480 dotclock'd displays
It is tested to work with displays in the Adafruit shop. Other displays
may need timing adjustments and are not guanteed to work.
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.
BSD license, check license.txt for more information.
All text above must be included in any redistribution.
@section HISTORY
v1.0 - First release
*/
/**************************************************************************/
#include <SPI.h>
#include "Adafruit_RA8875.h"
#if defined (ARDUINO_ARCH_ARC32)
uint32_t spi_speed = 12000000;
#else
uint32_t spi_speed = 4000000;
#endif
// If the SPI library has transaction support, these functions
// establish settings and protect from interference from other
// libraries. Otherwise, they simply do nothing.
#ifdef SPI_HAS_TRANSACTION
static inline void spi_begin(void) __attribute__((always_inline));
static inline void spi_begin(void) {
// max speed!
SPI.beginTransaction(SPISettings(spi_speed, MSBFIRST, SPI_MODE0));
}
static inline void spi_end(void) __attribute__((always_inline));
static inline void spi_end(void) {
SPI.endTransaction();
}
#else
#define spi_begin()
#define spi_end()
#endif
/**************************************************************************/
/*!
Constructor for a new RA8875 instance
@args CS[in] Location of the SPI chip select pin
@args RST[in] Location of the reset pin
*/
/**************************************************************************/
Adafruit_RA8875::Adafruit_RA8875(uint8_t CS, uint8_t RST) : Adafruit_GFX(800, 480) {
_cs = CS;
_rst = RST;
}
/**************************************************************************/
/*!
Initialises the LCD driver and any HW required by the display
@args s[in] The display size, which can be either:
'RA8875_480x272' (4.3" displays) r
'RA8875_800x480' (5" and 7" displays)
*/
/**************************************************************************/
boolean Adafruit_RA8875::begin(enum RA8875sizes s) {
_size = s;
if (_size == RA8875_480x272) {
_width = 480;
_height = 272;
}
if (_size == RA8875_800x480) {
_width = 800;
_height = 480;
}
pinMode(_cs, OUTPUT);
digitalWrite(_cs, HIGH);
pinMode(_rst, OUTPUT);
digitalWrite(_rst, LOW);
delay(100);
digitalWrite(_rst, HIGH);
delay(100);
SPI.begin();
#ifdef SPI_HAS_TRANSACTION
#if defined (ARDUINO_ARCH_ARC32)
spi_speed = 2000000;
#else
spi_speed = 125000;
#endif
#else
#ifdef __AVR__
SPI.setClockDivider(SPI_CLOCK_DIV128);
SPI.setDataMode(SPI_MODE0);
#endif
#endif
uint8_t x = readReg(0);
// Serial.print("x = 0x"); Serial.println(x,HEX);
if (x != 0x75) {
return false;
}
initialize();
#ifdef SPI_HAS_TRANSACTION
#if defined (ARDUINO_ARCH_ARC32)
spi_speed = 12000000L;
#else
spi_speed = 4000000L;
#endif
#else
#ifdef __AVR__
SPI.setClockDivider(SPI_CLOCK_DIV4);
#endif
#endif
return true;
}
/************************* Initialization *********************************/
/**************************************************************************/
/*!
Performs a SW-based reset of the RA8875
*/
/**************************************************************************/
void Adafruit_RA8875::softReset(void) {
writeCommand(RA8875_PWRR);
writeData(RA8875_PWRR_SOFTRESET);
writeData(RA8875_PWRR_NORMAL);
delay(1);
}
/**************************************************************************/
/*!
Initialise the PLL
*/
/**************************************************************************/
void Adafruit_RA8875::PLLinit(void) {
if (_size == RA8875_480x272) {
writeReg(RA8875_PLLC1, RA8875_PLLC1_PLLDIV1 + 10);
delay(1);
writeReg(RA8875_PLLC2, RA8875_PLLC2_DIV4);
delay(1);
}
if (_size == RA8875_800x480) {
writeReg(RA8875_PLLC1, RA8875_PLLC1_PLLDIV1 + 10);
delay(1);
writeReg(RA8875_PLLC2, RA8875_PLLC2_DIV4);
delay(1);
}
}
/**************************************************************************/
/*!
Initialises the driver IC (clock setup, etc.)
*/
/**************************************************************************/
void Adafruit_RA8875::initialize(void) {
PLLinit();
writeReg(RA8875_SYSR, RA8875_SYSR_16BPP | RA8875_SYSR_MCU8);
/* Timing values */
uint8_t pixclk;
uint8_t hsync_start;
uint8_t hsync_pw;
uint8_t hsync_finetune;
uint8_t hsync_nondisp;
uint8_t vsync_pw;
uint16_t vsync_nondisp;
uint16_t vsync_start;
/* Set the correct values for the display being used */
if (_size == RA8875_480x272)
{
pixclk = RA8875_PCSR_PDATL | RA8875_PCSR_4CLK;
hsync_nondisp = 10;
hsync_start = 8;
hsync_pw = 48;
hsync_finetune = 0;
vsync_nondisp = 3;
vsync_start = 8;
vsync_pw = 10;
}
else if (_size == RA8875_800x480)
{
pixclk = RA8875_PCSR_PDATL | RA8875_PCSR_2CLK;
hsync_nondisp = 26;
hsync_start = 32;
hsync_pw = 96;
hsync_finetune = 0;
vsync_nondisp = 32;
vsync_start = 23;
vsync_pw = 2;
}
writeReg(RA8875_PCSR, pixclk);
delay(1);
/* Horizontal settings registers */
writeReg(RA8875_HDWR, (_width / 8) - 1); // H width: (HDWR + 1) * 8 = 480
writeReg(RA8875_HNDFTR, RA8875_HNDFTR_DE_HIGH + hsync_finetune);
writeReg(RA8875_HNDR, (hsync_nondisp - hsync_finetune - 2)/8); // H non-display: HNDR * 8 + HNDFTR + 2 = 10
writeReg(RA8875_HSTR, hsync_start/8 - 1); // Hsync start: (HSTR + 1)*8
writeReg(RA8875_HPWR, RA8875_HPWR_LOW + (hsync_pw/8 - 1)); // HSync pulse width = (HPWR+1) * 8
/* Vertical settings registers */
writeReg(RA8875_VDHR0, (uint16_t)(_height - 1) & 0xFF);
writeReg(RA8875_VDHR1, (uint16_t)(_height - 1) >> 8);
writeReg(RA8875_VNDR0, vsync_nondisp-1); // V non-display period = VNDR + 1
writeReg(RA8875_VNDR1, vsync_nondisp >> 8);
writeReg(RA8875_VSTR0, vsync_start-1); // Vsync start position = VSTR + 1
writeReg(RA8875_VSTR1, vsync_start >> 8);
writeReg(RA8875_VPWR, RA8875_VPWR_LOW + vsync_pw - 1); // Vsync pulse width = VPWR + 1
/* Set active window X */
writeReg(RA8875_HSAW0, 0); // horizontal start point
writeReg(RA8875_HSAW1, 0);
writeReg(RA8875_HEAW0, (uint16_t)(_width - 1) & 0xFF); // horizontal end point
writeReg(RA8875_HEAW1, (uint16_t)(_width - 1) >> 8);
/* Set active window Y */
writeReg(RA8875_VSAW0, 0); // vertical start point
writeReg(RA8875_VSAW1, 0);
writeReg(RA8875_VEAW0, (uint16_t)(_height - 1) & 0xFF); // horizontal end point
writeReg(RA8875_VEAW1, (uint16_t)(_height - 1) >> 8);
/* ToDo: Setup touch panel? */
/* Clear the entire window */
writeReg(RA8875_MCLR, RA8875_MCLR_START | RA8875_MCLR_FULL);
delay(500);
}
/**************************************************************************/
/*!
Returns the display width in pixels
@returns The 1-based display width in pixels
*/
/**************************************************************************/
uint16_t Adafruit_RA8875::width(void) { return _width; }
/**************************************************************************/
/*!
Returns the display height in pixels
@returns The 1-based display height in pixels
*/
/**************************************************************************/
uint16_t Adafruit_RA8875::height(void) { return _height; }
/************************* Text Mode ***********************************/
/**************************************************************************/
/*!
Sets the display in text mode (as opposed to graphics mode)
*/
/**************************************************************************/
void Adafruit_RA8875::textMode(void)
{
/* Set text mode */
writeCommand(RA8875_MWCR0);
uint8_t temp = readData();
temp |= RA8875_MWCR0_TXTMODE; // Set bit 7
writeData(temp);
/* Select the internal (ROM) font */
writeCommand(0x21);
temp = readData();
temp &= ~((1<<7) | (1<<5)); // Clear bits 7 and 5
writeData(temp);
}
/**************************************************************************/
/*!
Sets the display in text mode (as opposed to graphics mode)
@args x[in] The x position of the cursor (in pixels, 0..1023)
@args y[in] The y position of the cursor (in pixels, 0..511)
*/
/**************************************************************************/
void Adafruit_RA8875::textSetCursor(uint16_t x, uint16_t y)
{
/* Set cursor location */
writeCommand(0x2A);
writeData(x & 0xFF);
writeCommand(0x2B);
writeData(x >> 8);
writeCommand(0x2C);
writeData(y & 0xFF);
writeCommand(0x2D);
writeData(y >> 8);
}
/**************************************************************************/
/*!
Sets the fore and background color when rendering text
@args foreColor[in] The RGB565 color to use when rendering the text
@args bgColor[in] The RGB565 colot to use for the background
*/
/**************************************************************************/
void Adafruit_RA8875::textColor(uint16_t foreColor, uint16_t bgColor)
{
/* Set Fore Color */
writeCommand(0x63);
writeData((foreColor & 0xf800) >> 11);
writeCommand(0x64);
writeData((foreColor & 0x07e0) >> 5);
writeCommand(0x65);
writeData((foreColor & 0x001f));
/* Set Background Color */
writeCommand(0x60);
writeData((bgColor & 0xf800) >> 11);
writeCommand(0x61);
writeData((bgColor & 0x07e0) >> 5);
writeCommand(0x62);
writeData((bgColor & 0x001f));
/* Clear transparency flag */
writeCommand(0x22);
uint8_t temp = readData();
temp &= ~(1<<6); // Clear bit 6
writeData(temp);
}
/**************************************************************************/
/*!
Sets the fore color when rendering text with a transparent bg
@args foreColor[in] The RGB565 color to use when rendering the text
*/
/**************************************************************************/
void Adafruit_RA8875::textTransparent(uint16_t foreColor)
{
/* Set Fore Color */
writeCommand(0x63);
writeData((foreColor & 0xf800) >> 11);
writeCommand(0x64);
writeData((foreColor & 0x07e0) >> 5);
writeCommand(0x65);
writeData((foreColor & 0x001f));
/* Set transparency flag */
writeCommand(0x22);
uint8_t temp = readData();
temp |= (1<<6); // Set bit 6
writeData(temp);
}
/**************************************************************************/
/*!
Sets the text enlarge settings, using one of the following values:
0 = 1x zoom
1 = 2x zoom
2 = 3x zoom
3 = 4x zoom
@args scale[in] The zoom factor (0..3 for 1-4x zoom)
*/
/**************************************************************************/
void Adafruit_RA8875::textEnlarge(uint8_t scale)
{
if (scale > 3) scale = 3;
/* Set font size flags */
writeCommand(0x22);
uint8_t temp = readData();
temp &= ~(0xF); // Clears bits 0..3
temp |= scale << 2;
temp |= scale;
writeData(temp);
_textScale = scale;
}
/**************************************************************************/
/*!
Renders some text on the screen when in text mode
@args buffer[in] The buffer containing the characters to render
@args len[in] The size of the buffer in bytes
*/
/**************************************************************************/
void Adafruit_RA8875::textWrite(const char* buffer, uint16_t len)
{
if (len == 0) len = strlen(buffer);
writeCommand(RA8875_MRWC);
for (uint16_t i=0;i<len;i++)
{
writeData(buffer[i]);
#if defined(__AVR__)
if (_textScale > 1) delay(1);
#elif defined(__arm__)
// This delay is needed with textEnlarge(1) because
// Teensy 3.X is much faster than Arduino Uno
if (_textScale > 0) delay(1);
#endif
}
}
/************************* Graphics ***********************************/
/**************************************************************************/
/*!
Sets the display in graphics mode (as opposed to text mode)
*/
/**************************************************************************/
void Adafruit_RA8875::graphicsMode(void) {
writeCommand(RA8875_MWCR0);
uint8_t temp = readData();
temp &= ~RA8875_MWCR0_TXTMODE; // bit #7
writeData(temp);
}
/**************************************************************************/
/*!
Waits for screen to finish by polling the status!
*/
/**************************************************************************/
boolean Adafruit_RA8875::waitPoll(uint8_t regname, uint8_t waitflag) {
/* Wait for the command to finish */
while (1)
{
uint8_t temp = readReg(regname);
if (!(temp & waitflag))
return true;
}
return false; // MEMEFIX: yeah i know, unreached! - add timeout?
}
/**************************************************************************/
/*!
Sets the current X/Y position on the display before drawing
@args x[in] The 0-based x location
@args y[in] The 0-base y location
*/
/**************************************************************************/
void Adafruit_RA8875::setXY(uint16_t x, uint16_t y) {
writeReg(RA8875_CURH0, x);
writeReg(RA8875_CURH1, x >> 8);
writeReg(RA8875_CURV0, y);
writeReg(RA8875_CURV1, y >> 8);
}
/**************************************************************************/
/*!
HW accelerated function to push a chunk of raw pixel data
@args num[in] The number of pixels to push
@args p[in] The pixel color to use
*/
/**************************************************************************/
void Adafruit_RA8875::pushPixels(uint32_t num, uint16_t p) {
digitalWrite(_cs, LOW);
SPI.transfer(RA8875_DATAWRITE);
while (num--) {
SPI.transfer(p >> 8);
SPI.transfer(p);
}
digitalWrite(_cs, HIGH);
}
/**************************************************************************/
/*!
*/
/**************************************************************************/
void Adafruit_RA8875::fillRect(void) {
writeCommand(RA8875_DCR);
writeData(RA8875_DCR_LINESQUTRI_STOP | RA8875_DCR_DRAWSQUARE);
writeData(RA8875_DCR_LINESQUTRI_START | RA8875_DCR_FILL | RA8875_DCR_DRAWSQUARE);
}
/**************************************************************************/
/*!
Draws a single pixel at the specified location
@args x[in] The 0-based x location
@args y[in] The 0-base y location
@args color[in] The RGB565 color to use when drawing the pixel
*/
/**************************************************************************/
void Adafruit_RA8875::drawPixel(int16_t x, int16_t y, uint16_t color)
{
writeReg(RA8875_CURH0, x);
writeReg(RA8875_CURH1, x >> 8);
writeReg(RA8875_CURV0, y);
writeReg(RA8875_CURV1, y >> 8);
writeCommand(RA8875_MRWC);
digitalWrite(_cs, LOW);
SPI.transfer(RA8875_DATAWRITE);
SPI.transfer(color >> 8);
SPI.transfer(color);
digitalWrite(_cs, HIGH);
}
/**************************************************************************/
/*!
Draws a HW accelerated line on the display
@args x0[in] The 0-based starting x location
@args y0[in] The 0-base starting y location
@args x1[in] The 0-based ending x location
@args y1[in] The 0-base ending y location
@args color[in] The RGB565 color to use when drawing the pixel
*/
/**************************************************************************/
void Adafruit_RA8875::drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color)
{
/* Set X */
writeCommand(0x91);
writeData(x0);
writeCommand(0x92);
writeData(x0 >> 8);
/* Set Y */
writeCommand(0x93);
writeData(y0);
writeCommand(0x94);
writeData(y0 >> 8);
/* Set X1 */
writeCommand(0x95);
writeData(x1);
writeCommand(0x96);
writeData((x1) >> 8);
/* Set Y1 */
writeCommand(0x97);
writeData(y1);
writeCommand(0x98);
writeData((y1) >> 8);
/* Set Color */
writeCommand(0x63);
writeData((color & 0xf800) >> 11);
writeCommand(0x64);
writeData((color & 0x07e0) >> 5);
writeCommand(0x65);
writeData((color & 0x001f));
/* Draw! */
writeCommand(RA8875_DCR);
writeData(0x80);
/* Wait for the command to finish */
waitPoll(RA8875_DCR, RA8875_DCR_LINESQUTRI_STATUS);
}
/**************************************************************************/
/*!
*/
/**************************************************************************/
void Adafruit_RA8875::drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color)
{
drawLine(x, y, x, y+h, color);
}
/**************************************************************************/
/*!
*/
/**************************************************************************/
void Adafruit_RA8875::drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color)
{
drawLine(x, y, x+w, y, color);
}
/**************************************************************************/
/*!
Draws a HW accelerated rectangle on the display
@args x[in] The 0-based x location of the top-right corner
@args y[in] The 0-based y location of the top-right corner
@args w[in] The rectangle width
@args h[in] The rectangle height
@args color[in] The RGB565 color to use when drawing the pixel
*/
/**************************************************************************/
void Adafruit_RA8875::drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
{
rectHelper(x, y, x+w, y+h, color, false);
}
/**************************************************************************/
/*!
Draws a HW accelerated filled rectangle on the display
@args x[in] The 0-based x location of the top-right corner
@args y[in] The 0-based y location of the top-right corner
@args w[in] The rectangle width
@args h[in] The rectangle height
@args color[in] The RGB565 color to use when drawing the pixel
*/
/**************************************************************************/
void Adafruit_RA8875::fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
{
rectHelper(x, y, x+w, y+h, color, true);
}
/**************************************************************************/
/*!
Fills the screen with the spefied RGB565 color
@args color[in] The RGB565 color to use when drawing the pixel
*/
/**************************************************************************/
void Adafruit_RA8875::fillScreen(uint16_t color)
{
rectHelper(0, 0, _width-1, _height-1, color, true);
}
/**************************************************************************/
/*!
Draws a HW accelerated circle on the display
@args x[in] The 0-based x location of the center of the circle
@args y[in] The 0-based y location of the center of the circle
@args w[in] The circle's radius
@args color[in] The RGB565 color to use when drawing the pixel
*/
/**************************************************************************/
void Adafruit_RA8875::drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color)
{
circleHelper(x0, y0, r, color, false);
}
/**************************************************************************/
/*!
Draws a HW accelerated filled circle on the display
@args x[in] The 0-based x location of the center of the circle
@args y[in] The 0-based y location of the center of the circle
@args w[in] The circle's radius
@args color[in] The RGB565 color to use when drawing the pixel
*/
/**************************************************************************/
void Adafruit_RA8875::fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color)
{
circleHelper(x0, y0, r, color, true);
}
/**************************************************************************/
/*!
Draws a HW accelerated triangle on the display
@args x0[in] The 0-based x location of point 0 on the triangle
@args y0[in] The 0-based y location of point 0 on the triangle
@args x1[in] The 0-based x location of point 1 on the triangle
@args y1[in] The 0-based y location of point 1 on the triangle
@args x2[in] The 0-based x location of point 2 on the triangle
@args y2[in] The 0-based y location of point 2 on the triangle
@args color[in] The RGB565 color to use when drawing the pixel
*/
/**************************************************************************/
void Adafruit_RA8875::drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color)
{
triangleHelper(x0, y0, x1, y1, x2, y2, color, false);
}
/**************************************************************************/
/*!
Draws a HW accelerated filled triangle on the display
@args x0[in] The 0-based x location of point 0 on the triangle
@args y0[in] The 0-based y location of point 0 on the triangle
@args x1[in] The 0-based x location of point 1 on the triangle
@args y1[in] The 0-based y location of point 1 on the triangle
@args x2[in] The 0-based x location of point 2 on the triangle
@args y2[in] The 0-based y location of point 2 on the triangle
@args color[in] The RGB565 color to use when drawing the pixel
*/
/**************************************************************************/
void Adafruit_RA8875::fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color)
{
triangleHelper(x0, y0, x1, y1, x2, y2, color, true);
}
/**************************************************************************/
/*!
Draws a HW accelerated ellipse on the display
@args xCenter[in] The 0-based x location of the ellipse's center
@args yCenter[in] The 0-based y location of the ellipse's center
@args longAxis[in] The size in pixels of the ellipse's long axis
@args shortAxis[in] The size in pixels of the ellipse's short axis
@args color[in] The RGB565 color to use when drawing the pixel
*/
/**************************************************************************/
void Adafruit_RA8875::drawEllipse(int16_t xCenter, int16_t yCenter, int16_t longAxis, int16_t shortAxis, uint16_t color)
{
ellipseHelper(xCenter, yCenter, longAxis, shortAxis, color, false);
}
/**************************************************************************/
/*!
Draws a HW accelerated filled ellipse on the display
@args xCenter[in] The 0-based x location of the ellipse's center
@args yCenter[in] The 0-based y location of the ellipse's center
@args longAxis[in] The size in pixels of the ellipse's long axis
@args shortAxis[in] The size in pixels of the ellipse's short axis
@args color[in] The RGB565 color to use when drawing the pixel
*/
/**************************************************************************/
void Adafruit_RA8875::fillEllipse(int16_t xCenter, int16_t yCenter, int16_t longAxis, int16_t shortAxis, uint16_t color)
{
ellipseHelper(xCenter, yCenter, longAxis, shortAxis, color, true);
}
/**************************************************************************/
/*!
Draws a HW accelerated curve on the display
@args xCenter[in] The 0-based x location of the ellipse's center
@args yCenter[in] The 0-based y location of the ellipse's center
@args longAxis[in] The size in pixels of the ellipse's long axis
@args shortAxis[in] The size in pixels of the ellipse's short axis
@args curvePart[in] The corner to draw, where in clock-wise motion:
0 = 180-270°
1 = 270-0°
2 = 0-90°
3 = 90-180°
@args color[in] The RGB565 color to use when drawing the pixel
*/
/**************************************************************************/
void Adafruit_RA8875::drawCurve(int16_t xCenter, int16_t yCenter, int16_t longAxis, int16_t shortAxis, uint8_t curvePart, uint16_t color)
{
curveHelper(xCenter, yCenter, longAxis, shortAxis, curvePart, color, false);
}
/**************************************************************************/
/*!
Draws a HW accelerated filled curve on the display
@args xCenter[in] The 0-based x location of the ellipse's center
@args yCenter[in] The 0-based y location of the ellipse's center
@args longAxis[in] The size in pixels of the ellipse's long axis
@args shortAxis[in] The size in pixels of the ellipse's short axis
@args curvePart[in] The corner to draw, where in clock-wise motion:
0 = 180-270°
1 = 270-0°
2 = 0-90°
3 = 90-180°
@args color[in] The RGB565 color to use when drawing the pixel
*/
/**************************************************************************/
void Adafruit_RA8875::fillCurve(int16_t xCenter, int16_t yCenter, int16_t longAxis, int16_t shortAxis, uint8_t curvePart, uint16_t color)
{
curveHelper(xCenter, yCenter, longAxis, shortAxis, curvePart, color, true);
}
/**************************************************************************/
/*!
Helper function for higher level circle drawing code
*/
/**************************************************************************/
void Adafruit_RA8875::circleHelper(int16_t x0, int16_t y0, int16_t r, uint16_t color, bool filled)
{
/* Set X */
writeCommand(0x99);
writeData(x0);
writeCommand(0x9a);
writeData(x0 >> 8);
/* Set Y */
writeCommand(0x9b);
writeData(y0);
writeCommand(0x9c);
writeData(y0 >> 8);
/* Set Radius */
writeCommand(0x9d);
writeData(r);
/* Set Color */
writeCommand(0x63);
writeData((color & 0xf800) >> 11);
writeCommand(0x64);
writeData((color & 0x07e0) >> 5);
writeCommand(0x65);
writeData((color & 0x001f));
/* Draw! */
writeCommand(RA8875_DCR);
if (filled)
{
writeData(RA8875_DCR_CIRCLE_START | RA8875_DCR_FILL);
}
else
{
writeData(RA8875_DCR_CIRCLE_START | RA8875_DCR_NOFILL);
}
/* Wait for the command to finish */
waitPoll(RA8875_DCR, RA8875_DCR_CIRCLE_STATUS);
}
/**************************************************************************/
/*!
Helper function for higher level rectangle drawing code
*/
/**************************************************************************/
void Adafruit_RA8875::rectHelper(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color, bool filled)
{
/* Set X */
writeCommand(0x91);
writeData(x);
writeCommand(0x92);
writeData(x >> 8);
/* Set Y */
writeCommand(0x93);
writeData(y);
writeCommand(0x94);
writeData(y >> 8);
/* Set X1 */
writeCommand(0x95);
writeData(w);
writeCommand(0x96);
writeData((w) >> 8);
/* Set Y1 */
writeCommand(0x97);
writeData(h);
writeCommand(0x98);
writeData((h) >> 8);
/* Set Color */
writeCommand(0x63);
writeData((color & 0xf800) >> 11);
writeCommand(0x64);
writeData((color & 0x07e0) >> 5);
writeCommand(0x65);
writeData((color & 0x001f));
/* Draw! */
writeCommand(RA8875_DCR);
if (filled)
{
writeData(0xB0);
}
else
{
writeData(0x90);
}
/* Wait for the command to finish */
waitPoll(RA8875_DCR, RA8875_DCR_LINESQUTRI_STATUS);
}
/**************************************************************************/
/*!
Helper function for higher level triangle drawing code
*/
/**************************************************************************/
void Adafruit_RA8875::triangleHelper(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color, bool filled)
{
/* Set Point 0 */
writeCommand(0x91);
writeData(x0);
writeCommand(0x92);
writeData(x0 >> 8);
writeCommand(0x93);
writeData(y0);
writeCommand(0x94);
writeData(y0 >> 8);
/* Set Point 1 */
writeCommand(0x95);
writeData(x1);
writeCommand(0x96);
writeData(x1 >> 8);
writeCommand(0x97);
writeData(y1);
writeCommand(0x98);
writeData(y1 >> 8);
/* Set Point 2 */
writeCommand(0xA9);
writeData(x2);
writeCommand(0xAA);
writeData(x2 >> 8);
writeCommand(0xAB);
writeData(y2);
writeCommand(0xAC);
writeData(y2 >> 8);
/* Set Color */
writeCommand(0x63);
writeData((color & 0xf800) >> 11);
writeCommand(0x64);
writeData((color & 0x07e0) >> 5);
writeCommand(0x65);
writeData((color & 0x001f));
/* Draw! */
writeCommand(RA8875_DCR);
if (filled)
{
writeData(0xA1);
}
else
{
writeData(0x81);
}
/* Wait for the command to finish */
waitPoll(RA8875_DCR, RA8875_DCR_LINESQUTRI_STATUS);
}
/**************************************************************************/
/*!
Helper function for higher level ellipse drawing code
*/
/**************************************************************************/
void Adafruit_RA8875::ellipseHelper(int16_t xCenter, int16_t yCenter, int16_t longAxis, int16_t shortAxis, uint16_t color, bool filled)
{
/* Set Center Point */
writeCommand(0xA5);
writeData(xCenter);
writeCommand(0xA6);
writeData(xCenter >> 8);
writeCommand(0xA7);
writeData(yCenter);
writeCommand(0xA8);
writeData(yCenter >> 8);
/* Set Long and Short Axis */
writeCommand(0xA1);
writeData(longAxis);
writeCommand(0xA2);
writeData(longAxis >> 8);
writeCommand(0xA3);
writeData(shortAxis);
writeCommand(0xA4);
writeData(shortAxis >> 8);
/* Set Color */
writeCommand(0x63);
writeData((color & 0xf800) >> 11);
writeCommand(0x64);
writeData((color & 0x07e0) >> 5);
writeCommand(0x65);
writeData((color & 0x001f));
/* Draw! */
writeCommand(0xA0);
if (filled)
{
writeData(0xC0);
}
else
{
writeData(0x80);
}
/* Wait for the command to finish */
waitPoll(RA8875_ELLIPSE, RA8875_ELLIPSE_STATUS);
}
/**************************************************************************/
/*!
Helper function for higher level curve drawing code
*/
/**************************************************************************/
void Adafruit_RA8875::curveHelper(int16_t xCenter, int16_t yCenter, int16_t longAxis, int16_t shortAxis, uint8_t curvePart, uint16_t color, bool filled)
{
/* Set Center Point */
writeCommand(0xA5);
writeData(xCenter);
writeCommand(0xA6);
writeData(xCenter >> 8);
writeCommand(0xA7);
writeData(yCenter);
writeCommand(0xA8);