-
Notifications
You must be signed in to change notification settings - Fork 1
/
RA8875.c
1719 lines (1547 loc) · 50.8 KB
/
RA8875.c
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
/*
* RA8875.c
*
* Created on: 09 lug 2020
* Author: luca.faccin
*/
#include "RA8875.h"
#include "string.h"
#include "header.h"
/**
* Static variables
*/
RA8875_sizes_e _size;
uint16_t _width, _height;
uint8_t _textScale;
uint8_t _rotation;
uint8_t _voffset;
GPIO_TypeDef *_reset_port = NULL;
uint16_t _reset_pin = 0;
GPIO_TypeDef *_wait_port = NULL;
uint16_t _wait_pin = 0;
RA8875_bpp_e _color_depth;
/**
* Helpers for PIN
*/
#define LCD_RESET_OFF _reset_port->BRR=_reset_pin;
#define LCD_RESET_ON _reset_port->BSRR=_reset_pin;
//Wait is active low in RA8875
#define LCD_WAIT_STATUS (_wait_port->IDR & _wait_pin)
static void swap (int16_t *x, int16_t *y)
{
int16_t temp = *x;
*x = *y;
*y = temp;
}
/**************************************************************************/
/*!
Performs a SW-based reset of the RA8875
*/
/**************************************************************************/
void RA8875_soft_reset (void)
{
RA8875_write_reg (RA8875_PWRR, RA8875_PWRR_SOFTRESET);
HAL_Delay (10);
RA8875_write_reg (RA8875_PWRR, RA8875_PWRR_NORMAL);
}
/**************************************************************************/
/*!
Initialise the PLL
*/
/**************************************************************************/
static void RA885_pll_init (void)
{
if (_size == RA8875_480x80 || _size == RA8875_480x128 || _size == RA8875_480x272)
{
RA8875_write_reg (RA8875_PLLC1, RA8875_PLLC1_PLLDIV1 + 8);
HAL_Delay (1);
RA8875_write_reg (RA8875_PLLC2, RA8875_PLLC2_DIV4);
HAL_Delay (1);
}
else /* (_size == RA8875_800x480) */
{
RA8875_write_reg (RA8875_PLLC1, RA8875_PLLC1_PLLDIV1 + 11);
HAL_Delay (1);
RA8875_write_reg (RA8875_PLLC2, RA8875_PLLC2_DIV4);
HAL_Delay (1);
}
}
/**************************************************************************/
/*!
Initialises the driver IC (clock setup, etc.)
*/
/**************************************************************************/
static void RA8875_init (uint16_t color_depth, uint16_t mcu_bus)
{
RA885_pll_init ();
RA8875_write_reg (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;
}
/**
* Set color dept and MCU Bus
*/
RA8875_write_reg (RA8875_SYSR, color_depth | mcu_bus);
RA8875_write_reg (RA8875_PCSR, pixclk);
HAL_Delay (1);
/* Horizontal settings registers */
RA8875_write_reg (RA8875_HDWR, (_width / 8) - 1); // H width: (HDWR + 1) * 8 = 480
RA8875_write_reg (RA8875_HNDFTR, RA8875_HNDFTR_DE_HIGH + hsync_finetune);
RA8875_write_reg (RA8875_HNDR, (hsync_nondisp - hsync_finetune - 2) / 8); // H non-display: HNDR * 8 + HNDFTR + 2 = 10
RA8875_write_reg (RA8875_HSTR, hsync_start / 8 - 1); // Hsync start: (HSTR + 1)*8
RA8875_write_reg (RA8875_HPWR,
RA8875_HPWR_LOW + (hsync_pw / 8 - 1)); // HSync pulse width = (HPWR+1) * 8
/* Vertical settings registers */
RA8875_write_reg (RA8875_VDHR0, (uint16_t) (_height - 1 + _voffset) & 0xFF);
RA8875_write_reg (RA8875_VDHR1, (uint16_t) (_height - 1 + _voffset) >> 8);
RA8875_write_reg (RA8875_VNDR0, vsync_nondisp - 1); // V non-display period = VNDR + 1
RA8875_write_reg (RA8875_VNDR1, vsync_nondisp >> 8);
RA8875_write_reg (RA8875_VSTR0, vsync_start - 1); // Vsync start position = VSTR + 1
RA8875_write_reg (RA8875_VSTR1, vsync_start >> 8);
RA8875_write_reg (RA8875_VPWR,
RA8875_VPWR_LOW + vsync_pw - 1); // Vsync pulse width = VPWR + 1
/* Set active window X */
RA8875_write_reg (RA8875_HSAW0, 0); // horizontal start point
RA8875_write_reg (RA8875_HSAW1, 0);
RA8875_write_reg (RA8875_HEAW0, (uint16_t) (_width - 1) & 0xFF); // horizontal end point
RA8875_write_reg (RA8875_HEAW1, (uint16_t) (_width - 1) >> 8);
/* Set active window Y */
RA8875_write_reg (RA8875_VSAW0, 0 + _voffset); // vertical start point
RA8875_write_reg (RA8875_VSAW1, 0 + _voffset);
RA8875_write_reg (RA8875_VEAW0, (uint16_t) (_height - 1 + _voffset) & 0xFF); // vertical end point
RA8875_write_reg (RA8875_VEAW1, (uint16_t) (_height - 1 + _voffset) >> 8);
/**
* LCD WITH 2 layer
*/
RA8875_write_reg (RA8875_DPCR, RA8875_DPCR_2_LAYER);
/* ToDo: Setup touch panel? */
/* Clear the entire window */
RA8875_write_reg (RA8875_MCLR, RA8875_MCLR_START | RA8875_MCLR_FULL);
HAL_Delay (500);
}
/**************************************************************************/
/*!
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 1 if we reached the end 0 if some error occurs
*/
/**************************************************************************/
uint8_t RA8875_begin (GPIO_TypeDef *reset_port, uint16_t reset_pin, GPIO_TypeDef *wait_port, uint16_t wait_pin, RA8875_sizes_e s, RA8875_bpp_e bpp)
{
_reset_port = reset_port;
_reset_pin = reset_pin;
_size = s;
_wait_port = wait_port;
_wait_pin = wait_pin;
_color_depth = bpp;
//Wait 50 ms
HAL_Delay (50);
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 0;
}
_rotation = 0;
//Display hardware reset. Reset is active LOW
LCD_RESET_OFF
;
HAL_Delay (10);
LCD_RESET_ON
;
HAL_Delay (10);
RA8875_soft_reset ();
HAL_Delay (10);
RA8875_init (((bpp == RA8875_8BPP) ? RA8875_SYSR_8BPP : RA8875_SYSR_16BPP), RA8875_SYSR_MCU8);
return 1;
}
/************************* Low Level ***********************************/
/**
* Wait for BUS Free
* @return 0 if bus not free, 1 otherwise
*/
static uint8_t RA8875_BUS_FREE ()
{
while (LCD_WAIT_STATUS == 0)
{
}
return 1;
}
/**************************************************************************/
/*!
Write data to the specified register
@param reg Register to write to
@param val Value to write
*/
/**************************************************************************/
void RA8875_write_reg (uint8_t reg, uint8_t val)
{
RA8875_write_command (reg);
RA8875_write_data (val);
}
/**************************************************************************/
/*!
Set the register to read from
@param reg Register to read
@return The value
*/
/**************************************************************************/
uint8_t RA8875_read_reg (uint8_t reg)
{
RA8875_write_command (reg);
return RA8875_read_data ();
}
/**************************************************************************/
/*!
Write data to the current register
@param d Data to write
*/
/**************************************************************************/
void RA8875_write_data (uint8_t d)
{
if (LCD_WAIT_STATUS == 0)
{
if (!(RA8875_BUS_FREE (1))) return;
}
RA8875_DATA->VAL = d;
}
/**************************************************************************/
/*!
Read the data from the current register
@return The Value
*/
/**************************************************************************/
uint8_t RA8875_read_data (void)
{
uint8_t data = 0;
//Wait is active low
if (LCD_WAIT_STATUS == 0)
{
if (!(RA8875_BUS_FREE (1))) return 0;
}
data = RA8875_DATA->VAL;
return data;
}
/**************************************************************************/
/*!
Write a command to the current register
@param d The data to write as a command
*/
/**************************************************************************/
void RA8875_write_command (uint8_t d)
{
//Wait is active low
if (LCD_WAIT_STATUS == 0)
{
if (!(RA8875_BUS_FREE (1))) return;
}
RA8875_REGISTER->VAL = d;
}
/**************************************************************************/
/*!
Read the status from the current register
@return The value
*/
/**************************************************************************/
uint8_t RA8875_read_status (void)
{
uint8_t status = 0;
//Wait is active low
if (LCD_WAIT_STATUS == 0)
{
if (!(RA8875_BUS_FREE (1))) return 0;
}
status = RA8875_REGISTER->VAL;
return status;
}
/**************************************************************************/
/*!
Returns the display width in pixels
@return The 1-based display width in pixels
*/
/**************************************************************************/
uint16_t RA8875_width (void)
{
return _width;
}
/**************************************************************************/
/*!
Returns the display height in pixels
@return The 1-based display height in pixels
*/
/**************************************************************************/
uint16_t RA8875_height (void)
{
return _height;
}
/**************************************************************************/
/*!
Returns the current rotation (0-3)
@return The Rotation Setting
*/
/**************************************************************************/
int8_t RA8875_get_rotation (void)
{
return _rotation;
}
/**************************************************************************/
/*!
Sets the current rotation (0-3)
@param rotation The Rotation Setting
*/
/**************************************************************************/
void RA8875_set_rotation (int8_t rotation)
{
switch (rotation)
{
case 2:
_rotation = rotation;
break;
default:
_rotation = 0;
break;
}
}
/************************* Graphics ***********************************/
/**************************************************************************/
/*!
Sets the display in graphics mode (as opposed to text mode)
*/
/**************************************************************************/
void RA8875_graphic_mode (void)
{
RA8875_write_command (RA8875_MWCR0);
uint8_t temp = RA8875_read_data ();
temp &= ~RA8875_MWCR0_TXTMODE; // bit #7
RA8875_write_data (temp);
}
/**
* Set the layer where we want to write/read
* @param layer: 0 or 1
*/
void RA8875_set_write_layer (uint8_t layer)
{
RA8875_write_reg (RA8875_MWCR1, (RA8875_read_reg (RA8875_MWCR1) & ~RA8875_MWCR1_LMASK & ~RA8875_MWCR1_WDMASK) | layer | RA8875_MWCR1_WD_LAYER);
}
/**
* Set the actual layer mode
* @param layer_mode: one of the RA8875_LPTR0_DM_XXX
*/
void RA8875_set_layer_mode(uint8_t layer_mode)
{
RA8875_write_reg (RA8875_LTPR0, (RA8875_read_reg (RA8875_LTPR0) & ~RA8875_LTPR0_DM_BITMASK)|layer_mode);
}
/**
* Set the transparent color for layer 0
* @param color: color in RGB565
*/
void RA8875_set_layer_transparent_color(uint16_t color)
{
//Red component
RA8875_write_reg(RA8875_BGTR0,(color & 0xf800) >> 11);
//Green
RA8875_write_reg(RA8875_BGTR1,(color & 0x07e0) >> 5);
//Blue
RA8875_write_reg(RA8875_BGTR2,(color & 0x001f));
}
/*!
Set the actual active window in the specified layer
@oaram x: x position
@oaram y: y position
@oaram w: width
@oaram h: height
*/
/**************************************************************************/
void RA8875_set_active_window (uint16_t x, uint16_t y, uint16_t w, uint16_t h)
{
RA8875_write_reg (RA8875_HSAW0, x);
RA8875_write_reg (RA8875_HSAW1, x >> 8);
RA8875_write_reg (RA8875_VSAW0, y);
RA8875_write_reg (RA8875_VSAW1, y >> 8);
RA8875_write_reg (RA8875_HEAW0, (x + w - 1));
RA8875_write_reg (RA8875_HEAW1, (x + w - 1) >> 8);
RA8875_write_reg (RA8875_VEAW0, (y + h - 1));
RA8875_write_reg (RA8875_VEAW1, (y + h - 1) >> 8);
}
/**
* Set the cursor direction according to the direction
* @param direction
*/
void RA8875_set_cursor_direction (RA8875_cursor_direction_e direction)
{
RA8875_write_reg (RA8875_MWCR0, (RA8875_read_reg (RA8875_MWCR0) & ~RA8875_MWCR0_DIRMASK) | direction);
}
/**
* Send the command to start the write
*/
void RA8875_write_ram (void)
{
RA8875_write_command (RA8875_MRWC);
}
/**************************************************************************/
/*!
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 1 if the expected status has been reached
*/
/**************************************************************************/
uint8_t RA8875_wait_poll (uint8_t regname, uint8_t waitflag)
{
/* Wait for the command to finish */
while (1)
{
uint8_t temp = RA8875_read_reg (regname);
if (!(temp & waitflag)) return 1;
}
return 0; // 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 RA8875_set_xy (uint16_t x, uint16_t y)
{
RA8875_write_reg (RA8875_CURH0, x);
RA8875_write_reg (RA8875_CURH1, x >> 8);
RA8875_write_reg (RA8875_CURV0, y);
RA8875_write_reg (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 RA8875_push_pixels (uint32_t num, uint16_t p)
{
while (num--)
{
if (_color_depth == RA8875_16BPP) RA8875_write_data (p >> 8);
RA8875_write_data (p);
}
}
/**
*!
HW accelerated function to push a chunk of raw pixel data
@param p The pixel color to use
*/
void RA8875_push_pixel (uint16_t p)
{
if (_color_depth == RA8875_16BPP) RA8875_write_data (p >> 8);
RA8875_write_data (p);
}
/**************************************************************************/
/*!
Apply current rotation in the X direction
@return the X value with current rotation applied
*/
/**************************************************************************/
static int16_t RA8875_apply_rotation_x (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
*/
/**************************************************************************/
static int16_t RA8875_apply_rotation_y (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 RA8875_draw_pixel (int16_t x, int16_t y, uint16_t color)
{
x = RA8875_apply_rotation_x (x);
y = RA8875_apply_rotation_y (y);
RA8875_write_reg (RA8875_CURH0, x);
RA8875_write_reg (RA8875_CURH1, x >> 8);
RA8875_write_reg (RA8875_CURV0, y);
RA8875_write_reg (RA8875_CURV1, y >> 8);
RA8875_write_command (RA8875_MRWC);
if (_color_depth == RA8875_16BPP) RA8875_write_data (color >> 8);
RA8875_write_data (color);
}
/**************************************************************************/
/*!
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 RA8875_draw_pixels (uint16_t *p, uint32_t num, int16_t x, int16_t y)
{
x = RA8875_apply_rotation_x (x);
y = RA8875_apply_rotation_y (y);
RA8875_write_reg (RA8875_CURH0, x);
RA8875_write_reg (RA8875_CURH1, x >> 8);
RA8875_write_reg (RA8875_CURV0, y);
RA8875_write_reg (RA8875_CURV1, y >> 8);
uint8_t dir = RA8875_MWCR0_LRTD;
if (_rotation == 2)
{
dir = RA8875_MWCR0_RLTD;
}
RA8875_write_reg (RA8875_MWCR0, (RA8875_read_reg (RA8875_MWCR0) & ~RA8875_MWCR0_DIRMASK) | dir);
RA8875_write_command (RA8875_MRWC);
while (num--)
{
uint16_t *d = p++;
if (_color_depth == RA8875_16BPP) RA8875_write_data ((*d) >> 8);
RA8875_write_data (*d);
}
}
/**************************************************************************/
/*!
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 RA8875_draw_line (int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color)
{
x0 = RA8875_apply_rotation_x (x0);
y0 = RA8875_apply_rotation_y (y0);
x1 = RA8875_apply_rotation_x (x1);
y1 = RA8875_apply_rotation_y (y1);
/* Set X */
RA8875_write_command (0x91);
RA8875_write_data (x0);
RA8875_write_command (0x92);
RA8875_write_data (x0 >> 8);
/* Set Y */
RA8875_write_command (0x93);
RA8875_write_data (y0);
RA8875_write_command (0x94);
RA8875_write_data (y0 >> 8);
/* Set X1 */
RA8875_write_command (0x95);
RA8875_write_data (x1);
RA8875_write_command (0x96);
RA8875_write_data ((x1) >> 8);
/* Set Y1 */
RA8875_write_command (0x97);
RA8875_write_data (y1);
RA8875_write_command (0x98);
RA8875_write_data ((y1) >> 8);
/* Set Color */
RA8875_write_command (0x63);
RA8875_write_data ((color & 0xf800) >> 11);
RA8875_write_command (0x64);
RA8875_write_data ((color & 0x07e0) >> 5);
RA8875_write_command (0x65);
RA8875_write_data ((color & 0x001f));
/* Draw! */
RA8875_write_command (RA8875_DCR);
RA8875_write_data (0x80);
/* Wait for the command to finish */
RA8875_wait_poll (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 RA8875_draw_fast_vline (int16_t x, int16_t y, int16_t h, uint16_t color)
{
RA8875_draw_line (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 RA8875_draw_fast_hline (int16_t x, int16_t y, int16_t w, uint16_t color)
{
RA8875_draw_line (x, y, x + w, y, color);
}
/**************************************************************************/
/*!
Helper function for higher level circle drawing code
*/
/**************************************************************************/
static void circleHelper (int16_t x, int16_t y, int16_t r, uint16_t color, uint8_t filled)
{
x = RA8875_apply_rotation_x (x);
y = RA8875_apply_rotation_y (y);
/* Set X */
RA8875_write_command (0x99);
RA8875_write_data (x);
RA8875_write_command (0x9a);
RA8875_write_data (x >> 8);
/* Set Y */
RA8875_write_command (0x9b);
RA8875_write_data (y);
RA8875_write_command (0x9c);
RA8875_write_data (y >> 8);
/* Set Radius */
RA8875_write_command (0x9d);
RA8875_write_data (r);
/* Set Color */
RA8875_write_command (0x63);
RA8875_write_data ((color & 0xf800) >> 11);
RA8875_write_command (0x64);
RA8875_write_data ((color & 0x07e0) >> 5);
RA8875_write_command (0x65);
RA8875_write_data ((color & 0x001f));
/* Draw! */
RA8875_write_command (RA8875_DCR);
if (filled)
{
RA8875_write_data (RA8875_DCR_CIRCLE_START | RA8875_DCR_FILL);
}
else
{
RA8875_write_data (RA8875_DCR_CIRCLE_START | RA8875_DCR_NOFILL);
}
/* Wait for the command to finish */
RA8875_wait_poll (RA8875_DCR, RA8875_DCR_CIRCLE_STATUS);
}
/**************************************************************************/
/*!
Helper function for higher level rectangle drawing code
*/
/**************************************************************************/
static void rectHelper (int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color, uint8_t filled)
{
x = RA8875_apply_rotation_x (x);
y = RA8875_apply_rotation_y (y);
w = RA8875_apply_rotation_x (w);
h = RA8875_apply_rotation_y (h);
/* Set X */
RA8875_write_command (0x91);
RA8875_write_data (x);
RA8875_write_command (0x92);
RA8875_write_data (x >> 8);
/* Set Y */
RA8875_write_command (0x93);
RA8875_write_data (y);
RA8875_write_command (0x94);
RA8875_write_data (y >> 8);
/* Set X1 */
RA8875_write_command (0x95);
RA8875_write_data (w);
RA8875_write_command (0x96);
RA8875_write_data ((w) >> 8);
/* Set Y1 */
RA8875_write_command (0x97);
RA8875_write_data (h);
RA8875_write_command (0x98);
RA8875_write_data ((h) >> 8);
/* Set Color */
RA8875_write_command (0x63);
RA8875_write_data ((color & 0xf800) >> 11);
RA8875_write_command (0x64);
RA8875_write_data ((color & 0x07e0) >> 5);
RA8875_write_command (0x65);
RA8875_write_data ((color & 0x001f));
/* Draw! */
RA8875_write_command (RA8875_DCR);
if (filled)
{
RA8875_write_data (0xB0);
}
else
{
RA8875_write_data (0x90);
}
/* Wait for the command to finish */
RA8875_wait_poll (RA8875_DCR, RA8875_DCR_LINESQUTRI_STATUS);
}
/**************************************************************************/
/*!
Helper function for higher level triangle drawing code
*/
/**************************************************************************/
static void triangleHelper (int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color, uint8_t filled)
{
x0 = RA8875_apply_rotation_x (x0);
y0 = RA8875_apply_rotation_y (y0);
x1 = RA8875_apply_rotation_x (x1);
y1 = RA8875_apply_rotation_y (y1);
x2 = RA8875_apply_rotation_x (x2);
y2 = RA8875_apply_rotation_y (y2);
/* Set Point 0 */
RA8875_write_command (0x91);
RA8875_write_data (x0);
RA8875_write_command (0x92);
RA8875_write_data (x0 >> 8);
RA8875_write_command (0x93);
RA8875_write_data (y0);
RA8875_write_command (0x94);
RA8875_write_data (y0 >> 8);
/* Set Point 1 */
RA8875_write_command (0x95);
RA8875_write_data (x1);
RA8875_write_command (0x96);
RA8875_write_data (x1 >> 8);
RA8875_write_command (0x97);
RA8875_write_data (y1);
RA8875_write_command (0x98);
RA8875_write_data (y1 >> 8);
/* Set Point 2 */
RA8875_write_command (0xA9);
RA8875_write_data (x2);
RA8875_write_command (0xAA);
RA8875_write_data (x2 >> 8);
RA8875_write_command (0xAB);
RA8875_write_data (y2);
RA8875_write_command (0xAC);
RA8875_write_data (y2 >> 8);
/* Set Color */
RA8875_write_command (0x63);
RA8875_write_data ((color & 0xf800) >> 11);
RA8875_write_command (0x64);
RA8875_write_data ((color & 0x07e0) >> 5);
RA8875_write_command (0x65);
RA8875_write_data ((color & 0x001f));
/* Draw! */
RA8875_write_command (RA8875_DCR);
if (filled)
{
RA8875_write_data (0xA1);
}
else
{
RA8875_write_data (0x81);
}
/* Wait for the command to finish */
RA8875_wait_poll (RA8875_DCR, RA8875_DCR_LINESQUTRI_STATUS);
}
/**************************************************************************/
/*!
Helper function for higher level ellipse drawing code
*/
/**************************************************************************/
static void ellipseHelper (int16_t xCenter, int16_t yCenter, int16_t longAxis, int16_t shortAxis, uint16_t color, uint8_t filled)
{
xCenter = RA8875_apply_rotation_x (xCenter);
yCenter = RA8875_apply_rotation_y (yCenter);
/* Set Center Point */
RA8875_write_command (0xA5);
RA8875_write_data (xCenter);
RA8875_write_command (0xA6);
RA8875_write_data (xCenter >> 8);
RA8875_write_command (0xA7);
RA8875_write_data (yCenter);
RA8875_write_command (0xA8);
RA8875_write_data (yCenter >> 8);
/* Set Long and Short Axis */
RA8875_write_command (0xA1);
RA8875_write_data (longAxis);
RA8875_write_command (0xA2);
RA8875_write_data (longAxis >> 8);
RA8875_write_command (0xA3);
RA8875_write_data (shortAxis);
RA8875_write_command (0xA4);
RA8875_write_data (shortAxis >> 8);
/* Set Color */
RA8875_write_command (0x63);
RA8875_write_data ((color & 0xf800) >> 11);
RA8875_write_command (0x64);
RA8875_write_data ((color & 0x07e0) >> 5);
RA8875_write_command (0x65);
RA8875_write_data ((color & 0x001f));
/* Draw! */
RA8875_write_command (0xA0);
if (filled)
{
RA8875_write_data (0xC0);
}
else
{
RA8875_write_data (0x80);
}
/* Wait for the command to finish */
RA8875_wait_poll (RA8875_ELLIPSE, RA8875_ELLIPSE_STATUS);
}
/**************************************************************************/
/*!
Helper function for higher level curve drawing code
*/
/**************************************************************************/
static void curveHelper (int16_t xCenter, int16_t yCenter, int16_t longAxis, int16_t shortAxis, uint8_t curvePart, uint16_t color, uint8_t filled)
{
xCenter = RA8875_apply_rotation_x (xCenter);
yCenter = RA8875_apply_rotation_y (yCenter);
curvePart = (curvePart + _rotation) % 4;
/* Set Center Point */
RA8875_write_command (0xA5);
RA8875_write_data (xCenter);
RA8875_write_command (0xA6);
RA8875_write_data (xCenter >> 8);
RA8875_write_command (0xA7);
RA8875_write_data (yCenter);
RA8875_write_command (0xA8);
RA8875_write_data (yCenter >> 8);
/* Set Long and Short Axis */
RA8875_write_command (0xA1);
RA8875_write_data (longAxis);
RA8875_write_command (0xA2);
RA8875_write_data (longAxis >> 8);
RA8875_write_command (0xA3);
RA8875_write_data (shortAxis);
RA8875_write_command (0xA4);
RA8875_write_data (shortAxis >> 8);
/* Set Color */
RA8875_write_command (0x63);
RA8875_write_data ((color & 0xf800) >> 11);
RA8875_write_command (0x64);
RA8875_write_data ((color & 0x07e0) >> 5);
RA8875_write_command (0x65);
RA8875_write_data ((color & 0x001f));
/* Draw! */
RA8875_write_command (0xA0);