-
Notifications
You must be signed in to change notification settings - Fork 58
/
Adafruit_RA8875.cpp
1806 lines (1561 loc) · 54.2 KB
/
Adafruit_RA8875.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
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
*
* @mainpage Adafruit RA8875 TFT Driver
*
* @author Limor Friend/Ladyada, K.Townsend/KTOWN for Adafruit Industries
*
* @section intro_sec Introduction
*
* 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!
*
* @section author Author
*
* Written by Limor Fried/Ladyada for Adafruit Industries.
*
* @section license License
*
* BSD license, check license.txt for more information.
* All text above must be included in any redistribution.
*
* @section HISTORY
*
* v1.0 - First release
*
*/
#include "Adafruit_RA8875.h"
/// @cond DISABLE
#if defined(EEPROM_SUPPORTED)
/// @endcond
#include <EEPROM.h>
/// @cond DISABLE
#endif
/// @endcond
#include <SPI.h>
/// @cond DISABLE
#if defined(ARDUINO_ARCH_ARC32)
/// @endcond
uint32_t spi_speed = 12000000; /*!< 12MHz */
/// @cond DISABLE
#else
/// @endcond
uint32_t spi_speed = 4000000; /*!< 4MHz */
/// @cond DISABLE
#endif
/// @endcond
// 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() ///< Create dummy Macro Function
#define spi_end() ///< Create dummy Macro Function
#endif
/**************************************************************************/
/*!
Constructor for a new RA8875 instance
@param CS Location of the SPI chip select pin
@param RST 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
@param s The display size, which can be either:
'RA8875_480x80' (3.8" displays) or
'RA8875_480x128' (3.9" displays) or
'RA8875_480x272' (4.3" displays) or
'RA8875_800x480' (5" and 7" displays)
@return True if we reached the end
*/
/**************************************************************************/
boolean Adafruit_RA8875::begin(enum RA8875sizes s) {
_size = s;
if (_size == RA8875_480x80) {
_width = 480;
_height = 80;
} else if (_size == RA8875_480x128) {
_width = 480;
_height = 128;
} else if (_size == RA8875_480x272) {
_width = 480;
_height = 272;
} else if (_size == RA8875_800x480) {
_width = 800;
_height = 480;
} else {
return false;
}
_rotation = 0;
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
/// @cond DISABLE
#if defined(ARDUINO_ARCH_ARC32)
/// @endcond
spi_speed = 2000000;
/// @cond DISABLE
#else
/// @endcond
spi_speed = 125000;
/// @cond DISABLE
#endif
/// @endcond
#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) {
Serial.println(x);
return false;
}
initialize();
#ifdef SPI_HAS_TRANSACTION
/// @cond DISABLE
#if defined(ARDUINO_ARCH_ARC32)
/// @endcond
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_480x80 || _size == RA8875_480x128 ||
_size == RA8875_480x272) {
writeReg(RA8875_PLLC1, RA8875_PLLC1_PLLDIV1 + 10);
delay(1);
writeReg(RA8875_PLLC2, RA8875_PLLC2_DIV4);
delay(1);
} else /* (_size == RA8875_800x480) */ {
writeReg(RA8875_PLLC1, RA8875_PLLC1_PLLDIV1 + 11);
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_480x80) {
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;
_voffset = 192; // This uses the bottom 80 pixels of a 272 pixel controller
} else if (_size == RA8875_480x128 || _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;
_voffset = 0;
} else // (_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;
_voffset = 0;
}
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 + _voffset) & 0xFF);
writeReg(RA8875_VDHR1, (uint16_t)(_height - 1 + _voffset) >> 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 + _voffset); // vertical start point
writeReg(RA8875_VSAW1, 0 + _voffset);
writeReg(RA8875_VEAW0,
(uint16_t)(_height - 1 + _voffset) & 0xFF); // vertical end point
writeReg(RA8875_VEAW1, (uint16_t)(_height - 1 + _voffset) >> 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
@return The 1-based display width in pixels
*/
/**************************************************************************/
uint16_t Adafruit_RA8875::width(void) { return _width; }
/**************************************************************************/
/*!
Returns the display height in pixels
@return The 1-based display height in pixels
*/
/**************************************************************************/
uint16_t Adafruit_RA8875::height(void) { return _height; }
/**************************************************************************/
/*!
Returns the current rotation (0-3)
@return The Rotation Setting
*/
/**************************************************************************/
int8_t Adafruit_RA8875::getRotation(void) { return _rotation; }
/**************************************************************************/
/*!
Sets the current rotation (0-3)
@param rotation The Rotation Setting
*/
/**************************************************************************/
void Adafruit_RA8875::setRotation(int8_t rotation) {
switch (rotation) {
case 2:
_rotation = rotation;
break;
default:
_rotation = 0;
break;
}
}
/************************* 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)
@param x The x position of the cursor (in pixels, 0..1023)
@param y The y position of the cursor (in pixels, 0..511)
*/
/**************************************************************************/
void Adafruit_RA8875::textSetCursor(uint16_t x, uint16_t y) {
x = applyRotationX(x);
y = applyRotationY(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
@param foreColor The RGB565 color to use when rendering the text
@param bgColor 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
@param foreColor 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
@param scale The zoom factor (0..3 for 1-4x zoom)
*/
/**************************************************************************/
void Adafruit_RA8875::textEnlarge(uint8_t scale) {
if (scale > 3)
scale = 3; // highest setting is 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;
}
/**************************************************************************/
/*!
Enable Cursor Visibility and Blink
Here we set bits 6 and 5 in 40h
As well as the set the blink rate in 44h
The rate is 0 through max 255
the lower the number the faster it blinks (00h is 1 frame time,
FFh is 256 Frames time.
Blink Time (sec) = BTCR[44h]x(1/Frame_rate)
@param rate The frame rate to blink
*/
/**************************************************************************/
void Adafruit_RA8875::cursorBlink(uint8_t rate) {
writeCommand(RA8875_MWCR0);
uint8_t temp = readData();
temp |= RA8875_MWCR0_CURSOR;
writeData(temp);
writeCommand(RA8875_MWCR0);
temp = readData();
temp |= RA8875_MWCR0_BLINK;
writeData(temp);
if (rate > 255)
rate = 255;
writeCommand(RA8875_BTCR);
writeData(rate);
}
/**************************************************************************/
/*!
Renders some text on the screen when in text mode
@param buffer The buffer containing the characters to render
@param len 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]);
/// @cond DISABLE
#if defined(__arm__)
/// @endcond
// This delay is needed with textEnlarge(1) because
// Teensy 3.X is much faster than Arduino Uno
if (_textScale > 0)
delay(1);
/// @cond DISABLE
#else
/// @endcond
// For others, delay starting with textEnlarge(2)
if (_textScale > 1)
delay(1);
/// @cond DISABLE
#endif
/// @endcond
}
}
/************************* 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!
@param regname The register name to check
@param waitflag The value to wait for the status register to match
@return True if the expected status has been reached
*/
/**************************************************************************/
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
@param x The 0-based x location
@param y 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
@param num The number of pixels to push
@param p 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);
}
/**************************************************************************/
/*!
Fill the screen with the current color
*/
/**************************************************************************/
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);
}
/**************************************************************************/
/*!
Apply current rotation in the X direction
@return the X value with current rotation applied
*/
/**************************************************************************/
int16_t Adafruit_RA8875::applyRotationX(int16_t x) {
switch (_rotation) {
case 2:
x = _width - 1 - x;
break;
}
return x;
}
/**************************************************************************/
/*!
Apply current rotation in the Y direction
@return the Y value with current rotation applied
*/
/**************************************************************************/
int16_t Adafruit_RA8875::applyRotationY(int16_t y) {
switch (_rotation) {
case 2:
y = _height - 1 - y;
break;
}
return y + _voffset;
}
/**************************************************************************/
/*!
Draws a single pixel at the specified location
@param x The 0-based x location
@param y The 0-base y location
@param color The RGB565 color to use when drawing the pixel
*/
/**************************************************************************/
void Adafruit_RA8875::drawPixel(int16_t x, int16_t y, uint16_t color) {
x = applyRotationX(x);
y = applyRotationY(y);
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 series of pixels at the specified location without the overhead
@param p An array of RGB565 color pixels
@param num The number of the pixels to draw
@param x The 0-based x location
@param y The 0-base y location
*/
/**************************************************************************/
void Adafruit_RA8875::drawPixels(uint16_t *p, uint32_t num, int16_t x,
int16_t y) {
x = applyRotationX(x);
y = applyRotationY(y);
writeReg(RA8875_CURH0, x);
writeReg(RA8875_CURH1, x >> 8);
writeReg(RA8875_CURV0, y);
writeReg(RA8875_CURV1, y >> 8);
uint8_t dir = RA8875_MWCR0_LRTD;
if (_rotation == 2) {
dir = RA8875_MWCR0_RLTD;
}
writeReg(RA8875_MWCR0, (readReg(RA8875_MWCR0) & ~RA8875_MWCR0_DIRMASK) | dir);
writeCommand(RA8875_MRWC);
digitalWrite(_cs, LOW);
SPI.transfer(RA8875_DATAWRITE);
while (num--) {
SPI.transfer16(*p++);
}
digitalWrite(_cs, HIGH);
}
/**************************************************************************/
/*!
Draws a HW accelerated line on the display
@param x0 The 0-based starting x location
@param y0 The 0-base starting y location
@param x1 The 0-based ending x location
@param y1 The 0-base ending y location
@param color 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) {
x0 = applyRotationX(x0);
y0 = applyRotationY(y0);
x1 = applyRotationX(x1);
y1 = applyRotationY(y1);
/* 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);
}
/**************************************************************************/
/*!
Draw a vertical line
@param x The X position
@param y The Y position
@param h Height
@param color The color
*/
/**************************************************************************/
void Adafruit_RA8875::drawFastVLine(int16_t x, int16_t y, int16_t h,
uint16_t color) {
drawLine(x, y, x, y + h, color);
}
/**************************************************************************/
/*!
Draw a horizontal line
@param x The X position
@param y The Y position
@param w Width
@param color The 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
@param x The 0-based x location of the top-right corner
@param y The 0-based y location of the top-right corner
@param w The rectangle width
@param h The rectangle height
@param color 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 - 1, y + h - 1, color, false);
}
/**************************************************************************/
/*!
Draws a HW accelerated filled rectangle on the display
@param x The 0-based x location of the top-right corner
@param y The 0-based y location of the top-right corner
@param w The rectangle width
@param h The rectangle height
@param color 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 - 1, y + h - 1, color, true);
}
/**************************************************************************/
/*!
Fills the screen with the spefied RGB565 color
@param color 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
@param x The 0-based x location of the center of the circle
@param y The 0-based y location of the center of the circle
@param r The circle's radius
@param color The RGB565 color to use when drawing the pixel
*/
/**************************************************************************/
void Adafruit_RA8875::drawCircle(int16_t x, int16_t y, int16_t r,
uint16_t color) {
circleHelper(x, y, r, color, false);
}
/**************************************************************************/
/*!
Draws a HW accelerated filled circle on the display
@param x The 0-based x location of the center of the circle
@param y The 0-based y location of the center of the circle
@param r The circle's radius
@param color The RGB565 color to use when drawing the pixel
*/
/**************************************************************************/
void Adafruit_RA8875::fillCircle(int16_t x, int16_t y, int16_t r,
uint16_t color) {
circleHelper(x, y, r, color, true);
}
/**************************************************************************/
/*!
Draws a HW accelerated triangle on the display
@param x0 The 0-based x location of point 0 on the triangle
@param y0 The 0-based y location of point 0 on the triangle
@param x1 The 0-based x location of point 1 on the triangle
@param y1 The 0-based y location of point 1 on the triangle
@param x2 The 0-based x location of point 2 on the triangle
@param y2 The 0-based y location of point 2 on the triangle
@param color 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
@param x0 The 0-based x location of point 0 on the triangle
@param y0 The 0-based y location of point 0 on the triangle
@param x1 The 0-based x location of point 1 on the triangle
@param y1 The 0-based y location of point 1 on the triangle
@param x2 The 0-based x location of point 2 on the triangle
@param y2 The 0-based y location of point 2 on the triangle
@param color 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
@param xCenter The 0-based x location of the ellipse's center
@param yCenter The 0-based y location of the ellipse's center
@param longAxis The size in pixels of the ellipse's long axis
@param shortAxis The size in pixels of the ellipse's short axis
@param color 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
@param xCenter The 0-based x location of the ellipse's center
@param yCenter The 0-based y location of the ellipse's center
@param longAxis The size in pixels of the ellipse's long axis
@param shortAxis The size in pixels of the ellipse's short axis
@param color 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
@param xCenter The 0-based x location of the ellipse's center
@param yCenter The 0-based y location of the ellipse's center
@param longAxis The size in pixels of the ellipse's long axis
@param shortAxis The size in pixels of the ellipse's short axis
@param curvePart The corner to draw, where in clock-wise motion:
0 = 180-270°
1 = 270-0°
2 = 0-90°
3 = 90-180°
@param color 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
@param xCenter The 0-based x location of the ellipse's center
@param yCenter The 0-based y location of the ellipse's center
@param longAxis The size in pixels of the ellipse's long axis
@param shortAxis The size in pixels of the ellipse's short axis
@param curvePart The corner to draw, where in clock-wise motion:
0 = 180-270°
1 = 270-0°
2 = 0-90°
3 = 90-180°
@param color 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);
}
/**************************************************************************/
/*!
Draws a HW accelerated rounded rectangle on the display
@param x The 0-based x location of the rectangle's upper left corner
@param y The 0-based y location of the rectangle's upper left corner
@param w The size in pixels of the rectangle's width